PowerShell/src/Microsoft.PowerShell.Commands.Management/cimSupport/cmdletization/cim/cimJobContext.cs

169 lines
5.3 KiB
C#
Raw Normal View History

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.Globalization;
using System.Management.Automation;
2019-04-30 07:25:11 +02:00
using Microsoft.Management.Infrastructure;
namespace Microsoft.PowerShell.Cmdletization.Cim
{
internal class CimJobContext
{
internal CimJobContext(
CimCmdletInvocationContext cmdletInvocationContext,
CimSession session,
object targetObject)
{
this.CmdletInvocationContext = cmdletInvocationContext;
this.Session = session;
this.TargetObject = targetObject ?? this.ClassName;
}
public CimCmdletInvocationContext CmdletInvocationContext { get; }
public CimSession Session { get; }
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
public object TargetObject { get; }
public string ClassName
{
get
{
return GetCimClassName(this.CmdletInvocationContext.CmdletDefinitionContext.CmdletizationClassName);
}
}
public string ClassNameOrNullIfResourceUriIsUsed
{
get
{
if (this.CmdletInvocationContext.CmdletDefinitionContext.ResourceUri != null)
{
return null;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
return this.ClassName;
}
}
public string Namespace
{
get
{
if (!string.IsNullOrEmpty(this.CmdletInvocationContext.NamespaceOverride))
{
return this.CmdletInvocationContext.NamespaceOverride;
}
Code cleanup: Add space after closing brace where needed (#8530) * Update TestService * Update WebListener * Update Controllers * Update ExpTest * Update MyApp * Update Logic * Update Logic * Update MyApp * Update Microsoft.Management.Infrastructure.CimCmdlets * Update Microsoft.PowerShell.Commands.Diagnostics * Update Microsoft.PowerShell.ScheduledJob * Update Microsoft.WSMan.Management * Update Microsoft.WSMan.Runtime * Update ResGen * Update TypeCatalogGen * Update commands * Update Eventing * Update Reader * Update utility * Update ShowCommand * Update trace * Update WebCmdlet * Update Common * Update CoreCLR * Update common * Update format-object * Update format-wide * Update out-file * Update out-printer * Update out-string * Update OutGridView * Update LocalAccounts * Update Commands * Update security * Update CoreCLR * Update DscSupport * Update engine * Update help * Update logging * Update namespaces * Update security * Update utils * Update config * Update perfCounters * Update tracing * Update cmdletization * Update other * Update cim * Update xml * Update CoreCLR * Update common * Update DefaultFormatters * Update out-console * Update out-textInterface * Update DisplayDatabase * Update Utilities * Update COM * Update ComInterop * Update CommandCompletion * Update debugger * Update ExperimentalFeature * Update hostifaces * Update interpreter * Update lang * Update Modules * Update parser * Update runtime * Update client * Update commands * Update common * Update fanin * Update server * Update WireDataFormat * Update Binding * Update Operations * Update interface * Update cmdletization * Update cim * Update management * Update WindowsTaskbarJumpList * Update msh
2018-12-24 07:20:06 +01:00
return GetCimNamespace(this.CmdletInvocationContext.CmdletDefinitionContext.CmdletizationClassName);
}
}
private static void ExtractCimNamespaceAndClassName(string cmdletizationClassName, out string cimNamespace, out string cimClassName)
{
int indexOfLastBackslash = cmdletizationClassName.LastIndexOf('\\');
int indexOfLastForwardSlash = cmdletizationClassName.LastIndexOf('/');
int indexOfLastSeparator = Math.Max(indexOfLastBackslash, indexOfLastForwardSlash);
if (indexOfLastSeparator != (-1))
{
cimNamespace = cmdletizationClassName.Substring(0, indexOfLastSeparator);
cimClassName = cmdletizationClassName.Substring(indexOfLastSeparator + 1, cmdletizationClassName.Length - indexOfLastSeparator - 1);
}
else
{
cimNamespace = null;
cimClassName = cmdletizationClassName;
}
}
private static string GetCimClassName(string cmdletizationClassName)
{
string throwAway;
string cimClassName;
ExtractCimNamespaceAndClassName(cmdletizationClassName, out throwAway, out cimClassName);
return cimClassName;
}
private static string GetCimNamespace(string cmdletizationClassName)
{
string cimNamespace;
string throwAway;
ExtractCimNamespaceAndClassName(cmdletizationClassName, out cimNamespace, out throwAway);
return cimNamespace;
}
internal string PrependComputerNameToMessage(string message)
{
string computerName = this.Session.ComputerName;
if (computerName == null)
{
return message;
}
return string.Format(
CultureInfo.InvariantCulture,
CmdletizationResources.CimJob_ComputerNameConcatenationTemplate,
computerName,
message);
}
public InvocationInfo CmdletInvocationInfo
{
get { return this.CmdletInvocationContext.CmdletInvocationInfo; }
}
public string CmdletizationClassName
{
get { return this.CmdletInvocationContext.CmdletDefinitionContext.CmdletizationClassName; }
}
public Version CmdletizationModuleVersion
{
get { return this.CmdletInvocationContext.CmdletDefinitionContext.CmdletizationModuleVersion; }
}
public ActionPreference ErrorActionPreference
{
get { return this.CmdletInvocationContext.ErrorActionPreference; }
}
public ActionPreference WarningActionPreference
{
get { return this.CmdletInvocationContext.WarningActionPreference; }
}
public ActionPreference VerboseActionPreference
{
get { return this.CmdletInvocationContext.VerboseActionPreference; }
}
public ActionPreference DebugActionPreference
{
get { return this.CmdletInvocationContext.DebugActionPreference; }
}
public bool IsRunningInBackground
{
get { return this.CmdletInvocationContext.IsRunningInBackground; }
}
public MshCommandRuntime.ShouldProcessPossibleOptimization ShouldProcessOptimization
{
get { return this.CmdletInvocationContext.ShouldProcessOptimization; }
}
public bool ShowComputerName
{
get { return this.CmdletInvocationContext.ShowComputerName; }
}
public bool SupportsShouldProcess
{
get { return this.CmdletInvocationContext.CmdletDefinitionContext.SupportsShouldProcess; }
}
}
}