コード例 #1
0
        private CimResponseType WriteErrorCallback(CimInstance cimError)
        {
            lock (this._jobStateLock)
            {
                this._jobHadErrors = true;
            }
            CimException     cimException          = new CimException(cimError);
            CimJobException  cimJobException       = CimJobException.CreateFromCimException(this.GetDescription(), this.JobContext, cimException);
            ErrorRecord      errorRecord           = cimJobException.ErrorRecord;
            ActionPreference errorActionPreference = this.JobContext.ErrorActionPreference;

            switch (errorActionPreference)
            {
            case ActionPreference.Stop:
            case ActionPreference.Inquire:
            {
                return(this.BlockingWriteError(errorRecord));
            }

            case ActionPreference.Continue:
            {
                this.WriteError(errorRecord);
                return(CimResponseType.Yes);
            }

            default:
            {
                this.WriteError(errorRecord);
                return(CimResponseType.Yes);
            }
            }
        }
コード例 #2
0
        public override void OnCompleted()
        {
            this.ExceptionSafeWrapper(
                delegate
            {
                foreach (ClientSideQuery.NotFoundError notFoundError in _cimQuery.GenerateNotFoundErrors())
                {
                    string errorId = "CmdletizationQuery_NotFound";
                    if (!string.IsNullOrEmpty(notFoundError.PropertyName))
                    {
                        errorId = errorId + "_" + notFoundError.PropertyName;
                    }

                    CimJobException cimJobException = CimJobException.CreateWithFullControl(
                        this.JobContext,
                        notFoundError.ErrorMessageGenerator(this.Description, this.JobContext.ClassName),
                        errorId,
                        ErrorCategory.ObjectNotFound);
                    if (!string.IsNullOrEmpty(notFoundError.PropertyName))
                    {
                        cimJobException.ErrorRecord.SetTargetObject(notFoundError.PropertyValue);
                    }

                    this.WriteError(cimJobException.ErrorRecord);
                }
            });
            base.OnCompleted();
        }
コード例 #3
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        internal static CimJobException CreateWithoutJobContext(string message, string errorId, ErrorCategory errorCategory, Exception inner = null)
        {
            CimJobException cimJobException = new CimJobException(message, inner);

            cimJobException.InitializeErrorRecord(null, errorId, errorCategory);
            return(cimJobException);
        }
コード例 #4
0
        private void OnNext(CimMethodStreamedResult streamedResult)
        {
            MethodParameter methodParameter = this.GetMethodOutputParameters()
                                              .SingleOrDefault(p => p.Name.Equals(streamedResult.ParameterName, StringComparison.OrdinalIgnoreCase));

            if (methodParameter == null)
            {
                string errorMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationResources.CimJob_InvalidOutputParameterName,
                    this.MethodSubject,
                    this.MethodName,
                    streamedResult.ParameterName);

                throw CimJobException.CreateWithFullControl(
                          this.JobContext,
                          errorMessage,
                          "CimJob_InvalidOutputParameterName",
                          ErrorCategory.MetadataError);
            }

            var array = LanguagePrimitives.GetEnumerable(streamedResult.ItemValue);

            if (array != null)
            {
                foreach (var element in array)
                {
                    this.WriteObject(element, methodParameter);
                }
            }
            else
            {
                this.WriteObject(streamedResult.ItemValue, methodParameter);
            }
        }
コード例 #5
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        internal static CimJobException CreateWithFullControl(CimJobContext jobContext, string message, string errorId, ErrorCategory errorCategory, Exception inner = null)
        {
            CimJobException cimJobException = new CimJobException(jobContext.PrependComputerNameToMessage(message), inner);

            cimJobException.InitializeErrorRecord(jobContext, errorId, errorCategory);
            return(cimJobException);
        }
コード例 #6
0
        private void OnNext(CimMethodStreamedResult streamedResult)
        {
            MethodParameter methodParameter = base.GetMethodOutputParameters().SingleOrDefault <MethodParameter>((MethodParameter p) => p.Name.Equals(streamedResult.ParameterName, StringComparison.OrdinalIgnoreCase));

            if (methodParameter != null)
            {
                IEnumerable enumerable = LanguagePrimitives.GetEnumerable(streamedResult.ItemValue);
                if (enumerable == null)
                {
                    this.WriteObject(streamedResult.ItemValue, methodParameter);
                }
                else
                {
                    foreach (object obj in enumerable)
                    {
                        this.WriteObject(obj, methodParameter);
                    }
                }
                return;
            }
            else
            {
                object[] methodSubject = new object[3];
                methodSubject[0] = base.MethodSubject;
                methodSubject[1] = base.MethodName;
                methodSubject[2] = streamedResult.ParameterName;
                string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_InvalidOutputParameterName, methodSubject);
                throw CimJobException.CreateWithFullControl(base.JobContext, str, "CimJob_InvalidOutputParameterName", ErrorCategory.MetadataError, null);
            }
        }
