/// <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)); } }
/// <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)); } }