private void OnConnectionOpened(object sender, ConnectionOpenedEventArgs e)
        {
            Invoke(new Action(() =>
            {
                if (e.IsSuccessful)
                {
                    Networks.Client client = sender as Networks.Client;

                    cbConnections.Items.Add(
                        new ComboBoxItem
                    {
                        ConnectionName = client.Name,
                        Client         = client
                    });

                    if (cbConnections.Items.Count == 1)
                    {
                        cbConnections.SelectedIndex = 0;
                    }

                    if (sender is TcpClient)
                    {
                        btnTcpConnect.Enabled = false;
                        MessageBox.Show("Connect to service through TCP successful!");
                    }
                }
            }));
        }
示例#2
0
        void ChangeStatus(UdpConnectionStatus status)
        {
            var oldStatus = this.Status;

            if (oldStatus != status)
            {
                this.Status = status;
                this.logger.Info($"{this} status changed to {status}");
                this.lastStatusChange = DateTime.UtcNow;
                UpdateTimeoutDeadline();

                if (Status == UdpConnectionStatus.Connected)
                {
                    var connectTcs_ = this.connectTcs;
                    if (connectTcs_ != null)
                    {
                        connectTcs_.TrySetResult(null);
                    }

                    this.lastPingSent = DateTime.UtcNow;

                    if (peer.Configuration.AutoMtuExpand)
                    {
                        ExpandMTU();
                    }

                    var openedArgs = new ConnectionOpenedEventArgs(this);
                    peer.Configuration.SynchronizeSafe(() =>
                    {
                        try
                        {
                            OnConnectionOpened(openedArgs);
                        }
                        catch (Exception ex)
                        {
                            logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnConnectionOpened)}: {ex}");
                        }

                        peer.OnConnectionOpenedInternalSynchronized(openedArgs);
                    }, logger);
                }

                var statusChangedArgs = new ConnectionStatusChangedEventArgs(this, status);
                peer.Configuration.SynchronizeSafe(() =>
                {
                    try
                    {
                        OnStatusChanged(statusChangedArgs);
                    }
                    catch (Exception ex)
                    {
                        logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnStatusChanged)}: {ex}");
                    }

                    peer.OnConnectionStatusChangedSynchronized(statusChangedArgs);
                }, logger);
            }
        }
示例#3
0
        void Mds_OnConnectionOpened(object sender, ConnectionOpenedEventArgs args)
        {
            // Obtem alertas cadastrados na base
            Dictionary <String, DadosAlerta> alertasCadastrados = dbAlertas.ListarAlertas();

            if (alertasCadastrados != null && alertasCadastrados.Count > 0)
            {
                gerenciadorAlertas.Carregar(alertasCadastrados);
                RecadastrarInstrumentosMDS();
            }
        }
        protected override void OnConnectionOpened(ConnectionOpenedEventArgs args)
        {
            if (!this.IsClientConnection)
            {
                return;
            }

            var message = Parent.CreateMessage();

            dh.SendHandshakeRequest(message.BaseStream);
            _ = SendMessageAsync(message);
            logger.Debug($"Secure handshake request sent!");
        }
示例#5
0
        /// <summary>
        /// Called when [open].
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="ConnectionOpenedEventArgs"/> instance containing the event data.</param>
        public override void OnOpen(IWebSocketConnection sender, ConnectionOpenedEventArgs args)
        {
            if (!Authenticate(sender, args))
            {
                return;
            }

            Logger.Info($"{sender.ClientIdentifier}/{sender.UniqueIdentifier} connected");

            RegisterInExtensions(sender);

            base.OnOpen(sender, args);
        }
