示例#1
0
 public override void OnReceive(Context context, Intent intent)
 {
     if (intent.Action == "android.net.conn.CONNECTIVITY_CHANGE")
     {
         ConnectivityChanged?.Invoke(this, EventArgs.Empty);
     }
 }
示例#2
0
        private void UpdateConnected(bool triggerChange = true)
        {
            var remoteHostStatus = _reachability?.RemoteHostStatus();
            var internetStatus   = _reachability?.InternetConnectionStatus();

            var previouslyConnected = _isConnected;

            _isConnected = (internetStatus == ConnectionType.Cellular ||
                            internetStatus == ConnectionType.WiFi) ||
                           (remoteHostStatus == ConnectionType.Cellular ||
                            remoteHostStatus == ConnectionType.WiFi);

            if (triggerChange)
            {
                if (previouslyConnected != _isConnected || _previousInternetStatus != internetStatus)
                {
                    ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(_isConnected));
                }

                var connectionTypes = this.ConnectionTypes.ToArray();
                ConnectivityTypeChanged?.Invoke(this, new ConnectivityTypeChangedEventArgs(_isConnected, connectionTypes));
            }

            _previousInternetStatus = internetStatus ?? ConnectionType.None;
        }
示例#3
0
 /// <summary>
 /// When connectivity changes
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnConnectivityChanged(ConnectivityChangedEventArgs e)
 {
     if (ConnectivityChanged != null)
     {
         ConnectivityChanged.Invoke(this, e);
     }
 }
示例#4
0
 private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs()
     {
         IsConnected = e.IsConnected
     });
 }
示例#5
0
        private async Task CheckConnectivityChanged()
        {
            var connected = Connected;

            Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed - waiting for activity to settle ({DEBOUNCE_DELAY}ms...(Old value: {connected})");
            try
            {
                _StateDate = DateTime.Now;
                //  wait for things to settle
                await Task.Delay(DEBOUNCE_DELAY);

                if (DateTime.Now.Subtract(_StateDate).TotalMilliseconds < DEBOUNCE_DELAY)
                {
                    return;
                }
                Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed...");
                //  check connection state
                var hasConnection = !((_NetworkService.ConnectionState == NetworkConnectionStates.None) || (_NetworkService.ConnectionState == NetworkConnectionStates.Unknown));
                //  check if we are able to ping our backend
                if (!hasConnection)
                {
                    Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed - NOT connected to the internet...");
                    Connected = hasConnection;
                    if (!Initialized)
                    {
                        Initialized = true;
                    }
                    return;
                }
                Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connected to internet, Pinging backend...");
                var result = await _RestService.PingAsync();

                Connected = result;
                Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Ping success: {Connected}...");
                if (!Initialized)
                {
                    Initialized = true;
                }
            }
            catch { /* do nothing */ }
            finally
            {
                if (connected != Connected)
                {
                    Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Connectivity has changed, raising event.");
                    ConnectivityChanged?.Invoke(this, new EventArgs());
                }
                else
                {
                    Debug.WriteLine($"*** {GetType().Name}.{nameof(CheckConnectivityChanged)} - Nothing has changed.");
                }
            }
        }
示例#6
0
        private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
        {
            ConnectionStatusChangedArgs args;

            if (e.IsConnected)
            {
                args = ConnectionStatusChangedArgs.ConnectionGained();
            }
            else
            {
                args = ConnectionStatusChangedArgs.ConnectionLost();
            }

            ConnectivityChanged?.Invoke(this, args);
        }
        /// <summary>
        /// Received a notification via BR.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="intent"></param>
        public override async void OnReceive(Context context, Intent intent)
        {
            if (intent.Action != ConnectivityManager.ConnectivityAction)
            {
                return;
            }

            //await 500ms to ensure that the the connection manager updates
            await Task.Delay(500);

            var newConnection = IsConnected;

            if (newConnection != _isConnected)
            {
                _isConnected = newConnection;

                ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(_isConnected));
            }


            var connectionTypes = ConnectivityService.GetConnectionTypes(ConnectivityManager);

            ConnectivityTypeChanged?.Invoke(this, new ConnectivityTypeChangedEventArgs(newConnection, connectionTypes));
        }
示例#8
0
 private void OnConnectivityChanged(object sender, Xamarin.Essentials.ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs((NetworkAccessEnum)e.NetworkAccess, GetProfiles(e.Profiles)));
 }
示例#9
0
 private void Current_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(e.IsConnected);
 }
示例#10
0
 internal static void OnConnectivityChanged(ConnectivityStates connectivity) =>
 ConnectivityChanged?.Invoke(connectivity);
示例#11
0
 protected virtual void OnConnectivityChanged(ConnectivityChangedEventArgs e)
 => ConnectivityChanged?.Invoke(this, e);
示例#12
0
 private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     IsConnected = e.IsConnected;
     ConnectivityChanged?.Invoke(this, EventArgs.Empty);
 }
示例#13
0
 private void OnConnectivityChanged(Data.Models.EventArgs.ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(this, e);
 }
 private void _nlm_NetworkConnectivityChanged(Guid networkId, NLM_CONNECTIVITY newConnectivity)
 {
     ConnectivityChanged?.Invoke(this, IsNetworkAvailable());
 }
示例#15
0
 /// <summary>
 ///     Bind to IConnectivity network events.
 /// </summary>
 /// <param name="crossConnectivity">The IConnectivity network events instance.</param>
 private void SubscribeEvents()
 {
     Connectivity.ConnectivityChanged += (sender, args) => ConnectivityChanged?.Invoke(this, args);
     //crossConnectivity.ConnectivityTypeChanged += (sender, args) => ConnectivityTypeChanged?.Invoke(this, args);
 }
 void OnConnectivityChange(object sender, ConnectivityChangedEventArgs e) => ConnectivityChanged?.Invoke(sender, e);
示例#17
0
 private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(e);
 }
示例#18
0
 private void CurrentConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     ConnectivityChanged?.Invoke(sender, e);
 }
        public void SetNetworkAccess(NetworkAccess networkAccess)
        {
            NetworkAccess = networkAccess;

            ConnectivityChanged?.Invoke(this, new ConnectivityChangedEventArgs(NetworkAccess, ConnectionProfiles));
        }