Beispiel #1
0
        public void DeserializeMessage_Returns_None_When_No_Type_Available()
        {
            var             typeLookup    = new Dictionary <string, Type>();
            Option <object> domainMessage = MessageDeserializer.Deserialize(
                typeLookup,
                TestEvent.MessageType,
                JsonConvert.SerializeObject(new TestEvent(Guid.NewGuid()))
                );

            domainMessage.IsNone.Should().BeTrue();
        }
        public void UtcDateDeserializedToUtc()
        {
            // Kind is set to Utc
            string json = "{\"assetPair\":\"BTCUSD\",\"isBuy\":true,\"timestamp\":\"2009-02-15T15:02:00Z\","
                          + "\"prices\":[{\"volume\":0.52,\"price\":933.89},{\"volume\":43.78618975,\"price\":933.88},{\"volume\":6.4028,\"price\":933.62}]}";

            var       deserializer = new MessageDeserializer();
            OrderBook model        = deserializer.Deserialize(Encoding.UTF8.GetBytes(json));

            Assert.Equal(model.Timestamp, new DateTime(2009, 2, 15, 15, 2, 0, DateTimeKind.Utc));
            Assert.Equal(0, model.Timestamp.Kind.CompareTo(DateTimeKind.Utc));
        }
        public void UnspecifiedDateDeserializedToUtc()
        {
            // Kind is unspecified
            string json = "{\"assetPair\":\"BTCUSD\",\"isBuy\":true,\"timestamp\":\"Jan 31, 2017 11:38:49 AM\","
                          + "\"prices\":[{\"volume\":0.52,\"price\":933.89},{\"volume\":43.78618975,\"price\":933.88},{\"volume\":6.4028,\"price\":933.62}]}";

            var       deserializer = new MessageDeserializer();
            OrderBook model        = deserializer.Deserialize(Encoding.UTF8.GetBytes(json));

            Assert.Equal(model.Timestamp, new DateTime(2017, 1, 31, 11, 38, 49, DateTimeKind.Utc));
            Assert.Equal(0, model.Timestamp.Kind.CompareTo(DateTimeKind.Utc));
        }
Beispiel #4
0
            public Option <object> ToDomainMessage(
                TransportMessage transportMessage)
            {
                var msgType = transportMessage.Metadata["messageType"]
                              .Value <string>();
                var             domainMessage = transportMessage.Message;
                Option <object> result        = MessageDeserializer.Deserialize(
                    _typeLookup,
                    msgType,
                    domainMessage);

                return(result);
            }
Beispiel #5
0
        public void can_deserialize_json_message_into_typed_equivalent()
        {
            var deserializer = new MessageDeserializer();
            var message      = deserializer.Deserialize(@"
                {
                    ""messageId"": ""b9f39581-ebc5-4544-8a15-acd08b144fd7"",
                    ""messageType"": ""query""
                }"
                                                        );

            Assert.That(message.MessageId, Is.EqualTo(Guid.Parse("b9f39581-ebc5-4544-8a15-acd08b144fd7")), "message id");
            Assert.That(message.PayloadType, Is.EqualTo(typeof(Query)), "message payload type");
            Assert.That(message.Payload, Is.TypeOf <Query>(), "message payload");
        }
Beispiel #6
0
        static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("Invalid parameter.\nUsage: {0} <hostID>",
                                  System.IO.Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location));
                return;
            }

            int hostID = 0;

            if (!int.TryParse(args[0], out hostID))
            {
                Console.WriteLine("FATAL: Failed to parse hostID commandline parameter.");
                return;
            }

            IPEndPoint localEndpoint = NetworkConfig.NodeEndpoints[hostID];

            ApplicationLogic   appLogic     = new ApplicationLogic();
            CommunicationLogic commLogic    = new CommunicationLogic(appLogic, hostID);
            ControlLogic       controlLogic = new ControlLogic(commLogic, localEndpoint);

            Console.WriteLine($"Node with Id {hostID} and IP-address {Dns.GetHostName().ToString()} started properly.");
            Console.WriteLine($"Listening to UDP-Port: {localEndpoint.Port}");
            var causallyOrderedMode = true;
            var modeString          = causallyOrderedMode ? "Causally ordered" : "Not causally ordered";

            Console.WriteLine($"Mode: {modeString}");
            Console.WriteLine("------------- Start listening to messages -------------");

            using (UdpClient client = new UdpClient(localEndpoint.Port, AddressFamily.InterNetwork))
            {
                while (true)
                {
                    IPEndPoint remoteEP = null;
                    byte[]     data     = client.Receive(ref remoteEP);

                    Message msg = MessageDeserializer.Deserialize(data);
                    controlLogic.HandleMessage(causallyOrderedMode, msg, remoteEP);
                }
            }
        }