示例#6
0
        public void OpenConnection()
        {
            try
            {
                if (thMsgDispatcher == null)
                {
                    bKeepRunning    = true;
                    thMsgDispatcher = new Thread(new ThreadStart(messageDispatcherProc));
                    thMsgDispatcher.Start();
                }

                logger.Info("Abrindo conexao com MDS: " + IpAddr + ":" + Port);

                bConectado = false;

                _ClientSocket =
                    new Socket(
                        AddressFamily.InterNetwork,
                        SocketType.Stream,
                        ProtocolType.Tcp
                        );


                IPAddress  IP    = IPAddress.Parse(IpAddr);
                IPEndPoint ipEnd = new IPEndPoint(IP, Convert.ToInt32(Port));

                _ClientSocket.Connect(ipEnd);

                bConectado = true;

                ConnectionOpenedEventArgs args = new ConnectionOpenedEventArgs();
                if (OnConnectionOpened != null)
                {
                    OnConnectionOpened(this, args);
                }

                this.LastPacket = DateTime.Now;

                this.WaitForData(_ClientSocket, 0);
            }
            catch (Exception ex)
            {
                logger.Error("OpenConnection(): " + ex.Message, ex);
            }
        }
        /// <summary>
        /// Handles an opened connection.
        /// </summary>
        /// <param name="connection">The connection.</param>
        /// <param name="isFirst">Whether the connection is the first one.</param>
        /// <param name="isNewCluster">Whether the cluster is a new/different cluster.</param>
        public async ValueTask OnConnectionOpened(MemberConnection connection, bool isFirst, bool isNewCluster)
        {
            // if it is the first connection, subscribe to events according to options
            if (isFirst)
            {
                // FIXME should this be cancelable?
                var cancellationToken = CancellationToken.None;
                foreach (var subscriber in _options.Subscribers)
                {
                    await subscriber.SubscribeAsync(this, cancellationToken).CfAwait();
                }
            }

            var args = new ConnectionOpenedEventArgs(isFirst);

            // trigger ConnectionOpened event
            await ForEachHandler <ConnectionOpenedEventHandler, ConnectionOpenedEventArgs>(
                (handler, sender, a) => handler.HandleAsync(sender, a), args).CfAwait();
        }
示例#8
0
        internal virtual void OnConnectionOpenedInternalSynchronized(ConnectionOpenedEventArgs args)
        {
            try
            {
                OnConnectionOpened(args);
            }
            catch (Exception ex)
            {
                Logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnConnectionOpened)}: {ex}");
            }

            try
            {
                OnConnectionOpenedEvent?.Invoke(args);
            }
            catch (Exception ex)
            {
                Logger.Error($"Unhandled exception on {this.GetType().Name}.{nameof(OnConnectionOpenedEvent)}: {ex}");
            }
        }
示例#9
0
        void Mds_OnConnectionOpened(object sender, ConnectionOpenedEventArgs args)
        {
            try
            {
                SocketPackage mdsSocket = sender as SocketPackage;

                // Obtem alertas cadastrados na base
                Dictionary <String, DadosAlerta> alertasCadastrados = dbAlertas.ListarAlertas();

                if (alertasCadastrados != null && alertasCadastrados.Count > 0)
                {
                    gerenciadorAlertas.Carregar(alertasCadastrados);
                    RecadastrarInstrumentosMDS(mdsSocket);
                }
            }
            catch (Exception ex)
            {
                logger.Error("Mds_OnConnectionOpened(): " + ex.Message, ex);
            }
        }
示例#10
0
        /// <summary>
        /// Authenticates the specified connection.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="ConnectionOpenedEventArgs"/> instance containing the event data.</param>
        /// <returns></returns>
        private bool Authenticate(IWebSocketConnection sender, ConnectionOpenedEventArgs args)
        {
            string userDomainId = args.Querystrings["userdomainid"];
            string userId       = args.Querystrings["userid"];
            string token        = args.Querystrings["token"];

            //Make sure that we have an ID in the querystring
            if (string.IsNullOrWhiteSpace(userDomainId) || string.IsNullOrEmpty(userId) || string.IsNullOrEmpty(token))
            {
                sender.Close();
                return(false);
            }

            //Assign it to the client identifier
            sender.ClientIdentifier     = $"{userId}";
            sender.Metadata["token"]    = token;
            sender.Metadata["domainId"] = userDomainId;

            return(true);
        }
        public async Task ConnectionLifecycleEventHandler()
        {
            var    count = 0;
            object eventSender = null, eventArgs = null;

            var handler = new ConnectionOpenedEventHandler((sender, args) =>
            {
                eventSender = sender;
                eventArgs   = args;
                count++;
                return(new ValueTask());
            });

            var client = Mock.Of <IHazelcastClient>();
            var args   = new ConnectionOpenedEventArgs(true);
            await handler.HandleAsync(client, args);

            Assert.That(count, Is.EqualTo(1));
            Assert.That(eventSender, Is.SameAs(client));
            Assert.That(eventArgs, Is.SameAs(args));
        }
