public void Serialize_Deserialize_TransportMessage()
        {
            var types = new List<Type> { typeof(C1), typeof(C2) };
            var mapper = new MessageMapper();
            mapper.Initialize(types);
            var serializer = new XmlMessageSerializer(mapper);
            serializer.Initialize(types);

            var transportMessage = new TransportMessage();
            transportMessage.Id = Guid.NewGuid().ToString();
            transportMessage.IdForCorrelation = Guid.NewGuid().ToString();
            transportMessage.ReturnAddress = Guid.NewGuid().ToString();
            transportMessage.WindowsIdentityName = string.Empty;
            transportMessage.TimeSent = DateTime.Now;
            transportMessage.Headers = new List<HeaderInfo>();
            transportMessage.Body = new object[] { new C1() { Data = "o'tool" }, new C2() { Data = "Timmy" } };

            var newTransportMessage = Execute(transportMessage, serializer);

            var messages = newTransportMessage.Body;
            Assert.AreEqual(2, messages.Count());
            Assert.AreEqual(1, messages.Count(x => x is C1));
            Assert.AreEqual(1, messages.Count(x => x is C2));
            Assert.AreEqual("o'tool", ((C1)messages.First(x => x is C1)).Data);
            Assert.AreEqual("Timmy", ((C2)messages.First(x => x is C2)).Data);
            Assert.AreEqual(transportMessage.Id, newTransportMessage.Id);
            Assert.AreEqual(transportMessage.IdForCorrelation, newTransportMessage.IdForCorrelation);
            Assert.AreEqual(transportMessage.ReturnAddress, newTransportMessage.ReturnAddress);
            Assert.AreEqual(transportMessage.TimeSent, newTransportMessage.TimeSent);
            Assert.AreEqual(transportMessage.Headers, newTransportMessage.Headers);
            Assert.AreNotSame(transportMessage, newTransportMessage);
        }
示例#2
0
        public void Serialize_Deserialize_Multiple_Namespaces() {
            var types = new List<Type> { typeof(C1), typeof(C2) };
            var mapper = new MessageMapper();
            mapper.Initialize(types);
            var serializer = new XmlMessageSerializer(mapper);

            serializer.Initialize(types);

            Time(new IMessage[] { new C1() { Data = "o'tool" }, new C2() { Data = "Timmy" } }, serializer);
        }
示例#3
0
        private IStartableMessageBus Build() {
            var messageTypes = MessageTypeConventions.ScanAssembliesForMessageTypes(assembliesToScan);
            var messageMapper = new MessageMapper();
            messageMapper.SetMessageTypeConventions(this.MessageTypeConventions);
            messageMapper.Initialize(messageTypes);
            var allMessageTypes = messageTypes.Concat(messageMapper.DynamicTypes);

            MessageSerializer = new XmlMessageSerializer(messageMapper);
            (MessageSerializer as XmlMessageSerializer).Initialize(messageTypes);

            this.MessageHandlers.AddAssembliesToScan(assembliesToScan);
            this.MessageHandlers.Init();
            if (executeTheseHandlersFirst.Any())
                this.MessageHandlers.ExecuteTheseHandlersFirst(executeTheseHandlersFirst);
            if (executeTheseHandlersLast.Any())
                this.MessageHandlers.ExecuteTheseHandlersLast(executeTheseHandlersLast);

            // Get endpoint mapping
            foreach (MessageEndpointMapping mapping in this.MessageEndpointMappingCollection) {
                try {
                    var messageType = Type.GetType(mapping.Messages, false);
                    if (messageType != null && MessageTypeConventions.IsMessageType(messageType))
                    {
                        typesToEndpoints[messageType] = mapping.Endpoint.Trim();
                        continue;
                    }
                } catch (Exception ex) {
                    Logger.Error("Problem loading message type: " + mapping.Messages, ex);
                }

                try {
                    var a = Assembly.Load(mapping.Messages);
                    foreach (var t in a.GetTypes().Where(t => MessageTypeConventions.IsMessageType(t)))
                        typesToEndpoints[t] = mapping.Endpoint.Trim();
                } catch (Exception ex) {
                    throw new ArgumentException("Problem loading message assembly: " + mapping.Messages, ex);
                }

            }

            var transport = TransportBuilder.Build();

            var messageDispatcher = new MessageDispatcher(ServiceLocator, this.MessageHandlers);
            var messageBus = new UnicastMessageBus(messageMapper, transport, messageDispatcher);
            messageBus.MapMessageTypesToAddress(typesToEndpoints);

            var performanceCounters = new PerformanceCounters();
            messageBus.MessageReceived += performanceCounters.OnMessageReceived;
            messageBus.MessageSent += performanceCounters.OnMessageSent;
            messageBus.MessageFailed += performanceCounters.OnMessageFailure;
            messageBus.MessageHandled += performanceCounters.OnMessageHandled;

            return messageBus;
        }
示例#4
0
        public void Serialize_Deserialize_Multiple_Namespaces()
        {
            var types = new List <Type> {
                typeof(C1), typeof(C2)
            };
            var mapper = new MessageMapper();

            mapper.Initialize(types);
            var serializer = new XmlMessageSerializer(mapper);

            serializer.Initialize(types);

            Time(new IMessage[] { new C1()
                                  {
                                      Data = "o'tool"
                                  }, new C2()
                                  {
                                      Data = "Timmy"
                                  } }, serializer);
        }