本文整理汇总了C#中System.Management.Automation.CmdletProviderContext.GetAccumulatedErrorObjects方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProviderContext.GetAccumulatedErrorObjects方法的具体用法?C# CmdletProviderContext.GetAccumulatedErrorObjects怎么用?C# CmdletProviderContext.GetAccumulatedErrorObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.CmdletProviderContext
的用法示例。
在下文中一共展示了CmdletProviderContext.GetAccumulatedErrorObjects方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetChildNamesInDir
private Collection<PSObject> GetChildNamesInDir(string dir, string leafElement, bool getAllContainers, CmdletProviderContext context, bool dirIsProviderPath, PSDriveInfo drive, ContainerCmdletProvider provider, out string modifiedDirPath)
{
string updatedPath = null;
string updatedFilter = null;
Collection<PSObject> collection4;
string filter = context.Filter;
bool flag = provider.ConvertPath(leafElement, context.Filter, ref updatedPath, ref updatedFilter, context);
if (flag)
{
tracer.WriteLine("Provider converted path and filter.", new object[0]);
tracer.WriteLine("Original path: " + leafElement, new object[0]);
tracer.WriteLine("Converted path: " + updatedPath, new object[0]);
tracer.WriteLine("Original filter: " + context.Filter, new object[0]);
tracer.WriteLine("Converted filter: " + updatedFilter, new object[0]);
leafElement = updatedPath;
context.Filter = updatedFilter;
}
ReturnContainers returnAllContainers = ReturnContainers.ReturnAllContainers;
if (!getAllContainers)
{
returnAllContainers = ReturnContainers.ReturnMatchingContainers;
}
CmdletProviderContext context2 = new CmdletProviderContext(context);
context2.SetFilters(new Collection<string>(), new Collection<string>(), context.Filter);
try
{
string path = null;
modifiedDirPath = null;
if (dirIsProviderPath)
{
modifiedDirPath = path = context.SuppressWildcardExpansion ? dir : RemoveGlobEscaping(dir);
}
else
{
modifiedDirPath = GetMshQualifiedPath(dir, drive);
ProviderInfo info = null;
CmdletProvider providerInstance = null;
Collection<string> collection = this.GetGlobbedProviderPathsFromMonadPath(modifiedDirPath, false, context2, out info, out providerInstance);
modifiedDirPath = context.SuppressWildcardExpansion ? modifiedDirPath : RemoveGlobEscaping(modifiedDirPath);
if (collection.Count > 0)
{
path = collection[0];
}
else
{
if (flag)
{
context.Filter = filter;
}
return new Collection<PSObject>();
}
}
if (provider.HasChildItems(path, context2))
{
provider.GetChildNames(path, returnAllContainers, context2);
}
if (context2.HasErrors())
{
Collection<ErrorRecord> accumulatedErrorObjects = context2.GetAccumulatedErrorObjects();
if ((accumulatedErrorObjects != null) && (accumulatedErrorObjects.Count > 0))
{
foreach (ErrorRecord record in accumulatedErrorObjects)
{
context.WriteError(record);
}
}
}
Collection<PSObject> accumulatedObjects = context2.GetAccumulatedObjects();
if (flag)
{
context.Filter = filter;
}
collection4 = accumulatedObjects;
}
finally
{
context2.RemoveStopReferral();
}
return collection4;
}
示例2: GetProviderPath
internal string GetProviderPath(string path, out ProviderInfo provider)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.sessionState.Internal.ExecutionContext);
PSDriveInfo drive = null;
provider = null;
string str = this.GetProviderPath(path, context, out provider, out drive);
if (context.HasErrors())
{
Collection<ErrorRecord> accumulatedErrorObjects = context.GetAccumulatedErrorObjects();
if ((accumulatedErrorObjects != null) && (accumulatedErrorObjects.Count > 0))
{
throw accumulatedErrorObjects[0].Exception;
}
}
return str;
}
示例3: GetChildNamesInDir
//.........这里部分代码省略.........
getChildNamesContext.SetFilters(
new Collection<string>(),
new Collection<string>(),
context.Filter);
try
{
// Use the provider to get the children
string unescapedDir = null;
modifiedDirPath = null;
if (dirIsProviderPath)
{
modifiedDirPath = unescapedDir = context.SuppressWildcardExpansion ? dir : RemoveGlobEscaping(dir);
}
else
{
Dbg.Diagnostics.Assert(
drive != null,
"Caller should verify that drive is not null when dirIsProviderPath is false");
// If the directory is an MSH path we must resolve it before calling GetChildNames()
// -- If the path is passed in by LiteralPath (context.SuppressWildcardExpansion == false), we surely should use 'dir' unchanged.
// -- If the path is passed in by Path (context.SuppressWildcardExpansion == true), we still should use 'dir' unchanged, in case that the special character
// in 'dir' is escaped
modifiedDirPath = GetMshQualifiedPath(dir, drive);
ProviderInfo providerIgnored = null;
CmdletProvider providerInstanceIgnored = null;
Collection<string> resolvedPaths =
GetGlobbedProviderPathsFromMonadPath(
modifiedDirPath,
false,
getChildNamesContext,
out providerIgnored,
out providerInstanceIgnored);
// After resolving the path, we unescape the modifiedDirPath if necessary.
modifiedDirPath = context.SuppressWildcardExpansion
? modifiedDirPath
: RemoveGlobEscaping(modifiedDirPath);
if (resolvedPaths.Count > 0)
{
unescapedDir = resolvedPaths[0];
}
else
{
// If there were no results from globbing but no
// exception was thrown, that means there was filtering.
// So return an empty collection and let the caller deal
// with it.
if (changedPathOrFilter)
{
context.Filter = originalFilter;
}
return new Collection<PSObject>();
}
}
if (provider.HasChildItems(unescapedDir, getChildNamesContext))
{
provider.GetChildNames(
unescapedDir,
returnContainers,
getChildNamesContext);
}
// First check to see if there were any errors, and write them
// to the real context if there are.
if (getChildNamesContext.HasErrors())
{
Collection<ErrorRecord> errors = getChildNamesContext.GetAccumulatedErrorObjects();
if (errors != null &&
errors.Count > 0)
{
foreach (ErrorRecord errorRecord in errors)
{
context.WriteError(errorRecord);
}
}
}
Collection<PSObject> childNamesObjectArray = getChildNamesContext.GetAccumulatedObjects();
if (changedPathOrFilter)
{
context.Filter = originalFilter;
}
return childNamesObjectArray;
}
finally
{
getChildNamesContext.RemoveStopReferral();
}
} // GetChildNamesInDir
示例4: GetGlobbedProviderPathsFromProviderPath
internal Collection<string> GetGlobbedProviderPathsFromProviderPath(string path, bool allowNonexistingPaths, string providerId, out CmdletProvider providerInstance)
{
providerInstance = null;
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.sessionState.Internal.ExecutionContext);
Collection<string> collection = this.GetGlobbedProviderPathsFromProviderPath(path, allowNonexistingPaths, providerId, context, out providerInstance);
if (context.HasErrors())
{
ErrorRecord record = context.GetAccumulatedErrorObjects()[0];
if (record != null)
{
throw record.Exception;
}
}
return collection;
}
示例5: GetProviderPath
} // GetProviderPath
/// <summary>
/// Gets a provider specific path when given an Msh path without resolving the
/// glob characters.
/// </summary>
///
/// <param name="path">
/// An Msh path.
/// </param>
///
/// <param name="provider">
/// The information of the provider that was used to resolve the path.
/// </param>
///
/// <returns>
/// A provider specific path that the Msh path represents.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="ProviderNotFoundException">
/// If the path is a provider-qualified path for a provider that is
/// not loaded into the system.
/// </exception>
///
/// <exception cref="DriveNotFoundException">
/// If the <paramref name="path"/> refers to a drive that could not be found.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider used to build the path threw an exception.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the provider that the <paramref name="path"/> represents is not a NavigationCmdletProvider
/// or ContainerCmdletProvider.
/// </exception>
///
/// <exception cref="InvalidOperationException">
/// If the <paramref name="path"/> starts with "~" and the home location is not set for
/// the provider.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider specified by <paramref name="provider"/> threw an
/// exception when its GetParentPath or MakePath was called while
/// processing the <paramref name="path"/>.
/// </exception>
///
/// <exception>
/// Any exception can be thrown by the provider that is called to build
/// the provider path.
/// </exception>
///
internal string GetProviderPath(string path, out ProviderInfo provider)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context =
new CmdletProviderContext(_sessionState.Internal.ExecutionContext);
PSDriveInfo drive = null;
provider = null;
string result = GetProviderPath(path, context, out provider, out drive);
if (context.HasErrors())
{
Collection<ErrorRecord> errors = context.GetAccumulatedErrorObjects();
if (errors != null &&
errors.Count > 0)
{
throw errors[0].Exception;
}
}
return result;
} // GetProviderPath