コード例 #7
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException)
        {
            string          cmdletizationClassName;
            CimJobException cimJobException = this;
            CimJobContext   cimJobContext   = jobContext;
            CimException    cimException1   = cimException;
            string          messageId       = cimException.MessageId;
            string          str             = messageId;

            if (messageId == null)
            {
                str = string.Concat("MiClientApiError_", cimException.NativeErrorCode);
            }
            cimJobException.InitializeErrorRecordCore(cimJobContext, cimException1, str, CimJobException.ConvertCimExceptionToErrorCategory(cimException));
            if (cimException.ErrorData != null)
            {
                this.errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
                ErrorCategoryInfo categoryInfo = this.errorRecord.CategoryInfo;
                if (jobContext != null)
                {
                    cmdletizationClassName = jobContext.CmdletizationClassName;
                }
                else
                {
                    cmdletizationClassName = null;
                }
                categoryInfo.TargetType = cmdletizationClassName;
            }
        }
コード例 #8
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        internal static CimJobException CreateFromCimException(string jobDescription, CimJobContext jobContext, CimException cimException)
        {
            string          str             = CimJobException.BuildErrorMessage(jobDescription, jobContext, cimException.Message);
            CimJobException cimJobException = new CimJobException(str, cimException);

            cimJobException.InitializeErrorRecord(jobContext, cimException);
            return(cimJobException);
        }
コード例 #9
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        internal static CimJobException CreateFromMethodErrorCode(string jobDescription, CimJobContext jobContext, string methodName, string errorCodeFromMethod)
        {
            object[] objArray = new object[1];
            objArray[0] = errorCodeFromMethod;
            string          str             = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_ErrorCodeFromMethod, objArray);
            string          str1            = CimJobException.BuildErrorMessage(jobDescription, jobContext, str);
            CimJobException cimJobException = new CimJobException(str1);

            cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", methodName, "_", errorCodeFromMethod), ErrorCategory.InvalidResult);
            return(cimJobException);
        }
コード例 #10
0
 internal void ExceptionSafeWrapper(Action action)
 {
     try
     {
         try
         {
             action();
         }
         catch (CimJobException cimJobException1)
         {
             CimJobException cimJobException = cimJobException1;
             this.ReportJobFailure(cimJobException);
         }
         catch (PSInvalidCastException pSInvalidCastException1)
         {
             PSInvalidCastException pSInvalidCastException = pSInvalidCastException1;
             this.ReportJobFailure(pSInvalidCastException);
         }
         catch (CimException cimException1)
         {
             CimException    cimException     = cimException1;
             CimJobException cimJobException2 = CimJobException.CreateFromCimException(this.GetDescription(), this.JobContext, cimException);
             this.ReportJobFailure(cimJobException2);
         }
         catch (PSInvalidOperationException pSInvalidOperationException)
         {
             lock (this._jobStateLock)
             {
                 bool flag = false;
                 if (this._jobWasStopped)
                 {
                     flag = true;
                 }
                 if (this._alreadyReachedCompletedState && this._jobHadErrors)
                 {
                     flag = true;
                 }
                 if (!flag)
                 {
                     throw;
                 }
             }
         }
     }
     catch (Exception exception1)
     {
         Exception       exception        = exception1;
         CimJobException cimJobException3 = CimJobException.CreateFromAnyException(this.GetDescription(), this.JobContext, exception);
         this.ReportJobFailure(cimJobException3);
     }
 }
