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


C# ProviderInfo.NameEquals方法代码示例

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


在下文中一共展示了ProviderInfo.NameEquals方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetProviderQualifiedPath

 internal static string GetProviderQualifiedPath(string path, ProviderInfo provider)
 {
     if (path == null)
     {
         throw PSTraceSource.NewArgumentNullException("path");
     }
     if (provider == null)
     {
         throw PSTraceSource.NewArgumentNullException("provider");
     }
     string str = path;
     bool flag = false;
     int index = path.IndexOf("::", StringComparison.Ordinal);
     if (index != -1)
     {
         string providerName = path.Substring(0, index);
         if (provider.NameEquals(providerName))
         {
             flag = true;
         }
     }
     if (!flag)
     {
         str = string.Format(CultureInfo.InvariantCulture, "{0}{1}{2}", new object[] { provider.FullName, "::", path });
     }
     tracer.WriteLine("result = {0}", new object[] { str });
     return str;
 }
开发者ID:nickchal,项目名称:pash,代码行数:28,代码来源:LocationGlobber.cs

示例2: InitializeProvider


//.........这里部分代码省略.........
            ProviderInfo provider,
            CmdletProviderContext context)
        {
            if (provider == null)
            {
                throw PSTraceSource.NewArgumentNullException("provider");
            }

            if (context == null)
            {
                context = new CmdletProviderContext(this.ExecutionContext);
            }

            // Initialize the provider so that it can add any drives
            // that it needs.

            List<PSDriveInfo> newDrives = new List<PSDriveInfo>();
            DriveCmdletProvider driveProvider =
                GetDriveProviderInstance(providerInstance);

            if (driveProvider != null)
            {
                try
                {
                    Collection<PSDriveInfo> drives = driveProvider.InitializeDefaultDrives(context);
                    if (drives != null && drives.Count > 0)
                    {
                        newDrives.AddRange(drives);
                        ProvidersCurrentWorkingDrive[provider] = drives[0];
                    }
                }
                catch (LoopFlowException)
                {
                    throw;
                }
                catch (PipelineStoppedException)
                {
                    throw;
                }
                catch (ActionPreferenceStopException)
                {
                    throw;
                }
                catch (Exception e) // Catch-all OK, 3rd party callout
                {
                    CommandProcessorBase.CheckForSevereException(e);
                    ProviderInvocationException providerException =
                        NewProviderInvocationException(
                            "InitializeDefaultDrivesException",
                            SessionStateStrings.InitializeDefaultDrivesException,
                            provider,
                            String.Empty,
                            e);

                    context.WriteError(
                        new ErrorRecord(
                            providerException,
                            "InitializeDefaultDrivesException",
                            ErrorCategory.InvalidOperation,
                            provider));
                }
            }

            if (newDrives != null && newDrives.Count > 0)
            {
                // Add the drives. 

                foreach (PSDriveInfo newDrive in newDrives)
                {
                    if (newDrive == null)
                    {
                        continue;
                    }

                    // Only mount drives for the current provider

                    if (!provider.NameEquals(newDrive.Provider.FullName))
                    {
                        continue;
                    }

                    try
                    {
                        PSDriveInfo validatedNewDrive = ValidateDriveWithProvider(driveProvider, newDrive, context, false);

                        if (validatedNewDrive != null)
                        {
                            // Since providers are global then the drives created
                            // through InitializeDefaultDrives should also be global.

                            GlobalScope.NewDrive(validatedNewDrive);
                        }
                    }
                    catch (SessionStateException exception)
                    {
                        context.WriteError(exception.ErrorRecord);
                    }
                } // foreach (drive in newDrives)
            }
        } // InitializeProvider
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:SessionStateProviderAPIs.cs

示例3: ProviderExists

        } // NewProvider

        private ProviderInfo ProviderExists(ProviderInfo provider)
        {
            List<ProviderInfo> matchingProviders = null;

            if (Providers.TryGetValue(provider.Name, out matchingProviders))
            {
                foreach (ProviderInfo possibleMatch in matchingProviders)
                {
                    if (provider.NameEquals(possibleMatch.FullName))
                    {
                        return possibleMatch;
                    }
                }
            }
            return null;
        }
