Ejemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Reachability.Reachability"/> class.
 /// </summary>
 /// <param name='reachability'>
 /// NetworkReachability instance to use
 /// </param>
 /// <param name='hasWWAN'>
 /// Platform has a WWAN interface
 /// </param>
 protected Reachability(NetworkReachability reachability, bool hasWWAN)
 {
     NetworkReachability = reachability;
     HasWWAN = hasWWAN;
     AllowWWAN = true;
     NetworkReachability.SetNotification(OnReachabilityNotification);
     NetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
 }
Ejemplo n.º 2
0
		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);
		}
Ejemplo n.º 3
0
		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);
		}
Ejemplo n.º 4
0
 static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         var ipAddress = new IPAddress(0);
         defaultRouteReachability = new NetworkReachability(ipAddress.MapToIPv6());
         defaultRouteReachability.SetNotification(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     return(defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags));
 }
        public void iOSNetworkWatcher()
        {
            if (_defaultRouteReachability == null)
            {
                _defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                _defaultRouteReachability.SetNotification(NetworkStatusChanged);
                _defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            UpdateIOSNetworkStatus();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns network reachability flags and network availability.
        /// </summary>
        /// <param name="flags">
        /// The network reachability flags.
        /// </param>
        /// <returns>
        /// True if network is available, otherwise false.
        /// </returns>
        public static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                defaultRouteReachability.SetCallback(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            return(defaultRouteReachability.TryGetFlags(out flags) && IsReachableWithoutRequiringConnection(flags));
        }
Ejemplo n.º 7
0
        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));
        }
Ejemplo n.º 8
0
        public ReachabilityManager(string ipAddress, NetworkReachability.Notification callback)
        {
            Callback  = callback;
            IpAddress = ipAddress;

            var flags = NetworkReachabilityFlags.Reachable;

            _reachability = new NetworkReachability("192.168.1.150");
            _reachability.TryGetFlags(out flags);
            _reachability.SetNotification(Callback);
            _reachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
        }
Ejemplo n.º 9
0
    //
    // 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);
    }
Ejemplo n.º 10
0
        static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(IPAddress.None);
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            bool a = defaultRouteReachability.TryGetFlags(out flags);
            bool b = IsReachableWithoutRequiringConnection(flags);

            return(a && b);
        }
        public bool IsNetworkAvailable()
        {
            if (_defaultRouteReachability == null)
            {
                _defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                _defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            NetworkReachabilityFlags flags;

            return(_defaultRouteReachability.TryGetFlags(out flags) &&
                   IsReachableWithoutRequiringConnection(flags));
        }
		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 ();
		}
Ejemplo n.º 13
0
 static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         defaultRouteReachability = new NetworkReachability(new IPAddress(0));
         defaultRouteReachability.SetNotification(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
     }
     if (!defaultRouteReachability.TryGetFlags(out flags))
     {
         return(false);
     }
     return(IsReachableWithoutRequiringConnection(flags));
 }
Ejemplo n.º 14
0
 public bool isNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultReachability == null)
     {
         defaultReachability = new NetworkReachability(new System.Net.IPAddress(0));
         defaultReachability.SetNotification(OnChange);
         defaultReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (!defaultReachability.TryGetFlags(out flags))
     {
         return(false);
     }
     return(IsReachableWithoutRequiredConnection(flags));
 }
Ejemplo n.º 15
0
 private bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         defaultRouteReachability = new NetworkReachability("www.163.com");
         defaultRouteReachability.SetNotification(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (!defaultRouteReachability.TryGetFlags(out flags))
     {
         return(false);
     }
     return(IsReachableWithoutRequiringConnection(flags));
 }
Ejemplo n.º 16
0
        /// <summary>
        /// Enables monitoring for changes in network availability.
        /// </summary>
        public void EnableMonitor()
        {
            using (NetworkReachability reachability = new NetworkReachability(new IPAddress(0)))
            {
                reachability.SetNotification(
                    flags =>
                {
                    this.currentAvailability = null;
                    this.AvailabilityChanged(this, EventArgs.Empty);
                });

                reachability.Schedule();
            }
        }
