本文整理汇总了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;
}
示例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;
}
示例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 ();
}
示例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;
}
示例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;
}
示例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;
}
示例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.
}
示例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;
}
示例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.
}
示例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;
}
示例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
}
示例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;
}