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); }
public static InternalConnectivityMode DetectInternalConnectivityModeForAutoDetect(Uri uri) { if (NetworkDetector.tcpConnectivityStatus == 3 && NetworkDetector.httpWebStreamConnectivityStatus == 3 && NetworkDetector.httpsWebStreamConnectivityStatus == 3) { NetworkDetector.Reset(); } Exception[] exceptionArray = new Exception[4]; if (NetworkDetector.IsNetTcpConnectivityAvailable(uri, out exceptionArray[0])) { return(InternalConnectivityMode.Tcp); } if (NetworkDetector.IsHttpsWebSocketConnectivityAvailable(uri, out exceptionArray[1])) { return(InternalConnectivityMode.HttpsWebSocket); } if (NetworkDetector.IsHttpWebStreamConnectivityAvailable(uri, out exceptionArray[2])) { return(InternalConnectivityMode.Http); } if (!NetworkDetector.IsHttpsWebStreamConnectivityAvailable(uri, out exceptionArray[3])) { 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, 9351, 9352 }; string str = string.Format(invariantCulture, "Unable to reach {0} via TCP ({1}, {2}) or 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); }