本文整理汇总了C#中System.Management.Automation.PSCmdlet.CurrentProviderLocation方法的典型用法代码示例。如果您正苦于以下问题:C# PSCmdlet.CurrentProviderLocation方法的具体用法?C# PSCmdlet.CurrentProviderLocation怎么用?C# PSCmdlet.CurrentProviderLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.PSCmdlet
的用法示例。
在下文中一共展示了PSCmdlet.CurrentProviderLocation方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateModuleDirectory
internal static DirectoryInfo CreateModuleDirectory(PSCmdlet cmdlet, string moduleNameOrPath, bool force)
{
DirectoryInfo targetObject = null;
try
{
string str = ModuleCmdletBase.ResolveRootedFilePath(moduleNameOrPath, cmdlet.Context);
if (string.IsNullOrEmpty(str) && moduleNameOrPath.StartsWith(".", StringComparison.OrdinalIgnoreCase))
{
str = Path.Combine(cmdlet.CurrentProviderLocation(cmdlet.Context.ProviderNames.FileSystem).ProviderPath, moduleNameOrPath);
}
if (string.IsNullOrEmpty(str))
{
str = Path.Combine(ModuleIntrinsics.GetPersonalModulePath(), moduleNameOrPath);
}
targetObject = new DirectoryInfo(str);
if (targetObject.Exists)
{
if (!force)
{
ErrorDetails details = new ErrorDetails(string.Format(CultureInfo.InvariantCulture, PathUtilsStrings.ExportPSSession_ErrorDirectoryExists, new object[] { targetObject.FullName }));
ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(details.Message), "ExportProxyCommand_OutputDirectoryExists", ErrorCategory.ResourceExists, targetObject);
cmdlet.ThrowTerminatingError(errorRecord);
}
return targetObject;
}
targetObject.Create();
}
catch (Exception exception)
{
CommandProcessorBase.CheckForSevereException(exception);
ErrorDetails details2 = new ErrorDetails(string.Format(CultureInfo.InvariantCulture, PathUtilsStrings.ExportPSSession_CannotCreateOutputDirectory, new object[] { moduleNameOrPath, exception.Message }));
ErrorRecord record2 = new ErrorRecord(new ArgumentException(details2.Message, exception), "ExportProxyCommand_CannotCreateOutputDirectory", ErrorCategory.ResourceExists, moduleNameOrPath);
cmdlet.ThrowTerminatingError(record2);
}
return targetObject;
}
示例2: CreateModuleDirectory
internal static DirectoryInfo CreateModuleDirectory(PSCmdlet cmdlet, string moduleNameOrPath, bool force)
{
Dbg.Assert(cmdlet != null, "Caller should verify cmdlet != null");
Dbg.Assert(!string.IsNullOrEmpty(moduleNameOrPath), "Caller should verify !string.IsNullOrEmpty(moduleNameOrPath)");
DirectoryInfo directoryInfo = null;
try
{
string rootedPath = Microsoft.PowerShell.Commands.ModuleCmdletBase.ResolveRootedFilePath(moduleNameOrPath, cmdlet.Context);
if (string.IsNullOrEmpty(rootedPath) && moduleNameOrPath.StartsWith(".", StringComparison.OrdinalIgnoreCase))
{
PathInfo currentPath = cmdlet.CurrentProviderLocation(cmdlet.Context.ProviderNames.FileSystem);
rootedPath = Path.Combine(currentPath.ProviderPath, moduleNameOrPath);
}
if (string.IsNullOrEmpty(rootedPath))
{
string personalModuleRoot = ModuleIntrinsics.GetPersonalModulePath();
rootedPath = Path.Combine(personalModuleRoot, moduleNameOrPath);
}
directoryInfo = new DirectoryInfo(rootedPath);
if (directoryInfo.Exists)
{
if (!force)
{
string errorMessage = string.Format(
CultureInfo.InvariantCulture, // directory name should be treated as culture-invariant
PathUtilsStrings.ExportPSSession_ErrorDirectoryExists,
directoryInfo.FullName);
ErrorDetails details = new ErrorDetails(errorMessage);
ErrorRecord errorRecord = new ErrorRecord(
new ArgumentException(details.Message),
"ExportProxyCommand_OutputDirectoryExists",
ErrorCategory.ResourceExists,
directoryInfo);
cmdlet.ThrowTerminatingError(errorRecord);
}
}
else
{
directoryInfo.Create();
}
}
catch (Exception e)
{
CommandProcessorBase.CheckForSevereException(e);
string errorMessage = string.Format(
CultureInfo.InvariantCulture, // directory name should be treated as culture-invariant
PathUtilsStrings.ExportPSSession_CannotCreateOutputDirectory,
moduleNameOrPath,
e.Message);
ErrorDetails details = new ErrorDetails(errorMessage);
ErrorRecord errorRecord = new ErrorRecord(
new ArgumentException(details.Message, e),
"ExportProxyCommand_CannotCreateOutputDirectory",
ErrorCategory.ResourceExists,
moduleNameOrPath);
cmdlet.ThrowTerminatingError(errorRecord);
}
return directoryInfo;
}