/// <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 endpointConnectData = data as ConnectionVerificationResponseData; if (endpointConnectData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } object value = null; if (endpointConnectData.ResponseData != null) { var dataType = TypeLoader.FromPartialInformation( endpointConnectData.DataType.FullName, endpointConnectData.DataType.AssemblyName); if (!m_TypeSerializers.HasSerializerFor(dataType)) { throw new MissingObjectDataSerializerException(); } var serializer = m_TypeSerializers.SerializerFor(dataType); value = serializer.Deserialize(endpointConnectData.ResponseData); } return(new ConnectionVerificationResponseMessage( endpointConnectData.Sender, data.Id, data.InResponseTo, value)); }
/// <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 invocationData = data as CommandInvocationResponseData; if (invocationData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } try { var typeInfo = invocationData.ReturnedType; var type = TypeLoader.FromPartialInformation(typeInfo.FullName, typeInfo.AssemblyName); var serializedObjectData = invocationData.Result; if (!m_TypeSerializers.HasSerializerFor(type)) { throw new MissingObjectDataSerializerException(); } var serializer = m_TypeSerializers.SerializerFor(type); var returnValue = serializer.Deserialize(serializedObjectData); return(new CommandInvokedResponseMessage( data.Sender, data.Id, data.InResponseTo, returnValue)); } catch (Exception) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } }
/// <summary> /// Accepts the messages. /// </summary> /// <param name="message">The message.</param> /// <returns>An object indicating that the data was received successfully.</returns> public MessageReceptionConfirmation AcceptMessage(IStoreV1CommunicationData message) { Task.Factory.StartNew(ProcessMessage, message); return(new MessageReceptionConfirmation { WasDataReceived = true, }); }
private ICommunicationMessage TranslateMessage(IStoreV1CommunicationData message) { if (!m_Converters.ContainsKey(message.GetType())) { return(new UnknownMessageTypeMessage(message.Sender, message.InResponseTo)); } var converter = m_Converters[message.GetType()]; return(converter.ToMessage(message)); }
/// <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 disconnectData = data as EndpointDisconnectData; if (disconnectData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } return(new EndpointDisconnectMessage(data.Sender, data.Id, disconnectData.DisconnectReason)); }
/// <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 downloadData = data as DownloadRequestData; if (downloadData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } return(new DataDownloadRequestMessage(downloadData.Sender, data.Id, downloadData.Token)); }
/// <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 successData = data as SuccessData; if (successData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } return(new SuccessMessage(successData.Sender, data.Id, successData.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 failureData = data as FailureData; if (failureData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } return(new FailureMessage(failureData.Sender, data.Id, failureData.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 EndpointInteractionInformationData; if (msg == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } try { var groups = new CommunicationSubjectGroup[msg.Groups.Length]; for (int i = 0; i < msg.Groups.Length; i++) { var serializedGroup = msg.Groups[i]; var commands = new VersionedTypeFallback[serializedGroup.Commands.Length]; for (int j = 0; j < serializedGroup.Commands.Length; j++) { var typeFallback = serializedGroup.Commands[j]; var types = typeFallback.Types.Select( t => new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(t.Type.FullName, new AssemblyName(t.Type.AssemblyName)), t.Version)) .ToArray(); commands[j] = new VersionedTypeFallback(types); } var notifications = new VersionedTypeFallback[serializedGroup.Notifications.Length]; for (int j = 0; j < serializedGroup.Notifications.Length; j++) { var typeFallBack = serializedGroup.Notifications[j]; var types = typeFallBack.Types.Select( t => new Tuple <OfflineTypeInformation, Version>( new OfflineTypeInformation(t.Type.FullName, new AssemblyName(t.Type.AssemblyName)), t.Version)) .ToArray(); notifications[j] = new VersionedTypeFallback(types); } groups[i] = new CommunicationSubjectGroup( new CommunicationSubject(serializedGroup.Subject), commands, notifications); } return(new EndpointInteractionInformationMessage(data.Sender, data.Id, groups)); } 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 CommandInvocationData; if (msg == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } try { var id = CommandIdExtensions.Deserialize(msg.CommandId); var parameterValues = new CommandParameterValueMap[msg.ParameterTypes.Length]; for (int i = 0; i < msg.ParameterTypes.Length; i++) { var typeInfo = msg.ParameterTypes[i]; var type = TypeLoader.FromPartialInformation(typeInfo.FullName, typeInfo.AssemblyName); var name = msg.ParameterNames[i]; var serializedObjectData = msg.ParameterValues[i]; if (!m_TypeSerializers.HasSerializerFor(type)) { throw new MissingObjectDataSerializerException(); } var serializer = m_TypeSerializers.SerializerFor(type); var value = serializer.Deserialize(serializedObjectData); parameterValues[i] = new CommandParameterValueMap( new CommandParameterDefinition(type, name, CommandParameterOrigin.FromCommand), value); } return(new CommandInvokedMessage( data.Sender, data.Id, new CommandInvokedData( id, parameterValues))); } 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 endpointConnectData = data as EndpointConnectData; if (endpointConnectData == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } return(new EndpointConnectMessage( endpointConnectData.Sender, data.Id, new DiscoveryInformation(endpointConnectData.DiscoveryAddress), new ProtocolInformation( endpointConnectData.ProtocolVersion, endpointConnectData.MessageAddress, endpointConnectData.DataAddress), endpointConnectData.Information)); }
/// <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 EndpointInteractionInformationResponseData; if (msg == null) { return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); } try { var state = (InteractionConnectionState)Enum.Parse(typeof(InteractionConnectionState), msg.State); return(new EndpointInteractionInformationResponseMessage( data.Sender, data.Id, data.InResponseTo, state)); } 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)); } }
public MessageReceptionConfirmation AcceptMessage(IStoreV1CommunicationData message) { return(m_OnAcceptMessage(message)); }
/// <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) { // Don't verify this just send the expected data otherwise we may end up in an infinite loop return(new UnknownMessageTypeMessage(data.Sender, data.Id, data.InResponseTo)); }
private void SendMessage(IStoreV1CommunicationData message, int retryCount) { var count = 0; Exception exception = null; while (count < retryCount) { EnsureChannelIsAvailable(); exception = null; try { var service = m_Service; if (!m_IsDisposed) { var confirmation = service.AcceptMessage(message); if ((m_Channel.State == CommunicationState.Opened) && (confirmation != null) && confirmation.WasDataReceived) { return; } } } catch (FaultException e) { m_Diagnostics.Log( LevelToLog.Error, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Exception occurred during the sending of message of type {0}. Exception was: {1}", message.GetType(), e)); // If there is no inner exception then there is no point in keeping the original call stack. // The originalexception orginates on the other side of the channel which means that there is no // useful stack trace to keep! m_WasFaulted = true; exception = e.InnerException != null ? new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e.InnerException) : new FailedToSendMessageException(); } catch (CommunicationException e) { // Either the connection was aborted or faulted (although it shouldn't be) // or something else nasty went wrong. m_WasFaulted = true; exception = new FailedToSendMessageException(Resources.Exceptions_Messages_FailedToSendMessage, e); } count++; } if ((m_Channel.State != CommunicationState.Opened) && (exception == null)) { exception = new FailedToSendMessageException(); } if (exception != null) { throw exception; } }