Windows-powershell / PowerShell-master /src /Microsoft.Management.Infrastructure.CimCmdlets /SetCimInstanceCommand.cs
| // Copyright (c) Microsoft Corporation. | |
| // Licensed under the MIT License. | |
| using System; | |
| using System.Collections; | |
| using System.Collections.Generic; | |
| using System.Diagnostics.CodeAnalysis; | |
| using System.Management.Automation; | |
| namespace Microsoft.Management.Infrastructure.CimCmdlets | |
| { | |
| /// <summary> | |
| /// <para> | |
| /// Enables the user to Set properties and keys on a specific <see cref="CimInstance"/> | |
| /// CimInstance must have values of all [KEY] properties. | |
| /// </para> | |
| /// </summary> | |
| [] | |
| [ | |
| ] | |
| public class SetCimInstanceCommand : CimBaseCommand | |
| { | |
| /// <summary> | |
| /// Initializes a new instance of the <see cref="SetCimInstanceCommand"/> class. | |
| /// </summary> | |
| public SetCimInstanceCommand() | |
| : base(parameters, parameterSets) | |
| { | |
| } | |
| /// <summary> | |
| /// The following is the definition of the input parameter "Session". | |
| /// CIM session used to set the CIM Instance. | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| [] | |
| public CimSession[] CimSession | |
| { | |
| get | |
| { | |
| return cimSession; | |
| } | |
| set | |
| { | |
| cimSession = value; | |
| base.SetParameter(value, nameCimSession); | |
| } | |
| } | |
| private CimSession[] cimSession; | |
| /// <summary> | |
| /// The following is the definition of the input parameter "ComputerName". | |
| /// </summary> | |
| [] | |
| [ | |
| ] | |
| [ | |
| ] | |
| [] | |
| public string[] ComputerName | |
| { | |
| get | |
| { | |
| return computername; | |
| } | |
| set | |
| { | |
| computername = value; | |
| base.SetParameter(value, nameComputerName); | |
| } | |
| } | |
| private string[] computername; | |
| /// <summary> | |
| /// <para> | |
| /// The following is the definition of the input parameter "ResourceUri". | |
| /// Define the Resource Uri for which the instances are retrieved. | |
| /// </para> | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| public Uri ResourceUri | |
| { | |
| get | |
| { | |
| return resourceUri; | |
| } | |
| set | |
| { | |
| this.resourceUri = value; | |
| base.SetParameter(value, nameResourceUri); | |
| } | |
| } | |
| private Uri resourceUri; | |
| /// <summary> | |
| /// The following is the definition of the input parameter "Namespace". | |
| /// The Namespace used to look for the Class instances under. | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| public string Namespace | |
| { | |
| get | |
| { | |
| return nameSpace; | |
| } | |
| set | |
| { | |
| nameSpace = value; | |
| base.SetParameter(value, nameNamespace); | |
| } | |
| } | |
| private string nameSpace; | |
| /// <summary> | |
| /// The following is the definition of the input parameter "OperationTimeoutSec". | |
| /// Used to set the invocation operation time out. This value overrides the | |
| /// CimSession operation timeout. | |
| /// </summary> | |
| [] | |
| [] | |
| public uint OperationTimeoutSec { get; set; } | |
| /// <summary> | |
| /// The following is the definition of the input parameter "InputObject". | |
| /// Used to get a CimInstance using Get-CimInstance | Set-CimInstance. | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| [] | |
| public CimInstance InputObject | |
| { | |
| get | |
| { | |
| return CimInstance; | |
| } | |
| set | |
| { | |
| CimInstance = value; | |
| base.SetParameter(value, nameCimInstance); | |
| } | |
| } | |
| /// <summary> | |
| /// Property for internal usage purpose. | |
| /// </summary> | |
| internal CimInstance CimInstance { get; private set; } | |
| /// <summary> | |
| /// The following is the definition of the input parameter "Query". | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| public string Query | |
| { | |
| get | |
| { | |
| return query; | |
| } | |
| set | |
| { | |
| query = value; | |
| base.SetParameter(value, nameQuery); | |
| } | |
| } | |
| private string query; | |
| /// <summary> | |
| /// The following is the definition of the input parameter "QueryDialect". | |
| /// Specifies the dialect used by the query Engine that interprets the Query | |
| /// string. | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| public string QueryDialect | |
| { | |
| get | |
| { | |
| return querydialect; | |
| } | |
| set | |
| { | |
| querydialect = value; | |
| base.SetParameter(value, nameQueryDialect); | |
| } | |
| } | |
| private string querydialect; | |
| /// <summary> | |
| /// <para> | |
| /// The following is the definition of the input parameter "Property", | |
| /// defines the value to be changed. | |
| /// </para> | |
| /// <para> | |
| /// The key properties will be ignored. Any invalid property will cause | |
| /// termination of the cmdlet execution. | |
| /// </para> | |
| /// </summary> | |
| [ | |
| ] | |
| [ | |
| ] | |
| [ | |
| ] | |
| [ | |
| ] | |
| [] | |
| [] | |
| public IDictionary Property | |
| { | |
| get | |
| { | |
| return property; | |
| } | |
| set | |
| { | |
| property = value; | |
| base.SetParameter(value, nameProperty); | |
| } | |
| } | |
| private IDictionary property; | |
| /// <summary> | |
| /// <para> | |
| /// The following is the definition of the input parameter "PassThru", | |
| /// indicate whether Set-CimInstance should output modified result instance or not. | |
| /// </para> | |
| /// <para> | |
| /// True indicates output the result instance, otherwise output nothing as by default | |
| /// behavior. | |
| /// </para> | |
| /// </summary> | |
| [] | |
| [] | |
| public SwitchParameter PassThru { get; set; } | |
| /// <summary> | |
| /// BeginProcessing method. | |
| /// </summary> | |
| protected override void BeginProcessing() | |
| { | |
| CimSetCimInstance cimSetCimInstance = this.GetOperationAgent() ?? CreateOperationAgent(); | |
| this.CmdletOperation = new CmdletOperationSetCimInstance(this, cimSetCimInstance); | |
| this.AtBeginProcess = false; | |
| } | |
| /// <summary> | |
| /// ProcessRecord method. | |
| /// </summary> | |
| protected override void ProcessRecord() | |
| { | |
| base.CheckParameterSet(); | |
| CimSetCimInstance cimSetCimInstance = this.GetOperationAgent(); | |
| cimSetCimInstance.SetCimInstance(this); | |
| cimSetCimInstance.ProcessActions(this.CmdletOperation); | |
| } | |
| /// <summary> | |
| /// EndProcessing method. | |
| /// </summary> | |
| protected override void EndProcessing() | |
| { | |
| CimSetCimInstance cimSetCimInstance = this.GetOperationAgent(); | |
| cimSetCimInstance?.ProcessRemainActions(this.CmdletOperation); | |
| } | |
| /// <summary> | |
| /// <para> | |
| /// Get <see cref="CimSetCimInstance"/> object, which is | |
| /// used to delegate all Set-CimInstance operations. | |
| /// </para> | |
| /// </summary> | |
| private CimSetCimInstance GetOperationAgent() | |
| { | |
| return this.AsyncOperation as CimSetCimInstance; | |
| } | |
| /// <summary> | |
| /// <para> | |
| /// Create <see cref="CimSetCimInstance"/> object, which is | |
| /// used to delegate all Set-CimInstance operations. | |
| /// </para> | |
| /// </summary> | |
| /// <returns></returns> | |
| private CimSetCimInstance CreateOperationAgent() | |
| { | |
| CimSetCimInstance cimSetCimInstance = new(); | |
| this.AsyncOperation = cimSetCimInstance; | |
| return cimSetCimInstance; | |
| } | |
| internal const string nameCimSession = "CimSession"; | |
| internal const string nameComputerName = "ComputerName"; | |
| internal const string nameResourceUri = "ResourceUri"; | |
| internal const string nameNamespace = "Namespace"; | |
| internal const string nameCimInstance = "InputObject"; | |
| internal const string nameQuery = "Query"; | |
| internal const string nameQueryDialect = "QueryDialect"; | |
| internal const string nameProperty = "Property"; | |
| /// <summary> | |
| /// Static parameter definition entries. | |
| /// </summary> | |
| private static readonly Dictionary<string, HashSet<ParameterDefinitionEntry>> parameters = new() | |
| { | |
| { | |
| nameCimSession, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceSessionSet, true), | |
| new ParameterDefinitionEntry(CimBaseCommand.QuerySessionSet, true), | |
| } | |
| }, | |
| { | |
| nameComputerName, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.QueryComputerSet, false), | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceComputerSet, false), | |
| } | |
| }, | |
| { | |
| nameNamespace, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.QuerySessionSet, false), | |
| new ParameterDefinitionEntry(CimBaseCommand.QueryComputerSet, false), | |
| } | |
| }, | |
| { | |
| nameCimInstance, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceComputerSet, true), | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceSessionSet, true), | |
| } | |
| }, | |
| { | |
| nameQuery, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.QueryComputerSet, true), | |
| new ParameterDefinitionEntry(CimBaseCommand.QuerySessionSet, true), | |
| } | |
| }, | |
| { | |
| nameQueryDialect, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.QuerySessionSet, false), | |
| new ParameterDefinitionEntry(CimBaseCommand.QueryComputerSet, false), | |
| } | |
| }, | |
| { | |
| nameProperty, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.QuerySessionSet, true), | |
| new ParameterDefinitionEntry(CimBaseCommand.QueryComputerSet, true), | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceSessionSet, false), | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceComputerSet, false), | |
| } | |
| }, | |
| { | |
| nameResourceUri, new HashSet<ParameterDefinitionEntry> { | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceComputerSet, false), | |
| new ParameterDefinitionEntry(CimBaseCommand.CimInstanceSessionSet, false), | |
| } | |
| }, | |
| }; | |
| /// <summary> | |
| /// Static parameter set entries. | |
| /// </summary> | |
| private static readonly Dictionary<string, ParameterSetEntry> parameterSets = new() | |
| { | |
| { CimBaseCommand.QuerySessionSet, new ParameterSetEntry(3) }, | |
| { CimBaseCommand.QueryComputerSet, new ParameterSetEntry(2) }, | |
| { CimBaseCommand.CimInstanceSessionSet, new ParameterSetEntry(2) }, | |
| { CimBaseCommand.CimInstanceComputerSet, new ParameterSetEntry(1, true) }, | |
| }; | |
| } | |
| } | |