当前位置: 首页>>代码示例>>C#>>正文


C# CmdletProviderContext.RemoveStopReferral方法代码示例

本文整理汇总了C#中System.Management.Automation.CmdletProviderContext.RemoveStopReferral方法的典型用法代码示例。如果您正苦于以下问题:C# CmdletProviderContext.RemoveStopReferral方法的具体用法?C# CmdletProviderContext.RemoveStopReferral怎么用?C# CmdletProviderContext.RemoveStopReferral使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Management.Automation.CmdletProviderContext的用法示例。


在下文中一共展示了CmdletProviderContext.RemoveStopReferral方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
 }
开发者ID:nickchal,项目名称:pash,代码行数:80,代码来源:LocationGlobber.cs

示例2: IsCurrentLocationOrAncestor


//.........这里部分代码省略.........
            // working drive

            if (drive == CurrentDrive)
            {
                // The path needs to be normalized to get rid of relative path tokens
                // so they don't interfere with our path comparisons below

                CmdletProviderContext normalizePathContext
                    = new CmdletProviderContext(context);

                try
                {
                    providerSpecificPath = NormalizeRelativePath(path, null, normalizePathContext);
                }
                catch (NotSupportedException)
                {
                    // Since the provider does not support normalizing the path, just
                    // use the path we currently have.
                }
                catch (LoopFlowException)
                {
                    throw;
                }
                catch (PipelineStoppedException)
                {
                    throw;
                }
                catch (ActionPreferenceStopException)
                {
                    throw;
                }
                finally
                {
                    normalizePathContext.RemoveStopReferral();
                }

                if (normalizePathContext.HasErrors())
                {
                    normalizePathContext.ThrowFirstErrorOrDoNothing();
                }

                s_tracer.WriteLine("Provider path = {0}", providerSpecificPath);

                // Get the current working directory provider specific path

                PSDriveInfo currentWorkingDrive = null;
                ProviderInfo currentDriveProvider = null;

                string currentWorkingPath =
                    Globber.GetProviderPath(
                        ".",
                        context,
                        out currentDriveProvider,
                        out currentWorkingDrive);

                Dbg.Diagnostics.Assert(
                    currentWorkingDrive == CurrentDrive,
                    "The current working drive should be the CurrentDrive.");

                s_tracer.WriteLine(
                    "Current working path = {0}",
                    currentWorkingPath);

                // See if the path is the current working directory or a parent
                // of the current working directory
开发者ID:40a,项目名称:PowerShell,代码行数:66,代码来源:SessionStateLocationAPIs.cs

示例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
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:LocationGlobber.cs

示例4: SetLocation


//.........这里部分代码省略.........
                        }
                    }
                    try
                    {
                    	str4 = this.NormalizeRelativePath(info4.Path, this.CurrentDrive.Root, context2);
                    }
                    catch (NotSupportedException)
                    {
                    }
                    catch (LoopFlowException)
                    {
                        throw;
                    }
                    catch (PipelineStoppedException)
                    {
                        throw;
                    }
                    catch (ActionPreferenceStopException)
                    {
                        throw;
                    }
                    catch (Exception exception3)
                    {
                        CommandProcessorBase.CheckForSevereException(exception3);
                        this.CurrentDrive = currentDrive;
                        throw;
                    }
                Label_01DF:
                    if (context2.HasErrors())
                    {
                        this.CurrentDrive = currentDrive;
                        context2.ThrowFirstErrorOrDoNothing();
                    }
                }
                finally
                {
                    context2.RemoveStopReferral();
                }
                bool flag5 = false;
                CmdletProviderContext context3 = new CmdletProviderContext(context) {
                    SuppressWildcardExpansion = true
                };
                try
                {
                    flag5 = this.IsItemContainer(info4.Path, context3);
                    if (context3.HasErrors())
                    {
                        this.CurrentDrive = currentDrive;
                        context3.ThrowFirstErrorOrDoNothing();
                    }
                }
                catch (NotSupportedException)
                {
                    if (str4.Length == 0)
                    {
                        flag5 = true;
                    }
                }
                finally
                {
                    context3.RemoveStopReferral();
                }
                if (flag5)
                {
                    if (flag)
                    {
                        this.CurrentDrive = currentDrive;
                        throw PSTraceSource.NewArgumentException("path", "SessionStateStrings", "PathResolvedToMultiple", new object[] { str });
                    }
                    path = str4;
                    flag2 = true;
                    flag3 = flag4;
                    flag = true;
                }
            }
            if (flag2)
            {
				if (!OSHelper.IsUnix)
				{
	                if (!LocationGlobber.IsProviderDirectPath(path))
	                {
	                    char ch = '\\';
	                    if (path.StartsWith(ch.ToString(), StringComparison.CurrentCulture) && !flag3)
	                    {
	                        path = path.Substring(1);
	                    }
	                }
				}
				tracer.WriteLine("New working path = {0}", new object[] { path });
				this.CurrentDrive.CurrentLocation = path;
            }
            else
            {
                this.CurrentDrive = currentDrive;
                throw new ItemNotFoundException(str, "PathNotFound", SessionStateStrings.PathNotFound);
            }
            this.ProvidersCurrentWorkingDrive[this.CurrentDrive.Provider] = this.CurrentDrive;
            this.SetVariable(SpecialVariables.PWDVarPath, this.CurrentLocation, false, true, CommandOrigin.Internal);
            return this.CurrentLocation;
        }
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:SessionStateInternal.cs

