コード例 #1
0
        public async Task GetConnectionId()
        {
            var httpContext = this.Context.GetHttpContext();
            var username    = httpContext.Request.Query["username"];

            if (string.IsNullOrEmpty(username))
            {
                username = Context.User.Identity.Name;
            }

            Debug.WriteLine($"GetConnectionId() username={username}");

            if (!string.IsNullOrEmpty(username))
            {
                _connectionManager.AddConnection(username, Context.ConnectionId);
            }


            var group = httpContext.Request.Query["group"];

            if (!string.IsNullOrEmpty(group))
            {
                await AddToGroup(group);
            }
        }
コード例 #2
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            disposables.Add(host);
            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    if (isDotCom)
                    {
                        GitHubHost = host;
                    }
                    else
                    {
                        EnterpriseHost = host;
                    }
                    connectionManager.AddConnection(address, usernameOrEmail);
                }
            }));
        }
コード例 #3
0
        public string GetConnectionId()
        {
            var httpContext = Context.GetHttpContext();
            var userId      = httpContext.Request.Query["userId"];

            _connectionManager.AddConnection(userId, Context.ConnectionId);
            return(Context.ConnectionId);
        }
コード例 #4
0
        public override Task OnConnectedAsync()
        {
            var httpContext = this.Context.GetHttpContext();
            var userName    = httpContext.Request.Query["username"];

            _connectionManager.AddConnection(userName, Context.ConnectionId);
            return(base.OnConnectedAsync());
        }
コード例 #5
0
        public string GetConnectionId()
        {
            var username = GetUsername();

            _manager.AddConnection(username, Context.ConnectionId);

            return(Context.ConnectionId);
        }
コード例 #6
0
        public override Task OnConnectedAsync()
        {
            string userId       = _authService.GetCurrentUserId();
            string connectionId = Context.ConnectionId;

            _connectionManager.AddConnection(userId, connectionId);

            return(base.OnConnectedAsync());
        }
コード例 #7
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            Guard.ArgumentNotNull(address, nameof(address));
            Guard.ArgumentNotEmptyString(usernameOrEmail, nameof(usernameOrEmail));
            Guard.ArgumentNotEmptyString(password, nameof(password));

            var isDotCom = HostAddress.GitHubDotComHostAddress == address;

            return(Observable.Defer(async() =>
            {
                var host = await RepositoryHostFactory.Create(address);

                return host.LogIn(usernameOrEmail, password)
                .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                .ObserveOn(RxApp.MainThreadScheduler)
                .Do(result =>
                {
                    bool successful = result.IsSuccess();
                    log.Information("Log in to {Host} host '{ApiUri}' with username '{UsernameOrEmail}' {Successful}",
                                    isDotCom ? "GitHub.com" : address.WebUri.Host,
                                    address.ApiUri,
                                    usernameOrEmail,
                                    successful ? "SUCCEEDED" : "FAILED"
                                    );
                    if (successful)
                    {
                        // Make sure that GitHubHost/EnterpriseHost are set when the connections
                        // changed event is raised and likewise that the connection is added when
                        // the property changed notification is sent.
                        if (isDotCom)
                        {
                            githubHost = host;
                        }
                        else
                        {
                            enterpriseHost = host;
                        }

                        connectionManager.AddConnection(address, usernameOrEmail);

                        if (isDotCom)
                        {
                            this.RaisePropertyChanged(nameof(GitHubHost));
                        }
                        else
                        {
                            this.RaisePropertyChanged(nameof(EnterpriseHost));
                        }
                    }
                });
            }));
        }
