public void FromPartialInformationWithTypeNameAssemblyNameAndAssemblyVersion() { var type = typeof(TypeLoader); var loadedType = TypeLoader.FromPartialInformation(type.FullName, type.Assembly.GetName().Name, type.Assembly.GetName().Version, true); Assert.AreEqual(type, loadedType); }
/// <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)); }
public void FromPartialInformationWithTypeName() { var type = typeof(TypeLoader); var loadedType = TypeLoader.FromPartialInformation(type.FullName, throwOnError: true); Assert.AreEqual(type, loadedType); }
/// <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> /// Override this method to map the specified type name and namespace to a data contract type during deserialization. /// </summary> /// <returns> /// The type the type name and namespace is mapped to. /// </returns> /// <param name="typeName">The type name that is used in the SOAP XML declaration.</param> /// <param name="typeNamespace">The type namespace that is used in the SOAP XML declaration.</param> /// <param name="declaredType">The type declared in the data contract.</param> /// <param name="knownTypeResolver">The known type resolver.</param> public override Type ResolveName( string typeName, string typeNamespace, Type declaredType, DataContractResolver knownTypeResolver) { var result = knownTypeResolver.ResolveName(typeName, typeNamespace, declaredType, null) ?? TypeLoader.FromPartialInformation(typeName, typeNamespace, throwOnError: false); return(result); }
/// <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)); } }
private Type LoadProxyType(EndpointId endpoint, OfflineTypeInformation serializedType) { // Hydrate the proxy type. This requires loading the assembly which a) might // be slow and b) might fail Type proxyType; try { proxyType = TypeLoader.FromPartialInformation(serializedType.TypeFullName, serializedType.AssemblyName.Name); m_Diagnostics.Log( LevelToLog.Trace, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Got {0} from endpoint [{1}] of type {2}.", TraceNameForProxyObjects(), endpoint, proxyType)); } catch (UnableToLoadTypeException) { m_Diagnostics.Log( LevelToLog.Error, CommunicationConstants.DefaultLogTextPrefix, string.Format( CultureInfo.InvariantCulture, "Could not load the {0} type: {1} for endpoint {2}", TraceNameForProxyObjects(), serializedType.TypeFullName, endpoint)); throw; } return(proxyType); }
/// <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)); } }