示例5: SetLocation


//.........这里部分代码省略.........
                        {
                            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();
                    }
                }
                catch (NotSupportedException)
                {
                    if (currentPath.Length == 0)
                    {
                        // Treat this as a container because providers that only 
开发者ID:40a,项目名称:PowerShell,代码行数:67,代码来源:SessionStateLocationAPIs.cs

示例6: IsCurrentLocationOrAncestor

 internal bool IsCurrentLocationOrAncestor(string path, CmdletProviderContext context)
 {
     bool flag = false;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     PSDriveInfo drive = null;
     ProviderInfo provider = null;
     string strA = this.Globber.GetProviderPath(path, context, out provider, out drive);
     if (drive != null)
     {
         tracer.WriteLine("Tracing drive", new object[0]);
         drive.Trace();
     }
     if (drive != null)
     {
         context.Drive = drive;
     }
     if (drive == this.CurrentDrive)
     {
         CmdletProviderContext context2 = new CmdletProviderContext(context);
         try
         {
             strA = this.NormalizeRelativePath(path, null, context2);
         }
         catch (NotSupportedException)
         {
         }
         catch (LoopFlowException)
         {
             throw;
         }
         catch (PipelineStoppedException)
         {
             throw;
         }
         catch (ActionPreferenceStopException)
         {
             throw;
         }
         finally
         {
             context2.RemoveStopReferral();
         }
         if (context2.HasErrors())
         {
             context2.ThrowFirstErrorOrDoNothing();
         }
         tracer.WriteLine("Provider path = {0}", new object[] { strA });
         PSDriveInfo info3 = null;
         ProviderInfo info4 = null;
         string strB = this.Globber.GetProviderPath(".", context, out info4, out info3);
         tracer.WriteLine("Current working path = {0}", new object[] { strB });
         tracer.WriteLine("Comparing {0} to {1}", new object[] { strA, strB });
         if (string.Compare(strA, strB, true, Thread.CurrentThread.CurrentCulture) == 0)
         {
             tracer.WriteLine("The path is the current working directory", new object[0]);
             flag = true;
         }
         else
         {
             string str3 = strB;
             while (str3.Length > 0)
             {
                 str3 = this.GetParentPath(drive.Provider, str3, string.Empty, context);
                 tracer.WriteLine("Comparing {0} to {1}", new object[] { str3, strA });
                 if (string.Compare(str3, strA, true, Thread.CurrentThread.CurrentCulture) == 0)
                 {
                     tracer.WriteLine("The path is a parent of the current working directory: {0}", new object[] { str3 });
                     flag = true;
                     break;
                 }
             }
         }
     }
     else
     {
         tracer.WriteLine("Drives are not the same", new object[0]);
     }
     tracer.WriteLine("result = {0}", new object[] { flag });
     return flag;
 }
开发者ID:nickchal,项目名称:pash,代码行数:83,代码来源:SessionStateInternal.cs

示例7: NormalizeRelativePath

 internal string NormalizeRelativePath(string path, string basePath, CmdletProviderContext context)
 {
     string str2;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context2 = new CmdletProviderContext(context);
     try
     {
         PSDriveInfo drive = null;
         ProviderInfo provider = null;
         string str = this.Globber.GetProviderPath(path, context2, out provider, out drive);
         if (context2.HasErrors())
         {
             context2.WriteErrorsToContext(context);
             return null;
         }
         if ((str == null) || (provider == null))
         {
             Exception exception = PSTraceSource.NewArgumentException("path");
             context.WriteError(new ErrorRecord(exception, "NormalizePathNullResult", ErrorCategory.InvalidArgument, path));
             return null;
         }
         if (drive != null)
         {
             context.Drive = drive;
             if (((this.GetProviderInstance(provider) is NavigationCmdletProvider) && !string.IsNullOrEmpty(drive.Root)) && path.StartsWith(drive.Root, StringComparison.OrdinalIgnoreCase))
             {
                 str = path;
             }
         }
         str2 = this.NormalizeRelativePath(provider, str, basePath, context);
     }
     finally
     {
         context2.RemoveStopReferral();
     }
     return str2;
 }
开发者ID:nickchal,项目名称:pash,代码行数:40,代码来源:SessionStateInternal.cs

示例8: 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);
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:82,代码来源:SessionStateInternal.cs

示例9: GetParentPath

 internal string GetParentPath(string path, string root, CmdletProviderContext context, bool useDefaultProvider)
 {
     string str4;
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     CmdletProviderContext context2 = new CmdletProviderContext(context);
     try
     {
         PSDriveInfo drive = null;
         ProviderInfo provider = null;
         try
         {
             this.Globber.GetProviderPath(path, context2, out provider, out drive);
         }
         catch (System.Management.Automation.DriveNotFoundException)
         {
             if (!useDefaultProvider)
             {
                 throw;
             }
             provider = this.PublicSessionState.Internal.GetSingleProvider("FileSystem");
         }
         if (context2.HasErrors())
         {
             context2.WriteErrorsToContext(context);
             return null;
         }
         if (drive != null)
         {
             context.Drive = drive;
         }
         bool isProviderQualified = false;
         bool isDriveQualified = false;
         string qualifier = null;
         string str2 = this.RemoveQualifier(path, out qualifier, out isProviderQualified, out isDriveQualified);
         string str3 = this.GetParentPath(provider, str2, root, context);
         if (!string.IsNullOrEmpty(qualifier) && !string.IsNullOrEmpty(str3))
         {
             str3 = this.AddQualifier(str3, qualifier, isProviderQualified, isDriveQualified);
         }
         tracer.WriteLine("result = {0}", new object[] { str3 });
         str4 = str3;
     }
     finally
     {
         context2.RemoveStopReferral();
     }
     return str4;
 }
开发者ID:nickchal,项目名称:pash,代码行数:51,代码来源:SessionStateInternal.cs

示例10: 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();
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:47,代码来源:SessionStateInternal.cs

示例11: NormalizeRelativePath


//.........这里部分代码省略.........
                    getProviderPathContext.WriteErrorsToContext(context);
                    return null;
                }

                if (workingPath == null ||
                    provider == null)
                {
                    // Since the provider didn't write an error, and we didn't get any
                    // results ourselves, we need to write out our own error.

                    Exception e = PSTraceSource.NewArgumentException("path");
                    context.WriteError(new ErrorRecord(e, "NormalizePathNullResult", ErrorCategory.InvalidArgument, path));
                    return null;
                }

                if (basePath != null)
                {
                    PSDriveInfo baseDrive = null;
                    ProviderInfo baseProvider = null;

                    Globber.GetProviderPath(
                         basePath,
                         getProviderPathContext,
                         out baseProvider,
                         out baseDrive);

                    if (drive != null && baseDrive != null)
                    {
                        if (!drive.Name.Equals(baseDrive.Name, StringComparison.OrdinalIgnoreCase))
                        {
                            // Make sure they are from physically different drives
                            // Doing StartsWith from both directions covers the following cases
                            // C:\ and C:\Temp
                            // C:\Temp and C:\
                            if (!(drive.Root.StartsWith(baseDrive.Root, StringComparison.OrdinalIgnoreCase) ||
                                (baseDrive.Root.StartsWith(drive.Root, StringComparison.OrdinalIgnoreCase))))
                            {
                                // In this case, no normalization is necessary
                                return path;
                            }
                        }
                    }
                }

                if (drive != null)
                {
                    context.Drive = drive;

                    // Detect if the original path was already a
                    // provider path. This happens when a drive doesn't
                    // have a rooted root -- such as HKEY_LOCAL_MACHINE instead of
                    // \\HKEY_LOCAL_MACHINE
                    if (
                        (GetProviderInstance(provider) is NavigationCmdletProvider) &&
                        (!String.IsNullOrEmpty(drive.Root)) &&
                        (path.StartsWith(drive.Root, StringComparison.OrdinalIgnoreCase)))
                    {
                        //
                        // If the drive root doesn't end with a path separator then there is a chance the
                        // path starts with the drive root name but doesn't actually refer to it.  For example,
                        // (see Win8 bug 922001) consider drive with root HKEY_LOCAL_MACHINE named 
                        // HKEY_LOCAL_MACHINE_foo.  The path would start with the drive root but is not a provider
                        // path.
                        //
                        // We will remediate this by only considering this a provider path if 
                        // 1.  The drive root ends with a path separator.
                        // OR
                        // 2.  The path starts with the drive root followed by a path separator
                        // OR
                        // 3.  The path exactly matches the drive root.
                        // 

                        // 1. Test for the drive root ending with a path separator.
                        bool driveRootEndsWithPathSeparator = IsPathSeparator(drive.Root[drive.Root.Length - 1]);


                        // 2. Test for the path starting with the drive root followed by a path separator
                        int indexAfterDriveRoot = drive.Root.Length;
                        bool pathStartsWithDriveRootAndPathSeparator = indexAfterDriveRoot < path.Length && IsPathSeparator(path[indexAfterDriveRoot]);


                        // 3. Test for the drive root exactly matching the path.
                        //    Since we know the path starts with the drive root then they are equal if the lengths are equal.
                        bool pathEqualsDriveRoot = drive.Root.Length == path.Length;


                        if (driveRootEndsWithPathSeparator || pathStartsWithDriveRootAndPathSeparator || pathEqualsDriveRoot)
                        {
                            workingPath = path;
                        }
                    }
                }

                return NormalizeRelativePath(provider, workingPath, basePath, context);
            }
            finally
            {
                getProviderPathContext.RemoveStopReferral();
            }
        } // NormalizeRelativePath
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:SessionStateNavigation.cs

