本文整理汇总了C#中System.Management.Automation.CmdletProviderContext.ThrowFirstErrorOrDoNothing方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProviderContext.ThrowFirstErrorOrDoNothing方法的具体用法?C# CmdletProviderContext.ThrowFirstErrorOrDoNothing怎么用?C# CmdletProviderContext.ThrowFirstErrorOrDoNothing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Management.Automation.CmdletProviderContext
的用法示例。
在下文中一共展示了CmdletProviderContext.ThrowFirstErrorOrDoNothing方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetParentPath
/// <summary>
/// Gets the path to the parent object for the given object
/// </summary>
///
/// <param name="path">
/// The path to the object to get the parent path from
/// </param>
///
/// <param name="root">
/// The root of the drive.
/// </param>
///
/// <returns>
/// The path to the parent object
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the <paramref name="providerInstance"/> does not support this operation.
/// </exception>
///
/// <exception cref="PipelineStoppedException">
/// If the pipeline is being stopped while executing the command.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </exception>
///
internal string GetParentPath(string path, string root)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
string result = GetParentPath(path, root, context);
context.ThrowFirstErrorOrDoNothing();
return result;
} //GetParentPath
示例2: BeforeOpenStreams
/// <summary>
/// Called by the base class before the streams are open for the path.
/// This override clears the content from the item.
/// </summary>
///
/// <param name="paths">
/// The path to the items that will be opened for writing content.
/// </param>
///
internal override void BeforeOpenStreams(string[] paths)
{
if (paths == null ||
(paths != null && paths.Length == 0))
{
throw PSTraceSource.NewArgumentNullException("paths");
}
CmdletProviderContext context = new CmdletProviderContext(GetCurrentContext());
foreach (string path in paths)
{
try
{
InvokeProvider.Content.Clear(path, context);
context.ThrowFirstErrorOrDoNothing(true);
}
catch (PSNotSupportedException)
{
// If the provider doesn't support clear, that is fine. Continue
// on with the setting of the content.
continue;
}
catch (DriveNotFoundException driveNotFound)
{
WriteError(
new ErrorRecord(
driveNotFound.ErrorRecord,
driveNotFound));
continue;
}
catch (ProviderNotFoundException providerNotFound)
{
WriteError(
new ErrorRecord(
providerNotFound.ErrorRecord,
providerNotFound));
continue;
}
catch (ItemNotFoundException)
{
//If the item is not found then there is nothing to clear so ignore this exception.
continue;
}
}
} // BeforeOpenStreams
示例3: ItemExists
/// <summary>
/// Determines if the monad virtual namespace path exists.
/// </summary>
///
/// <param name="path">
/// The path to the object to determine if it exists.
/// </param>
///
/// <param name="force">
/// Passed on to providers to force operations.
/// </param>
///
/// <param name="literalPath">
/// If true, globbing is not done on paths.
/// </param>
///
/// <returns>
/// true if the object specified by path exists, false otherwise.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="ProviderNotFoundException">
/// If the <paramref name="path"/> refers to a provider that could not be found.
/// </exception>
///
/// <exception cref="DriveNotFoundException">
/// If the <paramref name="path"/> refers to a drive that could not be found.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the provider that the <paramref name="path"/> refers to does
/// not support this operation.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </exception>
///
internal bool ItemExists(string path, bool force, bool literalPath)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
context.Force = force;
context.SuppressWildcardExpansion = literalPath;
bool result = ItemExists(path, context);
context.ThrowFirstErrorOrDoNothing();
return result;
} // ItemExists
示例4: GetContentReader
/// <summary>
/// Gets the content reader for the specified item.
/// </summary>
///
/// <param name="paths">
/// The path(s) to the item(s) to get the content reader for.
/// </param>
///
/// <param name="force">
/// Passed on to providers to force operations.
/// </param>
///
/// <param name="literalPath">
/// If true, globbing is not done on paths.
/// </param>
///
/// <returns>
/// The content readers for all items that the path resolves to.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="ProviderNotFoundException">
/// If the <paramref name="path"/> refers to a provider that could not be found.
/// </exception>
///
/// <exception cref="DriveNotFoundException">
/// If the <paramref name="path"/> refers to a drive that could not be found.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the provider that the <paramref name="path"/> refers to does
/// not support this operation.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </exception>
///
internal Collection<IContentReader> GetContentReader(string[] paths, bool force, bool literalPath)
{
if (paths == null)
{
throw PSTraceSource.NewArgumentNullException("paths");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
context.Force = force;
context.SuppressWildcardExpansion = literalPath;
Collection<IContentReader> results = GetContentReader(paths, context);
context.ThrowFirstErrorOrDoNothing();
return results;
} // GetContentReader
示例5: GetProperty
/// <summary>
/// Gets the specified properties from the specified item.
/// </summary>
///
/// <param name="paths">
/// The path(s) to the item(s) to get the properties from.
/// </param>
///
/// <param name="providerSpecificPickList">
/// A list of the properties that the provider should return.
/// </param>
///
/// <param name="literalPath">
/// If true, globbing is not done on paths.
/// </param>
///
/// <returns>
/// A property table container the properties and their values.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="ProviderNotFoundException">
/// If the <paramref name="path"/> refers to a provider that could not be found.
/// </exception>
///
/// <exception cref="DriveNotFoundException">
/// If the <paramref name="path"/> refers to a drive that could not be found.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the provider that the <paramref name="path"/> refers to does
/// not support this operation.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </exception>
///
internal Collection<PSObject> GetProperty(
string[] paths,
Collection<string> providerSpecificPickList,
bool literalPath)
{
if (paths == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
context.SuppressWildcardExpansion = literalPath;
GetProperty(paths, providerSpecificPickList, context);
context.ThrowFirstErrorOrDoNothing();
Collection<PSObject> results = context.GetAccumulatedObjects();
return results;
} // GetProperties
示例6: GetItem
/// <summary>
/// Gets the specified object
/// </summary>
///
/// <param name="paths">
/// The path(s) to the object(s). They can be either a relative (most common)
/// or absolute path.
/// </param>
///
/// <param name="force">
/// Passed on to providers to force operations.
/// </param>
///
/// <param name="literalPath">
/// If true, globbing is not done on paths.
/// </param>
///
/// <returns>
/// The item at the specified path.
/// </returns>
///
/// <exception cref="ArgumentNullException">
/// If <paramref name="path"/> is null.
/// </exception>
///
/// <exception cref="ProviderNotFoundException">
/// If the <paramref name="path"/> refers to a provider that could not be found.
/// </exception>
///
/// <exception cref="DriveNotFoundException">
/// If the <paramref name="path"/> refers to a drive that could not be found.
/// </exception>
///
/// <exception cref="NotSupportedException">
/// If the provider that the <paramref name="path"/> refers to does
/// not support this operation.
/// </exception>
///
/// <exception cref="ProviderInvocationException">
/// If the provider threw an exception.
/// </exception>
///
internal Collection<PSObject> GetItem(string[] paths, bool force, bool literalPath)
{
if (paths == null)
{
throw PSTraceSource.NewArgumentNullException("paths");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
context.Force = force;
context.SuppressWildcardExpansion = literalPath;
GetItem(paths, context);
context.ThrowFirstErrorOrDoNothing();
// Since there was not errors return the accumulated objects
Collection<PSObject> results = context.GetAccumulatedObjects();
return results;
} // GetItem
示例7: BeforeOpenStreams
internal override void BeforeOpenStreams(string[] paths)
{
if (paths == null || paths != null && (int)paths.Length == 0)
{
throw PSTraceSource.NewArgumentNullException("paths");
}
else
{
CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(base.GetCurrentContext());
string[] strArrays = paths;
for (int i = 0; i < (int)strArrays.Length; i++)
{
string str = strArrays[i];
try
{
base.InvokeProvider.Content.Clear(str, cmdletProviderContext);
cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
}
catch (PSNotSupportedException pSNotSupportedException)
{
}
catch (DriveNotFoundException driveNotFoundException1)
{
DriveNotFoundException driveNotFoundException = driveNotFoundException1;
base.WriteError(new ErrorRecord(driveNotFoundException.ErrorRecord, driveNotFoundException));
}
catch (ProviderNotFoundException providerNotFoundException1)
{
ProviderNotFoundException providerNotFoundException = providerNotFoundException1;
base.WriteError(new ErrorRecord(providerNotFoundException.ErrorRecord, providerNotFoundException));
}
catch (ItemNotFoundException itemNotFoundException)
{
}
}
return;
}
}
示例8: CopyProperty
internal Collection<PSObject> CopyProperty(string[] sourcePaths, string sourceProperty, string destinationPath, string destinationProperty, bool force, bool literalPath)
{
if (sourcePaths == null)
{
throw PSTraceSource.NewArgumentNullException("sourcePaths");
}
if (sourceProperty == null)
{
throw PSTraceSource.NewArgumentNullException("sourceProperty");
}
if (destinationPath == null)
{
throw PSTraceSource.NewArgumentNullException("destinationPath");
}
if (destinationProperty == null)
{
throw PSTraceSource.NewArgumentNullException("destinationProperty");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
Force = force,
SuppressWildcardExpansion = literalPath
};
this.CopyProperty(sourcePaths, sourceProperty, destinationPath, destinationProperty, context);
context.ThrowFirstErrorOrDoNothing();
return context.GetAccumulatedObjects();
}
示例9: SetLocation
//.........这里部分代码省略.........
catch (LoopFlowException)
{
throw;
}
catch (PipelineStoppedException)
{
throw;
}
catch (ActionPreferenceStopException)
{
throw;
}
catch (Exception e) // Catch-all OK, 3rd party callout
{
CommandProcessorBase.CheckForSevereException(e);
// Reset the drive to the previous drive and
// then rethrow the error
CurrentDrive = previousWorkingDrive;
throw;
}
}
// Now see if there was errors while normalizing the path
if (normalizePathContext.HasErrors())
{
// Set the current working drive back to the previous
// one in case it was changed.
CurrentDrive = previousWorkingDrive;
normalizePathContext.ThrowFirstErrorOrDoNothing();
}
}
finally
{
normalizePathContext.RemoveStopReferral();
}
// Check to see if the path is a container
bool isContainer = false;
CmdletProviderContext itemContainerContext =
new CmdletProviderContext(context);
itemContainerContext.SuppressWildcardExpansion = true;
try
{
isContainer =
IsItemContainer(
resolvedPath.Path,
itemContainerContext);
if (itemContainerContext.HasErrors())
{
// Set the current working drive back to the previous
// one in case it was changed.
CurrentDrive = previousWorkingDrive;
itemContainerContext.ThrowFirstErrorOrDoNothing();
}
}
示例10: NormalizeRelativePath
internal string NormalizeRelativePath(string path, string basePath)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
string str = this.NormalizeRelativePath(path, basePath, context);
context.ThrowFirstErrorOrDoNothing();
tracer.WriteLine("result = {0}", new object[] { str });
return str;
}
示例11: CopyItem
internal Collection<PSObject> CopyItem(string[] paths, string copyPath, bool recurse, CopyContainers copyContainers, bool force, bool literalPath)
{
if (paths == null)
{
throw PSTraceSource.NewArgumentNullException("paths");
}
if (copyPath == null)
{
copyPath = string.Empty;
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
Force = force,
SuppressWildcardExpansion = literalPath
};
this.CopyItem(paths, copyPath, recurse, copyContainers, context);
context.ThrowFirstErrorOrDoNothing();
return context.GetAccumulatedObjects();
}
示例12: NewDrive
internal PSDriveInfo NewDrive(PSDriveInfo drive, string scopeID)
{
if (drive == null)
{
throw PSTraceSource.NewArgumentNullException("drive");
}
PSDriveInfo baseObject = null;
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
this.NewDrive(drive, scopeID, context);
context.ThrowFirstErrorOrDoNothing();
Collection<PSObject> accumulatedObjects = context.GetAccumulatedObjects();
if (((accumulatedObjects != null) && (accumulatedObjects.Count > 0)) && !accumulatedObjects[0].immediateBaseObjectIsEmpty)
{
baseObject = (PSDriveInfo) accumulatedObjects[0].BaseObject;
}
return baseObject;
}
示例13: GetUnresolvedProviderPathFromPSPath
public string GetUnresolvedProviderPathFromPSPath(string path, out ProviderInfo provider, out PSDriveInfo drive)
{
CmdletProviderContext context = new CmdletProviderContext(this.sessionState.ExecutionContext);
string str = this.PathResolver.GetProviderPath(path, context, out provider, out drive);
context.ThrowFirstErrorOrDoNothing();
return str;
}
示例14: RenameItem
internal Collection<PSObject> RenameItem(string path, string newName, bool force)
{
if (path == null)
{
throw PSTraceSource.NewArgumentNullException("path");
}
CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext) {
Force = force
};
this.RenameItem(path, newName, context);
context.ThrowFirstErrorOrDoNothing();
return context.GetAccumulatedObjects();
}
示例15: NewProvider
//.........这里部分代码省略.........
// Set the new provider info in the instance in case the provider
// derived a new one
providerInstance.SetProviderInformation(newProviderInfo);
}
catch (LoopFlowException)
{
throw;
}
catch (PipelineStoppedException)
{
throw;
}
catch (ActionPreferenceStopException)
{
throw;
}
catch (InvalidOperationException)
{
throw;
}
catch (Exception e) // Catch-call OK, 3rd party callout
{
CommandProcessorBase.CheckForSevereException(e);
throw
NewProviderInvocationException(
"ProviderStartException",
SessionStateStrings.ProviderStartException,
provider,
null,
e);
}
context.ThrowFirstErrorOrDoNothing(true);
if (newProviderInfo == null)
{
throw
PSTraceSource.NewInvalidOperationException(
SessionStateStrings.InvalidProviderInfoNull);
}
if (newProviderInfo != provider)
{
// Since the references are not the same, ensure that the provider
// name is the same.
if (!string.Equals(newProviderInfo.Name, provider.Name, StringComparison.OrdinalIgnoreCase))
{
throw
PSTraceSource.NewInvalidOperationException(
SessionStateStrings.InvalidProviderInfo);
}
// Use the new provider info instead
provider = newProviderInfo;
}
// Add the newly create provider to the providers container
try
{
NewProviderEntry(provider);
}
catch (ArgumentException)
{