コード例 #1
0
        public bool Equals(UniFeederAuthorizationOption obj)
        {
            if (obj is null)
            {
                return(false);
            }

            return(
                obj.Login == this.Login &&
                obj.Password == this.Password
                );
        }
コード例 #2
0
        private void FillAuth(IRxSocketClient accept, UniFeederAuthorizationOption auth, string message)
        {
            if (string.IsNullOrEmpty(auth.Login))
            {
                auth.Login = message;

                "> Password: ".ToUniFeederByteArray().SendTo(accept);

                return;
            }

            if (string.IsNullOrEmpty(auth.Password))
            {
                auth.Password = message;
                return;
            }
        }
コード例 #3
0
 private bool Authentificate(UniFeederAuthorizationOption auth)
 {
     return(option.Value.Authorization.Any(a => a.Equals(auth)));
 }
コード例 #4
0
        protected void UniFeederServer(IRxSocketServer server)
        {
            server.AcceptObservable.Subscribe(onNext: accept =>
            {
                @"> Universal DDE Connector 9.00
> Copyright 1999 - 2008 MetaQuotes Software Corp.
> Login: "******"accepted new client {0}", clientId);

                accept.ReceiveObservable.ToUniFeederStrings().Subscribe(
                    onNext: message =>
                {
                    logger.LogDebug("client: {0} receive message: {1}", clientId, message);

                    if (!clients.ContainsKey(clientId) && DateTimeOffset.UtcNow >= ended)
                    {
                        accept.Dispose();
                        logger.LogInformation("a non-authenticated client {0} is disconnected after 5 seconds inactivity", clientId);
                        return;
                    }

                    if (!auth.IsFilled)
                    {
                        FillAuth(accept, auth, message);
                    }

                    if (auth.IsFilled)
                    {
                        if (Authentificate(auth))
                        {
                            if (clients.TryAdd(clientId, accept))
                            {
                                "> Access granted".ToUniFeederByteArray().SendTo(accept);
                            }
                            else
                            {
                                switch (message)
                                {
                                case "> Ping": "> Ping".ToUniFeederByteArray().SendTo(accept); logger.LogDebug("send Ping to client {0}", clientId); break;

                                default: break;
                                }
                            }
                        }
                        else
                        {
                            "> Access denied".ToUniFeederByteArray().SendTo(accept);
                            accept.Dispose();
                        }
                    }
                },
                    onError: e =>
                {
                    RemoveClient(clientId, 5);
                    logger.LogError("client: {0} rxsocket error {1}. client disposed. current clients: {2}", clientId, e.Message, clients.Count);
                },
                    onCompleted: () =>
                {
                    RemoveClient(clientId, 5);
                    logger.LogInformation("client: {0} rxsocket complited. client disposed. current clients: {1}", clientId, clients.Count);
                }
                    );
            });
        }