Пример #1
0
        internal static string RetrieveMessage(Exception e)
        {
            if (e == null)
            {
                return("");
            }
            IContainsErrorRecord record = e as IContainsErrorRecord;

            if (record != null)
            {
                System.Management.Automation.ErrorRecord errorRecord = record.ErrorRecord;
                if (errorRecord == null)
                {
                    return(e.Message);
                }
                ErrorDetails errorDetails = errorRecord.ErrorDetails;
                if (errorDetails == null)
                {
                    return(e.Message);
                }
                string message = errorDetails.Message;
                if (!string.IsNullOrEmpty(message))
                {
                    return(message);
                }
            }
            return(e.Message);
        }
Пример #2
0
 protected CmdletInvocationException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (info.GetBoolean("HasErrorRecord"))
     {
         this._errorRecord = (System.Management.Automation.ErrorRecord) info.GetValue("ErrorRecord", typeof(System.Management.Automation.ErrorRecord));
     }
 }
Пример #3
0
        internal ProviderInvocationException(string errorId, string resourceStr, System.Management.Automation.ProviderInfo provider, string path, Exception innerException, bool useInnerExceptionMessage) : base(RetrieveMessage(errorId, resourceStr, provider, path, innerException), innerException)
        {
            this._providerInfo = provider;
            this._message      = base.Message;
            Exception replaceParentContainsErrorRecordException = null;

            if (useInnerExceptionMessage)
            {
                replaceParentContainsErrorRecordException = innerException;
            }
            else
            {
                replaceParentContainsErrorRecordException = new ParentContainsErrorRecordException(this);
            }
            IContainsErrorRecord record = innerException as IContainsErrorRecord;

            if ((record != null) && (record.ErrorRecord != null))
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, replaceParentContainsErrorRecordException);
            }
            else
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(replaceParentContainsErrorRecordException, errorId, ErrorCategory.InvalidOperation, null);
            }
        }
Пример #4
0
 protected CmdletInvocationException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (info.GetBoolean("HasErrorRecord"))
     {
         this._errorRecord = (System.Management.Automation.ErrorRecord)info.GetValue("ErrorRecord", typeof(System.Management.Automation.ErrorRecord));
     }
 }
 internal ActionPreferenceStopException(InvocationInfo invocationInfo, System.Management.Automation.ErrorRecord errorRecord, string baseName, string resourceId, params object[] args) : this(invocationInfo, baseName, resourceId, args)
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._errorRecord = errorRecord;
 }
 protected ActionPreferenceStopException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (info.GetBoolean("HasErrorRecord"))
     {
         this._errorRecord = (System.Management.Automation.ErrorRecord) info.GetValue("ErrorRecord", typeof(System.Management.Automation.ErrorRecord));
     }
     base.SuppressPromptInInterpreter = true;
 }
Пример #7
0
 internal static Exception RetrieveException(System.Management.Automation.ErrorRecord errorRecord)
 {
     if (errorRecord == null)
     {
         return(null);
     }
     return(errorRecord.Exception);
 }
Пример #8
0
 internal void SetErrorId(string errorId)
 {
     if (this._errorId != errorId)
     {
         this._errorId     = errorId;
         this._errorRecord = null;
     }
 }
 internal ActionPreferenceStopException(System.Management.Automation.ErrorRecord error) : this(RuntimeException.RetrieveMessage(error))
 {
     if (error == null)
     {
         throw new ArgumentNullException("error");
     }
     this._errorRecord = error;
 }
 protected ActionPreferenceStopException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     if (info.GetBoolean("HasErrorRecord"))
     {
         this._errorRecord = (System.Management.Automation.ErrorRecord)info.GetValue("ErrorRecord", typeof(System.Management.Automation.ErrorRecord));
     }
     base.SuppressPromptInInterpreter = true;
 }
Пример #11
0
 internal ActionPreferenceStopException(InvocationInfo invocationInfo, System.Management.Automation.ErrorRecord errorRecord, string baseName, string resourceId, params object[] args) : this(invocationInfo, baseName, resourceId, args)
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._errorRecord = errorRecord;
 }
Пример #12
0
 internal void SetErrorCategory(ErrorCategory errorCategory)
 {
     if (this._errorCategory != errorCategory)
     {
         this._errorCategory = errorCategory;
         this._errorRecord   = null;
     }
 }
Пример #13
0
 internal ActionPreferenceStopException(System.Management.Automation.ErrorRecord error) : this(RuntimeException.RetrieveMessage(error))
 {
     if (error == null)
     {
         throw new ArgumentNullException("error");
     }
     this._errorRecord = error;
 }
