コード例 #1
0
        public void Login(string userName)
        {
            Contract.Requires(!string.IsNullOrEmpty(userName));

            currentUserName = userName;

            var loginCommand = new LoginCommand(new UserInfo(userName));
            var message = CreateMessage(loginCommand);
            SendMessage(message);
        }
コード例 #2
0
        public void ConvertLoginCommandTest()
        {
            long version = 1;
            long messageId = 12312;
            string userName = "******";
            LoginCommand command = new LoginCommand(new UserInfo(userName));
            Message message = new Message(version, messageId, command);

            // Converting to xml
            DynamicXmlMessageConverter converter = new DynamicXmlMessageConverter();
            XElement xml = converter.ConvertToXml(message);

            // And back again
            Message message2 = converter.ConvertFromXml(xml);

            // Check message equivalence
            Assert.That(message2.Version, Is.EqualTo(message.Version));
            Assert.That(message2.Id, Is.EqualTo(message.Id));
            LoginCommand command2 = (LoginCommand) message2.Command;
            Assert.That(command2.UserInfo.Name, Is.EqualTo(userName));
        }
コード例 #3
0
ファイル: Server.cs プロジェクト: SergeyTeplyakov/CrazyTalk
        private void HandleLoginMessage(long incomingMessageId, LoginCommand command, IPEndPoint endPoint)
        {
            using (usersSync.UseWriteLock())
            {
                // Finding existing user or creating new one
                var currentUser = users.SingleOrDefault(ui => ui.UserInfo.Name == command.UserInfo.Name);
                if (currentUser == null)
                {
                    currentUser = new FullUserInfo(command.UserInfo);
                    users.Add(currentUser);
                }

                // Changing user state
                currentUser.OnConnect(endPoint);

                // Sending Ack message
                var ackCommand = new AckCommand(incomingMessageId);
                var message = CreateMessage(ackCommand);
                SendMessage(endPoint, message);

                // Sending updated state
                SendUpdatedUserState(currentUser);
            }
        }