コード例 #1
0
        internal static ErrorRecord GetPowerShellError(object data)
        {
            if (data == null)
            {
                throw PSTraceSource.NewArgumentNullException("data");
            }
            PSObject serializedErrorRecord = data as PSObject;

            return(ErrorRecord.FromPSObjectForRemoting(serializedErrorRecord));
        }
コード例 #2
0
        internal static Exception GetExceptionFromSerializedErrorRecord(object serializedErrorRecord)
        {
            ErrorRecord record = ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(serializedErrorRecord));

            if (record == null)
            {
                throw new PSRemotingDataStructureException(RemotingErrorIdStrings.DecodingErrorForErrorRecord);
            }
            return(record.Exception);
        }
コード例 #3
0
 private void ReadXml()
 {
     try
     {
         Deserializer deserializer = new Deserializer(XmlReader.Create(this.streamReader, InternalDeserializer.XmlReaderSettingsForCliXml));
         while (!deserializer.Done())
         {
             string          str;
             object          obj2    = deserializer.Deserialize(out str);
             MinishellStream unknown = MinishellStream.Unknown;
             if (str != null)
             {
                 unknown = StringToMinishellStreamConverter.ToMinishellStream(str);
             }
             if (unknown == MinishellStream.Unknown)
             {
                 unknown = this.isOutput ? MinishellStream.Output : MinishellStream.Error;
             }
             if ((unknown == MinishellStream.Output) || (obj2 != null))
             {
                 if (unknown == MinishellStream.Error)
                 {
                     if (obj2 is PSObject)
                     {
                         obj2 = ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj2));
                     }
                     else
                     {
                         string targetObject = null;
                         try
                         {
                             targetObject = (string)LanguagePrimitives.ConvertTo(obj2, typeof(string), CultureInfo.InvariantCulture);
                         }
                         catch (PSInvalidCastException)
                         {
                             continue;
                         }
                         obj2 = new ErrorRecord(new RemoteException(targetObject), "NativeCommandError", ErrorCategory.NotSpecified, targetObject);
                     }
                 }
                 else if (((unknown == MinishellStream.Debug) || (unknown == MinishellStream.Verbose)) || (unknown == MinishellStream.Warning))
                 {
                     try
                     {
                         obj2 = LanguagePrimitives.ConvertTo(obj2, typeof(string), CultureInfo.InvariantCulture);
                     }
                     catch (PSInvalidCastException)
                     {
                         continue;
                     }
                 }
                 this.AddObjectToWriter(obj2, unknown);
             }
         }
     }
     catch (XmlException exception)
     {
         string       cliXmlError = NativeCP.CliXmlError;
         XmlException exception2  = new XmlException(string.Format(null, cliXmlError, new object[] { this.isOutput ? MinishellStream.Output : MinishellStream.Error, this.processPath, exception.Message }), exception);
         ErrorRecord  data        = new ErrorRecord(exception2, "ProcessStreamReader_CliXmlError", ErrorCategory.SyntaxError, this.processPath);
         this.AddObjectToWriter(data, MinishellStream.Error);
     }
 }
コード例 #4
0
        private void ReadXml()
        {
            try
            {
                Deserializer deserializer = new Deserializer((XmlReader) new XmlTextReader((TextReader)this.streamReader));
                while (!deserializer.Done())
                {
                    string          streamName;
                    object          obj    = deserializer.Deserialize(out streamName);
                    MinishellStream stream = MinishellStream.Unknown;
                    if (streamName != null)
                    {
                        stream = StringToMinishellStreamConverter.ToMinishellStream(streamName);
                    }
                    if (stream == MinishellStream.Unknown)
                    {
                        stream = this.isOutput ? MinishellStream.Output : MinishellStream.Error;
                    }
                    if (stream == MinishellStream.Output || obj != null)
                    {
                        switch (stream)
                        {
                        case MinishellStream.Error:
                            if (obj is PSObject)
                            {
                                obj = (object)ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(obj));
                                break;
                            }
                            string message;
                            try
                            {
                                message = (string)LanguagePrimitives.ConvertTo(obj, typeof(string), (IFormatProvider)CultureInfo.InvariantCulture);
                            }
                            catch (PSInvalidCastException ex)
                            {
                                ProcessStreamReader.tracer.TraceException((Exception)ex);
                                continue;
                            }
                            obj = (object)new ErrorRecord((Exception) new RemoteException(message), "NativeCommandError", ErrorCategory.NotSpecified, (object)message);
                            break;

                        case MinishellStream.Verbose:
                        case MinishellStream.Warning:
                        case MinishellStream.Debug:
                            try
                            {
                                obj = LanguagePrimitives.ConvertTo(obj, typeof(string), (IFormatProvider)CultureInfo.InvariantCulture);
                                break;
                            }
                            catch (PSInvalidCastException ex)
                            {
                                ProcessStreamReader.tracer.TraceException((Exception)ex);
                                continue;
                            }
                        }
                        this.AddObjectToWriter(obj, stream);
                    }
                }
            }
            catch (XmlException ex)
            {
                ProcessStreamReader.tracer.TraceException((Exception)ex);
                this.AddObjectToWriter((object)new ErrorRecord((Exception) new XmlException(string.Format((IFormatProvider)null, ResourceManagerCache.GetResourceString("NativeCP", "CliXmlError"), (object)(MinishellStream)(this.isOutput ? 0 : 1), (object)this.processPath, (object)ex.Message), (Exception)ex), "ProcessStreamReader_CliXmlError", ErrorCategory.SyntaxError, (object)this.processPath), MinishellStream.Error);
            }
        }
コード例 #5
0
 internal static ErrorRecord GetPowerShellError(object data)
 {
     using (RemotingDecoder._trace.TraceMethod())
         return(data != null?ErrorRecord.FromPSObjectForRemoting(data as PSObject) : throw RemotingDecoder._trace.NewArgumentNullException(nameof(data)));
 }
コード例 #6
0
 internal static Exception GetExceptionFromSerializedErrorRecord(
     object serializedErrorRecord)
 {
     using (RemotingDecoder._trace.TraceMethod())
         return((ErrorRecord.FromPSObjectForRemoting(PSObject.AsPSObject(serializedErrorRecord)) ?? throw new PSRemotingDataStructureException(PSRemotingErrorId.DecodingErrorForErrorRecord, new object[0])).Exception);
 }