Ejemplo n.º 1
0
 internal static void SetCustomOptions(CimOperationOptions operationOptions, IEnumerable <KeyValuePair <string, object> > customOptions)
 {
     if (customOptions != null)
     {
         foreach (KeyValuePair <string, object> customOption in customOptions)
         {
             CimOperationOptionsHelper.SetCustomOption(operationOptions, customOption.Key, customOption.Value);
         }
     }
 }
Ejemplo n.º 2
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);
        }
 internal void Apply(CimOperationOptions cimOperationOptions)
 {
     CimOperationOptionsHelper.SetCustomOptions(cimOperationOptions, this.GetSnapshot());
 }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 internal void Apply(CimOperationOptions cimOperationOptions, CimSensitiveValueConverter cimSensitiveValueConverter)
 {
     CimOperationOptionsHelper.SetCustomOptions(cimOperationOptions, this.GetSnapshot(), cimSensitiveValueConverter);
 }