/********************************************************************++ Copyright (c) Microsoft Corporation. All rights reserved. --********************************************************************/ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Management.Automation.Provider; using Dbg = System.Management.Automation; namespace System.Management.Automation { /// /// Exposes the APIs to manage the Cmdlet Providers the Cmdlet base class. The methods of this class /// get and set provider data in session state. /// public sealed class CmdletProviderManagementIntrinsics { #region Constructors /// /// Hide the default constructor since we always require an instance of SessionState /// private CmdletProviderManagementIntrinsics() { Dbg.Diagnostics.Assert( false, "This constructor should never be called. Only the constructor that takes an instance of SessionState should be called."); } // CmdletProviderManagementIntrinsics private /// /// The facade for managing providers /// /// /// /// The session to which this is a facade. /// /// /// /// If is null. /// /// internal CmdletProviderManagementIntrinsics(SessionStateInternal sessionState) { if (sessionState == null) { throw PSTraceSource.NewArgumentNullException("sessionState"); } _sessionState = sessionState; } // CmdletProviderManagementIntrinsics internal #endregion Constructors #region Public methods /// /// Gets the specified provider(s). /// /// /// /// Either the fully-qualified or friendly name for the provider. /// /// /// /// The provider information for the specified provider. /// /// /// /// If is null or empty. /// /// /// /// If the provider specified by is not currently /// loaded. /// public Collection Get(string name) { Dbg.Diagnostics.Assert( _sessionState != null, "The only constructor for this class should always set the sessionState field"); // Parameter validation is done in the session state object return _sessionState.GetProvider(name); } // Get /// /// Gets the specified provider(s). /// /// /// /// Either the fully-qualified or friendly name for the provider. /// /// /// /// The provider information for the specified provider. /// /// /// /// If is null or empty. /// /// /// /// If is not PSSnapin-qualified and more than one provider /// exists with the specified name. /// /// /// /// If the provider specified by is not currently /// loaded. /// public ProviderInfo GetOne(string name) { Dbg.Diagnostics.Assert( _sessionState != null, "The only constructor for this class should always set the sessionState field"); // Parameter validation is done in the session state object return _sessionState.GetSingleProvider(name); } // Get /// /// Gets all the Cmdlet Providers that are loaded. /// public IEnumerable GetAll() { Dbg.Diagnostics.Assert( _sessionState != null, "The only constructor for this class should always set the sessionState field"); return _sessionState.ProviderList; } // GetAll #endregion Public methods #region Internal methods /// /// Determines if the specified provider has the specified capability /// /// /// /// The capability to check the provider for. /// /// /// /// The provider information to use for the check. /// /// /// /// True, if the provider has the capability, false otherwise. /// /// internal static bool CheckProviderCapabilities( ProviderCapabilities capability, ProviderInfo provider) { // Check the capability return (provider.Capabilities & capability) != 0; } // CheckProviderCapabilities /// /// Gets the count of the number of providers that are loaded /// /// internal int Count { get { return _sessionState.ProviderCount; } } // Count #endregion Internal methods #region private data private SessionStateInternal _sessionState; #endregion private data } // ProviderIntrinsics }