예제 #1
0
        internal override void WriteObject(object outputObject)
        {
            CimInstance cimInstance = null;
            PSObject    pso         = null;

            if (outputObject is PSObject)
            {
                pso         = PSObject.AsPSObject(outputObject);
                cimInstance = pso.BaseObject as CimInstance;
            }
            else
            {
                cimInstance = outputObject as CimInstance;
            }
            if (cimInstance != null)
            {
                CimCmdletAdapter.AssociateSessionOfOriginWithInstance(cimInstance, this.JobContext.Session);
                CimCustomOptionsDictionary.AssociateCimInstanceWithCustomOptions(cimInstance, this.GetJobSpecificCustomOptions());
            }
            if (this.JobContext.ShowComputerName)
            {
                if (pso == null)
                {
                    pso = PSObject.AsPSObject(outputObject);
                }
                AddShowComputerNameMarker(pso);
                if (cimInstance == null)
                {
                    pso.Properties.Add(new PSNoteProperty(RemotingConstants.ComputerNameNoteProperty, this.JobContext.Session.ComputerName));
                }
            }

            base.WriteObject(outputObject);
        }
예제 #2
0
        internal override void WriteObject(object outputObject)
        {
            CimInstance baseObject;
            PSObject    pSObject = null;

            if (outputObject as PSObject == null)
            {
                baseObject = outputObject as CimInstance;
            }
            else
            {
                pSObject   = PSObject.AsPSObject(outputObject);
                baseObject = pSObject.BaseObject as CimInstance;
            }
            if (baseObject != null)
            {
                CimCmdletAdapter.AssociateSessionOfOriginWithInstance(baseObject, this.JobContext.Session);
                CimCustomOptionsDictionary.AssociateCimInstanceWithCustomOptions(baseObject, this.GetJobSpecificCustomOptions());
                if (this.JobContext.ShowComputerName)
                {
                    if (pSObject == null)
                    {
                        pSObject = PSObject.AsPSObject(outputObject);
                    }
                    CimChildJobBase <T> .AddShowComputerNameMarker(pSObject);
                }
            }
            base.WriteObject(outputObject);
        }
        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;
                }
            }
        }
        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;
                }
            }
        }