A bauyeux message
예제 #1
0
 private void Process(Message message)
 {
     IMessageHandler handler = this.messageHandlerFactory.GetMessageHandler(message.channel);
     MessageHandlerResult handlerResult = handler.HandleMessage(message);
     this.response.Add(handlerResult.Message);
     this.ShouldSendResultStraightBackToClient |= !handlerResult.CanTreatAsLongPoll;
 }
예제 #2
0
        public void HandleMessages(Message[] messages, ICometAsyncResult asyncResult)
        {
            // Do this before we process the messages in case it's a disconnect
            IClient sendingClient = GetSenderOf(messages);

            IMessagesProcessor processor = this.CreateProcessorAndProcess(messages);

            if (sendingClient == null)
            {
                asyncResult.CompleteRequestWithMessages(processor.Result);
                return;
            }

            if (sendingClient.CurrentAsyncResult != null)
            {
                sendingClient.FlushQueue();
            }

            sendingClient.CurrentAsyncResult = asyncResult;
            sendingClient.Enqueue(processor.Result);

            if (processor.ShouldSendResultStraightBackToClient)
            {
                sendingClient.FlushQueue();
            }
        }
예제 #3
0
 private void CopyMessageToMembers(object toDecode, Message message)
 {
     var data = message.data as Dictionary<string, object>;
     foreach (KeyValuePair<string, object> propertyValueCrt in data)
     {
         SetProperty(toDecode, propertyValueCrt.Key, propertyValueCrt.Value);
     }
 }
예제 #4
0
        public object Decode(Message message)
        {
            string typeCode = message.GetData<string>("type");

            Type objectType = FindObjectType(typeCode);
            var toDecode = Activator.CreateInstance(objectType);
            CopyMessageToMembers(toDecode, message);
            return toDecode;
        }
 public void MessageHandlerDispatchesByType()
 {
     Message message = new Message();
     message.SetData("type", "type1");
     MessageMap messageMap = new MessageMap(GetType().Assembly, "CometGateway.Server.Gateway.Tests.SampleMessages");
     SampleHandler handler = new SampleHandler(messageMap);
     handler.HandleMessage(message);
     Assert.AreEqual("SampleMessage1", handler.called);
 }
예제 #6
0
        public Message Encode(object toEncode)
        {
            string messageType = FindMessageType(toEncode.GetType());

            Message message = new Message();
            message.SetData("type", messageType);
            CopyMembersToMessage(message, toEncode);
            return message;
        }
        public void TestDecode()
        {
            var map = new MessageMap(new KeyValuePair<string, Type>[] { new KeyValuePair<string, Type>("type1", typeof(SampleObject)) });
            var message = new Message();
            message.SetData("type", "type1");
            message.SetData("V1", "ABC");
            message.SetData("V2", 5);
            var obj = map.Decode(message) as SampleObject;

            Assert.AreEqual("ABC", obj.V1);
            Assert.AreEqual(5, obj.V2);
        }
예제 #8
0
        private void CopyMembersToMessage(Message message, object toEncode)
        {
            foreach (string fieldNameCrt in GetFieldsOf(toEncode))
            {
                message.SetData(fieldNameCrt, GetFieldValue(toEncode, fieldNameCrt));
            }

            foreach (string propertyNameCrt in GetPropertiesOf(toEncode))
            {
                message.SetData(propertyNameCrt, GetPropertyValue(toEncode, propertyNameCrt));
            }
        }
        public static TelnetProtocolTranslator FindTranslatorObject(
            IMessageHandlerCache cache,
            Message message,
            Func<MessageHandler> messageHandlerFactory
            )
        {
            var messageHandler = cache[message.clientId];
            if (messageHandler == null)
            {
                messageHandler = messageHandlerFactory();
                cache[message.clientId] = messageHandler;
            }

            return cache[message.clientId] as TelnetProtocolTranslator;
        }
 public void Handle(TextEnteredMessage message, Message rawMessage)
 {
     socketConnection.Send(message.text);
 }
 public void Handle(ConnectMessage message, Message rawMessage)
 {
     socketConnection.StartConnect(message.server, message.port);
     ConfigureForHandling(rawMessage);
 }
        private void ConfigureForHandling(Message rawMessage)
        {
            ClientId = rawMessage.clientId;
            Channel = rawMessage.channel;

            socketConnection.ConnectionSucceeded += OnConnectSucceeded;
            socketConnection.ErrorOccurred += OnErrorOccurred;
            socketConnection.ServerDisconnected += OnDisconnected;
            socketConnection.DataReceived += OnDataReceived;
        }
