Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a <see cref="System.Management.Automation.Job"/> object that invokes a static method
        /// (of the class named by <see cref="Microsoft.PowerShell.Cmdletization.CmdletAdapter&lt;TObjectInstance&gt;.ClassName"/>)
        /// in the wrapped object model.
        /// </summary>
        /// <param name="session">Remote session to invoke the method in.</param>
        /// <param name="methodInvocationInfo">Method invocation details.</param>
        internal override StartableJob CreateStaticMethodInvocationJob(CimSession session, MethodInvocationInfo methodInvocationInfo)
        {
            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, isStaticCmdlet: true);

            if (tracker.IsSessionTerminated(session))
            {
                return(null);
            }

            if (!IsSupportedSession(session, tracker))
            {
                return(null);
            }

            CimJobContext jobContext = this.CreateJobContext(session, targetObject: null);

            StartableJob result;

            if (methodInvocationInfo.MethodName.Equals(CimCmdletAdapter.CreateInstance_MethodName, StringComparison.OrdinalIgnoreCase))
            {
                result = new CreateInstanceJob(
                    jobContext,
                    methodInvocationInfo);
            }
            else
            {
                result = new StaticMethodInvocationJob(
                    jobContext,
                    methodInvocationInfo);
            }

            return(result);
        }
		internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole) : base(jobContext, cimQuery)
		{
			this.associatedObject = associatedObject;
			this.associationName = associationName;
			this.resultRole = resultRole;
			this.sourceRole = sourceRole;
		}
Exemplo n.º 4
0
        private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
        {
            object        targetObject;
            Exception     exception1     = exception;
            string        str            = errorId;
            ErrorCategory errorCategory1 = errorCategory;

            if (jobContext != null)
            {
                targetObject = jobContext.TargetObject;
            }
            else
            {
                targetObject = null;
            }
            ErrorRecord errorRecord = new ErrorRecord(exception1, str, errorCategory1, targetObject);

            if (jobContext == null)
            {
                this.errorRecord = errorRecord;
                return;
            }
            else
            {
                OriginInfo originInfo = new OriginInfo(jobContext.Session.ComputerName, Guid.Empty);
                this.errorRecord = new RemotingErrorRecord(errorRecord, originInfo);
                this.errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
                this.errorRecord.PreserveInvocationInfoOnce = true;
                return;
            }
        }
Exemplo n.º 5
0
        internal QueryInstancesJob(CimJobContext jobContext, CimQuery cimQuery, string wqlCondition)
            : base(jobContext, cimQuery)
        {
            Dbg.Assert(wqlCondition != null, "Caller should verify that wqlCondition is not null");

            var wqlQueryBuilder = new StringBuilder();

            wqlQueryBuilder.Append("SELECT * FROM ");
            wqlQueryBuilder.Append(this.JobContext.ClassName);
            wqlQueryBuilder.Append(" ");
            wqlQueryBuilder.Append(wqlCondition);
            _wqlQuery = wqlQueryBuilder.ToString();

            if (string.IsNullOrWhiteSpace(wqlCondition))
            {
                _useEnumerateInstances = true;
            }
            else
            {
                if (jobContext.CmdletInvocationContext.CmdletDefinitionContext.UseEnumerateInstancesInsteadOfWql)
                {
                    _useEnumerateInstances = true;
                }
            }
        }
