当前位置: 首页>>代码示例>>C#>>正文


C# NetworkReachability.TryGetFlags方法代码示例

本文整理汇总了C#中NetworkReachability.TryGetFlags方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkReachability.TryGetFlags方法的具体用法?C# NetworkReachability.TryGetFlags怎么用?C# NetworkReachability.TryGetFlags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NetworkReachability的用法示例。


在下文中一共展示了NetworkReachability.TryGetFlags方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsHostReachable

		// Is the host reachable with the current network configuration
		public static bool IsHostReachable(string host)
		{
			if (string.IsNullOrEmpty(host))
				return false;

			using (var r = new NetworkReachability(host)) {
				NetworkReachabilityFlags flags;

				if (r.TryGetFlags(out flags))
					return IsReachableWithoutRequiringConnection(flags);
			}
			return false;
		}
开发者ID:CBrauer,项目名称:monotouch-samples,代码行数:14,代码来源:reachability.cs

示例2: IsHostReachable

		// Is the host reachable with the current network configuration
		public static bool IsHostReachable (string host)
		{
			if (host == null || host.Length == 0)
				return false;
	
			using (var r = new NetworkReachability (host)){
				NetworkReachabilityFlags flags;
	
				if (r.TryGetFlags (out flags)){
					return IsReachableWithoutRequiringConnection (flags);
				}
			}
			return false;
		}
开发者ID:oduma,项目名称:Sciendo.Fitas.Droid,代码行数:15,代码来源:Reachability.cs

示例3: InitializeReachability

		void InitializeReachability ()
		{
			networkReachability = new NetworkReachability (IPAddress.Any);
			networkReachability.SetNotification (flags => UpdateReachability (flags, NetworkIcon, NetworkStatusTextField));
			networkReachability.Schedule ();

			NetworkReachabilityFlags networkReachabilityFlags;
			networkReachability.TryGetFlags (out networkReachabilityFlags);
			UpdateReachability (networkReachabilityFlags, NetworkIcon, NetworkStatusTextField);

			CreateHostReachability ();

			HostTextField.Changed += (sender, e) => CreateHostReachability ();
		}
开发者ID:RafasTavares,项目名称:mac-samples,代码行数:14,代码来源:MainWindowController.cs

示例4: IsHostReachable

		/// <summary>
		/// Checks if host is reachable
		/// </summary>
		/// <param name="host"></param>
		/// <param name="port"></param>
		/// <returns></returns>
		public static bool IsHostReachable (string host, int port)
		{
			if (string.IsNullOrWhiteSpace (host))
				return false;

			IPAddress address;
			if (!IPAddress.TryParse (host + ":" + port, out address)) {
				Debug.WriteLine (host + ":" + port + " is not valid");
				return false;
			}
			using (var r = new NetworkReachability (host)) {

				NetworkReachabilityFlags flags;

				if (r.TryGetFlags (out flags)) {
					return IsReachableWithoutRequiringConnection (flags);
				}
			}
			return false;
		}
开发者ID:NateRickard,项目名称:Xamarin.Plugins,代码行数:26,代码来源:Reachability.cs

示例5: RemoteHostStatus

        public static NetworkStatus RemoteHostStatus(string HostName)
        {
            NetworkReachabilityFlags flags;
            bool reachable;

            if (remoteHostReachability == null) {
                remoteHostReachability = new NetworkReachability (HostName);

                // Need to probe before we queue, or we wont get any meaningful values
                // this only happens when you create NetworkReachability from a hostname
                reachable = remoteHostReachability.TryGetFlags (out flags);

                remoteHostReachability.SetCallback (OnChange);
                remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
            } else
                reachable = remoteHostReachability.TryGetFlags (out flags);

            if (!reachable)
                return NetworkStatus.NotReachable;

            if (!IsReachableWithoutRequiringConnection (flags))
                return NetworkStatus.NotReachable;

            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
                return NetworkStatus.ReachableViaCarrierDataNetwork;

            return NetworkStatus.ReachableViaWiFiNetwork;
        }
开发者ID:valryon,项目名称:super-koikoukesse,代码行数:28,代码来源:NetworkAvailability.cs

示例6: RemoteHostStatus

        /// <summary>
        /// 
        /// </summary>
        /// <param name="host">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="NetworkType"/>
        /// </returns>
        private static NetworkType RemoteHostStatus(string host)
        {
            bool reachable = IsHostReachable(host);;

            if (!reachable)
                return NetworkType.Unknown;

            using (var r = new NetworkReachability (host)){
                NetworkReachabilityFlags flags;

                if (r.TryGetFlags (out flags)){
                    if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
                        //return NetworkType.Carrier_GSM;  // TODO get which type of carrier is being used.
                        return NetworkType.Carrier_3G; // HARDCODED.
                }
            }

            return NetworkType.Wifi;
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:28,代码来源:IPhoneNet.cs

示例7: IsNetworkAvaialable

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flags">
        /// A <see cref="NetworkReachabilityFlags"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
        {
            NetworkReachability defaultRouteReachability = new NetworkReachability (new IPAddress (0));

            if (defaultRouteReachability.TryGetFlags (out flags))
                return false;
            return IsReachable (flags) && IsNoConnectionRequired(flags);  // is reachable without requiring connection.
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:17,代码来源:IPhoneNet.cs

示例8: IsHostReachable

        /// <summary>
        /// Is the host reachable with the current network configuration
        /// </summary>
        /// <param name="host">
        /// A <see cref="System.String"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        private static bool IsHostReachable(string host)
        {
            if (host == null || host.Length == 0)
                return false;

            using (var r = new NetworkReachability (host)){
                NetworkReachabilityFlags flags;

                if (r.TryGetFlags (out flags)){
                    return IsReachable (flags) && IsNoConnectionRequired(flags);  // is reachable without requiring connection.
                }
            }
            return false;
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:23,代码来源:IPhoneNet.cs

示例9: IsAdHocWiFiNetworkAvailable

        /// <summary>
        /// 
        /// </summary>
        /// <param name="flags">
        /// A <see cref="NetworkReachabilityFlags"/>
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>
        /// </returns>
        private static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            NetworkReachability adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte [] {169,254,0,0}));

            if (!adHocWiFiNetworkReachability.TryGetFlags (out flags))
                return false;

            return IsReachable (flags) && IsNoConnectionRequired(flags);  // is reachable without requiring connection.
        }
