// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#region Using directives
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation;
#endregion
namespace Microsoft.Management.Infrastructure.CimCmdlets
{
///
///
/// Enables the user to enumerate the list of CIM Classes under a specific
/// Namespace. If no list of classes is given, the Cmdlet returns all
/// classes in the given namespace.
///
///
/// NOTES: The class instance contains the Namespace properties
/// Should the class remember what Session it came from? No.
///
///
[Cmdlet(VerbsCommon.Get, GetCimClassCommand.Noun, DefaultParameterSetName = ComputerSetName, HelpUri = "https://go.microsoft.com/fwlink/?LinkId=227959")]
[OutputType(typeof(CimClass))]
public class GetCimClassCommand : CimBaseCommand
{
#region constructor
///
/// Constructor.
///
public GetCimClassCommand()
: base(parameters, parameterSets)
{
DebugHelper.WriteLogEx();
}
#endregion
#region parameters
///
///
/// The following is the definition of the input parameter "ClassName".
///
///
/// Wildcard expansion should be allowed.
///
///
[Parameter(
Position = 0,
ValueFromPipelineByPropertyName = true)]
public string ClassName
{
get { return className; }
set { className = value; }
}
private string className;
///
///
/// The following is the definition of the input parameter "Namespace".
/// Specifies the Namespace under which to look for the specified class name.
/// If no class name is specified, the cmdlet should return all classes under
/// the specified Namespace.
///
///
/// Default namespace is root\cimv2
///
///
[Parameter(
Position = 1,
ValueFromPipelineByPropertyName = true)]
public string Namespace
{
get { return nameSpace; }
set { nameSpace = value; }
}
private string nameSpace;
///
/// The following is the definition of the input parameter "OperationTimeoutSec".
/// Enables the user to specify the operation timeout in Seconds. This value
/// overwrites the value specified by the CimSession Operation timeout.
///
[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 "Session".
/// Uses a CimSession context.
///
[Parameter(
Mandatory = true,
ValueFromPipeline = true,
ParameterSetName = SessionSetName)]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays")]
public CimSession[] CimSession
{
get { return cimSession; }
set
{
cimSession = value;
base.SetParameter(value, nameCimSession);
}
}
private CimSession[] cimSession;
///
/// The following is the definition of the input parameter "ComputerName".
/// Provides the name of the computer from which to retrieve the
///
///
/// If no ComputerName is specified the default value is "localhost"
///
///
[Alias(AliasCN, AliasServerName)]
[Parameter(
ValueFromPipelineByPropertyName = true,
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 "MethodName",
/// Which may contains wildchar.
/// Then Filter the by given methodname
///
///
[Parameter(ValueFromPipelineByPropertyName = true)]
public string MethodName
{
get { return methodName; }
set { methodName = value; }
}
private string methodName;
///
///
/// The following is the definition of the input parameter "PropertyName",
/// Which may contains wildchar.
/// Filter the by given property name.
///
///
[Parameter(ValueFromPipelineByPropertyName = true)]
public string PropertyName
{
get { return propertyName; }
set { propertyName = value; }
}
private string propertyName;
///
///
/// The following is the definition of the input parameter "QualifierName",
/// Which may contains wildchar.
/// Filter the by given methodname
///
///
[Parameter(ValueFromPipelineByPropertyName = true)]
public string QualifierName
{
get { return qualifierName; }
set { qualifierName = value; }
}
private string qualifierName;
#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();
CimGetCimClass cimGetCimClass = this.GetOperationAgent();
if (cimGetCimClass == null)
{
cimGetCimClass = CreateOperationAgent();
}
cimGetCimClass.GetCimClass(this);
cimGetCimClass.ProcessActions(this.CmdletOperation);
}
///
/// EndProcessing method.
///
protected override void EndProcessing()
{
CimGetCimClass cimGetCimClass = this.GetOperationAgent();
if (cimGetCimClass != null)
{
cimGetCimClass.ProcessRemainActions(this.CmdletOperation);
}
}
#endregion
#region helper methods
///
///
/// Get object, which is
/// used to delegate all New-CimInstance operations.
///
///
CimGetCimClass GetOperationAgent()
{
return (this.AsyncOperation as CimGetCimClass);
}
///
///
/// Create object, which is
/// used to delegate all Get-CimClass operations.
///
///
///
CimGetCimClass CreateOperationAgent()
{
CimGetCimClass cimGetCimClass = new CimGetCimClass();
this.AsyncOperation = cimGetCimClass;
return cimGetCimClass;
}
#endregion
#region internal const strings
///
/// Noun of current cmdlet.
///
internal const string Noun = @"CimClass";
#endregion
#region private members
#region const string of parameter names
internal const string nameCimSession = "CimSession";
internal const string nameComputerName = "ComputerName";
#endregion
///
/// Static parameter definition entries.
///
static Dictionary> parameters = new Dictionary>
{
{
nameCimSession, new HashSet {
new ParameterDefinitionEntry(CimBaseCommand.SessionSetName, true),
}
},
{
nameComputerName, new HashSet {
new ParameterDefinitionEntry(CimBaseCommand.ComputerSetName, false),
}
},
};
///
/// Static parameter set entries.
///
static Dictionary parameterSets = new Dictionary
{
{ CimBaseCommand.SessionSetName, new ParameterSetEntry(1) },
{ CimBaseCommand.ComputerSetName, new ParameterSetEntry(0, true) },
};
#endregion
}
}