Пример #14
0
 internal CmdletInvocationException(System.Management.Automation.ErrorRecord errorRecord) : base(RuntimeException.RetrieveMessage(errorRecord), RuntimeException.RetrieveException(errorRecord))
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._errorRecord = errorRecord;
     Exception exception = errorRecord.Exception;
 }
Пример #15
0
 internal CmdletInvocationException(System.Management.Automation.ErrorRecord errorRecord) : base(RuntimeException.RetrieveMessage(errorRecord), RuntimeException.RetrieveException(errorRecord))
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._errorRecord = errorRecord;
     Exception exception = errorRecord.Exception;
 }
Пример #16
0
 internal ProviderInvocationException(System.Management.Automation.ProviderInfo provider, System.Management.Automation.ErrorRecord errorRecord) : base(RuntimeException.RetrieveMessage(errorRecord), RuntimeException.RetrieveException(errorRecord))
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._message      = base.Message;
     this._providerInfo = provider;
     this._errorRecord  = errorRecord;
 }
Пример #17
0
 internal ProviderInvocationException(System.Management.Automation.ProviderInfo provider, System.Management.Automation.ErrorRecord errorRecord) : base(RuntimeException.RetrieveMessage(errorRecord), RuntimeException.RetrieveException(errorRecord))
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._message = base.Message;
     this._providerInfo = provider;
     this._errorRecord = errorRecord;
 }
Пример #18
0
 internal ProviderInvocationException(System.Management.Automation.ProviderInfo provider, Exception innerException) : base(RuntimeException.RetrieveMessage(innerException), innerException)
 {
     this._message = base.Message;
     this._providerInfo = provider;
     IContainsErrorRecord record = innerException as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, innerException);
     }
     else
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(innerException, "ErrorRecordNotSpecified", ErrorCategory.InvalidOperation, null);
     }
 }
Пример #19
0
 internal RuntimeException(ErrorCategory errorCategory, InvocationInfo invocationInfo, IScriptExtent errorPosition, string errorIdAndResourceId, string message, Exception innerException) : base(message, innerException)
 {
     this._errorId = "RuntimeException";
     this.SetErrorCategory(errorCategory);
     this.SetErrorId(errorIdAndResourceId);
     if ((errorPosition == null) && (invocationInfo != null))
     {
         errorPosition = invocationInfo.ScriptPosition;
     }
     if (invocationInfo != null)
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), this._errorId, this._errorCategory, this._targetObject);
         this._errorRecord.SetInvocationInfo(new InvocationInfo(invocationInfo.MyCommand, errorPosition));
     }
 }
Пример #20
0
 internal RuntimeException(ErrorCategory errorCategory, InvocationInfo invocationInfo, IScriptExtent errorPosition, string errorIdAndResourceId, string message, Exception innerException) : base(message, innerException)
 {
     this._errorId = "RuntimeException";
     this.SetErrorCategory(errorCategory);
     this.SetErrorId(errorIdAndResourceId);
     if ((errorPosition == null) && (invocationInfo != null))
     {
         errorPosition = invocationInfo.ScriptPosition;
     }
     if (invocationInfo != null)
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), this._errorId, this._errorCategory, this._targetObject);
         this._errorRecord.SetInvocationInfo(new InvocationInfo(invocationInfo.MyCommand, errorPosition));
     }
 }
Пример #21
0
        internal ProviderInvocationException(System.Management.Automation.ProviderInfo provider, Exception innerException) : base(RuntimeException.RetrieveMessage(innerException), innerException)
        {
            this._message      = base.Message;
            this._providerInfo = provider;
            IContainsErrorRecord record = innerException as IContainsErrorRecord;

            if ((record != null) && (record.ErrorRecord != null))
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, innerException);
            }
            else
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(innerException, "ErrorRecordNotSpecified", ErrorCategory.InvalidOperation, null);
            }
        }
Пример #22
0
 internal static string RetrieveMessage(System.Management.Automation.ErrorRecord errorRecord)
 {
     if (errorRecord == null)
     {
         return("");
     }
     if ((errorRecord.ErrorDetails != null) && !string.IsNullOrEmpty(errorRecord.ErrorDetails.Message))
     {
         return(errorRecord.ErrorDetails.Message);
     }
     if (errorRecord.Exception == null)
     {
         return("");
     }
     return(errorRecord.Exception.Message);
 }
Пример #23
0
        internal static void WriteException(System.Management.Automation.ErrorRecord error)
        {
            if (ExecutingCmdlet != null)
            {
                ExecutingCmdlet.WriteError(error);
            }
            else
            {
                Console.WriteLine(error.ToString());
            }

            if (!string.IsNullOrEmpty(LogFile))
            {
                File.AppendAllText(LogFile, error.ToString() + "\r\n");
            }
        }