Exemplo n.º 6
0
        private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
        {
            ErrorRecord coreErrorRecord = new ErrorRecord(
                exception: exception,
                errorId: errorId,
                errorCategory: errorCategory,
                targetObject: jobContext != null ? jobContext.TargetObject : null);

            if (jobContext != null)
            {
                System.Management.Automation.Remoting.OriginInfo originInfo = new System.Management.Automation.Remoting.OriginInfo(
                    jobContext.Session.ComputerName,
                    Guid.Empty);

                _errorRecord = new System.Management.Automation.Runspaces.RemotingErrorRecord(
                    coreErrorRecord,
                    originInfo);

                _errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
                _errorRecord.PreserveInvocationInfoOnce = true;
            }
            else
            {
                _errorRecord = coreErrorRecord;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a <see cref="System.Management.Automation.Job"/> object that performs a query against the wrapped object model.
        /// </summary>
        /// <param name="session">Remote session to query</param>
        /// <param name="baseQuery">Query parameters</param>
        /// <returns><see cref="System.Management.Automation.Job"/> object that performs a query against the wrapped object model</returns>
        internal override StartableJob CreateQueryJob(CimSession session, QueryBuilder baseQuery)
        {
            CimQuery query = baseQuery as CimQuery;

            if (query == null)
            {
                throw new ArgumentNullException("baseQuery");
            }

            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, isStaticCmdlet: false);

            if (tracker.IsSessionTerminated(session))
            {
                return(null);
            }

            if (!IsSupportedSession(session, tracker))
            {
                return(null);
            }

            CimJobContext jobContext = this.CreateJobContext(session, targetObject: null);
            StartableJob  queryJob   = query.GetQueryJob(jobContext);

            return(queryJob);
        }
 internal MethodInvocationJobBase(CimJobContext jobContext, bool passThru, string methodSubject, MethodInvocationInfo methodInvocationInfo)
     : base(jobContext)
 {
     this._passThru             = passThru;
     this._methodSubject        = methodSubject;
     this._methodInvocationInfo = methodInvocationInfo;
 }
Exemplo n.º 9
0
        internal override StartableJob CreateStaticMethodInvocationJob(CimSession session, MethodInvocationInfo methodInvocationInfo)
        {
            StartableJob            staticMethodInvocationJob;
            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, true);

            if (!tracker.IsSessionTerminated(session))
            {
                if (this.IsSupportedSession(session, tracker))
                {
                    CimJobContext cimJobContext = this.CreateJobContext(session, null);
                    if (!methodInvocationInfo.MethodName.Equals("cim:CreateInstance", StringComparison.OrdinalIgnoreCase))
                    {
                        staticMethodInvocationJob = new StaticMethodInvocationJob(cimJobContext, methodInvocationInfo);
                    }
                    else
                    {
                        staticMethodInvocationJob = new CreateInstanceJob(cimJobContext, methodInvocationInfo);
                    }
                    return(staticMethodInvocationJob);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 10
0
        internal override StartableJob CreateQueryJob(CimSession session, QueryBuilder baseQuery)
        {
            CimQuery cimQuery = baseQuery as CimQuery;

            if (cimQuery != null)
            {
                TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, false);
                if (!tracker.IsSessionTerminated(session))
                {
                    if (this.IsSupportedSession(session, tracker))
                    {
                        CimJobContext cimJobContext = this.CreateJobContext(session, null);
                        StartableJob  queryJob      = cimQuery.GetQueryJob(cimJobContext);
                        return(queryJob);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                throw new ArgumentNullException("baseQuery");
            }
        }
Exemplo n.º 11
0
        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;
            }
        }
Exemplo n.º 12
0
 internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole) : base(jobContext, cimQuery)
 {
     this.associatedObject = associatedObject;
     this.associationName  = associationName;
     this.resultRole       = resultRole;
     this.sourceRole       = sourceRole;
 }
Exemplo n.º 13
0
 private void InitializeErrorRecord(CimJobContext jobContext, string errorId, ErrorCategory errorCategory)
 {
     InitializeErrorRecordCore(
         jobContext: jobContext,
         exception: this,
         errorId: errorId,
         errorCategory: errorCategory);
 }
Exemplo n.º 14
0
        private static string GetCimNamespace(string cmdletizationClassName)
        {
            string str  = null;
            string str1 = null;

            CimJobContext.ExtractCimNamespaceAndClassName(cmdletizationClassName, out str, out str1);
            return(str);
        }
Exemplo n.º 15
0
 internal PropertySettingJob(CimJobContext jobContext, bool passThru, CimInstance objectToModify, MethodInvocationInfo methodInvocationInfo)
     : base(
         jobContext,
         passThru,
         objectToModify.ToString(),
         methodInvocationInfo)
 {
 }
        private static CimInstance GetEmptyInstance(CimJobContext jobContext)
        {
            Dbg.Assert(jobContext != null, "Caller should verify jobContext != null");

            var result = new CimInstance(jobContext.ClassName, jobContext.Namespace);

            return(result);
        }
Exemplo n.º 17
0
        internal MethodInvocationJobBase(CimJobContext jobContext, bool passThru, string methodSubject, MethodInvocationInfo methodInvocationInfo)
            : base(jobContext)
        {
            Dbg.Assert(methodInvocationInfo != null, "Caller should verify methodInvocationInfo != null");
            Dbg.Assert(methodSubject != null, "Caller should verify methodSubject != null");

            _passThru             = passThru;
            MethodSubject         = methodSubject;
            _methodInvocationInfo = methodInvocationInfo;
        }
Exemplo n.º 18
0
 internal InstanceMethodInvocationJob(CimJobContext jobContext, bool passThru, CimInstance targetInstance, MethodInvocationInfo methodInvocationInfo)
     : base(
         jobContext,
         passThru,
         targetInstance.ToString(),
         methodInvocationInfo)
 {
     Dbg.Assert(targetInstance != null, "Caller should verify targetInstance != null");
     _targetInstance = targetInstance;
 }
Exemplo n.º 19
0
 internal InstanceMethodInvocationJob(CimJobContext jobContext, bool passThru, CimInstance targetInstance, MethodInvocationInfo methodInvocationInfo)
         : base(
             jobContext,
             passThru,
             targetInstance.ToString(),
             methodInvocationInfo)
 {
     Dbg.Assert(targetInstance != null, "Caller should verify targetInstance != null");
     _targetInstance = targetInstance;
 }
Exemplo n.º 20
0
 internal DeleteInstanceJob(CimJobContext jobContext, bool passThru, CimInstance objectToDelete, MethodInvocationInfo methodInvocationInfo)
     : base(
         jobContext,
         passThru,
         objectToDelete.ToString(),
         methodInvocationInfo)
 {
     Dbg.Assert(objectToDelete != null, "Caller should verify objectToDelete != null");
     _objectToDelete = objectToDelete;
 }
Exemplo n.º 21
0
 internal StartableJob GetQueryJob(CimJobContext jobContext)
 {
     if (_associationName == null)
     {
         return(new QueryInstancesJob(jobContext, this, _wqlCondition.ToString()));
     }
     else
     {
         return(new EnumerateAssociatedInstancesJob(jobContext, this, _associatedObject, _associationName, _resultRole, _sourceRole));
     }
 }
Exemplo n.º 22
0
        internal CimJobContext(CimCmdletInvocationContext cmdletInvocationContext, CimSession session, object targetObject)
        {
            this.CmdletInvocationContext = cmdletInvocationContext;
            this.Session = session;
            CimJobContext cimJobContext = this;
            object        obj           = targetObject;
            object        className     = obj;

            if (obj == null)
            {
                className = this.ClassName;
            }
            cimJobContext.TargetObject = className;
        }
Exemplo n.º 23
0
        private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException)
        {
            InitializeErrorRecordCore(
                jobContext: jobContext,
                exception: cimException,
                errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode,
                errorCategory: ConvertCimExceptionToErrorCategory(cimException));

            if (cimException.ErrorData != null)
            {
                _errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
                _errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null;
            }
        }