コード例 #11
0
        private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter methodParameter, IDictionary <string, MethodParameter> cmdletOutput)
        {
            object             value;
            CimMethodParameter item = methodResult.OutParameters[methodParameter.Name];

            if (item == null)
            {
                value = null;
            }
            else
            {
                value = item.Value;
            }
            object obj    = value;
            object dotNet = CimValueConverter.ConvertFromCimToDotNet(obj, methodParameter.ParameterType);

            if (MethodParameterBindings.Out != (methodParameter.Bindings & MethodParameterBindings.Out))
            {
                if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error))
                {
                    bool flag = (bool)LanguagePrimitives.ConvertTo(dotNet, typeof(bool), CultureInfo.InvariantCulture);
                    if (flag)
                    {
                        string          str             = (string)LanguagePrimitives.ConvertTo(dotNet, typeof(string), CultureInfo.InvariantCulture);
                        CimJobException cimJobException = CimJobException.CreateFromMethodErrorCode(base.GetDescription(), base.JobContext, base.MethodName, str);
                        throw cimJobException;
                    }
                }
            }
            else
            {
                methodParameter.Value = dotNet;
                cmdletOutput.Add(methodParameter.Name, methodParameter);
                CimInstance[] cimInstanceArray = dotNet as CimInstance[];
                if (cimInstanceArray != null)
                {
                    CimInstance[] cimInstanceArray1 = cimInstanceArray;
                    for (int i = 0; i < (int)cimInstanceArray1.Length; i++)
                    {
                        CimInstance cimInstance = cimInstanceArray1[i];
                        CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session);
                    }
                }
                CimInstance cimInstance1 = dotNet as CimInstance;
                if (cimInstance1 != null)
                {
                    CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance1, this.JobContext.Session);
                    return;
                }
            }
        }