Ejemplo n.º 17
0
        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();
        }
Ejemplo n.º 18
0
        private NetworkReachability SetReachability()
        {
            NetworkReachability reachability = new NetworkReachability(IPAddress.Any);
            var  status      = reachability.SetNotification(ReachablilityCallback);
            bool isScheduled = reachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

            if (!isScheduled)
            {
                System.Diagnostics.Debug.WriteLine($"NetworkReachability request was not scheduled");
                reachability.Dispose();
                reachability = null;
            }

            return(reachability);
        }
Ejemplo n.º 19
0
        private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
#warning Need to look at SetNotification instead - ios6 change
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            if (defaultRouteReachability.TryGetFlags(out flags))
            {
                return(false);
            }
            return(IsReachableWithoutRequiringConnection(flags));
        }
//        private bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
//        {
//            if (defaultRouteReachability == null)
//            {
//                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
//                defaultRouteReachability.SetCallback(OnChange);
//                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
//            }
//            if (!defaultRouteReachability.TryGetFlags(out flags))
//                return false;
//            return IsReachableWithoutRequiringConnection(flags);
//        }

        private bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                //SetCallback is depreciated
                //ORIG: defaultRouteReachability.SetCallback(OnChange);
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            if (!defaultRouteReachability.TryGetFlags(out flags))
            {
                return(false);
            }
            return(IsReachableWithoutRequiringConnection(flags));
        }
Ejemplo n.º 21
0
        private 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));
        }
Ejemplo n.º 22
0
        internal ReachabilityListener()
        {
            var ip = new IPAddress(0);

            defaultRouteReachability = new NetworkReachability(ip);
            defaultRouteReachability.SetNotification(OnChange);
            defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

            remoteHostReachability = new NetworkReachability(Reachability.HostName);

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

            remoteHostReachability.SetNotification(OnChange);
            remoteHostReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
        }
Ejemplo n.º 23
0
        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.SetCallback(OnChange);
                adHocWiFiNetworkReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

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

            return(IsReachableWithoutRequiringConnection(flags));
        }
Ejemplo n.º 24
0
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        imageCarrier = UIImage.FromFile("WWAN5.png");
        imageWiFi    = UIImage.FromFile("Airport.png");
        imageStop    = UIImage.FromFile("stop-32.png");

        nr = new NetworkReachability("www.apple.com");
        nr.SetCallback(ReachabilityChanged);
        nr.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);

        AddTable();
        //UpdateStatus ();
        //UpdateCarrierWarning ();

        window.MakeKeyAndVisible();

        return(true);
    }
Ejemplo n.º 25
0
    public override bool FinishedLaunching(UIApplication app, NSDictionary options)
    {
        imageCarrier = UIImage.FromFile ("WWAN5.png");
        imageWiFi = UIImage.FromFile ("Airport.png");
        imageStop = UIImage.FromFile ("stop-32.png");

        nr = new NetworkReachability ("www.apple.com");
        nr.SetCallback (ReachabilityChanged);
        nr.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);

        AddTable ();
        //UpdateStatus ();
        //UpdateCarrierWarning ();

        window.MakeKeyAndVisible ();

        return true;
    }
Ejemplo n.º 26
0
        /// <summary>
        /// Checks ad hoc wifi is available
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (adHocWiFiNetworkReachability == null)
            {
                //var ip = IPAddress.Parse("::ffff:169.254.0.0");
                //var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 169, 254, 0, 0 };
                var ip = new IPAddress(new byte[] { 169, 254, 0, 0 });
                adHocWiFiNetworkReachability = new NetworkReachability(ip);
                adHocWiFiNetworkReachability.SetNotification(OnChange);
                adHocWiFiNetworkReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
            }

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

            return(IsReachableWithoutRequiringConnection(flags));
        }