Пример #24
0
 internal CmdletInvocationException(Exception innerException, InvocationInfo invocationInfo) : base(RuntimeException.RetrieveMessage(innerException), innerException)
 {
     if (innerException == null)
     {
         throw new ArgumentNullException("innerException");
     }
     IContainsErrorRecord record = innerException as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, innerException);
     }
     else
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(innerException, innerException.GetType().FullName, ErrorCategory.NotSpecified, null);
     }
     this._errorRecord.SetInvocationInfo(invocationInfo);
 }
Пример #25
0
        internal CmdletInvocationException(Exception innerException, InvocationInfo invocationInfo) : base(RuntimeException.RetrieveMessage(innerException), innerException)
        {
            if (innerException == null)
            {
                throw new ArgumentNullException("innerException");
            }
            IContainsErrorRecord record = innerException as IContainsErrorRecord;

            if ((record != null) && (record.ErrorRecord != null))
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, innerException);
            }
            else
            {
                this._errorRecord = new System.Management.Automation.ErrorRecord(innerException, innerException.GetType().FullName, ErrorCategory.NotSpecified, null);
            }
            this._errorRecord.SetInvocationInfo(invocationInfo);
        }
Пример #26
0
 internal ProviderInvocationException(string errorId, string resourceStr, System.Management.Automation.ProviderInfo provider, string path, Exception innerException, bool useInnerExceptionMessage) : base(RetrieveMessage(errorId, resourceStr, provider, path, innerException), innerException)
 {
     this._providerInfo = provider;
     this._message = base.Message;
     Exception replaceParentContainsErrorRecordException = null;
     if (useInnerExceptionMessage)
     {
         replaceParentContainsErrorRecordException = innerException;
     }
     else
     {
         replaceParentContainsErrorRecordException = new ParentContainsErrorRecordException(this);
     }
     IContainsErrorRecord record = innerException as IContainsErrorRecord;
     if ((record != null) && (record.ErrorRecord != null))
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(record.ErrorRecord, replaceParentContainsErrorRecordException);
     }
     else
     {
         this._errorRecord = new System.Management.Automation.ErrorRecord(replaceParentContainsErrorRecordException, errorId, ErrorCategory.InvalidOperation, null);
     }
 }
Пример #27
0
 public RuntimeException(string message, Exception innerException, System.Management.Automation.ErrorRecord errorRecord) : base(message, innerException)
 {
     this._errorId     = "RuntimeException";
     this._errorRecord = errorRecord;
 }
Пример #28
0
 public PSSecurityException(string message, Exception innerException) : base(message, innerException)
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(message);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #29
0
 protected PSSecurityException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "MshSecurityManager", "CanNotRun", new object[0]);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #30
0
 public PSSecurityException()
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "MshSecurityManager", "CanNotRun", new object[0]);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #31
0
 internal void SetRemoteErrorRecord(System.Management.Automation.ErrorRecord remoteError)
 {
     this._remoteErrorRecord = remoteError;
 }
Пример #32
0
 public PSSecurityException()
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "MshSecurityManager", "CanNotRun", new object[0]);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #33
0
 public RuntimeException(string message, Exception innerException, System.Management.Automation.ErrorRecord errorRecord) : base(message, innerException)
 {
     this._errorId = "RuntimeException";
     this._errorRecord = errorRecord;
 }
Пример #34
0
 internal void SetErrorId(string errorId)
 {
     if (this._errorId != errorId)
     {
         this._errorId = errorId;
         this._errorRecord = null;
     }
 }
Пример #35
0
 internal void SetErrorCategory(ErrorCategory errorCategory)
 {
     if (this._errorCategory != errorCategory)
     {
         this._errorCategory = errorCategory;
         this._errorRecord = null;
     }
 }
Пример #36
0
 protected PSSecurityException(SerializationInfo info, StreamingContext context) : base(info, context)
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "MshSecurityManager", "CanNotRun", new object[0]);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #37
0
 public PSSecurityException(string message, Exception innerException) : base(message, innerException)
 {
     this._errorRecord = new System.Management.Automation.ErrorRecord(new ParentContainsErrorRecordException(this), "UnauthorizedAccess", ErrorCategory.SecurityError, null);
     this._errorRecord.ErrorDetails = new ErrorDetails(message);
     this._message = this._errorRecord.ErrorDetails.Message;
 }
Пример #38
0
 internal void SetRemoteErrorRecord(System.Management.Automation.ErrorRecord remoteError)
 {
     this._remoteErrorRecord = remoteError;
 }