コード例 #12
0
        internal void ExceptionSafeWrapper(Action action)
        {
            try
            {
                try
                {
                    Dbg.Assert(action != null, "Caller should verify action != null");
                    action();
                }
                catch (CimJobException e)
                {
                    this.ReportJobFailure(e);
                }
                catch (PSInvalidCastException e)
                {
                    this.ReportJobFailure(e);
                }
                catch (CimException e)
                {
                    var cje = CimJobException.CreateFromCimException(this.GetDescription(), this.JobContext, e);
                    this.ReportJobFailure(cje);
                }
                catch (PSInvalidOperationException)
                {
                    lock (_jobStateLock)
                    {
                        bool everythingIsOk = false;
                        if (_jobWasStopped)
                        {
                            everythingIsOk = true;
                        }

                        if (_alreadyReachedCompletedState && _jobHadErrors)
                        {
                            everythingIsOk = true;
                        }

                        if (!everythingIsOk)
                        {
                            Dbg.Assert(false, "PSInvalidOperationException should only happen in certain job states");
                            throw;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var cje = CimJobException.CreateFromAnyException(this.GetDescription(), this.JobContext, e);
                this.ReportJobFailure(cje);
            }
        }
コード例 #13
0
        internal static CimJobException CreateWithoutJobContext(
            string message,
            string errorId,
            ErrorCategory errorCategory,
            Exception inner = null)
        {
            Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
            Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");

            CimJobException cimJobException = new CimJobException(message, inner);

            cimJobException.InitializeErrorRecord(null, errorId, errorCategory);
            return(cimJobException);
        }
コード例 #14
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        private static ErrorCategory ConvertCimExceptionToErrorCategory(CimException cimException)
        {
            ErrorCategory errorCategory = ErrorCategory.NotSpecified;

            if (cimException.ErrorData != null)
            {
                errorCategory = CimJobException.ConvertCimErrorToErrorCategory(cimException.ErrorData);
            }
            if (errorCategory == ErrorCategory.NotSpecified)
            {
                errorCategory = CimJobException.ConvertCimNativeErrorCodeToErrorCategory(cimException.NativeErrorCode);
            }
            return(errorCategory);
        }
コード例 #15
0
        internal static CimJobException CreateFromCimException(
            string jobDescription,
            CimJobContext jobContext,
            CimException cimException)
        {
            Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(cimException != null, "Caller should verify cimException != null");

            string          message         = BuildErrorMessage(jobDescription, jobContext, cimException.Message);
            CimJobException cimJobException = new CimJobException(message, cimException);

            cimJobException.InitializeErrorRecord(jobContext, cimException);
            return(cimJobException);
        }
コード例 #16
0
        internal static CimJobException CreateFromMethodErrorCode(string jobDescription, CimJobContext jobContext, string methodName, string errorCodeFromMethod)
        {
            string rawErrorMessage = string.Format(
                CultureInfo.InvariantCulture,
                CmdletizationResources.CimJob_ErrorCodeFromMethod,
                errorCodeFromMethod);

            string errorMessage = BuildErrorMessage(jobDescription, jobContext, rawErrorMessage);

            CimJobException cje = new CimJobException(errorMessage);

            cje.InitializeErrorRecord(jobContext, "CimJob_" + methodName + "_" + errorCodeFromMethod, ErrorCategory.InvalidResult);

            return(cje);
        }
コード例 #17
0
        public virtual void OnError(Exception exception)
        {
            this.ExceptionSafeWrapper(
                delegate
            {
                if (IsWsManQuotaReached(exception))
                {
                    this.SleepAndRetry();
                    return;
                }

                var cje = CimJobException.CreateFromAnyException(this.GetDescription(), this.JobContext, exception);
                this.ReportJobFailure(cje);
            });
        }
コード例 #18
0
        internal static CimJobException CreateWithFullControl(
            CimJobContext jobContext,
            string message,
            string errorId,
            ErrorCategory errorCategory,
            Exception inner = null)
        {
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
            Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");

            CimJobException cimJobException = new CimJobException(jobContext.PrependComputerNameToMessage(message), inner);

            cimJobException.InitializeErrorRecord(jobContext, errorId, errorCategory);
            return(cimJobException);
        }
コード例 #19
0
 public virtual void OnError(Exception exception)
 {
     this.ExceptionSafeWrapper(() => {
         if (!CimChildJobBase <T> .IsWsManQuotaReached(exception))
         {
             CimJobException cimJobException = CimJobException.CreateFromAnyException(this.GetDescription(), this.JobContext, exception);
             this.ReportJobFailure(cimJobException);
             return;
         }
         else
         {
             this.SleepAndRetry();
             return;
         }
     }
                               );
 }
コード例 #20
0
        private void ProcessOutParameter(CimMethodResult methodResult, MethodParameter methodParameter, IDictionary <string, MethodParameter> cmdletOutput)
        {
            Dbg.Assert(methodResult != null, "Caller should verify methodResult != null");
            Dbg.Assert(methodParameter != null, "Caller should verify methodParameter != null");
            Dbg.Assert(0 != (methodParameter.Bindings & (MethodParameterBindings.Out | MethodParameterBindings.Error)), "Caller should verify that this is an out parameter");
            Dbg.Assert(cmdletOutput != null, "Caller should verify cmdletOutput != null");

            Dbg.Assert(this.MethodSubject != null, "MethodSubject property should be initialized before starting main job processing");

            CimMethodParameter outParameter            = methodResult.OutParameters[methodParameter.Name];
            object             valueReturnedFromMethod = (outParameter == null) ? null : outParameter.Value;

            object dotNetValue = CimValueConverter.ConvertFromCimToDotNet(valueReturnedFromMethod, methodParameter.ParameterType);

            if (MethodParameterBindings.Out == (methodParameter.Bindings & MethodParameterBindings.Out))
            {
                methodParameter.Value = dotNetValue;
                cmdletOutput.Add(methodParameter.Name, methodParameter);

                var cimInstances = dotNetValue as CimInstance[];
                if (cimInstances != null)
                {
                    foreach (var instance in cimInstances)
                    {
                        CimCmdletAdapter.AssociateSessionOfOriginWithInstance(instance, this.JobContext.Session);
                    }
                }

                var cimInstance = dotNetValue as CimInstance;
                if (cimInstance != null)
                {
                    CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session);
                }
            }
            else if (MethodParameterBindings.Error == (methodParameter.Bindings & MethodParameterBindings.Error))
            {
                var gotError = (bool)LanguagePrimitives.ConvertTo(dotNetValue, typeof(bool), CultureInfo.InvariantCulture);
                if (gotError)
                {
                    var             errorCodeAsString = (string)LanguagePrimitives.ConvertTo(dotNetValue, typeof(string), CultureInfo.InvariantCulture);
                    CimJobException cje = CimJobException.CreateFromMethodErrorCode(this.GetDescription(), this.JobContext, this.MethodName, errorCodeAsString);
                    throw cje;
                }
            }
        }
コード例 #21
0
ファイル: ClientSideQuery.cs プロジェクト: modulexcite/pash-1
 private object ConvertActualValueToExpectedType(object actualPropertyValue, object expectedPropertyValue)
 {
     if (actualPropertyValue as string != null && expectedPropertyValue as string == null)
     {
         actualPropertyValue = LanguagePrimitives.ConvertTo(actualPropertyValue, expectedPropertyValue.GetType(), CultureInfo.InvariantCulture);
     }
     if (ClientSideQuery.PropertyValueFilter.IsSameType(actualPropertyValue, expectedPropertyValue))
     {
         return(actualPropertyValue);
     }
     else
     {
         object[] fullName = new object[3];
         fullName[0] = this.propertyName;
         fullName[1] = actualPropertyValue.GetType().FullName;
         fullName[2] = expectedPropertyValue.GetType().FullName;
         string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_MismatchedTypeOfPropertyReturnedByQuery, fullName);
         throw CimJobException.CreateWithoutJobContext(str, "CimJob_PropertyTypeUnexpectedByClientSideQuery", ErrorCategory.InvalidType, null);
     }
 }
コード例 #22
0
ファイル: QueryJobBase.cs プロジェクト: modulexcite/pash-1
 public override void OnCompleted()
 {
     base.ExceptionSafeWrapper(() => {
         foreach (ClientSideQuery.NotFoundError notFoundError in this._cimQuery.GenerateNotFoundErrors())
         {
             string str = "CmdletizationQuery_NotFound";
             if (!string.IsNullOrEmpty(notFoundError.PropertyName))
             {
                 str = string.Concat(str, "_", notFoundError.PropertyName);
             }
             CimJobException cimJobException = CimJobException.CreateWithFullControl(base.JobContext, notFoundError.ErrorMessageGenerator(this.Description, base.JobContext.ClassName), str, ErrorCategory.ObjectNotFound, null);
             if (!string.IsNullOrEmpty(notFoundError.PropertyName))
             {
                 cimJobException.ErrorRecord.SetTargetObject(notFoundError.PropertyValue);
             }
             this.WriteError(cimJobException.ErrorRecord);
         }
     }
                               );
     base.OnCompleted();
 }
コード例 #23
0
        private CimResponseType WriteErrorCallback(CimInstance cimError)
        {
            lock (_jobStateLock)
            {
                _jobHadErrors = true;
            }

            var cimException = new CimException(cimError);
            var jobException = CimJobException.CreateFromCimException(this.GetDescription(), this.JobContext, cimException);
            var errorRecord  = jobException.ErrorRecord;

            switch (this.JobContext.ErrorActionPreference)
            {
            case ActionPreference.Stop:
            case ActionPreference.Inquire:
                return(this.BlockingWriteError(errorRecord));

            default:
                this.WriteError(errorRecord);
                return(CimResponseType.Yes);
            }
        }
コード例 #24
0
            private object ConvertActualValueToExpectedType(object actualPropertyValue, object expectedPropertyValue)
            {
                if (actualPropertyValue is string && expectedPropertyValue is not string)
                {
                    actualPropertyValue = LanguagePrimitives.ConvertTo(actualPropertyValue, expectedPropertyValue.GetType(), CultureInfo.InvariantCulture);
                }

                if (!IsSameType(actualPropertyValue, expectedPropertyValue))
                {
                    var errorMessage = string.Format(
                        CultureInfo.InvariantCulture,
                        CmdletizationResources.CimJob_MismatchedTypeOfPropertyReturnedByQuery,
                        PropertyName,
                        actualPropertyValue.GetType().FullName,
                        expectedPropertyValue.GetType().FullName);
                    throw CimJobException.CreateWithoutJobContext(
                              errorMessage,
                              "CimJob_PropertyTypeUnexpectedByClientSideQuery",
                              ErrorCategory.InvalidType);
                }

                return(actualPropertyValue);
            }
コード例 #25
0
        internal static CimJobException CreateFromAnyException(
            string jobDescription,
            CimJobContext jobContext,
            Exception inner)
        {
            Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(inner != null, "Caller should verify inner != null");

            CimException cimException = inner as CimException;

            if (cimException != null)
            {
                return(CreateFromCimException(jobDescription, jobContext, cimException));
            }

            string          message             = BuildErrorMessage(jobDescription, jobContext, inner.Message);
            CimJobException cimJobException     = new CimJobException(message, inner);
            var             containsErrorRecord = inner as IContainsErrorRecord;

            if (containsErrorRecord != null)
            {
                cimJobException.InitializeErrorRecord(
                    jobContext,
                    errorId: "CimJob_" + containsErrorRecord.ErrorRecord.FullyQualifiedErrorId,
                    errorCategory: containsErrorRecord.ErrorRecord.CategoryInfo.Category);
            }
            else
            {
                cimJobException.InitializeErrorRecord(
                    jobContext,
                    errorId: "CimJob_" + inner.GetType().Name,
                    errorCategory: ErrorCategory.NotSpecified);
            }

            return(cimJobException);
        }
コード例 #26
0
ファイル: CimJobException.cs プロジェクト: modulexcite/pash-1
        internal static CimJobException CreateFromAnyException(string jobDescription, CimJobContext jobContext, Exception inner)
        {
            CimException cimException = inner as CimException;

            if (cimException == null)
            {
                string               str                 = CimJobException.BuildErrorMessage(jobDescription, jobContext, inner.Message);
                CimJobException      cimJobException     = new CimJobException(str, inner);
                IContainsErrorRecord containsErrorRecord = inner as IContainsErrorRecord;
                if (containsErrorRecord == null)
                {
                    cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", inner.GetType().Name), ErrorCategory.NotSpecified);
                }
                else
                {
                    cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", containsErrorRecord.ErrorRecord.FullyQualifiedErrorId), containsErrorRecord.ErrorRecord.CategoryInfo.Category);
                }
                return(cimJobException);
            }
            else
            {
                return(CimJobException.CreateFromCimException(jobDescription, jobContext, cimException));
            }
        }
コード例 #27
0
ファイル: CimJobException.cs プロジェクト: 40a/PowerShell
        internal static CimJobException CreateFromCimException(
            string jobDescription,
            CimJobContext jobContext,
            CimException cimException)
        {
            Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(cimException != null, "Caller should verify cimException != null");

            string message = BuildErrorMessage(jobDescription, jobContext, cimException.Message);
            CimJobException cimJobException = new CimJobException(message, cimException);
            cimJobException.InitializeErrorRecord(jobContext, cimException);
            return cimJobException;
        }
コード例 #28
0
        internal void ReportJobFailure(IContainsErrorRecord exception)
        {
            TerminatingErrorTracker terminatingErrorTracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo);

            bool      sessionWasAlreadyTerminated = false;
            bool      isThisTerminatingError      = false;
            Exception brokenSessionException      = null;

            lock (_jobStateLock)
            {
                if (!_jobWasStopped)
                {
                    brokenSessionException = terminatingErrorTracker.GetExceptionIfBrokenSession(
                        this.JobContext.Session,
                        this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SkipTestConnection,
                        out sessionWasAlreadyTerminated);
                }
            }

            if (brokenSessionException != null)
            {
                string brokenSessionMessage = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationResources.CimJob_BrokenSession,
                    brokenSessionException.Message);
                exception = CimJobException.CreateWithFullControl(
                    this.JobContext,
                    brokenSessionMessage,
                    "CimJob_BrokenCimSession",
                    ErrorCategory.ResourceUnavailable,
                    brokenSessionException);
                isThisTerminatingError = true;
            }
            else
            {
                CimJobException cje = exception as CimJobException;
                if ((cje != null) && (cje.IsTerminatingError))
                {
                    terminatingErrorTracker.MarkSessionAsTerminated(this.JobContext.Session, out sessionWasAlreadyTerminated);
                    isThisTerminatingError = true;
                }
            }

            bool writeError = !sessionWasAlreadyTerminated;

            if (writeError)
            {
                lock (_jobStateLock)
                {
                    if (_jobWasStopped)
                    {
                        writeError = false;
                    }
                }
            }

            ErrorRecord errorRecord = exception.ErrorRecord;

            errorRecord.SetInvocationInfo(this.JobContext.CmdletInvocationInfo);
            errorRecord.PreserveInvocationInfoOnce = true;

            if (writeError)
            {
                lock (_jobStateLock)
                {
                    if (!_alreadyReachedCompletedState)
                    {
                        if (isThisTerminatingError)
                        {
                            this.Error.Add(errorRecord);
                            CmdletMethodInvoker <bool> methodInvoker = terminatingErrorTracker.GetErrorReportingDelegate(errorRecord);
                            this.Results.Add(new PSStreamObject(PSStreamObjectType.ShouldMethod, methodInvoker));
                        }
                        else
                        {
                            this.WriteError(errorRecord);
                        }
                    }
                }
            }

            this.SetCompletedJobState(JobState.Failed, errorRecord.Exception);
        }
