public void ComplicatedMessageDeserializationTest()
        {
            var xml = @"<ComplicatedMessage>
                  <Lookup>
                    <Element>
                      <Key>1</Key>
                      <Value>A</Value>
                    </Element>
                    <Element>
                      <Key>2</Key>
                      <Value>B</Value>
                    </Element>
                  </Lookup>
                  <Things>
                    <Element>C</Element>
                    <Element>D</Element>
                  </Things>
                </ComplicatedMessage>";

            var target = new SimpleXmlMessageSerializaion()
            {
                MessageTypes = new[] { typeof(ComplicatedMessage) }
            };
            
            var result = target.Deserialize(xml) as ComplicatedMessage;
            Assert.AreEqual("A", result.Lookup[1]);
            Assert.AreEqual("B", result.Lookup[2]);
            Assert.AreEqual("C", result.Things[0]);
            Assert.AreEqual("D", result.Things[1]);
        }
        public void ComplicatedMessageSerializationTest()
        {
            var expected = @"<ComplicatedMessage>
                  <Lookup>
                    <Element>
                      <Key>1</Key>
                      <Value>A</Value>
                    </Element>
                    <Element>
                      <Key>2</Key>
                      <Value>B</Value>
                    </Element>
                  </Lookup>
                  <Things>
                    <Element>C</Element>
                    <Element>D</Element>
                  </Things>
                </ComplicatedMessage>";

            var m = new ComplicatedMessage()
            {
                Lookup = new Dictionary<int, string> { { 1, "A" }, { 2, "B" }, },
                Things = new List<string> { "C", "D" }
            };
            var target = new SimpleXmlMessageSerializaion();
            var xml = target.Serialize(m);
            Assert.AreEqual(XElement.Parse(expected).ToString(), XElement.Parse(xml).ToString());
        }
示例#3
0
        public static IEventFeedSubscription AsASubscriber(string endpoint, string connectionStringName, Type[] eventTypes, Type[] handlerTypes)
        {
            var handlerCollection = new HandlerCollection();
            handlerCollection.AddRange(handlerTypes);

            var deserializer = new SimpleXmlMessageSerializaion { MessageTypes = eventTypes };

            var subscriberPersistance = new Subscriber.Persistance.SqlPersistance(connectionStringName);

            var failureChannel = new FailureChannel(subscriberPersistance)
            {
                PollingInterval = new TimeSpan(0, 1, 0)
            };

            var processingChannel = new ProcessingChannel(deserializer, handlerCollection);

            var subscription = new EventFeedObserver(new Uri(endpoint), new AtomFormatter(), new FeedChainFactory(), subscriberPersistance)
            {
                PollingInterval = new TimeSpan(0, 1, 0)
            };

            //deadletter messages when they fail
            processingChannel.MessageFailed += (sender, args) => failureChannel.DeadLetter(args.Message, args.Exception);

            //process messages in handlers when they're picked up from the feed
            subscription.EventReceived += processingChannel.ProcessEvent;

            //process failed messages again when they're reader
            failureChannel.MessageReadyForRetry += processingChannel.ProcessEvent;

            //remove failed messages once they're successfully processed
            processingChannel.MessageProcessed += (sender, message) => failureChannel.ClearFailure(message);

            failureChannel.Poll();

            return subscription;
        }
 public void DeserializeMessage()
 {
     var xml = @"<MessageA><Name>ABC</Name><Duration>1</Duration></MessageA>";
     var target = new SimpleXmlMessageSerializaion() { MessageTypes = new[] { typeof(MessageA) } };
     var result = target.Deserialize(xml);
     Assert.IsInstanceOf<MessageA>(result);
     Assert.AreEqual("ABC", (result as MessageA).Name);
     Assert.AreEqual(1, (result as MessageA).Duration);
 }
 public void SerializeMessage()
 {
     var target = new SimpleXmlMessageSerializaion();
     var xml = target.Serialize(new MessageA { Name = "ABC", Duration = 1 });
     Assert.AreEqual(XElement.Parse(@"<MessageA><Name>ABC</Name><Duration>1</Duration></MessageA>").ToString(), XElement.Parse(xml).ToString());
 }
 public void DeserializeMissingTypeMessage()
 {
     var xml = @"<MessageB></MessageB>";
     var target = new SimpleXmlMessageSerializaion() { MessageTypes = new[] { typeof(MessageA) } };
     var result = target.Deserialize(xml);
     Assert.IsInstanceOf<MissingMessage>(result);
 }