/// <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); }
/// <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<TObjectInstance>.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 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); } }
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"); } }
/// <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); }
internal override void StartJob() { lock (_jobStateLock) { if (_jobWasStopped) { this.SetCompletedJobState(JobState.Stopped, null); return; } Dbg.Assert(!_alreadyReachedCompletedState, "Job shouldn't reach completed state, before ThrottlingJob has a chance to register for job-completed/failed events"); TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo); if (tracker.IsSessionTerminated(this.JobContext.Session)) { this.SetCompletedJobState(JobState.Failed, new OperationCanceledException()); return; } if (!_jobWasStarted) { _jobWasStarted = true; this.SetJobState(JobState.Running); } } // This invocation can block (i.e. by calling Job.ShouldProcess) and wait for pipeline thread to unblock it // Therefore we have to do the invocation outside of the pipeline thread. ThreadPool.QueueUserWorkItem(delegate { this.ExceptionSafeWrapper(delegate { IObservable <T> observable = this.GetCimOperation(); if (observable != null) { observable.Subscribe(this); } }); }); }
internal override StartableJob CreateInstanceMethodInvocationJob(CimSession session, CimInstance objectInstance, MethodInvocationInfo methodInvocationInfo, bool passThru) { StartableJob instanceMethodInvocationJob; TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.CmdletInvocationInfo, false); if (!tracker.IsSessionTerminated(session)) { if (this.IsSupportedSession(session, tracker)) { CimJobContext cimJobContext = this.CreateJobContext(session, objectInstance); if (!methodInvocationInfo.MethodName.Equals("cim:DeleteInstance", StringComparison.OrdinalIgnoreCase)) { if (!methodInvocationInfo.MethodName.Equals("cim:ModifyInstance", StringComparison.OrdinalIgnoreCase)) { instanceMethodInvocationJob = new InstanceMethodInvocationJob(cimJobContext, passThru, objectInstance, methodInvocationInfo); } else { instanceMethodInvocationJob = new ModifyInstanceJob(cimJobContext, passThru, objectInstance, methodInvocationInfo); } } else { instanceMethodInvocationJob = new DeleteInstanceJob(cimJobContext, passThru, objectInstance, methodInvocationInfo); } return(instanceMethodInvocationJob); } else { return(null); } } else { return(null); } }
internal override void StartJob() { lock (this._jobStateLock) { if (!this._jobWasStopped) { TerminatingErrorTracker tracker = TerminatingErrorTracker.GetTracker(this.JobContext.CmdletInvocationInfo); if (!tracker.IsSessionTerminated(this.JobContext.Session)) { if (!this._jobWasStarted) { this._jobWasStarted = true; base.SetJobState(JobState.Running); } } else { this.SetCompletedJobState(JobState.Failed, new OperationCanceledException()); return; } } else { this.SetCompletedJobState(JobState.Stopped, null); return; } } ThreadPool.QueueUserWorkItem(param0 => this.ExceptionSafeWrapper(delegate { IObservable <T> cimOperation = this.GetCimOperation(); if (cimOperation != null) { cimOperation.Subscribe(this); } })); }