Пример #1
0
        private static ErrorRecord GetErrorRecordForRemotePipelineInvocation(Exception innerException, string errorMessageTemplate)
        {
            Exception       exception  = new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, errorMessageTemplate, new object[] { innerException.Message }), innerException);
            RemoteException exception2 = innerException as RemoteException;
            ErrorRecord     record     = (exception2 != null) ? exception2.ErrorRecord : null;
            string          errorId    = (record != null) ? record.FullyQualifiedErrorId : innerException.GetType().Name;

            return(new ErrorRecord(exception, errorId, (record != null) ? record.CategoryInfo.Category : ErrorCategory.NotSpecified, null));
        }
Пример #2
0
        private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
        {
            if (serializedErrorRecord == null)
            {
                throw PSTraceSource.NewArgumentNullException("serializedErrorRecord");
            }
            PSObject propertyValue = RemotingDecoder.GetPropertyValue <PSObject>(serializedErrorRecord, "Exception");
            object   targetObject  = RemotingDecoder.GetPropertyValue <object>(serializedErrorRecord, "TargetObject");
            PSObject serializedRemoteInvocationInfo = RemotingDecoder.GetPropertyValue <PSObject>(serializedErrorRecord, "InvocationInfo");
            string   str = null;

            if (propertyValue != null)
            {
                PSPropertyInfo info = propertyValue.Properties["Message"];
                if (info != null)
                {
                    str = info.Value as string;
                }
            }
            string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "FullyQualifiedErrorId");

            if (fullyQualifiedErrorId == null)
            {
                fullyQualifiedErrorId = "fullyQualifiedErrorId";
            }
            ErrorCategory   errorCategory = RemotingDecoder.GetPropertyValue <ErrorCategory>(serializedErrorRecord, "errorCategory_Category");
            string          str3          = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Activity");
            string          str4          = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Reason");
            string          str5          = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_TargetName");
            string          str6          = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_TargetType");
            string          str7          = RemotingDecoder.GetPropertyValue <string>(serializedErrorRecord, "ErrorCategory_Message");
            string          noteValue     = GetNoteValue(serializedErrorRecord, "ErrorDetails_Message") as string;
            string          str9          = GetNoteValue(serializedErrorRecord, "ErrorDetails_RecommendedAction") as string;
            RemoteException exception     = new RemoteException((str != null) ? str : str7, propertyValue, serializedRemoteInvocationInfo);

            this.PopulateProperties(exception, targetObject, fullyQualifiedErrorId, errorCategory, str3, str4, str5, str6, str7, noteValue, str9);
            exception.SetRemoteErrorRecord(this);
            this.serializeExtendedInfo = RemotingDecoder.GetPropertyValue <bool>(serializedErrorRecord, "SerializeExtendedInfo");
            if (this.serializeExtendedInfo)
            {
                this._invocationInfo = new System.Management.Automation.InvocationInfo(serializedErrorRecord);
                ArrayList list = RemotingDecoder.GetPropertyValue <ArrayList>(serializedErrorRecord, "PipelineIterationInfo");
                if (list != null)
                {
                    this.pipelineIterationInfo = new ReadOnlyCollection <int>((int[])list.ToArray(typeof(int)));
                }
            }
            else
            {
                this._invocationInfo = null;
            }
        }
Пример #3
0
        private static ErrorRecord GetErrorRecordForRemotePipelineInvocation(Exception innerException, string errorMessageTemplate)
        {
            string errorMessage = string.Format(
                CultureInfo.InvariantCulture,
                errorMessageTemplate,
                innerException.Message);
            Exception outerException = new InvalidOperationException(errorMessage, innerException);

            RemoteException remoteException   = innerException as RemoteException;
            ErrorRecord     remoteErrorRecord = remoteException != null ? remoteException.ErrorRecord : null;
            string          errorId           = remoteErrorRecord != null ? remoteErrorRecord.FullyQualifiedErrorId : innerException.GetType().Name;
            ErrorCategory   errorCategory     = remoteErrorRecord != null ? remoteErrorRecord.CategoryInfo.Category : ErrorCategory.NotSpecified;
            ErrorRecord     errorRecord       = new ErrorRecord(outerException, errorId, errorCategory, null);

            return(errorRecord);
        }
Пример #4
0
        private static Exception GetExceptionFromErrorRecord(ErrorRecord errorRecord)
        {
            RuntimeException exception = errorRecord.Exception as RuntimeException;

            if (exception == null)
            {
                return(null);
            }
            RemoteException exception2 = exception as RemoteException;

            if (exception2 == null)
            {
                return(null);
            }
            PSPropertyInfo info = exception2.SerializedRemoteException.Properties["WasThrownFromThrowStatement"];

            if ((info == null) || !((bool)info.Value))
            {
                return(null);
            }
            exception.WasThrownFromThrowStatement = true;
            return(exception);
        }