Beispiel #7
0
        public void DeserializeMessage_Correctly_Deserializes_Message()
        {
            var typeLookup = new Dictionary <string, Type>()
            {
                { TestEvent.MessageType, typeof(TestEvent) }
            };

            var testEvent = new TestEvent(Guid.NewGuid());

            Option <object> domainMessage = MessageDeserializer.Deserialize(
                typeLookup,
                TestEvent.MessageType,
                JsonConvert.SerializeObject(testEvent)
                );

            domainMessage.Match(
                m => m.As <TestEvent>().Should().Be(testEvent),
                () => "should be Some".AssertFail());
        }
        public async Task ListenToNode()
        {
            using (UdpClient client = new UdpClient(1340, AddressFamily.InterNetwork))
            {
                while (true)
                {
                    UdpReceiveResult result = await client.ReceiveAsync();

                    Message msg = MessageDeserializer.Deserialize(result.Buffer);

                    TextBoxContent += string.Format("{0:HH:mm:ss}: Answer from {1}. Message: {2}\n Balance: {3} Clock: {4}\n",
                                                    DateTime.Now,
                                                    result.RemoteEndPoint,
                                                    msg.controlBlock.Command,
                                                    msg.communicationBlock.payload.balance,
                                                    msg.communicationBlock.clock);

                    NodeFromMessage(msg).CurrentBalance = msg.communicationBlock.payload.balance;
                    NodeFromMessage(msg).CurrentClock   = msg.communicationBlock.clock.ToString();
                }
            }
        }
Beispiel #9
0
            public void DeserializeMessage()
            {
                var testMessage = new TestMessage();

                testMessage.Name = "Test";
                var testMessageJson = JsonConvert.SerializeObject(testMessage);

                BusBodyMessage busBodyMessage = new BusBodyMessage();

                busBodyMessage.Message = testMessageJson;
                var busBodyJson = JsonConvert.SerializeObject(busBodyMessage);

                var message = new Amazon.SQS.Model.Message
                {
                    Body = busBodyJson
                };

                var sut = new MessageDeserializer();

                var actual = sut.Deserialize <TestMessage>(message);

                actual.Name = "ExpectedMessage";
            }
Beispiel #10
0
        public static RBigInt Deserialize(BaseMessage baseMessage)
        {
            var deserializer = new MessageDeserializer <RBigInt>();

            return(deserializer.Deserialize(baseMessage));
        }
        public static RegisterResponse Deserialize(BaseMessage baseMessage)
        {
            var deserializer = new MessageDeserializer <RegisterResponse>();

            return(deserializer.Deserialize(baseMessage));
        }
Beispiel #12
0
        public static Login Deserialize(BaseMessage baseMessage)
        {
            var deserializer = new MessageDeserializer <Login>();

            return(deserializer.Deserialize(baseMessage));
        }
        public static UserMultiplicativeGroup Deserialize(BaseMessage baseMessage)
        {
            var deserializer = new MessageDeserializer <UserMultiplicativeGroup>();

            return(deserializer.Deserialize(baseMessage));
        }
Beispiel #14
0
        public static LeaveGroupNotifier Deserialize(BaseMessage baseMessage)
        {
            var deserializer = new MessageDeserializer <LeaveGroupNotifier>();

            return(deserializer.Deserialize(baseMessage));
        }
Beispiel #15
0
        public void Handle(string json)
        {
            var message = _deserializer.Deserialize(json);

            Handle(message);
        }
Beispiel #16
0
 public static Message Deserialize(BaseMessage baseMessage)
 {
     var deserializer = new MessageDeserializer<Message>();
     return deserializer.Deserialize(baseMessage);
 }