internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
		{
            bool flag = false;
			if (newCustomOptions != null)
			{
				lock (newCustomOptions._dictModificationLock)
				{
					if (newCustomOptions._dict.Count == 0)
					{
						return;
					}
				}
				CimCustomOptionsDictionary value = CimCustomOptionsDictionary.CimInstanceToCustomOptions.GetValue(cimInstance, (CimInstance param0) => {
					flag = false;
					return newCustomOptions;
				}
				);
				if (flag)
				{
					lock (value._dictModificationLock)
					{
						foreach (KeyValuePair<string, object> snapshot in newCustomOptions.GetSnapshot())
						{
							value._dict[snapshot.Key] = snapshot.Value;
						}
					}
				}
				return;
			}
			else
			{
				return;
			}
		}
        internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
        {
            bool flag = false;

            if (newCustomOptions != null)
            {
                lock (newCustomOptions._dictModificationLock)
                {
                    if (newCustomOptions._dict.Count == 0)
                    {
                        return;
                    }
                }
                CimCustomOptionsDictionary value = CimCustomOptionsDictionary.CimInstanceToCustomOptions.GetValue(cimInstance, (CimInstance param0) => {
                    flag = false;
                    return(newCustomOptions);
                }
                                                                                                                  );
                if (flag)
                {
                    lock (value._dictModificationLock)
                    {
                        foreach (KeyValuePair <string, object> snapshot in newCustomOptions.GetSnapshot())
                        {
                            value._dict[snapshot.Key] = snapshot.Value;
                        }
                    }
                }
                return;
            }
            else
            {
                return;
            }
        }
Exemple #3
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);
        }
        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);
        }
