11
11
using System . Text ;
12
12
using System . Threading . Tasks ;
13
13
using System . Web ;
14
+ using Microsoft . TeamFoundation ;
14
15
using Microsoft . TeamFoundation . Client ;
15
16
using Newtonsoft . Json ;
16
17
using Newtonsoft . Json . Linq ;
@@ -57,7 +58,7 @@ public static void CreateNewConfiguration()
57
58
LogService . WriteError ( e ) ;
58
59
throw ;
59
60
}
60
-
61
+
61
62
}
62
63
public static void UpdateConfiguration ( int id , ServiceConfig ic )
63
64
{
@@ -67,7 +68,7 @@ public static void UpdateConfiguration(int id, ServiceConfig ic)
67
68
if ( configuration == null )
68
69
throw new ArgumentException ( "Configuration with Id \" " + ic . Id + "\" can't be found." ) ;
69
70
if ( string . IsNullOrEmpty ( ic . Password ) || ic . Password . Equals ( ReturnPassword ) )
70
- {
71
+ {
71
72
var password = configuration . Password ;
72
73
ic . Password = password ;
73
74
}
@@ -94,7 +95,7 @@ public static ServiceConfig GetConfiguration(int id)
94
95
{
95
96
LogService . WriteError ( e ) ;
96
97
throw ;
97
- }
98
+ }
98
99
return configs ;
99
100
}
100
101
@@ -179,7 +180,7 @@ public static List<ServiceConfig> GetListOfConfigurationsNoPassword()
179
180
List < ServiceConfig > configs = null ;
180
181
try
181
182
{
182
- configs = GetListOfConfigurationsInternal ( ) . Select ( c => { c . Password = ReturnPassword ; return c ; } ) . ToList ( ) ;
183
+ configs = GetListOfConfigurationsInternal ( ) . Select ( c => { c . Password = ReturnPassword ; return c ; } ) . ToList ( ) ;
183
184
}
184
185
catch ( Exception e )
185
186
{
@@ -242,6 +243,10 @@ private static string CheckValidityOfConfig(IServiceConfig config)
242
243
}
243
244
catch ( AggregateException e )
244
245
{
246
+ if ( e . InnerException is Exception )
247
+ {
248
+ return e . InnerException . Message ;
249
+ }
245
250
return "DNS could not find server adress" ;
246
251
}
247
252
catch ( Exception e )
@@ -254,35 +259,34 @@ private static string CheckValidityOfConfig(IServiceConfig config)
254
259
private static async Task < bool > CanLogIn ( string username , string password , string uri , string configType )
255
260
{
256
261
bool response = false ;
257
- try
262
+ // VSO check
263
+ if ( configType == "VSO" )
258
264
{
259
- // VSO check
260
- if ( configType == "VSO" )
265
+ using ( var client = new HttpClient ( ) )
261
266
{
262
- using ( var client = new HttpClient ( ) )
263
- {
264
- client . BaseAddress = new Uri ( uri ) ;
265
- client . DefaultRequestHeaders . Accept . Clear ( ) ;
266
- client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" ,
267
- Convert . ToBase64String (
268
- Encoding . ASCII . GetBytes ( string . Format ( "{0}:{1}" , username , password ) ) ) ) ;
269
- Debug . WriteLine ( "Code: " + client . GetAsync ( "" ) . Result . StatusCode ) ;
270
- response = client . GetAsync ( "" ) . Result . StatusCode == HttpStatusCode . OK ;
271
- }
267
+ client . BaseAddress = new Uri ( uri ) ;
268
+ client . DefaultRequestHeaders . Accept . Clear ( ) ;
269
+ client . DefaultRequestHeaders . Authorization = new AuthenticationHeaderValue ( "Basic" ,
270
+ Convert . ToBase64String (
271
+ Encoding . ASCII . GetBytes ( string . Format ( "{0}:{1}" , username , password ) ) ) ) ;
272
+ Debug . WriteLine ( "Code: " + client . GetAsync ( "" ) . Result . StatusCode ) ;
273
+ response = client . GetAsync ( "" ) . Result . StatusCode == HttpStatusCode . OK ;
272
274
}
273
- // TFS check
274
- else if ( configType == "TFS" )
275
+ }
276
+ // TFS check
277
+ else if ( configType == "TFS" )
278
+ {
279
+ var credentials = new TfsClientCredentials ( new WindowsCredential ( new NetworkCredential ( username , password ) ) ) ;
280
+ var server = new TfsConfigurationServer ( new Uri ( uri ) , credentials ) ;
281
+ try
275
282
{
276
- var credentials = new TfsClientCredentials ( new WindowsCredential ( new NetworkCredential ( username , password ) ) ) ;
277
- var server = new TfsConfigurationServer ( new Uri ( uri ) , credentials ) ;
278
283
server . EnsureAuthenticated ( ) ;
279
- response = server . HasAuthenticated ;
280
284
}
281
- }
282
- catch ( Exception e )
283
- {
284
- LogService . WriteError ( e ) ;
285
- throw ;
285
+ catch ( TeamFoundationServerUnauthorizedException e )
286
+ {
287
+ return false ;
288
+ }
289
+ response = server . HasAuthenticated ;
286
290
}
287
291
return response ;
288
292
}
0 commit comments