Exemplo n.º 24
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);
        }
        internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole)
                : base(jobContext, cimQuery)
        {
            _associatedObject = associatedObject;
            Dbg.Assert(_associatedObject != null, "Caller should verify that associatedObject is not null");

            _associationName = associationName;
            Dbg.Assert(_associationName != null, "Caller should verify that associationName is not null");

            _resultRole = resultRole;
            Dbg.Assert(_resultRole != null, "Caller should verify that resultRole is not null");

            _sourceRole = sourceRole;
            Dbg.Assert(_sourceRole != null, "Caller should verify that sourceRole is not null");
        }
Exemplo n.º 26
0
        internal EnumerateAssociatedInstancesJob(CimJobContext jobContext, CimQuery cimQuery, CimInstance associatedObject, string associationName, string resultRole, string sourceRole)
            : base(jobContext, cimQuery)
        {
            _associatedObject = associatedObject;
            Dbg.Assert(_associatedObject != null, "Caller should verify that associatedObject is not null");

            _associationName = associationName;
            Dbg.Assert(_associationName != null, "Caller should verify that associationName is not null");

            _resultRole = resultRole;
            Dbg.Assert(_resultRole != null, "Caller should verify that resultRole is not null");

            _sourceRole = sourceRole;
            Dbg.Assert(_sourceRole != null, "Caller should verify that sourceRole is not null");
        }
