Exemplo n.º 1
0
        internal static RemoteDataObject <T> CreateFrom(
            Stream serializedDataStream,
            Fragmentor defragmentor)
        {
            if (serializedDataStream.Length - serializedDataStream.Position < 40L)
            {
                throw new PSRemotingTransportException(PSRemotingErrorId.NotEnoughHeaderForRemoteDataObject, new object[1]
                {
                    (object)61
                });
            }
            RemotingDestination destination = (RemotingDestination)RemoteDataObject <T> .DeserializeUInt(serializedDataStream);

            RemotingDataType dataType = (RemotingDataType)RemoteDataObject <T> .DeserializeUInt(serializedDataStream);

            Guid runspacePoolId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream);

            Guid powerShellId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream);

            object valueToConvert = (object)null;

            if (serializedDataStream.Length - 40L > 0L)
            {
                valueToConvert = (object)defragmentor.DeserializeToPSObject(serializedDataStream);
            }
            T data = (T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), (IFormatProvider)CultureInfo.CurrentCulture);

            return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, data));
        }
Exemplo n.º 2
0
        internal static RemoteDataObject <T> CreateFrom(Stream serializedDataStream, Fragmentor defragmentor)
        {
            if ((serializedDataStream.Length - serializedDataStream.Position) < 40L)
            {
                PSRemotingTransportException exception = new PSRemotingTransportException(PSRemotingErrorId.NotEnoughHeaderForRemoteDataObject, RemotingErrorIdStrings.NotEnoughHeaderForRemoteDataObject, new object[] { 0x3d });
                throw exception;
            }
            RemotingDestination destination = (RemotingDestination)RemoteDataObject <T> .DeserializeUInt(serializedDataStream);

            RemotingDataType dataType = (RemotingDataType)RemoteDataObject <T> .DeserializeUInt(serializedDataStream);

            Guid runspacePoolId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream);

            Guid powerShellId = RemoteDataObject <T> .DeserializeGuid(serializedDataStream);

            object valueToConvert = null;

            if ((serializedDataStream.Length - 40L) > 0L)
            {
                valueToConvert = defragmentor.DeserializeToPSObject(serializedDataStream);
            }
            return(new RemoteDataObject <T>(destination, dataType, runspacePoolId, powerShellId, (T)LanguagePrimitives.ConvertTo(valueToConvert, typeof(T), CultureInfo.CurrentCulture)));
        }