コード例 #29
0
ファイル: CimJobException.cs プロジェクト: nickchal/pash
		internal static CimJobException CreateWithFullControl(CimJobContext jobContext, string message, string errorId, ErrorCategory errorCategory, Exception inner = null)
		{
			CimJobException cimJobException = new CimJobException(jobContext.PrependComputerNameToMessage(message), inner);
			cimJobException.InitializeErrorRecord(jobContext, errorId, errorCategory);
			return cimJobException;
		}
コード例 #30
0
ファイル: CimJobException.cs プロジェクト: 40a/PowerShell
        internal static CimJobException CreateWithFullControl(
            CimJobContext jobContext,
            string message,
            string errorId,
            ErrorCategory errorCategory,
            Exception inner = null)
        {
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
            Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");

            CimJobException cimJobException = new CimJobException(jobContext.PrependComputerNameToMessage(message), inner);
            cimJobException.InitializeErrorRecord(jobContext, errorId, errorCategory);
            return cimJobException;
        }
コード例 #31
0
ファイル: CimJobException.cs プロジェクト: 40a/PowerShell
        internal static CimJobException CreateFromAnyException(
            string jobDescription,
            CimJobContext jobContext,
            Exception inner)
        {
            Dbg.Assert(!string.IsNullOrEmpty(jobDescription), "Caller should verify jobDescription != null");
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");
            Dbg.Assert(inner != null, "Caller should verify inner != null");

            CimException cimException = inner as CimException;
            if (cimException != null)
            {
                return CreateFromCimException(jobDescription, jobContext, cimException);
            }

            string message = BuildErrorMessage(jobDescription, jobContext, inner.Message);
            CimJobException cimJobException = new CimJobException(message, inner);
            var containsErrorRecord = inner as IContainsErrorRecord;
            if (containsErrorRecord != null)
            {
                cimJobException.InitializeErrorRecord(
                    jobContext,
                    errorId: "CimJob_" + containsErrorRecord.ErrorRecord.FullyQualifiedErrorId,
                    errorCategory: containsErrorRecord.ErrorRecord.CategoryInfo.Category);
            }
            else
            {
                cimJobException.InitializeErrorRecord(
                    jobContext,
                    errorId: "CimJob_" + inner.GetType().Name,
                    errorCategory: ErrorCategory.NotSpecified);
            }
            return cimJobException;
        }