Exemple #5
0
        internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
        {
            if (newCustomOptions is null)
            {
                return;
            }

            lock (newCustomOptions._dictModificationLock)
            {
                if (newCustomOptions._dict.Count == 0)
                {
                    return;
                }
            }

            bool foundAssociatedOptions = true;
            CimCustomOptionsDictionary oldCustomOptions = s_cimInstanceToCustomOptions.GetValue(
                cimInstance,
                delegate
            {
                foundAssociatedOptions = false;
                return(newCustomOptions);
            });

            if (foundAssociatedOptions)
            {
                lock (oldCustomOptions._dictModificationLock)
                {
                    foreach (KeyValuePair <string, object> newCustomOption in newCustomOptions.GetSnapshot())
                    {
                        oldCustomOptions._dict[newCustomOption.Key] = newCustomOption.Value;
                    }
                }
            }
        }
        internal static void AssociateCimInstanceWithCustomOptions(CimInstance cimInstance, CimCustomOptionsDictionary newCustomOptions)
        {
            if (newCustomOptions == null)
            {
                return;
            }

            lock (newCustomOptions._dictModificationLock)
            {
                if (newCustomOptions._dict.Count == 0)
                {
                    return;
                }
            }

            bool foundAssociatedOptions = true;
            CimCustomOptionsDictionary oldCustomOptions = s_cimInstanceToCustomOptions.GetValue(
                cimInstance,
                delegate
                    {
                        foundAssociatedOptions = false;
                        return newCustomOptions;
                    });

            if (foundAssociatedOptions)
            {
                lock (oldCustomOptions._dictModificationLock)
                {
                    foreach (KeyValuePair<string, object> newCustomOption in newCustomOptions.GetSnapshot())
                    {
                        oldCustomOptions._dict[newCustomOption.Key] = newCustomOption.Value;
                    }
                }
            }
        }
        internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, IEnumerable <CimInstance> instancesRelatedToThisOperation)
        {
            CimCustomOptionsDictionary cimCustomOptionsDictionary = optionsFromCommandLine;

            if (instancesRelatedToThisOperation != null)
            {
                foreach (CimInstance cimInstance in instancesRelatedToThisOperation)
                {
                    cimCustomOptionsDictionary = CimCustomOptionsDictionary.MergeOptions(cimCustomOptionsDictionary, cimInstance);
                }
            }
            return(cimCustomOptionsDictionary);
        }
        internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, IEnumerable <CimInstance> instancesRelatedToThisOperation)
        {
            CimCustomOptionsDictionary result = optionsFromCommandLine;

            if (instancesRelatedToThisOperation != null)
            {
                foreach (CimInstance instanceRelatedToThisOperation in instancesRelatedToThisOperation)
                {
                    result = MergeOptions(result, instanceRelatedToThisOperation);
                }
            }
            return(result);
        }
        internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
        {
            IDictionary <string, object> wrappedDictionary = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            foreach (MethodParameter parameter in this.GetMethodInputParametersCore(p => p.Name.StartsWith("cim:operationOption:", StringComparison.OrdinalIgnoreCase)))
            {
                if (parameter.Value != null)
                {
                    wrappedDictionary.Add(parameter.Name.Substring("cim:operationOption:".Length), parameter.Value);
                }
            }
            return(CimCustomOptionsDictionary.Create(wrappedDictionary));
        }
 internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
 {
     CimCustomOptionsDictionary instanceRelatedOptions;
     if (s_cimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out instanceRelatedOptions) && instanceRelatedOptions != null)
     {
         IEnumerable<KeyValuePair<string, object>> instanceRelatedOptionsSnapshot = instanceRelatedOptions.GetSnapshot();
         IEnumerable<KeyValuePair<string, object>> optionsFromCommandLineSnapshot = optionsFromCommandLine.GetSnapshot();
         var mergedOptions = instanceRelatedOptionsSnapshot.Concat(optionsFromCommandLineSnapshot); // note - order matters here
         return new CimCustomOptionsDictionary(mergedOptions);
     }
     else
     {
         return optionsFromCommandLine;
     }
 }
        internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
        {
            CimCustomOptionsDictionary cimCustomOptionsDictionary = null;

            if (!CimCustomOptionsDictionary.CimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out cimCustomOptionsDictionary) || cimCustomOptionsDictionary == null)
            {
                return(optionsFromCommandLine);
            }
            else
            {
                IEnumerable <KeyValuePair <string, object> > snapshot       = cimCustomOptionsDictionary.GetSnapshot();
                IEnumerable <KeyValuePair <string, object> > keyValuePairs  = optionsFromCommandLine.GetSnapshot();
                IEnumerable <KeyValuePair <string, object> > keyValuePairs1 = snapshot.Concat <KeyValuePair <string, object> >(keyValuePairs);
                return(new CimCustomOptionsDictionary(keyValuePairs1));
            }
        }
Exemple #12
0
        internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
        {
            CimCustomOptionsDictionary instanceRelatedOptions;

            if (s_cimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out instanceRelatedOptions) && instanceRelatedOptions != null)
            {
                IEnumerable <KeyValuePair <string, object> > instanceRelatedOptionsSnapshot = instanceRelatedOptions.GetSnapshot();
                IEnumerable <KeyValuePair <string, object> > optionsFromCommandLineSnapshot = optionsFromCommandLine.GetSnapshot();
                var mergedOptions = instanceRelatedOptionsSnapshot.Concat(optionsFromCommandLineSnapshot); // note - order matters here
                return(new CimCustomOptionsDictionary(mergedOptions));
            }
            else
            {
                return(optionsFromCommandLine);
            }
        }
Exemple #13
0
        internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
        {
            IDictionary <string, object> result = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);

            IEnumerable <MethodParameter> customOptions = this
                                                          .GetMethodInputParametersCore(p => p.Name.StartsWith(CustomOperationOptionPrefix, StringComparison.OrdinalIgnoreCase));

            foreach (MethodParameter customOption in customOptions)
            {
                if (customOption.Value == null)
                {
                    continue;
                }

                result.Add(customOption.Name.Substring(CustomOperationOptionPrefix.Length), customOption.Value);
            }

            return(CimCustomOptionsDictionary.Create(result));
        }