Exemplo n.º 27
0
 private static string BuildErrorMessage(string jobDescription, CimJobContext jobContext, string errorMessage)
 {
     if (!string.IsNullOrEmpty(jobDescription))
     {
         object[] objArray = new object[2];
         objArray[0] = errorMessage;
         objArray[1] = jobDescription;
         string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_GenericCimFailure, objArray);
         return(jobContext.PrependComputerNameToMessage(str));
     }
     else
     {
         return(jobContext.PrependComputerNameToMessage(errorMessage));
     }
 }
Exemplo n.º 28
0
		private static string BuildErrorMessage(string jobDescription, CimJobContext jobContext, string errorMessage)
		{
			if (!string.IsNullOrEmpty(jobDescription))
			{
				object[] objArray = new object[2];
				objArray[0] = errorMessage;
				objArray[1] = jobDescription;
				string str = string.Format(CultureInfo.InvariantCulture, CmdletizationResources.CimJob_GenericCimFailure, objArray);
				return jobContext.PrependComputerNameToMessage(str);
			}
			else
			{
				return jobContext.PrependComputerNameToMessage(errorMessage);
			}
		}
Exemplo n.º 29
0
        internal CimChildJobBase(CimJobContext jobContext)
            : base(Job.GetCommandTextFromInvocationInfo(jobContext.CmdletInvocationInfo), " " /* temporary name - reset below */)
        {
            _jobContext        = jobContext;
            this.PSJobTypeName = CIMJobType;

            this.Name             = this.GetType().Name + _myJobNumber.ToString(CultureInfo.InvariantCulture);
            UsesResultsCollection = true;

            lock (s_globalRandom)
            {
                _random = new Random(s_globalRandom.Next());
            }

            _jobSpecificCustomOptions = new Lazy <CimCustomOptionsDictionary>(this.CalculateJobSpecificCustomOptions);
        }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
0
        /// <summary>
        /// Creates a <see cref="System.Management.Automation.Job"/> object that invokes an instance method in the wrapped object model.
        /// </summary>
        /// <param name="session">Remote session to invoke the method in.</param>
        /// <param name="objectInstance">The object on which to invoke the method.</param>
        /// <param name="methodInvocationInfo">Method invocation details.</param>
        /// <param name="passThru"><see langword="true"/> if successful method invocations should emit downstream the <paramref name="objectInstance"/> being operated on.</param>
        /// <returns></returns>
        internal override StartableJob CreateInstanceMethodInvocationJob(CimSession session, CimInstance objectInstance, MethodInvocationInfo methodInvocationInfo, bool passThru)
        {
            TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, isStaticCmdlet: false);

            if (tracker.IsSessionTerminated(session))
            {
                return(null);
            }

            if (!IsSupportedSession(session, tracker))
            {
                return(null);
            }

            CimJobContext jobContext = this.CreateJobContext(session, objectInstance);

            Dbg.Assert(objectInstance != null, "Caller should verify objectInstance != null");

            StartableJob result;

            if (methodInvocationInfo.MethodName.Equals(CimCmdletAdapter.DeleteInstance_MethodName, StringComparison.OrdinalIgnoreCase))
            {
                result = new DeleteInstanceJob(
                    jobContext,
                    passThru,
                    objectInstance,
                    methodInvocationInfo);
            }
            else if (methodInvocationInfo.MethodName.Equals(CimCmdletAdapter.ModifyInstance_MethodName, StringComparison.OrdinalIgnoreCase))
            {
                result = new ModifyInstanceJob(
                    jobContext,
                    passThru,
                    objectInstance,
                    methodInvocationInfo);
            }
            else
            {
                result = new InstanceMethodInvocationJob(
                    jobContext,
                    passThru,
                    objectInstance,
                    methodInvocationInfo);
            }

            return(result);
        }
Exemplo n.º 32
0
        private static string BuildErrorMessage(string jobDescription, CimJobContext jobContext, string errorMessage)
        {
            Dbg.Assert(!string.IsNullOrEmpty(errorMessage), "Caller should verify !string.IsNullOrEmpty(errorMessage)");

            if (string.IsNullOrEmpty(jobDescription))
            {
                return(jobContext.PrependComputerNameToMessage(errorMessage));
            }
            else
            {
                string errorMessageWithJobDescription = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationResources.CimJob_GenericCimFailure,
                    errorMessage,
                    jobDescription);
                return(jobContext.PrependComputerNameToMessage(errorMessageWithJobDescription));
            }
        }