Пример #5
0
        protected void ProcessJobFailure(ExecutionCmdletHelper helper, out Exception failureException, out ErrorRecord failureErrorRecord)
        {
            RemotePipeline pipeline = helper.Pipeline as RemotePipeline;
            RemoteRunspace runspace = pipeline.GetRunspace() as RemoteRunspace;

            failureException   = null;
            failureErrorRecord = null;
            if (helper.InternalException != null)
            {
                string errorId = "RemotePipelineExecutionFailed";
                failureException = helper.InternalException;
                if ((failureException is InvalidRunspaceStateException) || (failureException is InvalidRunspacePoolStateException))
                {
                    errorId = "InvalidSessionState";
                    if (!string.IsNullOrEmpty(failureException.Source))
                    {
                        errorId = string.Format(CultureInfo.InvariantCulture, "{0},{1}", new object[] { errorId, failureException.Source });
                    }
                }
                failureErrorRecord = new ErrorRecord(helper.InternalException, errorId, ErrorCategory.OperationStopped, helper);
            }
            else if (runspace.RunspaceStateInfo.State == RunspaceState.Broken)
            {
                failureException = runspace.RunspaceStateInfo.Reason;
                object computerName = runspace.ConnectionInfo.ComputerName;
                string str2         = null;
                PSRemotingTransportException exception = failureException as PSRemotingTransportException;
                string fQEIDFromTransportError         = WSManTransportManagerUtils.GetFQEIDFromTransportError((exception != null) ? exception.ErrorCode : 0, "PSSessionStateBroken");
                if (exception != null)
                {
                    str2 = "[" + runspace.ConnectionInfo.ComputerName + "] ";
                    if (exception.ErrorCode == -2144108135)
                    {
                        string str4 = PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.URIRedirectionReported, new object[] { exception.Message, "MaximumConnectionRedirectionCount", "PSSessionOption", "AllowRedirection" });
                        str2 = str2 + str4;
                    }
                    else if (!string.IsNullOrEmpty(exception.Message))
                    {
                        str2 = str2 + exception.Message;
                    }
                    else if (!string.IsNullOrEmpty(exception.TransportMessage))
                    {
                        str2 = str2 + exception.TransportMessage;
                    }
                }
                if (failureException == null)
                {
                    failureException = new RuntimeException(PSRemotingErrorInvariants.FormatResourceString(RemotingErrorIdStrings.RemoteRunspaceOpenUnknownState, new object[] { runspace.RunspaceStateInfo.State }));
                }
                failureErrorRecord = new ErrorRecord(failureException, computerName, fQEIDFromTransportError, ErrorCategory.OpenError, null, null, null, null, null, str2, null);
            }
            else if (pipeline.PipelineStateInfo.State == PipelineState.Failed)
            {
                object targetObject = runspace.ConnectionInfo.ComputerName;
                failureException = pipeline.PipelineStateInfo.Reason;
                if (failureException != null)
                {
                    RemoteException exception2  = failureException as RemoteException;
                    ErrorRecord     errorRecord = null;
                    if (exception2 != null)
                    {
                        errorRecord = exception2.ErrorRecord;
                    }
                    else
                    {
                        errorRecord = new ErrorRecord(pipeline.PipelineStateInfo.Reason, "JobFailure", ErrorCategory.OperationStopped, targetObject);
                    }
                    string     str5       = ((RemoteRunspace)pipeline.GetRunspace()).ConnectionInfo.ComputerName;
                    Guid       instanceId = pipeline.GetRunspace().InstanceId;
                    OriginInfo originInfo = new OriginInfo(str5, instanceId);
                    failureErrorRecord = new RemotingErrorRecord(errorRecord, originInfo);
                }
            }
        }