开发者ID:jioe,项目名称:appverse-mobile,代码行数:18,代码来源:IPhoneNet.cs

示例10: RemoteHostStatus

    public static NetworkStatus RemoteHostStatus()
    {
        NetworkReachabilityFlags flags;
        bool reachable;

        if (remoteHostReachability == null)
        {
            remoteHostReachability = new NetworkReachability (HostName);

            reachable = remoteHostReachability.TryGetFlags (out flags);

            remoteHostReachability.SetCallback (OnChange);
            remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
        }
        else
            reachable = remoteHostReachability.TryGetFlags (out flags);

        if (!reachable)
            return NetworkStatus.NotReachable;

        if (!IsReachableWithoutRequiringConnection (flags))
            return NetworkStatus.NotReachable;

        if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            return NetworkStatus.ReachableViaCarrierDataNetwork;

        return NetworkStatus.ReachableViaWiFiNetwork;
    }
开发者ID:pmourfield,项目名称:AtlCodeCamp,代码行数:28,代码来源:Reachability.cs

示例11: IsHostReachable

        // Is the host reachable with the current network configuration
        public static bool IsHostReachable(string host)
        {
            if (host == null || host.Length == 0)
             return false;

            #if WINDOWS_PHONE
             //I know I know, but I'm trying to keep the behavior the same across platforms
             bool done = false;
             bool reachable = false;
             DeviceNetworkInformation.ResolveHostNameAsync(new DnsEndPoint(HostName, 80), (x) => {
             done = true;
             if (x.NetworkErrorCode == NetworkError.Success)
             reachable = true;
             else
             reachable = false;
             }, null);

             while (!done) { Thread.Sleep(200); }

             return reachable;

            #elif IPHONE

             using (var r = new NetworkReachability (host)){
             NetworkReachabilityFlags flags;

             if (r.TryGetFlags (out flags)){
             return IsReachableWithoutRequiringConnection (flags);
             }
             }
             return false;
            #else
             var test = new Ping();
             var reply = test.Send(HostName);

             if (reply.Status == IPStatus.Success)
             return true;
             else
             return false;
            #endif
        }
开发者ID:n1ckd0r,项目名称:mogade-csharp,代码行数:42,代码来源:Reachability.cs

示例12: RemoteHostStatus

        public static NetworkStatus RemoteHostStatus ()
        {
            NetworkReachabilityFlags flags;
            bool reachable;

            if (remoteHostReachability == null){
                remoteHostReachability = new NetworkReachability (HostName);

                // Need to probe before we queue, or we wont get any meaningful values
                // this only happens when you create NetworkReachability from a hostname
                reachable = remoteHostReachability.TryGetFlags (out flags);

                remoteHostReachability.SetNotification (OnChange);
                remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
            } else
                reachable = remoteHostReachability.TryGetFlags (out flags);         

            if (!reachable)
            {
                Application._networkstate = DataAccessLayer.NetworkState.Disconnected;
                if (Application._user != null) 
                                   Application._user.NetworkStatus = DataAccessLayer.NetworkState.Disconnected;
                return NetworkStatus.NotReachable;
            }

            if (!IsReachableWithoutRequiringConnection(flags))
            {
                Application._networkstate = DataAccessLayer.NetworkState.Disconnected;
                if (Application._user != null) 
                    Application._user.NetworkStatus = DataAccessLayer.NetworkState.Disconnected;
                return NetworkStatus.NotReachable;
            }

            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            {
                Application._networkstate = DataAccessLayer.NetworkState.ConnectedWifi;
                if (Application._user != null) 
                                   Application._user.NetworkStatus = DataAccessLayer.NetworkState.ConnectedWifi;
                return NetworkStatus.ReachableViaCarrierDataNetwork;
            }

            Application._networkstate = DataAccessLayer.NetworkState.ConnectedWifi;
            if (Application._user != null) 
                Application._user.NetworkStatus = DataAccessLayer.NetworkState.ConnectedWifi;
                       return NetworkStatus.ReachableViaWiFiNetwork;
        }
开发者ID:MbProg,项目名称:MasterDetailTestProject-IOS-64,代码行数:46,代码来源:Reachability.cs


注:本文中的NetworkReachability.TryGetFlags方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。