Ejemplo n.º 27
0
        internal ReachabilityListener()
        {
            var ip = new IPAddress(0);

            defaultRouteReachability = new NetworkReachability(ip);
            defaultRouteReachability.SetNotification(OnChange);
            defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

            remoteHostReachability = new NetworkReachability(WinRTFeatureConfiguration.NetworkInformation.ReachabilityHostname);

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

            remoteHostReachability.SetNotification(OnChange);
            remoteHostReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

#if __IOS__ && !__MACCATALYST__
            NetworkInformation.CellularData.RestrictionDidUpdateNotifier = new Action <CTCellularDataRestrictedState>(OnRestrictedStateChanged);
#endif
        }
		void CreateHostReachability ()
		{
			if (hostReachability != null) {
				hostReachability.Unschedule ();
				hostReachability.Dispose ();
			}

			if (String.IsNullOrEmpty (HostTextField.StringValue)) {
				HostIcon.Image = NSImage.ImageNamed ("disconnected");
				HostStatusTextField.StringValue = "Enter a host name or IP address";
				return;
			}

			hostReachability = new NetworkReachability (HostTextField.StringValue);
			hostReachability.SetNotification (flags => UpdateReachability (flags, HostIcon, HostStatusTextField));
			hostReachability.Schedule ();

			NetworkReachabilityFlags networkReachabilityFlags;
			networkReachability.TryGetFlags (out networkReachabilityFlags);
			UpdateReachability (networkReachabilityFlags, NetworkIcon, NetworkStatusTextField);
		}
Ejemplo n.º 29
0
        public static bool IsReachable()
        {
            NetworkReachabilityFlags flags;

            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            var defaultRouteAvailable = defaultRouteReachability.TryGetFlags(out flags);


            var isReachable = (flags & NetworkReachabilityFlags.Reachable) != 0;

            var noConnectionRequired = (flags & NetworkReachabilityFlags.ConnectionRequired) == 0 ||
                                       (flags & NetworkReachabilityFlags.IsWWAN) != 0;

            var canReachWithoutConnection =
                isReachable &&
                noConnectionRequired;

            var defaultNetworkAvailable =
                defaultRouteAvailable &&
                canReachWithoutConnection;

            if (defaultNetworkAvailable && ((flags & NetworkReachabilityFlags.IsDirect) != 0))
            {
                return(false);
            }
            else if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            {
                return(true);
            }
            else if (flags == 0)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 30
0
        /// <summary>
        /// Checks the remote host status
        /// </summary>
        /// <returns></returns>
        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.Main, CFRunLoop.ModeDefault);
            }
            else
            {
                reachable = remoteHostReachability.TryGetFlags(out flags);
            }

            if (!reachable)
            {
                return(NetworkStatus.NotReachable);
            }

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

#if __IOS__
            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            {
                return(NetworkStatus.ReachableViaCarrierDataNetwork);
            }
#endif

            return(NetworkStatus.ReachableViaWiFiNetwork);
        }
Ejemplo n.º 31
0
        public static MvxReachabilityStatus RemoteHostStatus()
        {
            NetworkReachabilityFlags flags;
            bool reachable;

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

                // 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);

#warning Need to look at SetNotification instead - ios6 change
                remoteHostReachability.SetNotification(OnChange);
                remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            else
            {
                reachable = remoteHostReachability.TryGetFlags(out flags);
            }

            if (!reachable)
            {
                return(MvxReachabilityStatus.Not);
            }

            if (!IsReachableWithoutRequiringConnection(flags))
            {
                return(MvxReachabilityStatus.Not);
            }

            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            {
                return(MvxReachabilityStatus.ViaCarrierDataNetwork);
            }

            return(MvxReachabilityStatus.ViaWiFiNetwork);
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Checks the remote host status
        /// </summary>
        /// <returns></returns>
        public ConnectionType 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.Main, CFRunLoop.ModeDefault);
            }
            else
            {
                reachable = _remoteHostReachability.TryGetFlags(out flags);
            }

            if (!reachable)
            {
                return(ConnectionType.None);
            }

            if (!IsReachableWithoutRequiringConnection(flags))
            {
                return(ConnectionType.None);
            }

            if ((flags & NetworkReachabilityFlags.IsWWAN) != 0)
            {
                return(ConnectionType.Cellular);
            }

            return(ConnectionType.WiFi);
        }
