// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #region Using directives using System; using System.Diagnostics.CodeAnalysis; using System.Management.Automation; using System.Collections.Generic; #endregion namespace Microsoft.Management.Infrastructure.CimCmdlets { /// /// /// The Cmdlet retrieves instances connected to the given instance, which /// is called the source instance, via a given association. In an /// association each instance has a named role, and the same instance can /// participate in an association in different roles. Hence, the Cmdlet /// takes SourceRole and AssociatorRole parameters in addition to the /// Association parameter. /// /// [Cmdlet(VerbsCommon.Get, GetCimAssociatedInstanceCommand.Noun, DefaultParameterSetName = CimBaseCommand.ComputerSetName, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=227958")] [OutputType(typeof(CimInstance))] public class GetCimAssociatedInstanceCommand : CimBaseCommand { #region constructor /// /// Constructor. /// public GetCimAssociatedInstanceCommand() : base(parameters, parameterSets) { DebugHelper.WriteLogEx(); } #endregion #region parameters /// /// The following is the definition of the input parameter "Association". /// Specifies the class name of the association to be traversed from the /// SourceRole to AssociatorRole. /// [Parameter( Position = 1, ValueFromPipelineByPropertyName = true)] public string Association { get { return association; } set { association = value; } } private string association; /// /// The following is the definition of the input parameter "ResultClassName". /// Specifies the class name of the result class name, which associated with /// the given instance. /// [Parameter] public string ResultClassName { get { return resultClassName; } set { resultClassName = value; } } private string resultClassName; /// /// /// The following is the definition of the input parameter "InputObject". /// Provides the instance from which the association traversal is to begin. /// /// [Parameter( Mandatory = true, Position = 0, ValueFromPipeline = true)] [Alias(CimBaseCommand.AliasCimInstance)] public CimInstance InputObject { get { return cimInstance; } set { cimInstance = value; base.SetParameter(value, nameCimInstance); } } /// /// Property for internal usage purpose. /// internal CimInstance CimInstance { get { return cimInstance; } } private CimInstance cimInstance; /// /// The following is the definition of the input parameter "Namespace". /// Identifies the Namespace in which the source class, indicated by ClassName, /// is registered. /// [Parameter(ValueFromPipelineByPropertyName = true)] public string Namespace { get { return nameSpace; } set { nameSpace = value; } } private string nameSpace; /// /// The following is the definition of the input parameter "OperationTimeoutSec". /// Specifies the operation timeout after which the client operation should be /// canceled. The default is the CimSession operation timeout. If this parameter /// is specified, then this value takes precedence over the CimSession /// OperationTimeout. /// [Alias(AliasOT)] [Parameter(ValueFromPipelineByPropertyName = true)] public UInt32 OperationTimeoutSec { get { return operationTimeout; } set { operationTimeout = value; } } private UInt32 operationTimeout; /// /// /// The following is the definition of the input parameter "ResourceUri". /// Define the Resource Uri for which the instances are retrieved. /// /// [Parameter] public Uri ResourceUri { get { return resourceUri; } set { this.resourceUri = value; base.SetParameter(value, nameResourceUri); } } private Uri resourceUri; /// /// /// The following is the definition of the input parameter "ComputerName". /// Specifies the name of the computer where the source instance is stored and /// where the association traversal should begin. /// /// /// This is an optional parameter and if it is not provided, the default value /// will be "localhost". /// /// [Alias(AliasCN, AliasServerName)] [Parameter( ParameterSetName = ComputerSetName)] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public string[] ComputerName { get { return computerName; } set { computerName = value; base.SetParameter(value, nameComputerName); } } private string[] computerName; /// /// The following is the definition of the input parameter "CimSession". /// Identifies the CimSession which is to be used to retrieve the instances. /// [Parameter( Mandatory = true, ValueFromPipeline = true, ParameterSetName = SessionSetName)] [SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")] public Microsoft.Management.Infrastructure.CimSession[] CimSession { get { return cimSession; } set { cimSession = value; base.SetParameter(value, nameCimSession); } } private Microsoft.Management.Infrastructure.CimSession[] cimSession; /// /// /// The following is the definition of the input parameter "KeyOnly". /// Indicates that only key properties of the retrieved instances should be /// returned to the client. /// /// [Parameter] public SwitchParameter KeyOnly { get { return keyOnly; } set { keyOnly = value; } } private SwitchParameter keyOnly; #endregion #region cmdlet methods /// /// BeginProcessing method. /// protected override void BeginProcessing() { this.CmdletOperation = new CmdletOperationBase(this); this.AtBeginProcess = false; } /// /// ProcessRecord method. /// protected override void ProcessRecord() { base.CheckParameterSet(); CimGetAssociatedInstance operation = this.GetOperationAgent(); if (operation == null) { operation = this.CreateOperationAgent(); } operation.GetCimAssociatedInstance(this); operation.ProcessActions(this.CmdletOperation); } /// /// EndProcessing method. /// protected override void EndProcessing() { CimGetAssociatedInstance operation = this.GetOperationAgent(); if (operation != null) operation.ProcessRemainActions(this.CmdletOperation); } #endregion #region helper methods /// /// /// Get object, which is /// used to delegate all Get-CimAssociatedInstance operations. /// /// CimGetAssociatedInstance GetOperationAgent() { return this.AsyncOperation as CimGetAssociatedInstance; } /// /// /// Create object, which is /// used to delegate all Get-CimAssociatedInstance operations. /// /// /// CimGetAssociatedInstance CreateOperationAgent() { this.AsyncOperation = new CimGetAssociatedInstance(); return GetOperationAgent(); } #endregion #region internal const strings /// /// Noun of current cmdlet. /// internal const string Noun = @"CimAssociatedInstance"; #endregion #region private members #region const string of parameter names internal const string nameCimInstance = "InputObject"; internal const string nameComputerName = "ComputerName"; internal const string nameCimSession = "CimSession"; internal const string nameResourceUri = "ResourceUri"; #endregion /// /// Static parameter definition entries. /// static Dictionary> parameters = new Dictionary> { { nameComputerName, new HashSet { new ParameterDefinitionEntry(CimBaseCommand.ComputerSetName, false), } }, { nameCimSession, new HashSet { new ParameterDefinitionEntry(CimBaseCommand.SessionSetName, true), } }, { nameCimInstance, new HashSet { new ParameterDefinitionEntry(CimBaseCommand.ComputerSetName, true), new ParameterDefinitionEntry(CimBaseCommand.SessionSetName, true), } }, { nameResourceUri, new HashSet { new ParameterDefinitionEntry(CimBaseCommand.ComputerSetName, false), new ParameterDefinitionEntry(CimBaseCommand.SessionSetName, false), } }, }; /// /// Static parameter set entries. /// static Dictionary parameterSets = new Dictionary { { CimBaseCommand.SessionSetName, new ParameterSetEntry(2, false) }, { CimBaseCommand.ComputerSetName, new ParameterSetEntry(1, true) }, }; #endregion } }