1: /// <summary>
2: /// This overload of the Connect Method will prompt
3: /// the users for a set of credentials, by means of the
4: /// UICredentialsProvider. It then calls our "generic"
5: /// connect method, which takes an ICredentialsProvider
6: /// as its second argument
7: /// </summary>
8: /// <param name="serverName"></param>
9: /// <returns></returns>
10: public bool Connect(string serverName)
11: { 12: using (new Tracer(LoggingCategoryConstant.TFS_CONNECTIVITY_CONNECT))
13: { 14: // Create an instance of our Creditials by means of the
15: // UICredentialsProvider. Since we are using the
16: // UICredentialsProvider here, this method will popup
17: // an authentication dialog for us and create a set
18: // of Credentials for us, which are passed to our other
19: // Connect overload that takes a generic
20: // ICredentialsProvider argument
21: // Create an instance of the UICredentialsProvider.
22: // Note that creating this instance will automatically
23: // popup the TFS authentication dialog
24: ICredentialsProvider provider = new UICredentialsProvider();
25: return Connect(serverName, new UICredentialsProvider());
26: }
27: } // method Connect
28:
29: /// <summary>
30: /// This overload of the Connect Method takes a NetworkCredential.
31: /// This method is typically used from a server client, which does
32: /// not have the possibility to prompt the client for a username/password
33: /// </summary>
34: /// <param name="serverName"></param>
35: /// <param name="credentials"></param>
36: /// <returns></returns>
37: public bool Connect(string serverName, NetworkCredential credentials)
38: { 39: using (new Tracer(LoggingCategoryConstant.TFS_CONNECTIVITY_CONNECT))
40: { 41: // Log our parameters
42: addLogEntry(
43: LoggingCategoryConstant.TFS_CONNECTIVITY_TRACE,
44: "Connect method with ServerName and Credentials Called",
45: EventIdentifier.ConnectToTfs,
46: EventPriority.StandardPriority,
47: TraceEventType.Verbose,
48: createCredentialsContextInfo(serverName, credentials));
49:
50: // Create our Network Credentials
51: NetworkCredential credentials = new NetworkCredential(TFSUserName, TFSPassword);
52:
53: // Here, we can pass the network credentials directly to the
54: // TeamFoundationServer constructor, so we have no need to used
55: // the factory here. You cannot use the factory methods with any
56: // object instance that implements ICreditials, but it is supported
57: // in the standard constructor, as we are using it here
58: try
59: { 60: m_tfsServer = new TeamFoundationServer(serverName, credentials);
61: m_tfsServer.Authenticate();
62:
63: // If we succcessfully authenticated, we can go ahead an extract
64: // some reference to some commonly used service interfaces
65: if (m_tfsServer.HasAuthenticated)
66: { 67: extractServiceInterfaces();
68: }
69: }
70: catch (Exception ex)
71: { 72: bool rethrow = ExceptionPolicy.HandleException(ex, ExceptionPolicyName.EXTERNAL_LIBRARY_POLICY);
73: if (rethrow)
74: { 75: throw;
76: }
77: }
78: }
79:
80: // Return the authentication status
81: return m_tfsServer.HasAuthenticated;
82:
83: } // method Conection
84:
85: /// <summary>
86: /// This is our "generic" Connect method. This method takes any object
87: /// instance that implements ICredentialsProvider. It uses the
88: /// TeamFoundationServerFactory GetServer method to retrieve the
89: /// TeamFoundationServer implementation
90: /// </summary>
91: /// <param name="serverName"></param>
92: /// <param name="credentialsProvider"></param>
93: /// <returns></returns>
94: public bool Connect(string serverName, ICredentialsProvider credentialsProvider)
95: { 96: using (new Tracer(LoggingCategoryConstant.TFS_CONNECTIVITY_CONNECT))
97: { 98: // Log our parameters
99: addLogEntry(
100: LoggingCategoryConstant.TFS_CONNECTIVITY_TRACE,
101: "Connect method with ServerName and Credentials Called",
102: EventIdentifier.ConnectToTfs,
103: EventPriority.StandardPriority,
104: TraceEventType.Verbose,
105: createCredentialsContextInfo(serverName, credentialsProvider));
106:
107: // Create a TeamFoundationServer instance through the factory,
108: // and authenticate
109: try
110: { 111: m_tfsServer =
112: TeamFoundationServerFactory.GetServer(serverName, credentialsProvider);
113: m_tfsServer.Authenticate();
114:
115: // If we succcessfully authenticated, we can go ahead an extract
116: // some reference to some commonly used service interfaces
117: if (m_tfsServer.HasAuthenticated)
118: { 119: extractServiceInterfaces();
120: }
121: }
122: catch (Exception ex)
123: { 124: bool rethrow = ExceptionPolicy.HandleException(ex, ExceptionPolicyName.EXTERNAL_LIBRARY_POLICY);
125: if (rethrow)
126: { 127: throw;
128: }
129: }
130:
131: }
132: // Return the authentication status
133: return m_tfsServer.HasAuthenticated;
134:
135: } // method Connect