예제 #1
0
        private static string RetrieveMessage(string errorId, string resourceStr, System.Management.Automation.ProviderInfo provider, string path, Exception innerException)
        {
            if (innerException == null)
            {
                return("");
            }
            if (string.IsNullOrEmpty(errorId))
            {
                return(RuntimeException.RetrieveMessage(innerException));
            }
            if (provider == null)
            {
                return(RuntimeException.RetrieveMessage(innerException));
            }
            string str = resourceStr;

            if (string.IsNullOrEmpty(str))
            {
                return(RuntimeException.RetrieveMessage(innerException));
            }
            if (path == null)
            {
                return(string.Format(Thread.CurrentThread.CurrentCulture, str, new object[] { provider.Name, RuntimeException.RetrieveMessage(innerException) }));
            }
            return(string.Format(Thread.CurrentThread.CurrentCulture, str, new object[] { provider.Name, path, RuntimeException.RetrieveMessage(innerException) }));
        }
예제 #2
0
 internal WildcardPatternException(ErrorRecord errorRecord) : base(RuntimeException.RetrieveMessage(errorRecord))
 {
     if (errorRecord == null)
     {
         throw new ArgumentNullException("errorRecord");
     }
     this._errorRecord = errorRecord;
 }
예제 #3
0
        private static string RetrieveMessage(
            string errorId,
            string resourceStr,
            ProviderInfo provider,
            string path,
            Exception innerException)
        {
            if (null == innerException)
            {
                Diagnostics.Assert(false,
                                   "ProviderInvocationException.RetrieveMessage needs innerException");
                return("");
            }
            if (String.IsNullOrEmpty(errorId))
            {
                Diagnostics.Assert(false,
                                   "ProviderInvocationException.RetrieveMessage needs errorId");
                return(RuntimeException.RetrieveMessage(innerException));
            }
            if (null == provider)
            {
                Diagnostics.Assert(false,
                                   "ProviderInvocationException.RetrieveMessage needs provider");
                return(RuntimeException.RetrieveMessage(innerException));
            }

            string format = resourceStr;

            if (String.IsNullOrEmpty(format))
            {
                Diagnostics.Assert(false,
                                   "ProviderInvocationException.RetrieveMessage bad errorId " + errorId);
                return(RuntimeException.RetrieveMessage(innerException));
            }
            string result = null;

            if (path == null)
            {
                result =
                    String.Format(
                        System.Globalization.CultureInfo.CurrentCulture,
                        format,
                        provider.Name,
                        RuntimeException.RetrieveMessage(innerException));
            }
            else
            {
                result =
                    String.Format(
                        System.Globalization.CultureInfo.CurrentCulture,
                        format,
                        provider.Name,
                        path,
                        RuntimeException.RetrieveMessage(innerException));
            }
            return(result);
        }
예제 #4
0
 internal CmdletInvocationException(Exception innerException, InvocationInfo invocationInfo)
     : base(RuntimeException.RetrieveMessage(innerException), innerException)
 {
     if (innerException == null)
     {
         throw new ArgumentNullException(nameof(innerException));
     }
     this._errorRecord = !(innerException is IContainsErrorRecord containsErrorRecord) || containsErrorRecord.ErrorRecord == null ? new ErrorRecord(innerException, innerException.GetType().FullName, ErrorCategory.NotSpecified, (object)null) : new ErrorRecord(containsErrorRecord.ErrorRecord, innerException);
     this._errorRecord.SetInvocationInfo(invocationInfo);
 }
예제 #5
0
        /// <summary>
        /// Constructs a ProviderInvocationException with provider information and an
        /// ErrorRecord.
        /// </summary>
        /// <param name="provider">
        /// Information about the provider to be used in formatting the message.
        /// </param>
        /// <param name="errorRecord">
        /// Detailed error information
        /// </param>
        internal ProviderInvocationException(ProviderInfo provider, ErrorRecord errorRecord)
            : base(RuntimeException.RetrieveMessage(errorRecord),
                   RuntimeException.RetrieveException(errorRecord))
        {
            if (errorRecord == null)
            {
                throw new ArgumentNullException(nameof(errorRecord));
            }

            _message      = base.Message;
            _providerInfo = provider;
            _errorRecord  = errorRecord;
        }
예제 #6
0
        /// <summary>
        /// Constructs a ProviderInvocationException with provider information and an inner exception.
        /// </summary>
        /// <param name="provider">
        /// Information about the provider to be used in formatting the message.
        /// </param>
        /// <param name="innerException">
        /// The inner exception for this exception.
        /// </param>
        internal ProviderInvocationException(ProviderInfo provider, Exception innerException)
            : base(RuntimeException.RetrieveMessage(innerException), innerException)
        {
            _message      = base.Message;
            _providerInfo = provider;

            IContainsErrorRecord icer = innerException as IContainsErrorRecord;

            if (icer != null && icer.ErrorRecord != null)
            {
                _errorRecord = new ErrorRecord(icer.ErrorRecord, innerException);
            }
            else
            {
                _errorRecord = new ErrorRecord(
                    innerException,
                    "ErrorRecordNotSpecified",
                    ErrorCategory.InvalidOperation,
                    null);
            }
        }
예제 #7
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;
 }
예제 #8
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);
            }
        }
예제 #9
0
 internal CmdletInvocationException(ErrorRecord errorRecord)
     : base(RuntimeException.RetrieveMessage(errorRecord), RuntimeException.RetrieveException(errorRecord))
 {
     this._errorRecord = errorRecord != null ? errorRecord : throw new ArgumentNullException(nameof(errorRecord));
     Exception exception = errorRecord.Exception;
 }
예제 #10
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);
        }
예제 #11
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;
 }
 internal ActionPreferenceStopException(ErrorRecord error)
     : this(RuntimeException.RetrieveMessage(error))
     => this._errorRecord = error != null ? error : throw new ArgumentNullException(nameof(error));
 internal WildcardPatternException(ErrorRecord errorRecord)
     : base(RuntimeException.RetrieveMessage(errorRecord))
     => this._errorRecord = errorRecord != null ? errorRecord : throw new ArgumentNullException(nameof(errorRecord));
 internal ActionPreferenceStopException(System.Management.Automation.ErrorRecord error) : this(RuntimeException.RetrieveMessage(error))
 {
     if (error == null)
     {
         throw new ArgumentNullException("error");
     }
     this._errorRecord = error;
 }