Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        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);
            }
        }