1111using System . Text ;
1212using System . Threading . Tasks ;
1313using System . Web ;
14+ using Microsoft . TeamFoundation ;
1415using Microsoft . TeamFoundation . Client ;
1516using Newtonsoft . Json ;
1617using Newtonsoft . Json . Linq ;
@@ -57,7 +58,7 @@ public static void CreateNewConfiguration()
5758 LogService . WriteError ( e ) ;
5859 throw ;
5960 }
60-
61+
6162 }
6263 public static void UpdateConfiguration ( int id , ServiceConfig ic )
6364 {
@@ -67,7 +68,7 @@ public static void UpdateConfiguration(int id, ServiceConfig ic)
6768 if ( configuration == null )
6869 throw new ArgumentException ( "Configuration with Id \" " + ic . Id + "\" can't be found." ) ;
6970 if ( string . IsNullOrEmpty ( ic . Password ) || ic . Password . Equals ( ReturnPassword ) )
70- {
71+ {
7172 var password = configuration . Password ;
7273 ic . Password = password ;
7374 }
@@ -94,7 +95,7 @@ public static ServiceConfig GetConfiguration(int id)
9495 {
9596 LogService . WriteError ( e ) ;
9697 throw ;
97- }
98+ }
9899 return configs ;
99100 }
100101
@@ -179,7 +180,7 @@ public static List<ServiceConfig> GetListOfConfigurationsNoPassword()
179180 List < ServiceConfig > configs = null ;
180181 try
181182 {
182- configs = GetListOfConfigurationsInternal ( ) . Select ( c => { c . Password = ReturnPassword ; return c ; } ) . ToList ( ) ;
183+ configs = GetListOfConfigurationsInternal ( ) . Select ( c => { c . Password = ReturnPassword ; return c ; } ) . ToList ( ) ;
183184 }
184185 catch ( Exception e )
185186 {
@@ -242,6 +243,10 @@ private static string CheckValidityOfConfig(IServiceConfig config)
242243 }
243244 catch ( AggregateException e )
244245 {
246+ if ( e . InnerException is Exception )
247+ {
248+ return e . InnerException . Message ;
249+ }
245250 return "DNS could not find server adress" ;
246251 }
247252 catch ( Exception e )
@@ -254,35 +259,34 @@ private static string CheckValidityOfConfig(IServiceConfig config)
254259 private static async Task < bool > CanLogIn ( string username , string password , string uri , string configType )
255260 {
256261 bool response = false ;
257- try
262+ // VSO check
263+ if ( configType == "VSO" )
258264 {
259- // VSO check
260- if ( configType == "VSO" )
265+ using ( var client = new HttpClient ( ) )
261266 {
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 ;
272274 }
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
275282 {
276- var credentials = new TfsClientCredentials ( new WindowsCredential ( new NetworkCredential ( username , password ) ) ) ;
277- var server = new TfsConfigurationServer ( new Uri ( uri ) , credentials ) ;
278283 server . EnsureAuthenticated ( ) ;
279- response = server . HasAuthenticated ;
280284 }
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 ;
286290 }
287291 return response ;
288292 }
0 commit comments