Ejemplo n.º 1
0
        /// <summary>
        /// Converts the communication message to a data structure.
        /// </summary>
        /// <param name="message">The communication message.</param>
        /// <returns>The data structure that contains all the information that was stored in the message.</returns>
        public IStoreV1CommunicationData FromMessage(ICommunicationMessage message)
        {
            var msg = message as UnregisterFromNotificationMessage;

            if (msg == null)
            {
                return(new UnknownMessageTypeData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                });
            }

            try
            {
                return(new NotificationUnregistrationData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                    NotificationId = NotificationIdExtensions.Serialize(msg.Notification),
                });
            }
            catch (Exception)
            {
                return(new UnknownMessageTypeData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                });
            }
        }
Ejemplo n.º 2
0
        public void ToMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Callback <Type>(t => Assert.IsTrue(typeof(int).Equals(t)))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new NotificationRaisedConverter(serializers.Object);

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var data = new NotificationRaisedData
            {
                Id                 = new MessageId(),
                InResponseTo       = new MessageId(),
                Sender             = new EndpointId("a"),
                NotificationId     = NotificationIdExtensions.Serialize(id),
                EventArgumentsType = new SerializedType
                {
                    FullName     = typeof(int).FullName,
                    AssemblyName = typeof(int).Assembly.GetName().Name,
                },
                EventArguments = new EventArgs(),
            };
            var msg = translator.ToMessage(data);

            Assert.IsInstanceOf(typeof(NotificationRaisedMessage), msg);
            Assert.AreSame(data.Id, msg.Id);
            Assert.AreSame(data.Sender, msg.Sender);
            Assert.AreEqual(id, ((NotificationRaisedMessage)msg).Notification.Notification);
            Assert.AreSame(data.EventArguments, ((NotificationRaisedMessage)msg).Notification.EventArgs);
        }
Ejemplo n.º 3
0
        public void FromMessage()
        {
            var serializers = new Mock <IStoreObjectSerializers>();
            {
                serializers.Setup(s => s.HasSerializerFor(It.IsAny <Type>()))
                .Returns(true);
                serializers.Setup(s => s.SerializerFor(It.IsAny <Type>()))
                .Returns(new NonTransformingObjectSerializer());
            }

            var translator = new NotificationRaisedConverter(serializers.Object);

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new NotificationRaisedMessage(
                new EndpointId("a"),
                new Interaction.NotificationRaisedData(id, new EventArgs()));
            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationRaisedData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationRaisedData)data).NotificationId);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().FullName,
                ((NotificationRaisedData)data).EventArgumentsType.FullName);
            Assert.AreEqual(
                msg.Notification.EventArgs.GetType().Assembly.GetName().Name,
                ((NotificationRaisedData)data).EventArgumentsType.AssemblyName);
            Assert.AreSame(msg.Notification.EventArgs, ((NotificationRaisedData)data).EventArguments);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Converts the communication message to a data structure.
        /// </summary>
        /// <param name="message">The communication message.</param>
        /// <returns>The data structure that contains all the information that was stored in the message.</returns>
        public IStoreV1CommunicationData FromMessage(ICommunicationMessage message)
        {
            var msg = message as NotificationRaisedMessage;

            if (msg == null)
            {
                return(new UnknownMessageTypeData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                });
            }

            try
            {
                var eventArgs               = msg.Notification.EventArgs;
                var eventArgsType           = msg.Notification.EventArgs.GetType();
                var serializedEventArgsType = new SerializedType
                {
                    FullName     = eventArgsType.FullName,
                    AssemblyName = eventArgsType.Assembly.GetName().Name
                };

                if (!m_TypeSerializers.HasSerializerFor(eventArgsType))
                {
                    throw new MissingObjectDataSerializerException();
                }

                var serializer = m_TypeSerializers.SerializerFor(eventArgsType);

                var value = serializer.Serialize(eventArgs);

                return(new NotificationRaisedData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                    NotificationId = NotificationIdExtensions.Serialize(msg.Notification.Notification),
                    EventArgumentsType = serializedEventArgsType,
                    EventArguments = value,
                });
            }
            catch (Exception)
            {
                return(new UnknownMessageTypeData
                {
                    Id = message.Id,
                    InResponseTo = message.InResponseTo,
                    Sender = message.Sender,
                });
            }
        }
Ejemplo n.º 5
0
        public void FromMessage()
        {
            var translator = new NotificationUnregistrationConverter();

            var id  = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var msg = new UnregisterFromNotificationMessage(new EndpointId("a"), id);

            var data = translator.FromMessage(msg);

            Assert.IsInstanceOf(typeof(NotificationUnregistrationData), data);
            Assert.AreSame(msg.Id, data.Id);
            Assert.AreSame(msg.Sender, data.Sender);
            Assert.AreSame(msg.InResponseTo, data.InResponseTo);
            Assert.AreEqual(NotificationIdExtensions.Serialize(id), ((NotificationUnregistrationData)data).NotificationId);
        }
Ejemplo n.º 6
0
        public void ToMessage()
        {
            var translator = new NotificationUnregistrationConverter();

            var id   = NotificationId.Create(typeof(InteractionExtensionsTest.IMockNotificationSetWithTypedEventHandler).GetEvent("OnMyEvent"));
            var data = new NotificationUnregistrationData
            {
                Id             = new MessageId(),
                InResponseTo   = new MessageId(),
                Sender         = new EndpointId("a"),
                NotificationId = NotificationIdExtensions.Serialize(id),
            };
            var msg = translator.ToMessage(data);

            Assert.IsInstanceOf(typeof(UnregisterFromNotificationMessage), msg);
            Assert.AreSame(data.Id, msg.Id);
            Assert.AreSame(data.Sender, msg.Sender);
            Assert.AreEqual(id, ((UnregisterFromNotificationMessage)msg).Notification);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Converts the data structure to a communication message.
        /// </summary>
        /// <param name="data">The data structure.</param>
        /// <returns>The communication message containing all the information that was stored in the data structure.</returns>
        public ICommunicationMessage ToMessage(IStoreV1CommunicationData data)
        {
            var msg = data as NotificationUnregistrationData;

            if (msg == null)
            {
                return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo));
            }

            try
            {
                return(new UnregisterFromNotificationMessage(
                           data.Sender,
                           data.Id,
                           NotificationIdExtensions.Deserialize(msg.NotificationId)));
            }
            catch (Exception)
            {
                return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Converts the data structure to a communication message.
        /// </summary>
        /// <param name="data">The data structure.</param>
        /// <returns>The communication message containing all the information that was stored in the data structure.</returns>
        public ICommunicationMessage ToMessage(IStoreV1CommunicationData data)
        {
            var msg = data as NotificationRaisedData;

            if (msg == null)
            {
                return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo));
            }

            try
            {
                var eventArgsType = TypeLoader.FromPartialInformation(
                    msg.EventArgumentsType.FullName,
                    msg.EventArgumentsType.AssemblyName);

                var serializedObjectData = msg.EventArguments;
                if (!m_TypeSerializers.HasSerializerFor(eventArgsType))
                {
                    throw new MissingObjectDataSerializerException();
                }

                var serializer = m_TypeSerializers.SerializerFor(eventArgsType);
                var eventArgs  = serializer.Deserialize(serializedObjectData) as EventArgs;

                return(new NotificationRaisedMessage(
                           data.Sender,
                           data.Id,
                           new Interaction.NotificationRaisedData(
                               NotificationIdExtensions.Deserialize(msg.NotificationId),
                               eventArgs)));
            }
            catch (Exception)
            {
                return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo));
            }
        }