示例12: GetParentPath

        /// <summary>
        /// Gets the path to the parent object for the given object.
        /// Allow to use FileSystem as the default provider when the
        /// given path is drive-qualified and the drive cannot be found.
        /// </summary>
        /// 
        /// <param name="path">
        /// The path to the object to get the parent path from
        /// </param>
        /// 
        /// <param name="root">
        /// The root of the drive. Namespace providers should
        /// return the root if GetParentPath is called for the root.
        /// </param>
        /// 
        /// <param name="context">
        /// The context which the core command is running.
        /// </param>
        /// 
        /// <param name="useDefaultProvider">
        /// Specify whether to use default provider when needed.
        /// </param>
        /// 
        /// <returns>
        /// The path to the parent object
        /// </returns>
        internal string GetParentPath(
            string path,
            string root,
            CmdletProviderContext context,
            bool useDefaultProvider)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }

            CmdletProviderContext getProviderPathContext =
                new CmdletProviderContext(context);

            try
            {
                PSDriveInfo drive = null;
                ProviderInfo provider = null;

                try
                {
                    Globber.GetProviderPath(
                        path,
                        getProviderPathContext,
                        out provider,
                        out drive);
                }
                catch (DriveNotFoundException)
                {
                    // the path is sure to be drive_qualified and it is absolute path, otherwise the
                    // drive would be set to the current drive and the DriveNotFoundException will not happen
                    if (useDefaultProvider)
                    {
                        // the default provider is FileSystem
                        provider = PublicSessionState.Internal.GetSingleProvider(Microsoft.PowerShell.Commands.FileSystemProvider.ProviderName);
                    }
                    else
                    {
                        throw;
                    }
                }

                if (getProviderPathContext.HasErrors())
                {
                    getProviderPathContext.WriteErrorsToContext(context);
                    return null;
                }

                if (drive != null)
                {
                    context.Drive = drive;
                }

                bool isProviderQualified = false;
                bool isDriveQualified = false;
                string qualifier = null;
                string pathNoQualifier = RemoveQualifier(path, provider, out qualifier, out isProviderQualified, out isDriveQualified);

                string result = GetParentPath(provider, pathNoQualifier, root, context);

                if (!String.IsNullOrEmpty(qualifier) && !String.IsNullOrEmpty(result))
                {
                    result = AddQualifier(result, provider, qualifier, isProviderQualified, isDriveQualified);
                }

                return result;
            }
            finally
            {
                getProviderPathContext.RemoveStopReferral();
            }
        } // GetParentPath