Exemplo n.º 33
0
        internal CimChildJobBase(CimJobContext jobContext) : base(Job.GetCommandTextFromInvocationInfo(jobContext.CmdletInvocationInfo), " ")
        {
            this._myJobNumber = Interlocked.Increment(ref CimChildJobBase <T> ._globalJobNumberCounter);
            this._sleepAndRetryDelayRangeMs = 0x3e8;
            this._cancellationTokenSource   = new CancellationTokenSource();
            this._jobStateLock = new object();
            this._activityIdToLastProgressRecord = new ConcurrentDictionary <int, ProgressRecord>();
            this._jobContext           = jobContext;
            base.PSJobTypeName         = "CimJob";
            base.Name                  = string.Concat(base.GetType().Name, this._myJobNumber.ToString(CultureInfo.InvariantCulture));
            base.UsesResultsCollection = true;
            lock (CimChildJobBase <T> .GlobalRandom)
            {
                this._random = new Random(CimChildJobBase <T> .GlobalRandom.Next());
            }
            CimChildJobBase <T> cimChildJobBase = this;

            this._jobSpecificCustomOptions = new Lazy <CimCustomOptionsDictionary>(new Func <CimCustomOptionsDictionary>(cimChildJobBase.CalculateJobSpecificCustomOptions));
        }
Exemplo n.º 34
0
		internal QueryInstancesJob(CimJobContext jobContext, CimQuery cimQuery, string wqlCondition) : base(jobContext, cimQuery)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("SELECT * FROM ");
			stringBuilder.Append(base.JobContext.ClassName);
			stringBuilder.Append(" ");
			stringBuilder.Append(wqlCondition);
			this._wqlQuery = stringBuilder.ToString();
			if (!string.IsNullOrWhiteSpace(wqlCondition))
			{
				if (jobContext.CmdletInvocationContext.CmdletDefinitionContext.UseEnumerateInstancesInsteadOfWql)
				{
					this._useEnumerateInstances = true;
				}
				return;
			}
			else
			{
				this._useEnumerateInstances = true;
				return;
			}
		}
Exemplo n.º 35
0
        internal QueryInstancesJob(CimJobContext jobContext, CimQuery cimQuery, string wqlCondition) : base(jobContext, cimQuery)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("SELECT * FROM ");
            stringBuilder.Append(base.JobContext.ClassName);
            stringBuilder.Append(" ");
            stringBuilder.Append(wqlCondition);
            this._wqlQuery = stringBuilder.ToString();
            if (!string.IsNullOrWhiteSpace(wqlCondition))
            {
                if (jobContext.CmdletInvocationContext.CmdletDefinitionContext.UseEnumerateInstancesInsteadOfWql)
                {
                    this._useEnumerateInstances = true;
                }
                return;
            }
            else
            {
                this._useEnumerateInstances = true;
                return;
            }
        }
Exemplo n.º 36
0
        internal QueryInstancesJob(CimJobContext jobContext, CimQuery cimQuery, string wqlCondition)
                : base(jobContext, cimQuery)
        {
            Dbg.Assert(wqlCondition != null, "Caller should verify that wqlCondition is not null");

            var wqlQueryBuilder = new StringBuilder();
            wqlQueryBuilder.Append("SELECT * FROM ");
            wqlQueryBuilder.Append(this.JobContext.ClassName);
            wqlQueryBuilder.Append(" ");
            wqlQueryBuilder.Append(wqlCondition);
            _wqlQuery = wqlQueryBuilder.ToString();

            if (string.IsNullOrWhiteSpace(wqlCondition))
            {
                _useEnumerateInstances = true;
            }
            else
            {
                if (jobContext.CmdletInvocationContext.CmdletDefinitionContext.UseEnumerateInstancesInsteadOfWql)
                {
                    _useEnumerateInstances = true;
                }
            }
        }
Exemplo n.º 37
0
		internal InstanceMethodInvocationJob(CimJobContext jobContext, bool passThru, CimInstance targetInstance, MethodInvocationInfo methodInvocationInfo) : base(jobContext, passThru, targetInstance.ToString(), methodInvocationInfo)
		{
			this.targetInstance = targetInstance;
		}