开发者ID:40a,项目名称:PowerShell,代码行数:18,代码来源:SessionStateProviderAPIs.cs

示例4: GetProviderQualifiedPath

        } // RemoveDriveQualifier

        /// <summary>
        /// Given an Msh path, returns a provider-qualified path.
        /// No globbing or relative path character expansion is done.
        /// </summary>
        ///
        /// <param name="path">
        /// The path to get the drive qualified path from.
        /// </param>
        ///
        /// <param name="provider">
        /// The provider the path should be qualified with.
        /// </param>
        ///
        /// <returns>
        /// A drive-qualified absolute Msh path.
        /// </returns>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="path"/> or <paramref name="provider"/> is null.
        /// </exception>
        /// 
        internal static string GetProviderQualifiedPath(string path, ProviderInfo provider)
        {
            if (path == null)
            {
                throw PSTraceSource.NewArgumentNullException("path");
            }


            if (provider == null)
            {
                throw PSTraceSource.NewArgumentNullException("provider");
            }

            string result = path;
            bool pathResolved = false;

            // Check to see if the path is already provider qualified

            int providerSeparatorIndex = path.IndexOf("::", StringComparison.Ordinal);
            if (providerSeparatorIndex != -1)
            {
                string possibleProvider = path.Substring(0, providerSeparatorIndex);

                if (provider.NameEquals(possibleProvider))
                {
                    pathResolved = true;
                }
            }

            if (!pathResolved)
            {
                result =
                    String.Format(
                        System.Globalization.CultureInfo.InvariantCulture,
                        "{0}{1}{2}",
                        provider.FullName,
                        StringLiterals.ProviderPathSeparator,
                        path);
            }

            return result;
        } // GetProviderQualifiedPath
开发者ID:40a,项目名称:PowerShell,代码行数:65,代码来源:LocationGlobber.cs

示例5: ProviderExists

 private ProviderInfo ProviderExists(ProviderInfo provider)
 {
     List<ProviderInfo> list = null;
     if (this.Providers.TryGetValue(provider.Name, out list))
     {
         foreach (ProviderInfo info in list)
         {
             if (provider.NameEquals(info.FullName))
             {
                 return info;
             }
         }
     }
     return null;
 }
开发者ID:nickchal,项目名称:pash,代码行数:15,代码来源:SessionStateInternal.cs

示例6: InitializeProvider

 internal void InitializeProvider(CmdletProvider providerInstance, ProviderInfo provider, CmdletProviderContext context)
 {
     if (provider == null)
     {
         throw PSTraceSource.NewArgumentNullException("provider");
     }
     if (context == null)
     {
         context = new CmdletProviderContext(this.ExecutionContext);
     }
     List<PSDriveInfo> list = new List<PSDriveInfo>();
     DriveCmdletProvider driveProviderInstance = GetDriveProviderInstance(providerInstance);
     if (driveProviderInstance != null)
     {
         try
         {
             Collection<PSDriveInfo> collection = driveProviderInstance.InitializeDefaultDrives(context);
             if ((collection != null) && (collection.Count > 0))
             {
                 list.AddRange(collection);
                 this.ProvidersCurrentWorkingDrive[provider] = collection[0];
             }
         }
         catch (LoopFlowException)
         {
             throw;
         }
         catch (PipelineStoppedException)
         {
             throw;
         }
         catch (ActionPreferenceStopException)
         {
             throw;
         }
         catch (Exception exception)
         {
             CommandProcessorBase.CheckForSevereException(exception);
             ProviderInvocationException exception2 = this.NewProviderInvocationException("InitializeDefaultDrivesException", SessionStateStrings.InitializeDefaultDrivesException, provider, string.Empty, exception);
             context.WriteError(new ErrorRecord(exception2, "InitializeDefaultDrivesException", ErrorCategory.InvalidOperation, provider));
         }
     }
     if ((list != null) && (list.Count > 0))
     {
         foreach (PSDriveInfo info in list)
         {
             if ((info != null) && provider.NameEquals(info.Provider.FullName))
             {
                 try
                 {
                     PSDriveInfo newDrive = this.ValidateDriveWithProvider(driveProviderInstance, info, context, false);
                     if (newDrive != null)
                     {
                         this._globalScope.NewDrive(newDrive);
                     }
                 }
                 catch (SessionStateException exception3)
                 {
                     context.WriteError(exception3.ErrorRecord);
                 }
             }
         }
     }
 }