Exemple #14
0
        internal CimOperationOptions CreateOperationOptions()
        {
            var operationOptions = new CimOperationOptions(mustUnderstand: false)
            {
                CancellationToken = _cancellationTokenSource.Token,
                WriteProgress     = this.WriteProgressCallback,
                WriteMessage      = this.WriteMessageCallback,
                WriteError        = this.WriteErrorCallback,
                PromptUser        = this.PromptUserCallback,
            };

            operationOptions.SetOption("__MI_OPERATIONOPTIONS_IMPROVEDPERF_STREAMING", 1);

            operationOptions.Flags |= this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SchemaConformanceLevel;

            if (this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ResourceUri != null)
            {
                operationOptions.ResourceUri = this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ResourceUri;
            }

            if ((
                    (_jobContext.WarningActionPreference == ActionPreference.SilentlyContinue) ||
                    (_jobContext.WarningActionPreference == ActionPreference.Ignore)
                    ) && (!_jobContext.IsRunningInBackground))
            {
                operationOptions.DisableChannel((UInt32)MessageChannel.Warning);
            }
            else
            {
                operationOptions.EnableChannel((UInt32)MessageChannel.Warning);
            }

            if ((
                    (_jobContext.VerboseActionPreference == ActionPreference.SilentlyContinue) ||
                    (_jobContext.VerboseActionPreference == ActionPreference.Ignore)
                    ) && (!_jobContext.IsRunningInBackground))
            {
                operationOptions.DisableChannel((UInt32)MessageChannel.Verbose);
            }
            else
            {
                operationOptions.EnableChannel((UInt32)MessageChannel.Verbose);
            }

            if ((
                    (_jobContext.DebugActionPreference == ActionPreference.SilentlyContinue) ||
                    (_jobContext.DebugActionPreference == ActionPreference.Ignore)
                    ) && (!_jobContext.IsRunningInBackground))
            {
                operationOptions.DisableChannel((UInt32)MessageChannel.Debug);
            }
            else
            {
                operationOptions.EnableChannel((UInt32)MessageChannel.Debug);
            }

            switch (this.JobContext.ShouldProcessOptimization)
            {
            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoNo_CanCallShouldProcessAsynchronously:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.Report, automaticConfirmation: false);
                break;

            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoYes_CanCallShouldProcessAsynchronously:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.Report, automaticConfirmation: true);
                break;

            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoYes_CanSkipShouldProcessCall:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.Ignore, automaticConfirmation: true);
                break;

            case MshCommandRuntime.ShouldProcessPossibleOptimization.NoOptimizationPossible:
            default:
                operationOptions.PromptUserMode = CimCallbackMode.Inquire;
                break;
            }

            switch (this.JobContext.ErrorActionPreference)
            {
            case ActionPreference.Continue:
            case ActionPreference.SilentlyContinue:
            case ActionPreference.Ignore:
                operationOptions.WriteErrorMode = CimCallbackMode.Report;
                break;

            case ActionPreference.Stop:
            case ActionPreference.Inquire:
            default:
                operationOptions.WriteErrorMode = CimCallbackMode.Inquire;
                break;
            }

            if (!string.IsNullOrWhiteSpace(this.GetProviderVersionExpectedByJob()))
            {
                CimOperationOptionsHelper.SetCustomOption(
                    operationOptions,
                    "MI_OPERATIONOPTIONS_PROVIDERVERSION",
                    this.GetProviderVersionExpectedByJob(),
                    CimSensitiveValueConverter);
            }

            if (this.JobContext.CmdletizationModuleVersion != null)
            {
                CimOperationOptionsHelper.SetCustomOption(
                    operationOptions,
                    "MI_OPERATIONOPTIONS_POWERSHELL_MODULEVERSION",
                    this.JobContext.CmdletizationModuleVersion,
                    CimSensitiveValueConverter);
            }

            CimOperationOptionsHelper.SetCustomOption(
                operationOptions,
                "MI_OPERATIONOPTIONS_POWERSHELL_CMDLETNAME",
                this.JobContext.CmdletInvocationInfo.MyCommand.Name,
                CimSensitiveValueConverter);
            if (!string.IsNullOrWhiteSpace(this.JobContext.Session.ComputerName))
            {
                CimOperationOptionsHelper.SetCustomOption(
                    operationOptions,
                    "MI_OPERATIONOPTIONS_POWERSHELL_COMPUTERNAME",
                    this.JobContext.Session.ComputerName,
                    CimSensitiveValueConverter);
            }

            CimCustomOptionsDictionary jobSpecificCustomOptions = this.GetJobSpecificCustomOptions();

            if (jobSpecificCustomOptions != null)
            {
                jobSpecificCustomOptions.Apply(operationOptions, CimSensitiveValueConverter);
            }

            return(operationOptions);
        }