コード例 #8
0
ファイル: LoginHandler.cs プロジェクト: anlei-fu/Jasmine
        public override void ChannelRead(IChannelHandlerContext context, object message)
        {
            var msg = message as Event;

            if (msg == null)
            {
            }

            if (!_manager.ConnectionRegisted(context.Channel.Id.AsLongText()))
            {
                if (msg.EventType == EventType.Login)
                {
                    if (_serializer.TryDeserialize <LoginInfo>(msg.Content, out var info))
                    {
                        if (_validator.Validate(info.User, info.Password))
                        {
                            _manager.AddConnection(context.Channel.Id.AsLongText(), new ConnectionInfo(context.Channel));
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                    }
                }
                else
                {
                }
            }
            else if (msg.EventType == EventType.HeartBeat)
            {
            }
            else if (msg.EventType == EventType.Request)
            {
                if (_serializer.TryDeserialize <ConfigCenterServiceRequest>(msg.Content, out var request))
                {
                }
                else
                {
                    context.FireChannelRead(request);
                }
            }
            else
            {
            }
        }
コード例 #9
0
        public IObservable <AuthenticationResult> LogIn(
            HostAddress address,
            string usernameOrEmail,
            string password)
        {
            var isDotCom = HostAddress.GitHubDotComHostAddress == address;
            var host     = RepositoryHostFactory.Create(address);

            return(host.LogIn(usernameOrEmail, password)
                   .Catch <AuthenticationResult, Exception>(Observable.Throw <AuthenticationResult>)
                   .Do(result =>
            {
                bool successful = result.IsSuccess();
                log.Info(CultureInfo.InvariantCulture, "Log in to {3} host '{0}' with username '{1}' {2}",
                         address.ApiUri,
                         usernameOrEmail,
                         successful ? "SUCCEEDED" : "FAILED",
                         isDotCom ? "GitHub.com" : address.WebUri.Host
                         );
                if (successful)
                {
                    // Make sure that GitHubHost/EnterpriseHost are set when the connections
                    // changed event is raised and likewise that the connection is added when
                    // the property changed notification is sent.
                    if (isDotCom)
                    {
                        githubHost = host;
                    }
                    else
                    {
                        enterpriseHost = host;
                    }

                    connectionManager.AddConnection(address, usernameOrEmail);

                    if (isDotCom)
                    {
                        this.RaisePropertyChanged(nameof(GitHubHost));
                    }
                    else
                    {
                        this.RaisePropertyChanged(nameof(EnterpriseHost));
                    }
                }
            }));
        }
コード例 #10
0
        public async Task ProcessIncomingPacketAsync(Packet packet)
        {
            if (packet is ConnectionPacket)
            {
                var connectionPacket = packet as ConnectionPacket;
                var acceptPacket     = new AcceptConnectionPacket();

                var addedClient     = _connectionManager.AddConnection(connectionPacket);
                var connectedClient = _connectionManager.GetClientById(addedClient.Id);

                _gameStateManager.AddPlayer(connectedClient.Id);

                var currentWorldState = _gameStateManager.GetLastWorldState();

                await _socketManager.SendAsync(acceptPacket.SetIdentifier(addedClient.Id)
                                               .SetWorldState(currentWorldState)
                                               .Serialize(),
                                               connectedClient);

                await _socketManager.SendAsync(connectionPacket
                                               .SetIdentifier(addedClient.Id)
                                               .Serialize(),
                                               recipients : _connectionManager.GetAllAvailableRecipients(),
                                               except : connectedClient
                                               );
            }

            if (packet is PingPacket)
            {
                var pingPacket = packet as PingPacket;

                _connectionManager.SetAsPinged(pingPacket.ClientId);

                await _clientManager.PingClientAsync(pingPacket.ClientId);
            }

            if (packet is MovementPacket)
            {
                var movementPacket = packet as MovementPacket;

                _gameStateManager.MovePlayer(movementPacket.ClientId, movementPacket.PacketSequenceNumber, movementPacket.Direction);
            }
        }
コード例 #11
0
        public Task <string> GetConnectionId()
        {
            _connectionManager.AddConnection(Guid.Empty, Context.ConnectionId);

            return(Task.FromResult(Context.ConnectionId));
        }
コード例 #12
0
 public override async Task OnConnectedAsync() => await _connectionManager.AddConnection(Context.ConnectionId);
コード例 #13
0
        public async Task ConnectionAddAsync(string userId)
        {
            await Groups.AddToGroupAsync(Context.ConnectionId, userId);

            await _connectionManager.AddConnection(userId, Context.ConnectionId);
        }