예제 #13
0
        private void SendSyncMessage(
            IEnumerable<IClient> clients,
            string channel, bool isReply,
            int fromRevisionNumber, WikiPageRevision toRevision,
            string patch
            )
        {
            Contract.Requires<ArgumentException>(isReply || !string.IsNullOrEmpty(patch));

            var html = this.syntax.Convert(toRevision.Text, this.htmlWikiOutput);
            var message = new Message {
                channel = channel,
                data = new {
                    isreply = isReply,
                    revision = new {
                        from = fromRevisionNumber,
                        to = toRevision.Number
                    },
                    patch, html
                }
            };

            foreach (var client in clients) {
                client.Enqueue(message);
                client.FlushQueue();
            }
        }
 public void Handle(SampleMessage2 message, Message rawMessage)
 {
     Record("SampleMessage2", rawMessage.clientId);
 }
        public void FindTranslatorObject_MakesNewObjectIfNeeded()
        {
            MockRepository mockRepository = new MockRepository();

            var clientRepository = mockRepository.Stub<IClientRepository>();
            var aClient = mockRepository.StrictMock<IClient>();
            clientRepository.Expect(repository => repository.GetByID("abc"))
                            .Return(aClient);

            var message = new Message();
            message.clientId = "abc";

            var cache = new MessageHandlerCache();
            TelnetProtocolTranslator translator = new TelnetProtocolTranslator(null, null, null);

            Assert.AreEqual(translator, TelnetProtocolTranslator.FindTranslatorObject(cache, message, ()=>translator));
        }
        public void FindTranslatorObject_ReturnsExistingObject()
        {
            MockRepository mockRepository = new MockRepository();

            var clientRepository = mockRepository.Stub<IClientRepository>();
            var aClient = mockRepository.StrictMock<IClient>();
            clientRepository.Expect(repository => repository.GetByID("abc"))
                            .Return(aClient);

            Message message = new Message();
            message.clientId = "abc";

            var cache = new MessageHandlerCache();
            var translator = new TelnetProtocolTranslator(null, null, null);
            cache["abc"] = translator;

            Assert.AreEqual(translator, TelnetProtocolTranslator.FindTranslatorObject(cache, message, null));
        }
        public void ConnectStartsConnectionAndCaches()
        {
            MockRepository mockRepository = new MockRepository();
            var socketConnection = mockRepository.DynamicMock<IHTMLConnection>();
            TelnetProtocolTranslator connectMessageHandler =
                new TelnetProtocolTranslator(socketConnection, null, null);

            socketConnection.Expect(connection => connection.StartConnect("test.com", 25));

            socketConnection.Expect(connection => connection.ServerDisconnected += connectMessageHandler.OnDisconnected);
            socketConnection.Expect(connection => connection.ConnectionSucceeded += connectMessageHandler.OnConnectSucceeded);
            socketConnection.Expect(connection => connection.ErrorOccurred += connectMessageHandler.OnErrorOccurred);

            var message = new Message();
            message.SetData("type", "connect");
            message.SetData("server", "test.com");
            message.SetData("port", 25);
            message.clientId = "abc";
            message.channel = "def";

            mockRepository.ReplayAll();
            connectMessageHandler.HandleMessage(message);
            Assert.AreEqual("abc", connectMessageHandler.ClientId);
            Assert.AreEqual("def", connectMessageHandler.Channel);
            mockRepository.VerifyAll();
        }
        public void TextTypedForwardsLine()
        {
            MockRepository mockRepository = new MockRepository();
            var socketConnection = mockRepository.DynamicMock<IHTMLConnection>();
            var connectMessageHandler = new TelnetProtocolTranslator(socketConnection, null, null);

            socketConnection.Expect(connection => connection.Send("line typed"));

            var message = new Message();
            message.SetData("type", "textEntered");
            message.SetData("text", "line typed");

            mockRepository.ReplayAll();
            connectMessageHandler.HandleMessage(message);
            mockRepository.VerifyAll();
        }