Exemple #15
0
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.MergeOptions(
                base.CalculateJobSpecificCustomOptions(),
                _objectToDelete));
 }
Exemple #16
0
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.MergeOptions(
                base.CalculateJobSpecificCustomOptions(),
                _targetInstance));
 }
Exemple #17
0
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.MergeOptions(
                base.CalculateJobSpecificCustomOptions(),
                _associatedObject));
 }
		internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, CimInstance instanceRelatedToThisOperation)
		{
			CimCustomOptionsDictionary cimCustomOptionsDictionary = null;
			if (!CimCustomOptionsDictionary.CimInstanceToCustomOptions.TryGetValue(instanceRelatedToThisOperation, out cimCustomOptionsDictionary) || cimCustomOptionsDictionary == null)
			{
				return optionsFromCommandLine;
			}
			else
			{
				IEnumerable<KeyValuePair<string, object>> snapshot = cimCustomOptionsDictionary.GetSnapshot();
				IEnumerable<KeyValuePair<string, object>> keyValuePairs = optionsFromCommandLine.GetSnapshot();
				IEnumerable<KeyValuePair<string, object>> keyValuePairs1 = snapshot.Concat<KeyValuePair<string, object>>(keyValuePairs);
				return new CimCustomOptionsDictionary(keyValuePairs1);
			}
		}
