本文整理汇总了C#中NetworkReachabilityFlags类的典型用法代码示例。如果您正苦于以下问题:C# NetworkReachabilityFlags类的具体用法?C# NetworkReachabilityFlags怎么用?C# NetworkReachabilityFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NetworkReachabilityFlags类属于命名空间,在下文中一共展示了NetworkReachabilityFlags类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsReachableWithoutRequiringConnection
public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags)
{
// Is it reachable with the current network configuration?
bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;
// Do we need a connection to reach it?
bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0;
// Since the network stack will automatically try to get the WAN up,
// probe that
if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
noConnectionRequired = true;
if (isReachable && noConnectionRequired)
{
Application._networkstate = DataAccessLayer.NetworkState.ConnectedWifi;
if (Application._user != null)
Application._user.NetworkStatus = DataAccessLayer.NetworkState.ConnectedWifi;
}
else
{
Application._networkstate = DataAccessLayer.NetworkState.Disconnected;
if (Application._user != null)
Application._user.NetworkStatus = DataAccessLayer.NetworkState.Disconnected;
}
return isReachable && noConnectionRequired;
}
示例2: OnChange
static void OnChange(NetworkReachabilityFlags flags)
{
var h = ReachabilityChanged;
if (h != null)
{
h(null, EventArgs.Empty);
}
}
示例3: IsNetworkAvailable
static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
{
if (defaultRouteReachability == null) {
defaultRouteReachability = new NetworkReachability(new IPAddress(0));
defaultRouteReachability.SetNotification(OnChange);
defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
}
return defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags);
}
示例4: IsReachableWithoutRequiringConnection
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags)
{
bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;
bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0;
if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
noConnectionRequired = true;
return isReachable && noConnectionRequired;
}
示例5: UpdateReachability
void UpdateReachability (NetworkReachabilityFlags flags, NSImageView icon, NSTextField statusField)
{
if (flags.HasFlag (NetworkReachabilityFlags.Reachable) && !flags.HasFlag (NetworkReachabilityFlags.ConnectionRequired)) {
icon.Image = NSImage.ImageNamed ("connected");
} else {
icon.Image = NSImage.ImageNamed ("disconnected");
}
statusField.StringValue = flags == 0 ? String.Empty : flags.ToString ();
}
示例6: IsReachableWithoutRequiringConnection
/// <summary>
/// Checks if reachable without requireing a connection
/// </summary>
/// <param name="flags"></param>
/// <returns></returns>
public static bool IsReachableWithoutRequiringConnection (NetworkReachabilityFlags flags)
{
// Is it reachable with the current network configuration?
bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;
// Do we need a connection to reach it?
bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0;
return isReachable && noConnectionRequired;
}
示例7: IsAdHocWiFiNetworkAvailable
public static bool IsAdHocWiFiNetworkAvailable (out NetworkReachabilityFlags flags)
{
if (adHocWiFiNetworkReachability == null) {
adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte [] { 169, 254, 0, 0 }));
adHocWiFiNetworkReachability.SetNotification(OnChange);
adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
}
return adHocWiFiNetworkReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags);
}
示例8: OnChange
static void OnChange (NetworkReachabilityFlags flags)
{
var h = ReachabilityChanged;
if (h != null)
h (null, EventArgs.Empty);
if (pictureViewController != null)
{
NetworkStatus internetStatus = Reachability.InternetConnectionStatus();
pictureViewController.UpdateNetwork(internetStatus == NetworkStatus.ReachableViaWiFiNetwork || internetStatus == NetworkStatus.ReachableViaCarrierDataNetwork);
}
}
示例9: NetworkStatusHelper
private NetworkStatus NetworkStatusHelper(NetworkReachabilityFlags flags)
{
if (!IsReachableWithoutRequiringConnection(flags))
_networkStatus = NetworkStatus.NotReachable;
else if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
_networkStatus = NetworkStatus.ReachableViaCarrierDataNetwork;
else
_networkStatus = NetworkStatus.ReachableViaWiFiNetwork;
return _networkStatus;
}
示例10: IsAdHocWiFiNetworkAvailable
//
// Returns true if it is possible to reach the AdHoc WiFi network
// and optionally provides extra network reachability flags as the
// out parameter
//
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
{
if (_adHocWiFiNetworkReachability == null) {
_adHocWiFiNetworkReachability = new NetworkReachability (new IPAddress (new byte[] { 169, 254, 0, 0 }));
_adHocWiFiNetworkReachability.SetCallback (OnChange);
_adHocWiFiNetworkReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
}
if (!_adHocWiFiNetworkReachability.TryGetFlags (out flags))
return false;
return IsReachableWithoutRequiringConnection (flags);
}
示例11: HandleReachabilityChanged
private void HandleReachabilityChanged(NetworkReachabilityFlags flags)
{
Console.WriteLine (flags);
var requiresConnection = (flags & NetworkReachabilityFlags.ConnectionRequired) > 0;
// It's reachable if Reachable flag is set and no connection is required.
reachable = !requiresConnection && (flags & NetworkReachabilityFlags.Reachable) > 0;
// Trigger callback.
if (this.connectivityChanged != null)
{
this.connectivityChanged (reachable);
}
}
示例12: IsReachableWithoutRequiringConnection
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags)
{
// Is it reachable with the current network configuration?
bool isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;
// Do we need a connection to reach it?
bool noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0;
// Since the network stack will automatically try to get the WAN up, probe that
if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
noConnectionRequired = true;
return isReachable && noConnectionRequired;
}
示例13: IsAdHocWiFiNetworkAvailable
public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
{
if (adHocWiFiNetworkReachability == null)
{
adHocWiFiNetworkReachability = new NetworkReachability(new IPAddress(new byte[] {169, 254, 0, 0}));
#warning Need to look at SetNotification instead - ios6 change
adHocWiFiNetworkReachability.SetNotification(OnChange);
adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
}
if (!adHocWiFiNetworkReachability.TryGetFlags(out flags))
return false;
return IsReachableWithoutRequiringConnection(flags);
}
示例14: IsReachableWithoutRequiringConnection
/// <summary>
/// Checks if network is reachable without requiring connection.
/// </summary>
/// <param name="flags">
/// The reachability flags.
/// </param>
/// <returns>
/// True if reachable, false if connection is required.
/// </returns>
public static bool IsReachableWithoutRequiringConnection(NetworkReachabilityFlags flags)
{
return (flags & NetworkReachabilityFlags.Reachable) != 0 &&
(((flags & NetworkReachabilityFlags.IsWWAN) != 0) || (flags & NetworkReachabilityFlags.ConnectionRequired) == 0);
}
示例15: ReachabilityChanged
static void ReachabilityChanged(NetworkReachabilityFlags flags)
{
FAARegistry.flags = flags;
haveFlags = true;
}