コード例 #1
0
 public static InternalConnectivityMode DetectInternalConnectivityModeForHttp(Uri uri)
 {
     if (NetworkDetector.httpWebStreamConnectivityStatus == 3 && NetworkDetector.httpsWebSocketConnectivityStatus == 3 && NetworkDetector.httpsWebStreamConnectivityStatus == 3)
     {
         NetworkDetector.Reset();
     }
     Exception[] exceptionArray = new Exception[3];
     if (NetworkDetector.IsHttpsWebSocketConnectivityAvailable(uri, out exceptionArray[0]))
     {
         return(InternalConnectivityMode.HttpsWebSocket);
     }
     if (NetworkDetector.IsHttpWebStreamConnectivityAvailable(uri, out exceptionArray[1]))
     {
         return(InternalConnectivityMode.Http);
     }
     if (!NetworkDetector.IsHttpsWebStreamConnectivityAvailable(uri, out exceptionArray[2]))
     {
         Exception[] array = (
             from e in (IEnumerable <Exception>)exceptionArray
             where e != null
             select e).ToArray <Exception>();
         CultureInfo invariantCulture = CultureInfo.InvariantCulture;
         object[]    host             = new object[] { uri.Host };
         string      str = string.Format(invariantCulture, "Unable to reach {0} HTTP (80, 443)", host);
         if ((int)array.Length <= 0)
         {
             throw Fx.Exception.AsError(new CommunicationException(str), null);
         }
         throw Fx.Exception.AsError(new CommunicationException(str, new AggregateException(array)), null);
     }
     return(InternalConnectivityMode.Https);
 }
コード例 #2
0
 public static ConnectivityMode DetectConnectivityModeForAutoDetect(Uri uri)
 {
     if (NetworkDetector.tcpConnectivityStatus == 3 && NetworkDetector.httpConnectivityStatus == 3)
     {
         NetworkDetector.Reset();
     }
     Exception[] exceptionArray = new Exception[2];
     if (NetworkDetector.IsNetTcpConnectivityAvailable(uri, out exceptionArray[0]))
     {
         return(ConnectivityMode.Tcp);
     }
     if (!NetworkDetector.IsHttpConnectivityAvailable(uri, out exceptionArray[1]))
     {
         Exception[] array = (
             from e in (IEnumerable <Exception>)exceptionArray
             where e != null
             select e).ToArray <Exception>();
         string reach = SRClient.UnableToReach(uri.Host, 9351, 9352);
         if ((int)array.Length <= 0)
         {
             throw Fx.Exception.AsError(new CommunicationException(reach), null);
         }
         throw Fx.Exception.AsError(new CommunicationException(reach, new AggregateException(array)), null);
     }
     return(ConnectivityMode.Http);
 }
コード例 #3
0
 static NetworkDetector()
 {
     NetworkChange.NetworkAvailabilityChanged += new NetworkAvailabilityChangedEventHandler((object o, NetworkAvailabilityEventArgs ea) => NetworkDetector.Reset());
     NetworkChange.NetworkAddressChanged      += new NetworkAddressChangedEventHandler((object o, EventArgs ea) => NetworkDetector.Reset());
 }