本文整理汇总了C#中System.Management.Automation.CmdletProviderContext.WriteObject方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProviderContext.WriteObject方法的具体用法?C# CmdletProviderContext.WriteObject怎么用?C# CmdletProviderContext.WriteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.CmdletProviderContext
的用法示例。
在下文中一共展示了CmdletProviderContext.WriteObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NewDrive
internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext context)
{
if (drive == null)
{
throw PSTraceSource.NewArgumentNullException("drive");
}
if (context == null)
{
throw PSTraceSource.NewArgumentNullException("context");
}
if (!IsValidDriveName(drive.Name))
{
throw PSTraceSource.NewArgumentException("drive.Name", "SessionStateStrings", "DriveNameIllegalCharacters", new object[0]);
}
PSDriveInfo newDrive = this.ValidateDriveWithProvider(drive, context, true);
if (newDrive != null)
{
if (string.Compare(newDrive.Name, drive.Name, true, Thread.CurrentThread.CurrentCulture) != 0)
{
throw this.NewProviderInvocationException("NewDriveProviderFailed", SessionStateStrings.NewDriveProviderFailed, drive.Provider, drive.Root, PSTraceSource.NewArgumentException("root"));
}
try
{
SessionStateScope currentScope = this.currentScope;
if (!string.IsNullOrEmpty(scopeID))
{
currentScope = this.GetScopeByID(scopeID);
}
currentScope.NewDrive(newDrive);
}
catch (ArgumentException exception2)
{
context.WriteError(new ErrorRecord(exception2, "NewDriveError", ErrorCategory.InvalidArgument, newDrive));
return;
}
catch (SessionStateException)
{
throw;
}
if (this.ProvidersCurrentWorkingDrive[drive.Provider] == null)
{
this.ProvidersCurrentWorkingDrive[drive.Provider] = drive;
}
context.WriteObject(newDrive);
}
}
示例2: GetChildNames
internal void GetChildNames(string path, ReturnContainers returnContainers, bool recurse, CmdletProviderContext context)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
Collection<WildcardPattern> includeMatcher = SessionStateUtilities.CreateWildcardsFromStrings(context.Include, WildcardOptions.IgnoreCase);
Collection<WildcardPattern> excludeMatcher = SessionStateUtilities.CreateWildcardsFromStrings(context.Exclude, WildcardOptions.IgnoreCase);
if (LocationGlobber.ShouldPerformGlobbing(path, context))
{
ProviderInfo info = null;
CmdletProvider providerInstance = null;
CmdletProviderContext context2 = new CmdletProviderContext(context);
context2.SetFilters(new Collection<string>(), new Collection<string>(), null);
Collection<string> collection3 = this.Globber.GetGlobbedProviderPathsFromMonadPath(path, false, context2, out info, out providerInstance);
if (context2.Drive != null)
{
context.Drive = context2.Drive;
}
bool flag = LocationGlobber.StringContainsGlobCharacters(path);
foreach (string str in collection3)
{
if (context.Stopping)
{
break;
}
if ((!flag || recurse) && this.IsItemContainer(providerInstance, str, context))
{
this.DoGetChildNamesManually(providerInstance, str, string.Empty, returnContainers, includeMatcher, excludeMatcher, context, recurse);
}
else if (providerInstance is NavigationCmdletProvider)
{
string text = this.GetChildName(providerInstance, str, context, false);
bool flag2 = SessionStateUtilities.MatchesAnyWildcardPattern(text, includeMatcher, true);
bool flag3 = SessionStateUtilities.MatchesAnyWildcardPattern(text, excludeMatcher, false);
if (flag2 && !flag3)
{
context.WriteObject(text);
}
}
else
{
context.WriteObject(str);
}
}
}
else
{
ProviderInfo provider = null;
PSDriveInfo drive = null;
string str3 = this.Globber.GetProviderPath(path, context, out provider, out drive);
ContainerCmdletProvider containerProviderInstance = this.GetContainerProviderInstance(provider);
if (drive != null)
{
context.Drive = drive;
}
if (!containerProviderInstance.ItemExists(str3, context))
{
ItemNotFoundException exception = new ItemNotFoundException(str3, "PathNotFound", SessionStateStrings.PathNotFound);
throw exception;
}
if (recurse)
{
this.DoGetChildNamesManually(containerProviderInstance, str3, string.Empty, returnContainers, includeMatcher, excludeMatcher, context, recurse);
}
else
{
this.GetChildNames(containerProviderInstance, str3, returnContainers, context);
}
}
}
示例3: DoGetChildNamesManually
private void DoGetChildNamesManually(CmdletProvider providerInstance, string providerPath, string relativePath, ReturnContainers returnContainers, Collection<WildcardPattern> includeMatcher, Collection<WildcardPattern> excludeMatcher, CmdletProviderContext context, bool recurse)
{
string path = this.MakePath(providerInstance, providerPath, relativePath, context);
CmdletProviderContext context2 = new CmdletProviderContext(context);
try
{
this.GetChildNames(providerInstance, path, ReturnContainers.ReturnMatchingContainers, context2);
foreach (PSObject obj2 in context2.GetAccumulatedObjects())
{
if (context.Stopping)
{
return;
}
string baseObject = obj2.BaseObject as string;
if (((baseObject != null) && SessionStateUtilities.MatchesAnyWildcardPattern(baseObject, includeMatcher, true)) && !SessionStateUtilities.MatchesAnyWildcardPattern(baseObject, excludeMatcher, false))
{
string str3 = this.MakePath(providerInstance, relativePath, baseObject, context);
context.WriteObject(str3);
}
}
if (recurse)
{
this.GetChildNames(providerInstance, path, ReturnContainers.ReturnAllContainers, context2);
foreach (PSObject obj3 in context2.GetAccumulatedObjects())
{
if (context.Stopping)
{
return;
}
string child = obj3.BaseObject as string;
if (child != null)
{
string str5 = this.MakePath(providerInstance, relativePath, child, context);
string str6 = this.MakePath(providerInstance, providerPath, str5, context);
if (this.IsItemContainer(providerInstance, str6, context))
{
this.DoGetChildNamesManually(providerInstance, providerPath, str5, returnContainers, includeMatcher, excludeMatcher, context, true);
}
}
}
}
}
finally
{
context2.RemoveStopReferral();
}
}
示例4: NewDrive
//.........这里部分代码省略.........
/// If the provider threw an exception or returned null.
/// </exception>
///
/// <exception cref="SessionStateOverflowException">
/// If creating the drive will overflow the MaximumDriveCount limit.
/// </exception>
///
internal void NewDrive(PSDriveInfo drive, string scopeID, CmdletProviderContext context)
{
if (drive == null)
{
throw PSTraceSource.NewArgumentNullException("drive");
}
if (context == null)
{
throw PSTraceSource.NewArgumentNullException("context");
}
if (!IsValidDriveName(drive.Name))
{
ArgumentException e =
PSTraceSource.NewArgumentException(
"drive.Name",
SessionStateStrings.DriveNameIllegalCharacters);
throw e;
}
// Allow the provider a chance to approve the drive and set
// provider specific data
PSDriveInfo result = ValidateDriveWithProvider(drive, context, true);
// We assume that the provider wrote the error message as they
// are suppose to.
if (result == null)
{
return;
}
if (String.Compare(result.Name, drive.Name, StringComparison.CurrentCultureIgnoreCase) == 0)
{
// Set the drive in the current scope.
try
{
SessionStateScope scope = _currentScope;
if (!String.IsNullOrEmpty(scopeID))
{
scope = GetScopeByID(scopeID);
}
scope.NewDrive(result);
}
catch (ArgumentException argumentException)
{
// Wrap up the exception and write it to the error stream
context.WriteError(
new ErrorRecord(
argumentException,
"NewDriveError",
ErrorCategory.InvalidArgument,
result));
return;
}
catch (SessionStateException)
{
// This should be a pipeline terminating condition
throw;
}
if (ProvidersCurrentWorkingDrive[drive.Provider] == null)
{
// Set the new drive as the current
// drive for the provider since there isn't one set.
ProvidersCurrentWorkingDrive[drive.Provider] = drive;
}
// Upon success, write the drive to the pipeline
context.WriteObject(result);
}
else
{
ProviderInvocationException e =
NewProviderInvocationException(
"NewDriveProviderFailed",
SessionStateStrings.NewDriveProviderFailed,
drive.Provider,
drive.Root,
PSTraceSource.NewArgumentException("root"));
throw e;
}
} // NewDrive
示例5: DoGetChildNamesManually
//.........这里部分代码省略.........
Collection<PSObject> results = childNamesContext.GetAccumulatedObjects();
foreach (PSObject result in results)
{
// Making sure to obey the StopProcessing.
if (context.Stopping)
{
return;
}
string name = result.BaseObject as string;
if (name == null)
{
continue;
}
bool isIncludeMatch =
SessionStateUtilities.MatchesAnyWildcardPattern(
name,
includeMatcher,
true);
if (isIncludeMatch)
{
if (!SessionStateUtilities.MatchesAnyWildcardPattern(
name,
excludeMatcher,
false))
{
string resultPath = MakePath(providerInstance, relativePath, name, context);
context.WriteObject(resultPath);
}
}
}
if (recurse)
{
// Now get all the children that are containers and recurse into them
// Limiter for recursion
if (depth > 0) // this includes special case 'depth == uint.MaxValue' for unlimited recursion
{
GetChildNames(
providerInstance,
newProviderPath,
ReturnContainers.ReturnAllContainers,
childNamesContext);
results = childNamesContext.GetAccumulatedObjects();
foreach (PSObject result in results)
{
// Making sure to obey the StopProcessing.
if (context.Stopping)
{
return;
}
string name = result.BaseObject as string;
if (name == null)
{
continue;
示例6: GetChildNames
//.........这里部分代码省略.........
context,
recurse,
depth);
}
else
{
// Since the original path did not contain glob characters,
// if the provider is a NavigationCmdletProvider, write
// out the child name, else write out the name as it
// was resolved.
if (providerInstance is NavigationCmdletProvider)
{
string childName =
GetChildName(
providerInstance,
providerPath,
context, false);
bool isIncludeMatch =
SessionStateUtilities.MatchesAnyWildcardPattern(
childName,
includeMatcher,
true);
bool isExcludeMatch =
SessionStateUtilities.MatchesAnyWildcardPattern(
childName,
excludeMatcher,
false);
if (isIncludeMatch && !isExcludeMatch)
{
context.WriteObject(childName);
}
}
else
{
context.WriteObject(providerPath);
}
}
}
}
else
{
// Figure out which provider to use
ProviderInfo provider = null;
PSDriveInfo drive = null;
string providerPath =
Globber.GetProviderPath(
path,
context,
out provider,
out drive);
ContainerCmdletProvider providerInstance = GetContainerProviderInstance(provider);
if (drive != null)
{
context.Drive = drive;
}
if (!providerInstance.ItemExists(providerPath, context))
{