示例#12
0
        private static void MqttConnectionOpened(object sender, ConnectionOpenedEventArgs e)
        {
            Debug.WriteLine($"Connection open");
            Debug.WriteLine($"  ClientID: {((MqttClient)sender).ClientId}");
            Debug.WriteLine($"  Assigned client id: {e.Message.AssignedClientIdentifier}");
            if (e.Message.AuthenticationData != null)
            {
                Debug.WriteLine($"  Auth data length: {e.Message.AuthenticationData.Length}");
            }
            Debug.WriteLine($"  Auth method: {e.Message.AuthenticationMethod}");
            Debug.WriteLine($"  Dup flag: {e.Message.DupFlag}");
            Debug.WriteLine($"  Max packet size: {e.Message.MaximumPacketSize}");
            Debug.WriteLine($"  Max QoS: {e.Message.MaximumQoS}");
            Debug.WriteLine($"  Msg ID: {e.Message.MessageId}");
            Debug.WriteLine($"  Qos level: {e.Message.QosLevel}");
            Debug.WriteLine($"  Reason: {e.Message.Reason}");
            Debug.WriteLine($"  Receive max: {e.Message.ReceiveMaximum}");
            Debug.WriteLine($"  Rep info: {e.Message.ResponseInformation}");
            Debug.WriteLine($"  Retain: {e.Message.Retain}");
            Debug.WriteLine($"  Retain available: {e.Message.RetainAvailable}");
            Debug.WriteLine($"  Return code: {e.Message.ReturnCode}");
            Debug.WriteLine($"  Server keep alive: {e.Message.ServerKeepAlive}");
            Debug.WriteLine($"  Server ref: {e.Message.ServerReference}");
            Debug.WriteLine($"  Session exp inter: {e.Message.SessionExpiryInterval}");
            Debug.WriteLine($"  Session present: {e.Message.SessionPresent}");
            Debug.WriteLine($"  Shared subs available: {e.Message.SharedSubscriptionAvailable}");
            Debug.WriteLine($"  Shared identifier available: {e.Message.SubscriptionIdentifiersAvailable}");
            Debug.WriteLine($"  Topic alias max: {e.Message.TopicAliasMaximum}");
            Debug.WriteLine($"  Num user props: {e.Message.UserProperties.Count}");
            foreach (UserProperty prop in e.Message.UserProperties)
            {
                Debug.WriteLine($"    Key  : {prop.Name}");
                Debug.WriteLine($"    Value: {prop.Value}");
            }

            Debug.WriteLine($"  Wildcard available: {e.Message.WildcardSubscriptionAvailable}");
        }
示例#13
0
        private void OnConnectionOpened(object sender, ConnectionOpenedEventArgs e)
        {
            NetworkConnection connection = e.Connection;

            Console.WriteLine("{0}: {1} connected to service", connection.BelongListener.Name, connection.Id);
        }
示例#14
0
 protected virtual void OnConnectionOpened(ConnectionOpenedEventArgs args)
 {
 }
示例#15
0
 /// <summary>
 /// Called when [open].
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="args">The <see cref="T:PWebSocketServer.Common.Events.ConnectionOpenedEventArgs" /> instance containing the event data.</param>
 public virtual void OnOpen(IWebSocketConnection sender, ConnectionOpenedEventArgs args)
 {
 }
示例#16
0
 protected override void OnConnectionOpened(ConnectionOpenedEventArgs args)
 {
     InitSession();
 }