Beispiel #1
0
        public void Connect(string host, int port, string login, string password, Proxy proxy)
        {
            if (IsConnected || IsConnecting)
            {
                return;
            }

            IsConnecting = true;
            var command = new CommandConnect()
            {
                Host          = host,
                Port          = port,
                Login         = login,
                Password      = password,
                AutoPos       = this.AutoPos,
                LogsDirectory = this.LogsDirectory.EndsWith("\\") ? this.LogsDirectory : this.LogsDirectory + "\\",
                LogLevel      = this.LogLevel,
                NotesFileName = this.NotesFileName,
                Proxy         = proxy,
            };

            try
            {
                SendCommand(command);
            }
            catch
            {
                IsConnecting = false;
                throw;
            }
        }
        public MainWindow()
        {
            InitializeComponent();

            EndpointAddress endpointAddress = new EndpointAddress("http://localhost:31337/BesiegedServer/BesiegedMessage");
            DuplexChannelFactory<IBesiegedServer> duplexChannelFactory = new DuplexChannelFactory<IBesiegedServer>(m_Client, new WSDualHttpBinding(), endpointAddress);
            m_BesiegedServer = duplexChannelFactory.CreateChannel();

            // Subscribe in a separate thread to preserve the UI thread
            Task.Factory.StartNew(() =>
            {
                CommandConnect commandConnect = new CommandConnect();
                m_BesiegedServer.SendMessage(commandConnect.ToXml());
            });

            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    Command command = m_Client.MessageQueue.Take();
                    ProcessMessage(command);
                }
            }, TaskCreationOptions.LongRunning);

            GameLobbyCollection = new ObservableCollection<CommandNotifyGame>();
            DataContext = this;
        }
Beispiel #3
0
 public static BaseCommand ToBaseCommand(this CommandConnect connect)
 {
     return(new BaseCommand
     {
         type = BaseCommand.Type.Connect,
         Connect = connect
     });
 }
Beispiel #4
0
 public static BaseCommand AsBaseCommand(this CommandConnect command)
 {
     return(new BaseCommand
     {
         CommandType = BaseCommand.Type.Connect,
         Connect = command
     });
 }
 public ConnectionPool(CommandConnect commandConnect, Uri serviceUrl, Connector connector, EncryptionPolicy encryptionPolicy, TimeSpan closeInactiveConnectionsInterval)
 {
     _lock                     = new AsyncLock();
     _commandConnect           = commandConnect;
     _serviceUrl               = serviceUrl;
     _connector                = connector;
     _encryptionPolicy         = encryptionPolicy;
     _connections              = new ConcurrentDictionary <Uri, Connection>();
     _cancellationTokenSource  = new CancellationTokenSource();
     _closeInactiveConnections = CloseInactiveConnections(closeInactiveConnectionsInterval, _cancellationTokenSource.Token);
 }
Beispiel #6
0
 public ConnectionPool(CommandConnect commandConnect, Uri serviceUrl, Connector connector, EncryptionPolicy encryptionPolicy)
 {
     _lock                     = new AsyncLock();
     _commandConnect           = commandConnect;
     _serviceUrl               = serviceUrl;
     _connector                = connector;
     _encryptionPolicy         = encryptionPolicy;
     _connections              = new ConcurrentDictionary <Uri, Connection>();
     _cancellationTokenSource  = new CancellationTokenSource();
     _closeInactiveConnections = CloseInactiveConnections(TimeSpan.FromSeconds(60), _cancellationTokenSource.Token);  //TODO Get '60' from configuration
 }
Beispiel #7
0
 public PulsarClientBuilder()
 {
     _commandConnect = new CommandConnect
     {
         ProtocolVersion = Constants.ProtocolVersion,
         ClientVersion   = Constants.ClientVersion
     };
     _retryInterval              = TimeSpan.FromSeconds(3);
     _serviceUrl                 = new Uri(Constants.PulsarScheme + "://localhost:" + Constants.DefaultPulsarPort);
     _clientCertificates         = new X509Certificate2Collection();
     _verifyCertificateAuthority = true;
     _verifyCertificateName      = false;
 }
Beispiel #8
0
 private static CommandConnect WithProxyToBroker(CommandConnect commandConnect, Uri logicalUrl)
 {
     return(new CommandConnect
     {
         AuthData = commandConnect.AuthData,
         AuthMethod = commandConnect.AuthMethod,
         AuthMethodName = commandConnect.AuthMethodName,
         ClientVersion = commandConnect.ClientVersion,
         OriginalPrincipal = commandConnect.OriginalPrincipal,
         ProtocolVersion = commandConnect.ProtocolVersion,
         OriginalAuthData = commandConnect.OriginalAuthData,
         OriginalAuthMethod = commandConnect.OriginalAuthMethod,
         ProxyToBrokerUrl = $"{logicalUrl.Host}:{logicalUrl.Port}"
     });
 }
Beispiel #9
0
        public async Task <BaseCommand> Send(CommandConnect command, CancellationToken cancellationToken)
        {
            ThrowIfDisposed();

            Task <BaseCommand>?responseTask;

            using (await _lock.Lock(cancellationToken).ConfigureAwait(false))
            {
                responseTask = _channelManager.Outgoing(command);
                var sequence = Serializer.Serialize(command.AsBaseCommand());
                await _stream.Send(sequence).ConfigureAwait(false);
            }

            return(await responseTask.ConfigureAwait(false));
        }
