first.working.version
[tfs.git] / class / MonoDevelop.TeamFoundation / TeamFoundationPad.cs
blobf258782c8c47bf4b1c84bd9ece9d7a36d6210c0d
1 using System;
2 using System.IO;
3 using System.Net;
4 using Gtk;
6 using MonoDevelop.Core;
7 using MonoDevelop.Ide.Gui;
8 using MonoDevelop.Ide.Gui.Pads;
9 using MonoDevelop.Components.Commands;
11 using Microsoft.TeamFoundation.Client;
12 using Microsoft.TeamFoundation.VersionControl.Common;
13 using Microsoft.TeamFoundation.VersionControl.Client;
14 using Gtk.TeamFoundation;
16 namespace MonoDevelop.TeamFoundation
18 public class TeamFoundationPad : AbstractPadContent, IVersionControlServerFactory
20 CredentialCache credentialCache = new CredentialCache();
21 ExploreView exploreView;
23 public TeamFoundationPad() : base ("Team Foundation Browser")
25 exploreView = new ExploreView(this, 50);
26 exploreView.ShowAll();
29 public override Gtk.Widget Control {
30 get { return exploreView; }
33 public VersionControlServer GetVersionControlServer(string url)
35 ICredentials creds = GetCredentials(url);
36 TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(url, creds);
37 return tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
40 protected NetworkCredential GetCredentials(string url)
42 Uri uri = new Uri(url);
43 NetworkCredential creds = credentialCache.GetCredential(uri, "NTLM");
44 if (creds != null) return creds;
46 string login = TeamFoundationSettings.Current.Get(url);
47 string userinfo = String.Empty;
49 string username = String.Empty;
50 string domain = String.Empty;
51 string password = String.Empty;
53 int comma = login.IndexOf(",");
54 if (comma != -1)
56 userinfo = login.Substring(0, comma);
57 password = login.Substring(comma+1);
59 else userinfo = login;
61 // try to find domain portion if given
62 int slash = userinfo.IndexOf('\\');
63 if (-1 != slash)
65 domain = userinfo.Substring(0, slash);
66 username = userinfo.Substring(slash+1);
68 else
70 int atsign = userinfo.IndexOf('@');
71 if (-1 != atsign)
73 username = userinfo.Substring(0, atsign);
74 domain = userinfo.Substring(atsign+1);
76 else username = userinfo;
79 creds = new NetworkCredential(username, password, domain);
80 credentialCache.Add(uri, "NTLM", creds);
82 return creds;