本文整理汇总了C#中System.Management.Automation.Provider.CmdletProvider.IsFilterSet方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProvider.IsFilterSet方法的具体用法?C# CmdletProvider.IsFilterSet怎么用?C# CmdletProvider.IsFilterSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.Provider.CmdletProvider
的用法示例。
在下文中一共展示了CmdletProvider.IsFilterSet方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoManualGetChildItems
private void DoManualGetChildItems(CmdletProvider providerInstance, string path, bool recurse, CmdletProviderContext context, bool skipIsItemContainerCheck = false)
{
Collection<WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(context.Include, WildcardOptions.IgnoreCase);
Collection<WildcardPattern> collection2 = SessionStateUtilities.CreateWildcardsFromStrings(context.Exclude, WildcardOptions.IgnoreCase);
if (skipIsItemContainerCheck || this.IsItemContainer(providerInstance, path, context))
{
CmdletProviderContext context2 = new CmdletProviderContext(context);
Collection<PSObject> accumulatedObjects = null;
Dictionary<string, bool> dictionary = null;
try
{
this.GetChildNames(providerInstance, path, recurse ? ReturnContainers.ReturnAllContainers : ReturnContainers.ReturnMatchingContainers, context2);
context2.WriteErrorsToContext(context);
accumulatedObjects = context2.GetAccumulatedObjects();
if (recurse && providerInstance.IsFilterSet())
{
context2.RemoveStopReferral();
context2 = new CmdletProviderContext(context);
Collection<PSObject> collection4 = new Collection<PSObject>();
dictionary = new Dictionary<string, bool>();
this.GetChildNames(providerInstance, path, ReturnContainers.ReturnMatchingContainers, context2);
foreach (PSObject obj2 in context2.GetAccumulatedObjects())
{
string baseObject = obj2.BaseObject as string;
if (baseObject != null)
{
dictionary[baseObject] = true;
}
}
}
}
finally
{
context2.RemoveStopReferral();
}
for (int i = 0; i < accumulatedObjects.Count; i++)
{
if (context.Stopping)
{
return;
}
string child = accumulatedObjects[i].BaseObject as string;
if (child != null)
{
string str3 = this.MakePath(providerInstance, path, child, context);
if (str3 != null)
{
if (SessionStateUtilities.MatchesAnyWildcardPattern(child, patterns, true) && !SessionStateUtilities.MatchesAnyWildcardPattern(child, collection2, false))
{
bool flag2 = true;
if (dictionary != null)
{
bool flag3 = false;
flag2 = dictionary.TryGetValue(child, out flag3);
}
if (flag2)
{
this.GetItemPrivate(providerInstance, str3, context);
}
}
if (this.IsItemContainer(providerInstance, str3, context) && recurse)
{
if (context.Stopping)
{
return;
}
this.DoManualGetChildItems(providerInstance, str3, recurse, context, true);
}
}
}
}
}
else
{
string text = path;
text = this.GetChildName(providerInstance, path, context, true);
if (SessionStateUtilities.MatchesAnyWildcardPattern(text, patterns, true) && !SessionStateUtilities.MatchesAnyWildcardPattern(text, collection2, false))
{
this.GetItemPrivate(providerInstance, path, context);
}
}
}
示例2: ProcessPathItems
//.........这里部分代码省略.........
Collection<WildcardPattern> excludeMatcher =
SessionStateUtilities.CreateWildcardsFromStrings(
context.Exclude,
WildcardOptions.IgnoreCase);
// If the item is a container we have to filter its children
// Use a hint + lazy evaluation to skip a container check
if (skipIsItemContainerCheck || IsItemContainer(providerInstance, path, context))
{
CmdletProviderContext newContext =
new CmdletProviderContext(context);
Collection<PSObject> childNameObjects = null;
System.Collections.Generic.Dictionary<string, bool> filteredChildNameDictionary = null;
try
{
// Get all the child names
GetChildNames(
providerInstance,
path,
(recurse) ? ReturnContainers.ReturnAllContainers : ReturnContainers.ReturnMatchingContainers,
newContext);
newContext.WriteErrorsToContext(context);
childNameObjects = newContext.GetAccumulatedObjects();
// The code above initially retrieves all of the containers so that it doesn't limit the recursion,
// but then emits the non-matching container further down. The public API doesn't support a way to
// differentiate the two, so we need to do a diff.
// So if there was a filter, do it again to get the fully filtered items.
if (recurse && (providerInstance.IsFilterSet()))
{
newContext.RemoveStopReferral();
newContext = new CmdletProviderContext(context);
filteredChildNameDictionary = new System.Collections.Generic.Dictionary<string, bool>();
GetChildNames(
providerInstance,
path,
ReturnContainers.ReturnMatchingContainers,
newContext);
var filteredChildNameObjects = newContext.GetAccumulatedObjects();
foreach (PSObject filteredChildName in filteredChildNameObjects)
{
string filteredName = filteredChildName.BaseObject as string;
if (filteredName != null)
{
filteredChildNameDictionary[filteredName] = true;
}
}
}
}
finally
{
newContext.RemoveStopReferral();
}
// Now loop through all the child objects matching the filters and recursing
// into containers
for (int index = 0; index < childNameObjects.Count; ++index)
{
// Making sure to obey the StopProcessing.