コード例 #32
0
ファイル: CimJobException.cs プロジェクト: 40a/PowerShell
        internal static CimJobException CreateFromMethodErrorCode(string jobDescription, CimJobContext jobContext, string methodName, string errorCodeFromMethod)
        {
            string rawErrorMessage = string.Format(
                CultureInfo.InvariantCulture,
                CmdletizationResources.CimJob_ErrorCodeFromMethod,
                errorCodeFromMethod);

            string errorMessage = BuildErrorMessage(jobDescription, jobContext, rawErrorMessage);

            CimJobException cje = new CimJobException(errorMessage);
            cje.InitializeErrorRecord(jobContext, "CimJob_" + methodName + "_" + errorCodeFromMethod, ErrorCategory.InvalidResult);

            return cje;
        }
コード例 #33
0
ファイル: CimJobException.cs プロジェクト: 40a/PowerShell
        internal static CimJobException CreateWithoutJobContext(
            string message,
            string errorId,
            ErrorCategory errorCategory,
            Exception inner = null)
        {
            Dbg.Assert(!string.IsNullOrEmpty(message), "Caller should verify message != null");
            Dbg.Assert(!string.IsNullOrEmpty(errorId), "Caller should verify errorId != null");

            CimJobException cimJobException = new CimJobException(message, inner);
            cimJobException.InitializeErrorRecord(null, errorId, errorCategory);
            return cimJobException;
        }