开发者ID:40a,项目名称:PowerShell,代码行数:98,代码来源:SessionStateNavigation.cs

示例13: DoGetChildNamesManually


//.........这里部分代码省略.........

                    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;
                            }

                            // Generate the relative path from the provider path

                            string resultRelativePath =
                                MakePath(
                                    providerInstance,
                                    relativePath,
                                    name,
                                    context);

                            // Generate the provider path for the child item to see
                            // if it is a container

                            string resultProviderPath =
                                    MakePath(
                                        providerInstance,
                                        providerPath,
                                        resultRelativePath,
                                        context);

                            // If the item is a container recurse into it and output its
                            // child names

                            if (IsItemContainer(providerInstance, resultProviderPath, context))
                            {
                                DoGetChildNamesManually(
                                    providerInstance,
                                    providerPath,
                                    resultRelativePath,
                                    returnContainers,
                                    includeMatcher,
                                    excludeMatcher,
                                    context,
                                    true,
                                    depth - 1);
                            }
                        } // foreach
                    } // if
                } // recurse
            }
            finally
            {
                childNamesContext.RemoveStopReferral();
            }
        } // DoGetChildNamesRecurseManually
开发者ID:dfinke,项目名称:powershell,代码行数:101,代码来源:SessionStateContainer.cs

示例14: ProcessPathItems


//.........这里部分代码省略.........
                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.
                    if (context.Stopping)
                    {
开发者ID:dfinke,项目名称:powershell,代码行数:67,代码来源:SessionStateContainer.cs


注:本文中的System.Management.Automation.CmdletProviderContext.RemoveStopReferral方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。