Beispiel #10
0
        public PulsarClientBuilder()
        {
            _commandConnect = new CommandConnect
            {
                ProtocolVersion = Constants.ProtocolVersion,
                ClientVersion   = Constants.ClientVersion
            };

            _exceptionHandlers                = new List <IHandleException>();
            _retryInterval                    = TimeSpan.FromSeconds(3);
            _serviceUrl                       = new Uri($"{Constants.PulsarScheme}://localhost:{Constants.DefaultPulsarPort}");
            _clientCertificates               = new X509Certificate2Collection();
            _verifyCertificateAuthority       = true;
            _verifyCertificateName            = false;
            _closeInactiveConnectionsInterval = TimeSpan.FromSeconds(60);
        }
Beispiel #11
0
        public static ReadOnlySequence <byte> NewConnect(string authMethodName, string authData, int protocolVersion, string libVersion, string targetBroker, string originalPrincipal, string originalAuthData, string originalAuthMethod)
        {
            var connect = new CommandConnect
            {
                ClientVersion  = libVersion ?? "Pulsar Client",
                AuthMethodName = authMethodName,
                FeatureFlags   = new FeatureFlags {
                    SupportsAuthRefresh = true
                }
            };

            if ("ycav1".Equals(authMethodName))
            {
                // Handle the case of a client that gets updated before the broker and starts sending the string auth method
                // name. An example would be in broker-to-broker replication. We need to make sure the clients are still
                // passing both the enum and the string until all brokers are upgraded.
                connect.AuthMethod = AuthMethod.AuthMethodYcaV1;
            }

            if (!ReferenceEquals(targetBroker, null))
            {
                // When connecting through a proxy, we need to specify which broker do we want to be proxied through
                connect.ProxyToBrokerUrl = targetBroker;
            }

            if (!ReferenceEquals(authData, null))
            {
                connect.AuthData = ByteString.CopyFromUtf8(authData).ToByteArray();
            }

            if (!ReferenceEquals(originalPrincipal, null))
            {
                connect.OriginalPrincipal = originalPrincipal;
            }

            if (!ReferenceEquals(originalAuthData, null))
            {
                connect.OriginalAuthData = originalAuthData;
            }

            if (!ReferenceEquals(originalAuthMethod, null))
            {
                connect.OriginalAuthMethod = originalAuthMethod;
            }
            connect.ProtocolVersion = protocolVersion;
            return(Serializer.Serialize(connect.ToBaseCommand()));
        }
Beispiel #12
0
        public static ReadOnlySequence <byte> NewConnect(string authMethodName, AuthData authData, int protocolVersion, string libVersion, string targetBroker, string originalPrincipal, AuthData originalAuthData, string originalAuthMethod)
        {
            var connect = new CommandConnect
            {
                ClientVersion  = libVersion,
                AuthMethodName = authMethodName,
                FeatureFlags   = new FeatureFlags {
                    SupportsAuthRefresh = true
                }
            };

            if (!string.IsNullOrWhiteSpace(targetBroker))
            {
                // When connecting through a proxy, we need to specify which broker do we want to be proxied through
                connect.ProxyToBrokerUrl = targetBroker;
            }

            if (authData != null)
            {
                connect.AuthData = authData.auth_data;
            }

            if (!string.IsNullOrWhiteSpace(originalPrincipal))
            {
                connect.OriginalPrincipal = originalPrincipal;
            }

            if (originalAuthData != null)
            {
                connect.OriginalAuthData = Encoding.UTF8.GetString(originalAuthData.auth_data);
            }

            if (!string.IsNullOrWhiteSpace(originalAuthMethod))
            {
                connect.OriginalAuthMethod = originalAuthMethod;
            }
            connect.ProtocolVersion = protocolVersion;
            var ba = connect.ToBaseCommand();

            return(Serializer.Serialize(ba));
        }
Beispiel #13
0
        //Connect to server
        private void Connect(string login, string password, string server, string port)
        {
            IsDisconnecting = false;
            //create xml command
            var cmd = new CommandConnect
            {
                Id             = "connect",
                Login          = login,
                Password       = password,
                Host           = server,
                Port           = port,
                Language       = "en",
                Milliseconds   = true,
                Rqdelay        = 100,
                SessionTimeout = 200,
                RequestTimeout = 20
            };
            string command;

            using (var stream = new StringWriter())
            {
                using (var writer = XmlWriter.Create(stream, new XmlWriterSettings
                {
                    Indent = true,
                    OmitXmlDeclaration = true
                }))
                {
                    new XmlSerializer(typeof(Models.CommandConnect)).Serialize(writer, cmd,
                                                                               new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty }));
                    command = stream.ToString();
                }
            }
            TXmlConnector.ConnectorSendCommand(command);
            Status = "Status: Connecting..."; //set status string
            MenuItemConnectEnabled = false;   //disable connect/disconnect button until status is changed
            IsActive = true;
        }
 public Task <BaseCommand> Send(CommandConnect command, CancellationToken cancellationToken)
 => SendRequestResponse(command.AsBaseCommand(), cancellationToken);
Beispiel #15
0
 public Task <BaseCommand> Outgoing(CommandConnect command)
 => _requestResponseHandler.Outgoing(command);
Beispiel #16
0
 public Task <BaseCommand> Outgoing(CommandConnect _1)
 => _requests.CreateTask(new ConnectRequest());
Beispiel #17
0
 public async Task <BaseCommand> Send(CommandConnect command) => await SendRequestResponse(command.AsBaseCommand());