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


C# ProviderInfo.CreateInstance方法代码示例

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


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

示例1: 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;
        }
开发者ID:bitwiseman,项目名称:Pash,代码行数:21,代码来源:CmdletProviderManagementIntrinsics.cs

示例2: AddProvider

        private CmdletProvider AddProvider(ProviderInfo providerInfo)
        {
            CmdletProvider provider = providerInfo.CreateInstance();

            provider.Start(providerInfo, new ProviderRuntime(_executionContext));
            provider.SetProviderInfo(providerInfo);

            // Cache the Provider's Info
            if (!_providers.ContainsKey(providerInfo.Name))
            {
                _providers.Add(providerInfo.Name, new List<ProviderInfo>());
            }
            _providers[providerInfo.Name].Add(providerInfo);

            return provider;
        }
开发者ID:staxmanade,项目名称:Pash,代码行数:16,代码来源:SessionStateGlobal.cs

示例3: GetProviderInstance

        } // GetProviderInstance

        /// <summary>
        /// Gets an instance of a provider given the provider information.
        /// </summary>
        /// 
        /// <param name="provider">
        /// The provider to return an instance of.
        /// </param>
        /// 
        /// <returns>
        /// An instance of the specified provider.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="provider"/> is null.
        /// </exception>
        /// 
        internal Provider.CmdletProvider GetProviderInstance(ProviderInfo provider)
        {
            if (provider == null)
            {
                throw PSTraceSource.NewArgumentNullException("provider");
            }

            return provider.CreateInstance();
        } // GetProviderInstance
开发者ID:40a,项目名称:PowerShell,代码行数:27,代码来源:SessionStateProviderAPIs.cs