Ejemplo n.º 33
0
        public ReachabilityService(IConfiguration configuration)
        {
            _configuration = configuration;
            _reachability  = new NetworkReachability(_configuration.Host);

            _initializeTask = Task.Run(() =>
            {
                NetworkReachabilityFlags flags;

                var resultFlags = _reachability.TryGetFlags(out flags)
                            ? flags
                                : (NetworkReachabilityFlags)0;

                return(resultFlags);
            })
                              .ContinueWithUIThread(previousTask =>
            {
                OnNotification(previousTask.Result);

                _reachability.SetNotification(OnNotification);
                _reachability.Schedule();
            });
        }
Ejemplo n.º 34
0
        internal ReachabilityListener()
        {
            var ip = new IPAddress(0);

            defaultRouteReachability = new NetworkReachability(ip);
            defaultRouteReachability.SetNotification(OnChange);
            defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

            remoteHostReachability = new NetworkReachability(Reachability.HostName);

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

            remoteHostReachability.SetNotification(OnChange);
            remoteHostReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

#if !(MACCATALYST || MACOS)
#pragma warning disable BI1234, CA1416 // Analyzer bug https://github.com/dotnet/roslyn-analyzers/issues/5938
            ConnectivityImplementation.CellularData.RestrictionDidUpdateNotifier = new Action <CTCellularDataRestrictedState>(OnRestrictedStateChanged);
#pragma warning restore BI1234, CA1416
#endif
        }
		public void CreateConnectivityWatchDog (Action<bool> connectivityChanged)
		{
			this.connectivityChanged = connectivityChanged;

			if (remoteHostReachability == null)
			{
				if (remoteHostReachability != null)
				{
					remoteHostReachability.Unschedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
				}

				// Create new instance if host address changed.
				remoteHostReachability = new NetworkReachability(new System.Net.IPAddress(0));
				remoteHostReachability.SetNotification(HandleReachabilityChanged);
				remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
			}

			// Trigger callback.
			if (this.connectivityChanged != null)
			{
				this.connectivityChanged (true);
			}
		}
        public void CreateConnectivityWatchDog(Action <bool> connectivityChanged)
        {
            this.connectivityChanged = connectivityChanged;

            if (remoteHostReachability == null)
            {
                if (remoteHostReachability != null)
                {
                    remoteHostReachability.Unschedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
                }

                // Create new instance if host address changed.
                remoteHostReachability = new NetworkReachability(new System.Net.IPAddress(0));
                remoteHostReachability.SetNotification(HandleReachabilityChanged);
                remoteHostReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }

            // Trigger callback.
            if (this.connectivityChanged != null)
            {
                this.connectivityChanged(true);
            }
        }
        internal ReachabilityListener()
        {
            var ip = new IPAddress(0);

            defaultRouteReachability = new NetworkReachability(ip);
            defaultRouteReachability.SetNotification(OnChange);
            defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

            remoteHostReachability = new NetworkReachability(Reachability.HostName);

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

            remoteHostReachability.SetNotification(OnChange);
            remoteHostReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);

#if __IOS__
#pragma warning disable BI1234
            Connectivity.CellularData.RestrictionDidUpdateNotifier = new Action <CTCellularDataRestrictedState>(OnRestrictedStateChanged);
#pragma warning restore BI1234
#endif
        }