Пример #6
0
        private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
        {
            if (serializedErrorRecord == null)
            {
                throw PSTraceSource.NewArgumentNullException("serializedErrorRecord");
            }

            //Get Exception
            PSObject serializedException = RemotingDecoder.GetPropertyValue<PSObject>(serializedErrorRecord, "Exception");

            //Get Target object
            object targetObject = RemotingDecoder.GetPropertyValue<object>(serializedErrorRecord, "TargetObject");

            string exceptionMessage = null;
            if (serializedException != null)
            {
                PSPropertyInfo messageProperty = serializedException.Properties["Message"] as PSPropertyInfo;
                if (messageProperty != null)
                {
                    exceptionMessage = messageProperty.Value as string;
                }
            }

            //Get FullyQualifiedErrorId
            string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "FullyQualifiedErrorId") ??
                                           "fullyQualifiedErrorId";

            //Get ErrorCategory...
            ErrorCategory errorCategory = RemotingDecoder.GetPropertyValue<ErrorCategory>(serializedErrorRecord, "errorCategory_Category");

            //Get Various ErrorCategory fileds
            string errorCategory_Activity = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Activity");
            string errorCategory_Reason = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Reason");
            string errorCategory_TargetName = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_TargetName");
            string errorCategory_TargetType = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_TargetType");
            string errorCategory_Message = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Message");

            //Get InvocationInfo (optional property)
            PSObject invocationInfo = Microsoft.PowerShell.DeserializingTypeConverter.GetPropertyValue<PSObject>(
                serializedErrorRecord,
                "InvocationInfo",
                Microsoft.PowerShell.DeserializingTypeConverter.RehydrationFlags.MissingPropertyOk);

            //Get Error Detail (these note properties are optional, so can't right now use RemotingDecoder...)
            string errorDetails_Message =
                GetNoteValue(serializedErrorRecord, "ErrorDetails_Message") as string;

            string errorDetails_RecommendedAction =
                GetNoteValue(serializedErrorRecord, "ErrorDetails_RecommendedAction") as string;

            string errorDetails_ScriptStackTrace =
                GetNoteValue(serializedErrorRecord, "ErrorDetails_ScriptStackTrace") as string;

            RemoteException re = new RemoteException((String.IsNullOrWhiteSpace(exceptionMessage) == false) ? exceptionMessage : errorCategory_Message, serializedException, invocationInfo);

            //Create ErrorRecord
            PopulateProperties(
                re,
                targetObject,
                fullyQualifiedErrorId,
                errorCategory,
                errorCategory_Activity,
                errorCategory_Reason,
                errorCategory_TargetName,
                errorCategory_TargetType,
                errorCategory_Message,
                errorDetails_Message,
                errorDetails_RecommendedAction,
                errorDetails_ScriptStackTrace
                );

            re.SetRemoteErrorRecord(this);

            //
            // Get the InvocationInfo
            //
            _serializeExtendedInfo = RemotingDecoder.GetPropertyValue<bool>(serializedErrorRecord, "SerializeExtendedInfo");

            if (_serializeExtendedInfo)
            {
                _invocationInfo = new InvocationInfo(serializedErrorRecord);

                ArrayList iterationInfo = RemotingDecoder.GetPropertyValue<ArrayList>(serializedErrorRecord, "PipelineIterationInfo");
                if (null != iterationInfo)
                {
                    _pipelineIterationInfo = new ReadOnlyCollection<int>((int[])iterationInfo.ToArray(typeof(Int32)));
                }
            }
            else
            {
                _invocationInfo = null;
            }
        }
Пример #7
0
 private void ConstructFromPSObjectForRemoting(PSObject serializedErrorRecord)
 {
     if (serializedErrorRecord == null)
     {
         throw PSTraceSource.NewArgumentNullException("serializedErrorRecord");
     }
     PSObject propertyValue = RemotingDecoder.GetPropertyValue<PSObject>(serializedErrorRecord, "Exception");
     object targetObject = RemotingDecoder.GetPropertyValue<object>(serializedErrorRecord, "TargetObject");
     PSObject serializedRemoteInvocationInfo = RemotingDecoder.GetPropertyValue<PSObject>(serializedErrorRecord, "InvocationInfo");
     string str = null;
     if (propertyValue != null)
     {
         PSPropertyInfo info = propertyValue.Properties["Message"];
         if (info != null)
         {
             str = info.Value as string;
         }
     }
     string fullyQualifiedErrorId = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "FullyQualifiedErrorId");
     if (fullyQualifiedErrorId == null)
     {
         fullyQualifiedErrorId = "fullyQualifiedErrorId";
     }
     ErrorCategory errorCategory = RemotingDecoder.GetPropertyValue<ErrorCategory>(serializedErrorRecord, "errorCategory_Category");
     string str3 = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Activity");
     string str4 = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Reason");
     string str5 = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_TargetName");
     string str6 = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_TargetType");
     string str7 = RemotingDecoder.GetPropertyValue<string>(serializedErrorRecord, "ErrorCategory_Message");
     string noteValue = GetNoteValue(serializedErrorRecord, "ErrorDetails_Message") as string;
     string str9 = GetNoteValue(serializedErrorRecord, "ErrorDetails_RecommendedAction") as string;
     RemoteException exception = new RemoteException((str != null) ? str : str7, propertyValue, serializedRemoteInvocationInfo);
     this.PopulateProperties(exception, targetObject, fullyQualifiedErrorId, errorCategory, str3, str4, str5, str6, str7, noteValue, str9);
     exception.SetRemoteErrorRecord(this);
     this.serializeExtendedInfo = RemotingDecoder.GetPropertyValue<bool>(serializedErrorRecord, "SerializeExtendedInfo");
     if (this.serializeExtendedInfo)
     {
         this._invocationInfo = new System.Management.Automation.InvocationInfo(serializedErrorRecord);
         ArrayList list = RemotingDecoder.GetPropertyValue<ArrayList>(serializedErrorRecord, "PipelineIterationInfo");
         if (list != null)
         {
             this.pipelineIterationInfo = new ReadOnlyCollection<int>((int[]) list.ToArray(typeof(int)));
         }
     }
     else
     {
         this._invocationInfo = null;
     }
 }