开发者ID:nickchal,项目名称:pash,代码行数:64,代码来源:SessionStateInternal.cs

示例7: GetProviderRootFromSpecifiedRoot

 private string GetProviderRootFromSpecifiedRoot(string root, ProviderInfo provider)
 {
     string str = root;
     SessionState state = new SessionState(this._context.TopLevelSessionState);
     Collection<string> resolvedProviderPathFromPSPath = null;
     ProviderInfo info = null;
     try
     {
         resolvedProviderPathFromPSPath = state.Path.GetResolvedProviderPathFromPSPath(root, out info);
         if (((resolvedProviderPathFromPSPath != null) && (resolvedProviderPathFromPSPath.Count == 1)) && provider.NameEquals(info.FullName))
         {
             ProviderIntrinsics intrinsics = new ProviderIntrinsics(this);
             if (intrinsics.Item.Exists(root))
             {
                 str = resolvedProviderPathFromPSPath[0];
             }
         }
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         throw;
     }
     catch (System.Management.Automation.DriveNotFoundException)
     {
     }
     catch (ProviderNotFoundException)
     {
     }
     catch (ItemNotFoundException)
     {
     }
     catch (NotSupportedException)
     {
     }
     catch (InvalidOperationException)
     {
     }
     catch (ProviderInvocationException)
     {
     }
     catch (ArgumentException)
     {
     }
     return str;
 }
开发者ID:nickchal,项目名称:pash,代码行数:53,代码来源:SessionStateInternal.cs

示例8: GetProviderRootFromSpecifiedRoot

        /// <summary>
        /// Tries to resolve the drive root as an MSH path. If it successfully resolves
        /// to a single path then the resolved provider internal path is returned. If it
        /// does not resolve to a single MSH path the root is returned as it was passed.
        /// </summary>
        /// 
        /// <param name="root">
        /// The root path of the drive to be resolved.
        /// </param>
        /// 
        /// <param name="provider">
        /// The provider that should be used when resolving the path.
        /// </param>
        /// 
        /// <returns>
        /// The new root path of the drive.
        /// </returns>
        /// 
        private string GetProviderRootFromSpecifiedRoot(string root, ProviderInfo provider)
        {
            Dbg.Diagnostics.Assert(
                root != null,
                "Caller should have verified the root");

            Dbg.Diagnostics.Assert(
                provider != null,
                "Caller should have verified the provider");

            string result = root;

            SessionState sessionState = new SessionState(ExecutionContext.TopLevelSessionState);
            Collection<string> resolvedPaths = null;
            ProviderInfo resolvedProvider = null;

            try
            {
                // First try to resolve the root as an MSH path

                resolvedPaths =
                    sessionState.Path.GetResolvedProviderPathFromPSPath(root, out resolvedProvider);

                // If a single path was resolved...

                if (resolvedPaths != null &&
                    resolvedPaths.Count == 1)
                {
                    // and the provider used to resolve the path, 
                    // matches the one specified by the drive...

                    if (provider.NameEquals(resolvedProvider.FullName))
                    {
                        // and the item exists

                        ProviderIntrinsics providerIntrinsics =
                            new ProviderIntrinsics(this);

                        if (providerIntrinsics.Item.Exists(root))
                        {
                            // then use the resolved path as the root of the drive

                            result = resolvedPaths[0];
                        }
                    }
                }
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            // If any of the following exceptions are thrown we assume that
            // the path is a file system path not an MSH path and try
            // to create the drive with that root.
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (ItemNotFoundException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (ArgumentException)
            {
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:SessionStateDriveAPIs.cs


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