コード例 #34
0
ファイル: CimJobException.cs プロジェクト: nickchal/pash
		internal static CimJobException CreateFromMethodErrorCode(string jobDescription, CimJobContext jobContext, string methodName, string errorCodeFromMethod)
		{
			object[] objArray = new object[1];
			objArray[0] = errorCodeFromMethod;
			string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_ErrorCodeFromMethod, objArray);
			string str1 = CimJobException.BuildErrorMessage(jobDescription, jobContext, str);
			CimJobException cimJobException = new CimJobException(str1);
			cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", methodName, "_", errorCodeFromMethod), ErrorCategory.InvalidResult);
			return cimJobException;
		}
コード例 #35
0
ファイル: CimJobException.cs プロジェクト: nickchal/pash
		internal static CimJobException CreateWithoutJobContext(string message, string errorId, ErrorCategory errorCategory, Exception inner = null)
		{
			CimJobException cimJobException = new CimJobException(message, inner);
			cimJobException.InitializeErrorRecord(null, errorId, errorCategory);
			return cimJobException;
		}
コード例 #36
0
        internal void ReportJobFailure(IContainsErrorRecord exception)
        {
            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo);
            bool      flag  = false;
            bool      flag1 = false;
            Exception exceptionIfBrokenSession = null;

            lock (this._jobStateLock)
            {
                if (!this._jobWasStopped)
                {
                    exceptionIfBrokenSession = tracker.GetExceptionIfBrokenSession(this.JobContext.Session, this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SkipTestConnection, out flag);
                }
            }
            if (exceptionIfBrokenSession == null)
            {
                CimJobException cimJobException = exception as CimJobException;
                if (cimJobException != null && cimJobException.IsTerminatingError)
                {
                    tracker.MarkSessionAsTerminated(this.JobContext.Session, out flag);
                    flag1 = true;
                }
            }
            else
            {
                object[] message = new object[1];
                message[0] = exceptionIfBrokenSession.Message;
                string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_BrokenSession, message);
                exception = CimJobException.CreateWithFullControl(this.JobContext, str, "CimJob_BrokenCimSession", ErrorCategory.ResourceUnavailable, exceptionIfBrokenSession);
                flag1     = true;
            }
            bool flag2 = !flag;

            if (flag2)
            {
                lock (this._jobStateLock)
                {
                    if (this._jobWasStopped)
                    {
                        flag2 = false;
                    }
                }
            }
            ErrorRecord errorRecord = exception.ErrorRecord;

            errorRecord.SetInvocationInfo(this.JobContext.CmdletInvocationInfo);
            errorRecord.PreserveInvocationInfoOnce = true;
            if (flag2)
            {
                lock (this._jobStateLock)
                {
                    if (!this._alreadyReachedCompletedState)
                    {
                        if (!flag1)
                        {
                            this.WriteError(errorRecord);
                        }
                        else
                        {
                            base.Error.Add(errorRecord);
                            CmdletMethodInvoker <bool> errorReportingDelegate = tracker.GetErrorReportingDelegate(errorRecord);
                            base.Results.Add(new PSStreamObject(PSStreamObjectType.ShouldMethod, errorReportingDelegate));
                        }
                    }
                }
            }
            this.SetCompletedJobState(JobState.Failed, errorRecord.Exception);
        }
