Beispiel #1
0
 void RaiseIsConnectedChanged(bool isOnline)
 {
     IsConnectedChanged?.Invoke(this, new ConnectedEventArgs {
         IsConnected = isOnline
     });
     OnPropertyChanged("IsConnected");
 }
Beispiel #2
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);
                    }
                });
            };
        }
Beispiel #3
0
        void TryToConnect()
        {
            if (MyState != State.Connecting)
            {
                return;
            }

            Safely(() => {
                Connect();
                MyState = State.Connected;
                SyncContext.Current.Post(() => IsConnectedChanged.Fire(true));
                AfterConnect();
            });
        }
        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));
            }
        }
Beispiel #5
0
        void Heartbeat()
        {
            if (MyState == State.Disposed)
            {
                return;
            }

            HeartbeatCookie = PumpTimer.DoLater(1000, Heartbeat);
            if (Connection == null || !Connection.IsOpen)
            {
                MyState = State.Connecting;
                SyncContext.Current.Post(() => IsConnectedChanged.Fire(false));
                TryToConnect();
            }
        }
Beispiel #6
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);
                }
            }
        }
Beispiel #7
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));
                 }
             }
         });
     };
 }
Beispiel #8
0
 protected void ConnectionBroke()
 {
     CleanupRabbit();
     MyState = State.Connecting;
     SyncContext.Current.Post(() => IsConnectedChanged.Fire(false));
 }
Beispiel #9
0
 protected virtual void OnIsConnectedChanged(ConnectedEventArgs e)
 {
     IsConnectedChanged?.Invoke(this, e);
 }
Beispiel #10
0
 private void OnConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     IsConnectedChanged?.Invoke(this, e.IsConnected);
 }
Beispiel #11
0
 public AsyncWorkQueueConsumer(WorkQueueInfo wq)
 {
     Consumer = new AsyncConsumer(new ConsumerInfo(wq.Host, wq.Name, true, wq.IsPersistent, 1), msg => Received.Fire(msg));
     Consumer.IsConnectedChanged += x => IsConnectedChanged.Fire(x);
 }
Beispiel #12
0
 /// <summary>
 /// Handler for when the connection status changes.
 /// </summary>
 protected virtual void OnIsConnectedChanged()
 {
     IsConnectedChanged?.Invoke(this, EventArgs.Empty);
 }