示例4: NewProvider

        } // InitializeProvider



        /// <summary>
        /// Creates and adds a provider to the provider container 
        /// </summary>
        /// 
        /// <param name="provider">
        /// The provider to add.
        /// </param>
        /// 
        /// <returns>
        /// The provider that was added or null if the provider failed to be added.
        /// </returns>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="provider"/> is null.
        /// </exception>
        /// 
        /// <exception cref="SessionStateException">
        /// If the provider already exists.
        /// </exception>
        /// 
        /// <exception cref="ProviderInvocationException">
        /// If there was a failure to load the provider or the provider
        /// threw an exception.
        /// </exception>
        /// 
        internal ProviderInfo NewProvider(ProviderInfo provider)
        {
            if (provider == null)
            {
                throw PSTraceSource.NewArgumentNullException("provider");
            }

            // Check to see if the provider already exists.
            // We do the check instead of allowing the hashtable to 
            // throw the exception so that we give a better error
            // message.
            ProviderInfo existingProvider = ProviderExists(provider);
            if (existingProvider != null)
            {
                // If it's an already loaded provider, don't return an error...
                if (existingProvider.ImplementingType == provider.ImplementingType)
                    return existingProvider;

                SessionStateException sessionStateException =
                    new SessionStateException(
                        provider.Name,
                        SessionStateCategory.CmdletProvider,
                        "CmdletProviderAlreadyExists",
                        SessionStateStrings.CmdletProviderAlreadyExists,
                        ErrorCategory.ResourceExists);

                throw sessionStateException;
            }


            // Make sure we are able to create an instance of the provider.
            // Note, this will also set the friendly name if the user didn't
            // specify one.

            Provider.CmdletProvider providerInstance = provider.CreateInstance();

            // Now call start to let the provider initialize itself
            CmdletProviderContext context = new CmdletProviderContext(this.ExecutionContext);
            ProviderInfo newProviderInfo = null;

            try
            {
                newProviderInfo = providerInstance.Start(provider, context);

                // 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",
//.........这里部分代码省略.........
开发者ID:40a,项目名称:PowerShell,代码行数:101,代码来源:SessionStateProviderAPIs.cs

示例5: NewProvider

 internal ProviderInfo NewProvider(ProviderInfo provider)
 {
     if (provider == null)
     {
         throw PSTraceSource.NewArgumentNullException("provider");
     }
     ProviderInfo info = this.ProviderExists(provider);
     if (info != null)
     {
         if (info.ImplementingType == provider.ImplementingType)
         {
             return info;
         }
         SessionStateException exception = new SessionStateException(provider.Name, SessionStateCategory.CmdletProvider, "CmdletProviderAlreadyExists", SessionStateStrings.CmdletProviderAlreadyExists, ErrorCategory.ResourceExists, new object[0]);
         throw exception;
     }
     CmdletProvider providerInstance = provider.CreateInstance();
     CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(this.ExecutionContext);
     ProviderInfo providerInfoToSet = null;
     try
     {
         providerInfoToSet = providerInstance.Start(provider, cmdletProviderContext);
         providerInstance.SetProviderInformation(providerInfoToSet);
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         throw;
     }
     catch (InvalidOperationException)
     {
         throw;
     }
     catch (Exception exception2)
     {
         CommandProcessorBase.CheckForSevereException(exception2);
         throw this.NewProviderInvocationException("ProviderStartException", SessionStateStrings.ProviderStartException, provider, null, exception2);
     }
     cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
     if (providerInfoToSet == null)
     {
         throw PSTraceSource.NewInvalidOperationException("SessionStateStrings", "InvalidProviderInfoNull", new object[0]);
     }
     if (providerInfoToSet != provider)
     {
         if (!string.Equals(providerInfoToSet.Name, provider.Name, StringComparison.OrdinalIgnoreCase))
         {
             throw PSTraceSource.NewInvalidOperationException("SessionStateStrings", "InvalidProviderInfo", new object[0]);
         }
         provider = providerInfoToSet;
     }
     try
     {
         this.NewProviderEntry(provider);
     }
     catch (ArgumentException)
     {
         SessionStateException exception3 = new SessionStateException(provider.Name, SessionStateCategory.CmdletProvider, "CmdletProviderAlreadyExists", SessionStateStrings.CmdletProviderAlreadyExists, ErrorCategory.ResourceExists, new object[0]);
         throw exception3;
     }
     this.ProvidersCurrentWorkingDrive.Add(provider, null);
     bool flag = false;
     try
     {
         this.InitializeProvider(providerInstance, provider, cmdletProviderContext);
         cmdletProviderContext.ThrowFirstErrorOrDoNothing(true);
     }
     catch (LoopFlowException)
     {
         throw;
     }
     catch (PipelineStoppedException)
     {
         flag = true;
         throw;
     }
     catch (ActionPreferenceStopException)
     {
         flag = true;
         throw;
     }
     catch (NotSupportedException)
     {
         flag = false;
     }
     catch (SessionStateException)
     {
         flag = true;
         throw;
     }
     finally
     {
         if (flag)
//.........这里部分代码省略.........
开发者ID:nickchal,项目名称:pash,代码行数:101,代码来源:SessionStateInternal.cs

示例6: MakePath

 internal string MakePath(ProviderInfo provider, string parent, string child, CmdletProviderContext context)
 {
     CmdletProvider providerInstance = provider.CreateInstance();
     return this.MakePath(providerInstance, parent, child, context);
 }
开发者ID:nickchal,项目名称:pash,代码行数:5,代码来源:SessionStateInternal.cs

示例7: GetChildName

 private string GetChildName(ProviderInfo provider, string path, CmdletProviderContext context)
 {
     CmdletProvider providerInstance = provider.CreateInstance();
     return this.GetChildName(providerInstance, path, context, true);
 }
开发者ID:nickchal,项目名称:pash,代码行数:5,代码来源:SessionStateInternal.cs

示例8: GetProviderPathFromDriveQualifiedPath

 string GetProviderPathFromDriveQualifiedPath(string path, ProviderRuntime runtime, out ProviderInfo providerInfo, out PSDriveInfo drive)
 {
     var idx = path.IndexOf(":");
     var driveName = path.Substring(0, idx);
     // TODO: validate drive name?
     drive = _sessionState.Drive.Get(driveName);
     providerInfo = drive.Provider;
     path = path.Substring(idx + 1).TrimStart(PathIntrinsics.CorrectSlash, PathIntrinsics.WrongSlash);
     return Path.Combine(providerInfo.CreateInstance(), drive.Root, path, runtime);
 }
开发者ID:mauve,项目名称:Pash,代码行数:10,代码来源:PathGlobber.cs

示例9: GetChildName

        } // GetChildName

        /// <summary>
        /// Gets the leaf element of the specified path.
        /// </summary>
        /// 
        /// <param name="provider">
        /// The provider to use.
        /// </param>
        /// 
        /// <param name="path">
        /// The path to the item if it was specified on the command line.
        /// </param>
        /// 
        /// <param name="context">
        /// The context which the core command is running.
        /// </param>
        /// 
        /// <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>
        /// 
        private string GetChildName(
            ProviderInfo provider,
            string path,
            CmdletProviderContext context)
        {
            // All parameters should have been validated by caller
            Dbg.Diagnostics.Assert(
                provider != null,
                "Caller should validate provider before calling this method");

            Dbg.Diagnostics.Assert(
                path != null,
                "Caller should validate path before callin g this method");

            Dbg.Diagnostics.Assert(
                context != null,
                "Caller should validate context before calling this method");


            CmdletProvider providerInstance = provider.CreateInstance();

            return GetChildName(providerInstance, path, context, true);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:53,代码来源:SessionStateNavigation.cs

示例10: MakePath

        } // MakePath

        /// <summary>
        /// Uses the specified provider to put the two parts of a path together
        /// </summary>
        /// 
        /// <param name="provider">
        /// The provider to use.
        /// </param>
        /// 
        /// <param name="parent">
        /// The parent part of the path to join with the child.
        /// </param>
        /// 
        /// <param name="child">
        /// The child part of the path to join with the parent.
        /// </param>
        /// 
        /// <param name="context">
        /// The context under which the command is running.
        /// </param>
        /// 
        /// <returns>
        /// The combined path.
        /// </returns>
        /// 
        /// <exception cref="NotSupportedException">
        /// If the <paramref name="providerId"/> 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 MakePath(
            ProviderInfo provider,
            string parent,
            string child,
            CmdletProviderContext context)
        {
            // All parameters should have been validated by caller
            Dbg.Diagnostics.Assert(
                provider != null,
                "Caller should validate provider before calling this method");

            Dbg.Diagnostics.Assert(
                context != null,
                "Caller should validate context before calling this method");

            // Get an instance of the provider


            Provider.CmdletProvider providerInstance = provider.CreateInstance();

            return MakePath(providerInstance, parent, child, context);
        }
开发者ID:40a,项目名称:PowerShell,代码行数:60,代码来源:SessionStateNavigation.cs


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