コード例 #37
0
ファイル: CimJobException.cs プロジェクト: nickchal/pash
		internal static CimJobException CreateFromAnyException(string jobDescription, CimJobContext jobContext, Exception inner)
		{
			CimException cimException = inner as CimException;
			if (cimException == null)
			{
				string str = CimJobException.BuildErrorMessage(jobDescription, jobContext, inner.Message);
				CimJobException cimJobException = new CimJobException(str, inner);
				IContainsErrorRecord containsErrorRecord = inner as IContainsErrorRecord;
				if (containsErrorRecord == null)
				{
					cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", inner.GetType().Name), ErrorCategory.NotSpecified);
				}
				else
				{
					cimJobException.InitializeErrorRecord(jobContext, string.Concat("CimJob_", containsErrorRecord.ErrorRecord.FullyQualifiedErrorId), containsErrorRecord.ErrorRecord.CategoryInfo.Category);
				}
				return cimJobException;
			}
			else
			{
				return CimJobException.CreateFromCimException(jobDescription, jobContext, cimException);
			}
		}
コード例 #38
0
ファイル: CimJobException.cs プロジェクト: nickchal/pash
		internal static CimJobException CreateFromCimException(string jobDescription, CimJobContext jobContext, CimException cimException)
		{
			string str = CimJobException.BuildErrorMessage(jobDescription, jobContext, cimException.Message);
			CimJobException cimJobException = new CimJobException(str, cimException);
			cimJobException.InitializeErrorRecord(jobContext, cimException);
			return cimJobException;
		}