本文整理汇总了C#中System.Management.Automation.PSCmdlet类的典型用法代码示例。如果您正苦于以下问题:C# PSCmdlet类的具体用法?C# PSCmdlet怎么用?C# PSCmdlet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PSCmdlet类属于System.Management.Automation命名空间,在下文中一共展示了PSCmdlet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdatableHelpSystemDrive
internal UpdatableHelpSystemDrive(PSCmdlet cmdlet, string path, PSCredential credential)
{
for (int i = 0; i < 6; i++)
{
this._driveName = Path.GetFileNameWithoutExtension(Path.GetRandomFileName());
this._cmdlet = cmdlet;
if (path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase) || path.EndsWith("/", StringComparison.OrdinalIgnoreCase))
{
path = path.Remove(path.Length - 1);
}
PSDriveInfo atScope = cmdlet.SessionState.Drive.GetAtScope(this._driveName, "local");
if (atScope != null)
{
if (atScope.Root.Equals(path))
{
return;
}
if (i < 5)
{
continue;
}
cmdlet.SessionState.Drive.Remove(this._driveName, true, "local");
}
atScope = new PSDriveInfo(this._driveName, cmdlet.SessionState.Internal.GetSingleProvider("FileSystem"), path, string.Empty, credential);
cmdlet.SessionState.Drive.New(atScope, "local");
return;
}
}
示例2: AliasDefinitionsTypeValidationCallback
private static bool AliasDefinitionsTypeValidationCallback(string key, object obj, PSCmdlet cmdlet, string path)
{
Hashtable[] hashtableArray = DISCPowerShellConfiguration.TryGetHashtableArray(obj);
if (hashtableArray == null)
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustBeHashtableArray, key, path));
return false;
}
foreach (Hashtable hashtable in hashtableArray)
{
if (!hashtable.ContainsKey(AliasNameToken))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasNameToken, path }));
return false;
}
if (!hashtable.ContainsKey(AliasValueToken))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeMustContainKey, new object[] { key, AliasValueToken, path }));
return false;
}
foreach (string str in hashtable.Keys)
{
if ((!string.Equals(str, AliasNameToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasValueToken, StringComparison.OrdinalIgnoreCase)) && (!string.Equals(str, AliasDescriptionToken, StringComparison.OrdinalIgnoreCase) && !string.Equals(str, AliasOptionsToken, StringComparison.OrdinalIgnoreCase)))
{
cmdlet.WriteVerbose(StringUtil.Format(RemotingErrorIdStrings.DISCTypeContainsInvalidKey, new object[] { str, key, path }));
return false;
}
}
}
return true;
}
示例3: SetDelimiter
internal static char SetDelimiter(PSCmdlet Cmdlet, string ParameterSetName, char Delimiter, bool UseCulture)
{
switch (ParameterSetName)
{
case "Delimiter":
if (Delimiter == '\0')
{
Delimiter = ',';
}
return Delimiter;
case "UseCulture":
if (UseCulture)
{
string str = Registry.CurrentUser.OpenSubKey(@"Control Panel\International").GetValue("sList").ToString();
if (string.IsNullOrEmpty(str))
{
Delimiter = ',';
return Delimiter;
}
Delimiter = str[0];
}
return Delimiter;
}
Delimiter = ',';
return Delimiter;
}
示例4: WriteToPs1Xml
/// <summary>
/// Writes a collection of format view definitions to XML file
/// </summary>
/// <param name="typeDefinitions">collection of PSTypeDefinition</param>
/// <param name="filepath">path to XML file</param>
/// <param name="cmdlet">cmdlet from which this si used</param>
/// <param name="force">true - to force write the file</param>
/// <param name="writeScriptBlock">true - to export scriptblocks</param>
/// <param name="noclobber">true - do not overwrite the file</param>
/// <param name="isLiteralPath">true - bypass wildcard expansion on the file name</param>
internal static void WriteToPs1Xml(PSCmdlet cmdlet, List<ExtendedTypeDefinition> typeDefinitions,
string filepath, bool force, bool noclobber, bool writeScriptBlock, bool isLiteralPath)
{
StreamWriter streamWriter;
FileStream fileStream;
FileInfo fileInfo;
PathUtils.MasterStreamOpen(cmdlet, filepath, "ascii", true, false, force, noclobber,
out fileStream, out streamWriter, out fileInfo, isLiteralPath);
try
{
using (XmlWriter xmlWriter = XmlWriter.Create(streamWriter))
{
var writer = new FormatXmlWriter
{
_writer = xmlWriter,
_exportScriptBlock = writeScriptBlock
};
writer.WriteToXml(typeDefinitions);
}
}
finally
{
streamWriter.Dispose();
fileStream.Dispose();
}
}
示例5: CheckForSevereException
// Keep in sync:
// S.M.A.CommandProcessorBase.CheckForSevereException
// S.M.A.Internal.ConsoleHost.CheckForSevereException
// S.M.A.Commands.CommandsCommon.CheckForSevereException
// S.M.A.Commands.UtilityCommon.CheckForSevereException
/// <summary>
/// Checks whether the exception is a severe exception which should
/// cause immediate process failure.
/// </summary>
/// <param name="cmdlet">can be null</param>
/// <param name="e"></param>
/// <remarks>
/// CB says 02/23/2005: I personally would err on the side
/// of treating OOM like an application exception, rather than
/// a critical system failure.I think this will be easier to justify
/// in Orcas, if we tease apart the two cases of OOM better.
/// But even in Whidbey, how likely is it that we couldnt JIT
/// some backout code? At that point, the process or possibly
/// the machine is likely to stop executing soon no matter
/// what you do in this routine. So I would just consider
/// AccessViolationException. (I understand why you have SO here,
/// at least temporarily).
/// </remarks>
internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e)
{
if (e is AccessViolationException || e is StackOverflowException)
{
try
{
if (!alreadyFailing)
{
alreadyFailing = true;
// Get the ExecutionContext from the thread.
ExecutionContext context =
(null != cmdlet)
? cmdlet.Context
: LocalPipeline.GetExecutionContextFromTLS();
// Log a command health event for this critical error.
MshLog.LogCommandHealthEvent(context, e, Severity.Critical);
}
}
finally
{
if (!designForTestability_SkipFailFast)
WindowsErrorReporting.FailFast(e);
}
}
}
示例6: ExecuteCmdletBase
public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
{
ManagementService client = CreateManagementServiceClient();
var relyingParties = client.RelyingParties;
List<string> relyingPartyRelayAddresses = new List<string>();
long relyingPartyId = -1;
foreach (var relyingParty in relyingParties)
{
string name = relyingParty.Name;
if (name == RelyingParty)
{
relyingPartyId = relyingParty.Id;
}
}
foreach (RelyingPartyAddress address in client.RelyingPartyAddresses)
{
if (address.RelyingPartyId == relyingPartyId)
{
relyingPartyRelayAddresses.Add(address.Address);
}
}
callingCmdlet.WriteObject(relyingPartyRelayAddresses, true); ;
}
示例7: MasterStreamOpen
internal static void MasterStreamOpen(
PSCmdlet cmdlet,
string filePath,
string encoding,
bool defaultEncoding,
bool append,
bool force,
bool noClobber,
out FileStream fileStream,
out StreamWriter streamWriter,
out FileInfo readOnlyFileInfo,
bool isLiteralPath)
{
var resolvedEncoding = EncodingConversion.Convert(cmdlet, encoding);
MasterStreamOpen(
cmdlet,
filePath,
resolvedEncoding,
defaultEncoding,
append,
force,
noClobber,
out fileStream,
out streamWriter,
out readOnlyFileInfo,
isLiteralPath);
}
示例8: ExecuteCmdletBase
public void ExecuteCmdletBase(PSCmdlet callingCmdlet)
{
ManagementService client = CreateManagementServiceClient();
var relyingParties = client.RelyingParties;
if (relyingParties != null)
{
foreach (var relyingParty in relyingParties)
{
string name = relyingParty.Name;
if (name == RelyingParty)
{
RelyingPartyAddress address = new RelyingPartyAddress();
address.Address = RelyingPartyRelayAddress;
address.EndpointType = "Reply";
client.AddRelatedObject(relyingParty, "RelyingPartyAddresses", address);
client.SaveChanges(SaveChangesOptions.Batch);
}
}
}
else
{
throw new Exception("Failed to get the Relying Parties list from the ACS Management Service.");
}
}
示例9: ShowHelpWindow
private static void ShowHelpWindow(PSObject helpObj, PSCmdlet cmdlet)
{
Window ownerWindow = ShowCommandHelper.GetHostWindow(cmdlet);
if (ownerWindow != null)
{
ownerWindow.Dispatcher.Invoke(
new SendOrPostCallback(
delegate(object ignored)
{
HelpWindow helpWindow = new HelpWindow(helpObj);
helpWindow.Owner = ownerWindow;
helpWindow.Show();
helpWindow.Closed += new EventHandler(delegate(object sender, EventArgs e) { ownerWindow.Focus(); });
}),
String.Empty);
return;
}
Thread guiThread = new Thread(
(ThreadStart)delegate
{
HelpWindow helpWindow = new HelpWindow(helpObj);
helpWindow.ShowDialog();
});
guiThread.SetApartmentState(ApartmentState.STA);
guiThread.Start();
}
示例10: Glob
/// <summary>
///
/// </summary>
/// <param name="files"></param>
/// <param name="errorId"></param>
/// <param name="cmdlet"></param>
/// <returns></returns>
internal static Collection<string> Glob(string[] files, string errorId, PSCmdlet cmdlet)
{
Collection<string> retValue = new Collection<string>();
foreach (string file in files)
{
Collection<string> providerPaths;
ProviderInfo provider = null;
try
{
providerPaths = cmdlet.SessionState.Path.GetResolvedProviderPathFromPSPath(file, out provider);
}
catch (SessionStateException e)
{
cmdlet.WriteError(new ErrorRecord(e, errorId, ErrorCategory.InvalidOperation, file));
continue;
}
if (!provider.NameEquals(cmdlet.Context.ProviderNames.FileSystem))
{
ReportWrongProviderType(provider.FullName, errorId, cmdlet);
continue;
}
foreach (string providerPath in providerPaths)
{
if (!providerPath.EndsWith(".ps1xml", StringComparison.OrdinalIgnoreCase))
{
ReportWrongExtension(providerPath, "WrongExtension", cmdlet);
continue;
}
retValue.Add(providerPath);
}
}
return retValue;
}
示例11: DomainDispatcher
public DomainDispatcher(PSCmdlet cmdlet)
{
Contract.Requires(cmdlet != null);
_cmdlet = cmdlet;
_dte = (DTE)cmdlet.GetVariableValue("DTE");
}
示例12: TerminatingErrorContext
internal TerminatingErrorContext(PSCmdlet command)
{
if (command == null)
{
throw PSTraceSource.NewArgumentNullException("command");
}
this._command = command;
}
示例13: ImportCsvHelper
internal ImportCsvHelper(PSCmdlet cmdlet, char delimiter, IList<string> header, string typeName, StreamReader streamReader)
{
this._cmdlet = cmdlet;
this._delimiter = delimiter;
this._header = header;
this._typeName = typeName;
this._sr = streamReader;
}
示例14: ReportWrongExtension
private static void ReportWrongExtension(string file, string errorId, PSCmdlet cmdlet)
{
ErrorRecord errorRecord = new ErrorRecord(
PSTraceSource.NewInvalidOperationException(UpdateDataStrings.UpdateData_WrongExtension, file, "ps1xml"),
errorId,
ErrorCategory.InvalidArgument,
null);
cmdlet.WriteError(errorRecord);
}
示例15: PSHostTraceListener
internal PSHostTraceListener(PSCmdlet cmdlet) : base("")
{
this.cachedWrite = new StringBuilder();
if (cmdlet == null)
{
throw new PSArgumentNullException("cmdlet");
}
this.ui = cmdlet.Host.UI as InternalHostUserInterface;
}