Ejemplo n.º 38
0
        public static NetworkStatus RemoteHostStatus()
        {
            NetworkReachabilityFlags flags;
            bool reachable;

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

                reachable = remoteHostReachability.TryGetFlags(out flags);

                remoteHostReachability.SetNotification(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);
        }
 static bool IsNetworkAvailable (out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null){
         defaultRouteReachability = new NetworkReachability (new IPAddress (0));
         defaultRouteReachability.SetNotification (OnChange);
         defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (!defaultRouteReachability.TryGetFlags(out flags))
     {
         Application._networkstate = DataAccessLayer.NetworkState.Disconnected;
         if (Application._user != null) 
         Application._user.NetworkStatus = DataAccessLayer.NetworkState.Disconnected;
         return false;
     }
         
     return IsReachableWithoutRequiringConnection (flags);
 }   
        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;
        }
Ejemplo n.º 41
0
 private static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (_defaultRouteReachability == null) {
         _defaultRouteReachability = new NetworkReachability (new IPAddress (0));
         _defaultRouteReachability.SetCallback (OnChange);
         _defaultRouteReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (!_defaultRouteReachability.TryGetFlags (out flags))
         return false;
     return IsReachableWithoutRequiringConnection (flags);
 }
 //        private bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 //        {
 //            if (defaultRouteReachability == null)
 //            {
 //                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
 //                defaultRouteReachability.SetCallback(OnChange);
 //                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
 //            }
 //            if (!defaultRouteReachability.TryGetFlags(out flags))
 //                return false;
 //            return IsReachableWithoutRequiringConnection(flags);
 //        }
 private bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
 {
     if (defaultRouteReachability == null)
     {
         defaultRouteReachability = new NetworkReachability(new IPAddress(0));
         //SetCallback is depreciated
         //ORIG: defaultRouteReachability.SetCallback(OnChange);
         defaultRouteReachability.SetNotification(OnChange);
         defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
     }
     if (!defaultRouteReachability.TryGetFlags(out flags))
         return false;
     return IsReachableWithoutRequiringConnection(flags);
 }
Ejemplo n.º 43
0
        private static bool IsNetworkAvaialable(out NetworkReachabilityFlags flags)
        {
            if (defaultRouteReachability == null)
            {
                defaultRouteReachability = new NetworkReachability(new IPAddress(0));
#warning Need to look at SetNotification instead - ios6 change
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
            }
            if (defaultRouteReachability.TryGetFlags(out flags))
                return false;
            return IsReachableWithoutRequiringConnection(flags);
        }
Ejemplo n.º 44
0
        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);
        }
Ejemplo n.º 45
0
		public NetworkChangedListener ()
		{
			reachabilityChecker = new NetworkReachability (new IPAddress(0));
			reachabilityChecker.SetNotification (OnReachabilityChanged);
			reachabilityChecker.Schedule(CFRunLoop.Current, CFRunLoop.ModeDefault);
		}
Ejemplo n.º 46
0
    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;
    }
        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;
        }
Ejemplo n.º 48
0
        /// <summary>
        /// Checks ad hoc wifi is available
        /// </summary>
        /// <param name="flags"></param>
        /// <returns></returns>
        public static bool IsAdHocWiFiNetworkAvailable(out NetworkReachabilityFlags flags)
        {
            if (adHocWiFiNetworkReachability == null)
            {
                //var ip = IPAddress.Parse("::ffff:169.254.0.0");
                var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 169, 254, 0, 0 };
                var ip = new IPAddress(data, 0);
                adHocWiFiNetworkReachability = new NetworkReachability(ip);
                adHocWiFiNetworkReachability.SetNotification(OnChange);
                adHocWiFiNetworkReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
            }

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

            return IsReachableWithoutRequiringConnection(flags);
        }
Ejemplo n.º 49
0
        static bool IsNetworkAvailable(out NetworkReachabilityFlags flags)
        {

            if (defaultRouteReachability == null)
            {
                var data = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 0, 0, 0, 0 };
                var ip = new IPAddress(data, 0);
                defaultRouteReachability = new NetworkReachability(ip);
                defaultRouteReachability.SetNotification(OnChange);
                defaultRouteReachability.Schedule(CFRunLoop.Main, CFRunLoop.ModeDefault);
            }
            if (!defaultRouteReachability.TryGetFlags(out flags))
                return false;
            return IsReachableWithoutRequiringConnection(flags);
        }