Exemplo n.º 38
0
		private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
		{
			object targetObject;
			Exception exception1 = exception;
			string str = errorId;
			ErrorCategory errorCategory1 = errorCategory;
			if (jobContext != null)
			{
				targetObject = jobContext.TargetObject;
			}
			else
			{
				targetObject = null;
			}
			ErrorRecord errorRecord = new ErrorRecord(exception1, str, errorCategory1, targetObject);
			if (jobContext == null)
			{
				this.errorRecord = errorRecord;
				return;
			}
			else
			{
				OriginInfo originInfo = new OriginInfo(jobContext.Session.ComputerName, Guid.Empty);
				this.errorRecord = new RemotingErrorRecord(errorRecord, originInfo);
				this.errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
				this.errorRecord.PreserveInvocationInfoOnce = true;
				return;
			}
		}
Exemplo n.º 39
0
        private static string BuildErrorMessage(string jobDescription, CimJobContext jobContext, string errorMessage)
        {
            Dbg.Assert(!string.IsNullOrEmpty(errorMessage), "Caller should verify !string.IsNullOrEmpty(errorMessage)");

            if (string.IsNullOrEmpty(jobDescription))
            {
                return jobContext.PrependComputerNameToMessage(errorMessage);
            }
            else
            {
                string errorMessageWithJobDescription = string.Format(
                    CultureInfo.InvariantCulture,
                    CmdletizationResources.CimJob_GenericCimFailure,
                    errorMessage,
                    jobDescription);
                return jobContext.PrependComputerNameToMessage(errorMessageWithJobDescription);
            }
        }
Exemplo n.º 40
0
        private void InitializeErrorRecordCore(CimJobContext jobContext, Exception exception, string errorId, ErrorCategory errorCategory)
        {
            ErrorRecord coreErrorRecord = new ErrorRecord(
                exception: exception,
                errorId: errorId,
                errorCategory: errorCategory,
                targetObject: jobContext != null ? jobContext.TargetObject : null);

            if (jobContext != null)
            {
                System.Management.Automation.Remoting.OriginInfo originInfo = new System.Management.Automation.Remoting.OriginInfo(
                    jobContext.Session.ComputerName,
                    Guid.Empty);

                _errorRecord = new System.Management.Automation.Runspaces.RemotingErrorRecord(
                    coreErrorRecord,
                    originInfo);

                _errorRecord.SetInvocationInfo(jobContext.CmdletInvocationInfo);
                _errorRecord.PreserveInvocationInfoOnce = true;
            }
            else
            {
                _errorRecord = coreErrorRecord;
            }
        }
Exemplo n.º 41
0
 private void InitializeErrorRecord(CimJobContext jobContext, string errorId, ErrorCategory errorCategory)
 {
     InitializeErrorRecordCore(
         jobContext: jobContext,
         exception: this,
         errorId: errorId,
         errorCategory: errorCategory);
 }
Exemplo n.º 42
0
		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;
			}
		}
Exemplo n.º 43
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;
        }
Exemplo n.º 44
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;
        }
Exemplo n.º 45
0
		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;
		}
Exemplo n.º 46
0
		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);
			}
		}
Exemplo n.º 47
0
		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;
		}
Exemplo n.º 48
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;
        }
Exemplo n.º 49
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;
        }
Exemplo n.º 50
0
		internal StaticMethodInvocationJob(CimJobContext jobContext, MethodInvocationInfo methodInvocationInfo) : base(jobContext, false, jobContext.CmdletizationClassName, methodInvocationInfo)
		{
		}
Exemplo n.º 51
0
        private void InitializeErrorRecord(CimJobContext jobContext, CimException cimException)
        {
            InitializeErrorRecordCore(
                jobContext: jobContext,
                exception: cimException,
                errorId: cimException.MessageId ?? "MiClientApiError_" + cimException.NativeErrorCode,
                errorCategory: ConvertCimExceptionToErrorCategory(cimException));

            if (cimException.ErrorData != null)
            {
                _errorRecord.CategoryInfo.TargetName = cimException.ErrorSource;
                _errorRecord.CategoryInfo.TargetType = jobContext != null ? jobContext.CmdletizationClassName : null;
            }
        }
Exemplo n.º 52
0
		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;
		}
Exemplo n.º 53
0
		private void InitializeErrorRecord(CimJobContext jobContext, string errorId, ErrorCategory errorCategory)
		{
			this.InitializeErrorRecordCore(jobContext, this, errorId, errorCategory);
		}