// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #region Using directives using System.Collections.Generic; using System.Management.Automation; #endregion namespace Microsoft.Management.Infrastructure.CimCmdlets { /// /// Containing all information originated from /// the parameters of /// internal class CimGetCimClassContext : XOperationContextBase { /// /// Initializes a new instance of the class. /// /// /// /// internal CimGetCimClassContext( string theClassName, string theMethodName, string thePropertyName, string theQualifierName) { this.ClassName = theClassName; this.MethodName = theMethodName; this.PropertyName = thePropertyName; this.QualifierName = theQualifierName; } /// /// /// The following is the definition of the input parameter "ClassName". /// /// /// Wildcard expansion should be allowed. /// /// public string ClassName { get; set; } /// /// /// The following is the definition of the input parameter "MethodName", /// Which may contains wildchar. /// Then Filter the by given methodname /// /// internal string MethodName { get; } /// /// /// The following is the definition of the input parameter "PropertyName", /// Which may contains wildchar. /// Filter the by given property name. /// /// internal string PropertyName { get; } /// /// /// The following is the definition of the input parameter "QualifierName", /// Which may contains wildchar. /// Filter the by given methodname /// /// internal string QualifierName { get; } } /// /// /// Implements operations of get-cimclass cmdlet. /// /// internal sealed class CimGetCimClass : CimAsyncOperation { /// /// Initializes a new instance of the class. /// public CimGetCimClass() : base() { } /// /// /// Base on parametersetName to retrieve /// /// /// object. public void GetCimClass(GetCimClassCommand cmdlet) { List proxys = new(); string nameSpace = ConstValue.GetNamespace(cmdlet.Namespace); string className = cmdlet.ClassName ?? @"*"; CimGetCimClassContext context = new( cmdlet.ClassName, cmdlet.MethodName, cmdlet.PropertyName, cmdlet.QualifierName); switch (cmdlet.ParameterSetName) { case CimBaseCommand.ComputerSetName: { IEnumerable computerNames = ConstValue.GetComputerNames( cmdlet.ComputerName); foreach (string computerName in computerNames) { CimSessionProxy proxy = CreateSessionProxy(computerName, cmdlet); proxy.ContextObject = context; proxys.Add(proxy); } } break; case CimBaseCommand.SessionSetName: { foreach (CimSession session in cmdlet.CimSession) { CimSessionProxy proxy = CreateSessionProxy(session, cmdlet); proxy.ContextObject = context; proxys.Add(proxy); } } break; default: return; } if (WildcardPattern.ContainsWildcardCharacters(className)) { // retrieve all classes and then filter based on // classname, propertyname, methodname, and qualifiername foreach (CimSessionProxy proxy in proxys) { proxy.EnumerateClassesAsync(nameSpace); } } else { foreach (CimSessionProxy proxy in proxys) { proxy.GetClassAsync(nameSpace, className); } } } #region private methods /// /// /// Set properties /// /// /// /// private static void SetSessionProxyProperties( ref CimSessionProxy proxy, GetCimClassCommand cmdlet) { proxy.OperationTimeout = cmdlet.OperationTimeoutSec; proxy.Amended = cmdlet.Amended; } /// /// /// Create and set properties /// /// /// /// /// private CimSessionProxy CreateSessionProxy( string computerName, GetCimClassCommand cmdlet) { CimSessionProxy proxy = new CimSessionProxyGetCimClass(computerName); this.SubscribeEventAndAddProxytoCache(proxy); SetSessionProxyProperties(ref proxy, cmdlet); return proxy; } /// /// Create and set properties. /// /// /// /// private CimSessionProxy CreateSessionProxy( CimSession session, GetCimClassCommand cmdlet) { CimSessionProxy proxy = new CimSessionProxyGetCimClass(session); this.SubscribeEventAndAddProxytoCache(proxy); SetSessionProxyProperties(ref proxy, cmdlet); return proxy; } #endregion } }