Exemple #1
0
        protected ConnectableNotifier()
        {
            PropertyChanged += (s, e) =>
            {
                e.Case(() => KeepAliveInterval, p =>
                {
                    //Si KeepAliveInterval es menor que 1 lanzo una ArgumentException
                    if (p.ActualValue.TotalMilliseconds < 1)
                    {
                        throw new ArgumentException(
                            "El valor de '" + s.GetMemberName(() => s.KeepAliveInterval) + "' no puede ser cero o negativo, para deshabilitar el KeepAlive establezca la propiedad '" + s.GetMemberName(() => s.IsKeepAliveEnabled) + "' en False.",
                            s.GetMemberName(() => s.KeepAliveInterval));
                    }
                });
                e.Case(() => ConnectionMode, p =>
                {
                    //Si cambia el modo de conexión a automática y no estoy conectado o conectando debo llamar a Connect
                    if (p.ActualValue == ConnectionMode.Automatic && State != ConnectionState.Opened && State != ConnectionState.Opening)
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    {
                        Connect();
                    }
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                });
                e.Case(() => State, p =>
                {
                    //Si cambia el estado hacia o desde Opened abrá que disparar el cambio de la propiedad IsConnected y el evento IsConnectedChanged
                    if (p.PreviousValue == ConnectionState.Opened || p.ActualValue == ConnectionState.Opened)
                    {
                        RaisePropertyChanged(() => IsConnected, p.PreviousValue == ConnectionState.Opened, p.ActualValue == ConnectionState.Opened);
                        this.Invoke(actualValue => IsConnectedChanged?.Invoke(this, new EventArgs <bool>(actualValue == ConnectionState.Opened)), p.ActualValue);
                    }
                });
            };
        }
Exemple #2
0
 void RaiseIsConnectedChanged(bool isOnline)
 {
     IsConnectedChanged?.Invoke(this, new ConnectedEventArgs {
         IsConnected = isOnline
     });
     OnPropertyChanged("IsConnected");
 }
        private void NetworkInformation_NetworkStatusChanged(object sender)
        {
            bool oldStatus = IsConnected;
            bool newStatus = IsInternetConnected();

            IsConnected = newStatus;

            if (oldStatus != newStatus)
            {
                DetectConnectionType();
                IsConnectedChanged?.Invoke(this, EventArgs.Empty);
                RaisePropertyChanged(nameof(IsConnected));
            }
        }
Exemple #4
0
        /// <summary>
        /// Handler for when the connection status changes.
        /// </summary>
        protected void OnIsConnectedChanged()
        {
            IsConnectedChanged?.Invoke(this, new ConnectedEventArgs {
                Connected = GetConnections().ToArray()
            });

            if (!IsConnected &&
                (StartupPolicy & StartupPolicy.ReconnectPreviousAddresses) == StartupPolicy.ReconnectPreviousAddresses)
            {
                foreach (var node in connectedNodes)
                {
                    Connect(node.Address);
                }
            }
        }
Exemple #5
0
 protected ConnectableNotifier()
 {
     PropertyChanged += (s, e) =>
     {
         e.Case(() => KeepAliveInterval, p =>
         {
             //Si KeepAliveInterval es menor que 1 lanzo una ArgumentException
             if (p.ActualValue.TotalMilliseconds < 1)
             {
                 throw new ArgumentException(
                     "El valor de '" + s.GetMemberName(() => s.KeepAliveInterval) + "' no puede ser cero o negativo, para deshabilitar el KeepAlive establezca la propiedad '" + s.GetMemberName(() => s.IsKeepAliveEnable) + "' en False.",
                     s.GetMemberName(() => s.KeepAliveInterval));
             }
         });
         e.Case(() => ConnectionMode, p =>
         {
             //Si cambia el modo de conexión a automática y no estoy conectado o conectando debo llamar a Connect
             if (p.ActualValue == ConnectionMode.Automatic && State != ConnectionState.Opened && State != ConnectionState.Opening)
             {
                 Connect();
             }
         });
         e.Case(() => State, p =>
         {
             //Si cambia el estado hacia o desde Opened abrá que disparar el cambio de la propiedad IsConnected y el evento IsConnectedChanged
             if (p.PreviousValue == ConnectionState.Opened || p.ActualValue == ConnectionState.Opened)
             {
                 RaisePropertyChanged(() => IsConnected, p.PreviousValue == ConnectionState.Opened, p.ActualValue == ConnectionState.Opened);
                 if (Synchronizer != null)
                 {
                     Synchronizer.Invoke(actualValue => IsConnectedChanged?.Invoke(this, new EventArgs <bool>(actualValue == ConnectionState.Opened)), p.ActualValue);
                 }
                 else
                 {
                     IsConnectedChanged?.Invoke(this, new EventArgs <bool>(p.ActualValue == ConnectionState.Opened));
                 }
             }
         });
     };
 }
Exemple #6
0
 protected virtual void OnIsConnectedChanged(ConnectedEventArgs e)
 {
     IsConnectedChanged?.Invoke(this, e);
 }
Exemple #7
0
 private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     IsConnectedChanged?.Invoke(this, e.IsConnected);
 }
Exemple #8
0
 /// <summary>
 /// Handler for when the connection status changes.
 /// </summary>
 protected virtual void OnIsConnectedChanged()
 {
     IsConnectedChanged?.Invoke(this, EventArgs.Empty);
 }