本文整理汇总了C#中Pash.Implementation.ProviderRuntime类的典型用法代码示例。如果您正苦于以下问题:C# ProviderRuntime类的具体用法?C# ProviderRuntime怎么用?C# ProviderRuntime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ProviderRuntime类属于Pash.Implementation命名空间,在下文中一共展示了ProviderRuntime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetResolvedPSPathFromPSPath
public Collection<PathInfo> GetResolvedPSPathFromPSPath(string path)
{
var runtime = new ProviderRuntime(_sessionState);
var res = GetResolvedPSPathFromPSPath(new [] { path }, runtime);
runtime.ThrowFirstErrorOrContinue();
return res;
}
示例2: Copy
public Collection<PSObject> Copy(string[] path, string destinationPath, bool recurse, CopyContainers copyContainers,
bool force, bool literalPath)
{
var runtime = new ProviderRuntime(SessionState, force, literalPath);
Copy(path, destinationPath, recurse, copyContainers, runtime);
return runtime.ThrowFirstErrorOrReturnResults();
}
示例3: HasChild
public bool HasChild(string path, bool force, bool literalPath)
{
var runtime = new ProviderRuntime(SessionState, force, literalPath);
var res = HasChild(path, runtime);
runtime.ThrowFirstErrorOrContinue();
return res;
}
示例4: Exists
public bool Exists(string path, bool force, bool literalPath)
{
var runtime = new ProviderRuntime(SessionState, force, literalPath);
bool result = Exists(path, runtime);
runtime.ThrowFirstErrorOrContinue();
return result;
}
示例5: GetNames
public Collection<string> GetNames(string[] path, ReturnContainers returnContainers, bool recurse, bool force,
bool literalPath)
{
var runtime = new ProviderRuntime(SessionState, force, literalPath);
GetNames(path, returnContainers, recurse, runtime);
var packedResults = runtime.ThrowFirstErrorOrReturnResults();
var results = (from r in packedResults select r.ToString()).ToList();
return new Collection<string>(results);
}
示例6: Get
// actual work with callid the providers
internal void Get(string[] paths, bool recurse, ProviderRuntime runtime)
{
// the include/exclude filters apply to the results, not to the globbing process. Make this sure
runtime.IgnoreFiltersForGlobbing = true;
// globbing is here a little more complicated, so we do it "manually" (without GlobAndInvoke)
foreach (var curPath in paths)
{
var path = curPath;
// if the path won't be globbed or filtered, we will directly list it's child
var listChildsWithoutRecursion = !Globber.ShouldGlob(path, runtime) && !runtime.HasFilters();
// the Path might be a mixture of a path and an include filter
bool clearIncludeFilter;
path = SplitFilterFromPath(path, recurse, runtime, out clearIncludeFilter);
// now perform the actual globbing
CmdletProvider provider;
var globbed = Globber.GetGlobbedProviderPaths(path, runtime, out provider);
var containerProvider = CmdletProvider.As<ContainerCmdletProvider>(provider);
var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, false);
foreach (var globPath in globbed)
{
try
{
// if we need to actively filter that stuff, we have to handle the recursion manually
if (!filter.CanBeIgnored)
{
ManuallyGetChildItems(containerProvider, globPath, recurse, filter, runtime);
return;
}
// otherwise just get the child items / the item directly
if (recurse || listChildsWithoutRecursion)
{
GetItemOrChildItems(containerProvider, globPath, recurse, runtime);
return;
}
// no recursion and globbing was performed: get the item, not the child items
containerProvider.GetItem(globPath, runtime);
}
catch (Exception e)
{
HandleCmdletProviderInvocationException(e);
}
}
// clean up the include filter of the runtime for the next item, if we split a filter from the path
if (clearIncludeFilter)
{
runtime.Include.Clear();
}
}
}
示例7: ProviderRuntime
public ProviderRuntime(ProviderRuntime runtime)
: this(runtime.SessionState, runtime.Force, runtime.AvoidGlobbing)
{
_cmdlet = runtime._cmdlet;
PassThru = runtime.PassThru;
PSDriveInfo = runtime.PSDriveInfo;
Include = new Collection<string>(runtime.Include);
Exclude = new Collection<string>(runtime.Exclude);
Filter = runtime.Filter;
AvoidGlobbing = runtime.AvoidGlobbing;
IgnoreFiltersForGlobbing = runtime.IgnoreFiltersForGlobbing;
Credential = new PSCredential(runtime.Credential);
DynamicParameters = runtime.DynamicParameters;
}
示例8: New
public Collection<PSObject> New(string[] paths, string name, string itemTypeName, object content, bool force)
{
// TODO: support globbing (e.g. * in filename)
Path normalizedPath;
var runtime = new ProviderRuntime(_cmdlet.ExecutionContext);
runtime.Force = force;
foreach (var path in paths)
{
var provider = GetContainerProviderByPath(path, name, out normalizedPath);
provider.NewItem(normalizedPath, itemTypeName, content, runtime);
}
runtime.ThrowFirstErrorOrContinue();
return runtime.RetreiveAllProviderData();
}
示例9: GetGlobbedProviderPaths
internal Collection<string> GetGlobbedProviderPaths(string path, ProviderRuntime runtime, bool itemMustExist,
out CmdletProvider provider)
{
var results = new Collection<string>();
ProviderInfo providerInfo;
// get internal path, resolve home path and set provider info and drive info (if resolved)
path = GetProviderSpecificPath(path, runtime, out providerInfo);
provider = _sessionState.Provider.GetInstance(providerInfo);
if (!ShouldGlob(path, runtime))
{
// Although even ItemCmdletProvider supports ItemExists, PS doesn't seem
// to throw errors when resolving paths with ItemProviders, only for ContainerProviders or higher
// this behavior can be seen in the tests
var containerProvider = provider as ContainerCmdletProvider;
if (itemMustExist && containerProvider != null && !containerProvider.ItemExists(path, runtime))
{
var msg = String.Format("An item with path {0} doesn't exist", path);
runtime.WriteError(new ItemNotFoundException(msg).ErrorRecord);
return results;
}
results.Add(path);
return results;
}
if (providerInfo.Capabilities.HasFlag(ProviderCapabilities.ExpandWildcards))
{
var filter = new IncludeExcludeFilter(runtime.Include, runtime.Exclude, runtime.IgnoreFiltersForGlobbing);
foreach (var expanded in CmdletProvider.As<ItemCmdletProvider>(provider).ExpandPath(path, runtime))
{
if (filter.Accepts(expanded))
{
results.Add(expanded);
}
}
}
else
{
results = BuiltInGlobbing(provider, path, runtime);
}
return results;
}
示例10: GetProviderSpecificPath
internal string GetProviderSpecificPath(string path, ProviderRuntime runtime, out ProviderInfo providerInfo)
{
// differentiate between drive-qualified, provider-qualified, provider-internal, and provider-direct paths
// then strip provider prefix, set provider, set drive is possible or get from Drive.Current
PSDriveInfo drive;
string resolvedPath = null;
if (IsProviderQualifiedPath(path))
{
resolvedPath = GetProviderPathFromProviderQualifiedPath(path, out providerInfo);
// in case there is no CurrentDrive, set a dummy drive to keep track of the used provider
drive = providerInfo.CurrentDrive ?? providerInfo.DummyDrive;
}
else if (IsDriveQualifiedPath(path))
{
resolvedPath = GetProviderPathFromDriveQualifiedPath(path, runtime, out providerInfo, out drive);
}
// otherwise we first need to know about the provider/drive in use to properly resolve the path
else if (runtime.PSDriveInfo != null)
{
drive = runtime.PSDriveInfo;
providerInfo = drive.Provider;
}
else
{
drive = _sessionState.Path.CurrentLocation.Drive;
providerInfo = _sessionState.Path.CurrentLocation.Provider;
}
// TODO: check for provider internal path beginning with \\ or //
// make sure to set the drive to a dummy drive then
runtime.PSDriveInfo = drive;
// if we had no success, yet, we deal with some kind of provider specific (maybe relative) path
if (resolvedPath == null)
{
resolvedPath = ResolveHomePath(path, runtime, providerInfo);
resolvedPath = ResolveRelativePath(resolvedPath, runtime, providerInfo);
}
return resolvedPath;
}
示例11: Add
internal CmdletProvider Add(ProviderInfo providerInfo, ExecutionContext executionContext)
{
CmdletProvider provider = providerInfo.CreateInstance();
var runtime = new ProviderRuntime(executionContext.SessionState);
providerInfo = provider.Start(providerInfo, runtime);
provider.SetProviderInfo(providerInfo);
// Cache the Provider's Info and instance
if (!_providers.ContainsKey(providerInfo.Name))
{
_providers.Add(providerInfo.Name, new List<ProviderInfo>());
}
_providers[providerInfo.Name].Add(providerInfo);
_providerInstances[providerInfo] = provider;
// provider is added, default drives can be added
AddDefaultDrives(provider, runtime);
return provider;
}
示例12: SetPathTypes
void SetPathTypes(string path, SessionState sessionState)
{
ProviderInfo pinfo;
// use the globber to parse the path and set the different types
var runtime = new ProviderRuntime(sessionState);
runtime.PSDriveInfo = Drive;
var globber = new PathGlobber(sessionState);
_path = globber.GetProviderSpecificPath(path, runtime, out pinfo);
// update the Provider and Drive in case it changed
Provider = pinfo;
Drive = runtime.PSDriveInfo;
_providerQualified = globber.GetProviderQualifiedPath(_path, Provider);
Path = _providerQualified;
if (Drive != null && !String.IsNullOrEmpty(Drive.Name))
{
_driveQualified = globber.GetDriveQualifiedPath(_path, Drive);
Path = _driveQualified;
}
}
示例13: ItemExists
private bool ItemExists(CmdletProvider provider, string path, ProviderRuntime providerRuntime)
{
ItemCmdletProvider itemProvider = provider as ItemCmdletProvider;
if (itemProvider == null)
return false;
return itemProvider.ItemExists(path, providerRuntime);
}
示例14: SetLocation
internal PathInfo SetLocation(string path, ProviderRuntime providerRuntime)
{
// TODO: deal with paths starting with ".\"
if (path == null)
{
throw new NullReferenceException("Path can't be null");
}
path = PathIntrinsics.NormalizePath(path);
ProviderInfo provider = null;
string driveName = null;
string str = path;
PSDriveInfo currentDrive = CurrentDrive;
// If path doesn't start with a drive name
if (path.StartsWith(PathIntrinsics.CorrectSlash.ToString()))
{
provider = CurrentLocation.Provider;
}
else if (PathIntrinsics.IsAbsolutePath(path, out driveName))
{
_currentDrive = GetDrive(driveName, null);
path = PathIntrinsics.NormalizePath(PathIntrinsics.RemoveDriveName(path));
}
_currentDrive.CurrentLocation = path;
_providersCurrentDrive[CurrentDrive.Provider] = CurrentDrive;
SetVariable("PWD", CurrentLocation);
return CurrentLocation;
}
示例15: IsItemContainer
private bool IsItemContainer(CmdletProvider provider, string path, ProviderRuntime providerRuntime)
{
NavigationCmdletProvider navigationProvider = provider as NavigationCmdletProvider;
if (navigationProvider == null)
return false;
return navigationProvider.IsItemContainer(path, providerRuntime);
}