Esempio n. 1
0
File: Ssh.cs Progetto: 4vz/Aveezo
        private async Task Main()
        {
            IsReconnect = true;

            while (true)
            {
                try
                {
                    if (client != null)
                    {
                        client.Dispose();
                    }

                    await OnBeforeConnect();

                    BeforeConnect?.Invoke(this, new EventArgs());

                    client = new SshClient(Host, User, Password);

                    await OnConnecting();

                    Connecting?.Invoke(this, new EventArgs());

                    client.Connect();
                }
                catch (Exception ex)
                {
                    var connectionFailArgs = new SshConnectionFailEventArgs(ex.Message switch
                    {
                        "No such host is known" => SshConnectionFailReason.HostUnknown,
                        "A socket operation was attempted to an unreachable host." => SshConnectionFailReason.HostUnreachable,
                        string b when b.IndexOf("connected party did not properly") > -1 => SshConnectionFailReason.TimeOut,
                        "Permission denied (password)." => SshConnectionFailReason.AuthenticationFailed,
                        _ => SshConnectionFailReason.Unknown
                    }, ex.Message);
Esempio n. 2
0
            protected override (CircuitHost, bool) ConnectCore(string circuitId, IClientProxy clientProxy, string connectionId)
            {
                if (BeforeConnect != null)
                {
                    Assert.True(BeforeConnect?.Wait(TimeSpan.FromSeconds(10)), "BeforeConnect failed to be set");
                }

                return(base.ConnectCore(circuitId, clientProxy, connectionId));
            }
Esempio n. 3
0
        private void _listener_Accepted(IChannelListener <TChannel> sender, TChannel channel)
        {
            channel.OnDisconnect += Channel_OnDisconnect;

            if (!channel.IsConnected)
            {
                return;
            }
            var connection = _connectionBuilder.UseChannel(channel).Build();

            var beforeConnectEventArgs = new BeforeConnectEventArgs <TContract, TChannel>(connection);

            BeforeConnect?.Invoke(this, beforeConnectEventArgs);
            if (!beforeConnectEventArgs.AllowConnection)
            {
                return;
            }

            channel.AllowReceive = true;
            _connections.TryAdd(channel, connection);
            AfterConnect?.Invoke(this, connection);
        }