Exemple #19
0
        internal CimOperationOptions CreateOperationOptions()
        {
            CimOperationOptions operationOptions = new CimOperationOptions(false)
            {
                CancellationToken = new CancellationToken?(this._cancellationTokenSource.Token),
                WriteProgress     = new Microsoft.Management.Infrastructure.WriteProgressCallback(this.WriteProgressCallback),
                WriteMessage      = new Microsoft.Management.Infrastructure.WriteMessageCallback(this.WriteMessageCallback),
                WriteError        = new Microsoft.Management.Infrastructure.WriteErrorCallback(this.WriteErrorCallback),
                PromptUser        = new Microsoft.Management.Infrastructure.PromptUserCallback(this.PromptUserCallback)
            };

            operationOptions.SetOption("__MI_OPERATIONOPTIONS_IMPROVEDPERF_STREAMING", (uint)1);
            operationOptions.Flags |= this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.SchemaConformanceLevel;
            if (this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ResourceUri != null)
            {
                operationOptions.ResourceUri = this.JobContext.CmdletInvocationContext.CmdletDefinitionContext.ResourceUri;
            }
            if (((this._jobContext.WarningActionPreference == ActionPreference.SilentlyContinue) || (this._jobContext.WarningActionPreference == ActionPreference.Ignore)) && !this._jobContext.IsRunningInBackground)
            {
                operationOptions.DisableChannel(0);
            }
            else
            {
                operationOptions.EnableChannel(0);
            }
            if (((this._jobContext.VerboseActionPreference == ActionPreference.SilentlyContinue) || (this._jobContext.VerboseActionPreference == ActionPreference.Ignore)) && !this._jobContext.IsRunningInBackground)
            {
                operationOptions.DisableChannel(1);
            }
            else
            {
                operationOptions.EnableChannel(1);
            }
            if (((this._jobContext.DebugActionPreference == ActionPreference.SilentlyContinue) || (this._jobContext.DebugActionPreference == ActionPreference.Ignore)) && !this._jobContext.IsRunningInBackground)
            {
                operationOptions.DisableChannel(2);
            }
            else
            {
                operationOptions.EnableChannel(2);
            }
            switch (this.JobContext.ShouldProcessOptimization)
            {
            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoYes_CanSkipShouldProcessCall:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.Ignore, true);
                break;

            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoYes_CanCallShouldProcessAsynchronously:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.None, true);
                break;

            case MshCommandRuntime.ShouldProcessPossibleOptimization.AutoNo_CanCallShouldProcessAsynchronously:
                operationOptions.SetPromptUserRegularMode(CimCallbackMode.None, false);
                break;

            default:
                operationOptions.PromptUserMode = CimCallbackMode.Inquire;
                break;
            }
            switch (this.JobContext.ErrorActionPreference)
            {
            case ActionPreference.SilentlyContinue:
            case ActionPreference.Continue:
            case ActionPreference.Ignore:
                operationOptions.WriteErrorMode = CimCallbackMode.None;
                break;

            default:
                operationOptions.WriteErrorMode = CimCallbackMode.Inquire;
                break;
            }
            if (!string.IsNullOrWhiteSpace(this.GetProviderVersionExpectedByJob()))
            {
                CimOperationOptionsHelper.SetCustomOption(operationOptions, "MI_OPERATIONOPTIONS_PROVIDERVERSION", this.GetProviderVersionExpectedByJob());
            }
            if (this.JobContext.CmdletizationModuleVersion != null)
            {
                CimOperationOptionsHelper.SetCustomOption(operationOptions, "MI_OPERATIONOPTIONS_POWERSHELL_MODULEVERSION", this.JobContext.CmdletizationModuleVersion);
            }
            CimOperationOptionsHelper.SetCustomOption(operationOptions, "MI_OPERATIONOPTIONS_POWERSHELL_CMDLETNAME", this.JobContext.CmdletInvocationInfo.MyCommand.Name);
            if (!string.IsNullOrWhiteSpace(this.JobContext.Session.ComputerName))
            {
                CimOperationOptionsHelper.SetCustomOption(operationOptions, "MI_OPERATIONOPTIONS_POWERSHELL_COMPUTERNAME", this.JobContext.Session.ComputerName);
            }
            CimCustomOptionsDictionary jobSpecificCustomOptions = this.GetJobSpecificCustomOptions();

            if (jobSpecificCustomOptions != null)
            {
                jobSpecificCustomOptions.Apply(operationOptions);
            }
            return(operationOptions);
        }
		internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, IEnumerable<CimInstance> instancesRelatedToThisOperation)
		{
			CimCustomOptionsDictionary cimCustomOptionsDictionary = optionsFromCommandLine;
			if (instancesRelatedToThisOperation != null)
			{
				foreach (CimInstance cimInstance in instancesRelatedToThisOperation)
				{
					cimCustomOptionsDictionary = CimCustomOptionsDictionary.MergeOptions(cimCustomOptionsDictionary, cimInstance);
				}
			}
			return cimCustomOptionsDictionary;
		}
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.MergeOptions(base.CalculateJobSpecificCustomOptions(), this.ObjectToModify));
 }
Exemple #22
0
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.Create(_cimQuery.queryOptions));
 }
Exemple #23
0
 internal override CimCustomOptionsDictionary CalculateJobSpecificCustomOptions()
 {
     return(CimCustomOptionsDictionary.MergeOptions(
                base.CalculateJobSpecificCustomOptions(),
                this.GetCimInstancesFromArguments()));
 }
 internal static CimCustomOptionsDictionary MergeOptions(CimCustomOptionsDictionary optionsFromCommandLine, IEnumerable<CimInstance> instancesRelatedToThisOperation)
 {
     CimCustomOptionsDictionary result = optionsFromCommandLine;
     if (instancesRelatedToThisOperation != null)
     {
         foreach (CimInstance instanceRelatedToThisOperation in instancesRelatedToThisOperation)
         {
             result = MergeOptions(result, instanceRelatedToThisOperation);
         }
     }
     return result;
 }