Ejemplo n.º 1
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description, string home, string helpFile, PSSnapInInfo psSnapIn)
 {
     this.helpFile = "";
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     if (implementingType == null)
     {
         throw PSTraceSource.NewArgumentNullException("implementingType");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     this.sessionState = sessionState;
     this.name = name;
     this.description = description;
     this.home = home;
     this.implementingType = implementingType;
     this.helpFile = helpFile;
     this.pssnapin = psSnapIn;
     this.hiddenDrive = new PSDriveInfo(this.FullName, this, "", "", null);
     this.hiddenDrive.Hidden = true;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a CmdletInfo object from the raw cmdlet data.  This should only
        /// be used for Intrinsic commands.
        /// </summary>
        /// 
        /// <param name="name">
        /// The name of the cmdlet.
        /// </param>
        /// 
        /// <param name="implementingType">
        /// The type information about the class that implements the cmdlet.
        /// </param>
        /// 
        /// <param name="helpFile">
        /// The name of the help file associated with the cmdlet
        /// </param>
        ///
        /// <param name="PSSnapin">
        /// The PSSnapInInfo of the PSSnapin the cmdlet comes from.
        /// </param>
        /// 
        /// <param name="context">
        /// The current engine context.
        /// </param>
        /// 
        internal CmdletInfo(
            string name,
            Type implementingType,
            string helpFile,
            PSSnapInInfo PSSnapin,
            ExecutionContext context)
            : base(name, CommandTypes.Cmdlet, context)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw PSTraceSource.NewArgumentException("name");
            }

            // Get the verb and noun from the name
            if (!SplitCmdletName(name, out _verb, out _noun))
            {
                throw
                    PSTraceSource.NewArgumentException(
                        "name",
                        DiscoveryExceptions.InvalidCmdletNameFormat,
                        name);
            }

            _implementingType = implementingType;
            _helpFilePath = helpFile;
            _PSSnapin = PSSnapin;
            _options = ScopedItemOptions.ReadOnly;
            this.DefiningLanguageMode = PSLanguageMode.FullLanguage;
        }
 internal Collection<ProviderInfo> Get(PSSnapInInfo snapinInfo)
 {
     var providers = from p in GetAll()
                     where p.PSSnapIn != null && p.PSSnapIn.Equals(snapinInfo)
                     select p;
     return new Collection<ProviderInfo>(providers.ToList());
 }
Ejemplo n.º 4
0
 public CmdletInfo(string name, Type implementingType) : base(name, CommandTypes.Cmdlet, null)
 {
     this.verb = string.Empty;
     this.noun = string.Empty;
     this.helpFilePath = string.Empty;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     if (implementingType == null)
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     if (!typeof(Cmdlet).IsAssignableFrom(implementingType))
     {
         throw PSTraceSource.NewInvalidOperationException("DiscoveryExceptions", "CmdletDoesNotDeriveFromCmdletType", new object[] { "implementingType", implementingType.FullName });
     }
     if (!SplitCmdletName(name, out this.verb, out this.noun))
     {
         throw PSTraceSource.NewArgumentException("name", "DiscoveryExceptions", "InvalidCmdletNameFormat", new object[] { name });
     }
     this.implementingType = implementingType;
     this.helpFilePath = string.Empty;
     this._PSSnapin = null;
     this.options = ScopedItemOptions.ReadOnly;
 }
Ejemplo n.º 5
0
 internal FormatConfigurationEntry(string name, string fileName, PSSnapInInfo psSnapinInfo) : base(name, psSnapinInfo)
 {
     if (string.IsNullOrEmpty(fileName) || string.IsNullOrEmpty(fileName.Trim()))
     {
         throw PSTraceSource.NewArgumentException("fileName");
     }
     this._fileName = fileName.Trim();
 }
Ejemplo n.º 6
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description, string home, string helpFile, PSSnapInInfo psSnapIn)
 {
     _sessionState = sessionState;
     PSSnapIn = psSnapIn;
     Name = name;
     Description = description;
     Home = home;
     ImplementingType = implementingType;
     Capabilities = GetCapabilities(implementingType);
     HelpFile = helpFile;
 }
Ejemplo n.º 7
0
 internal CmdletInfo(CmdletInfo other) : base(other)
 {
     this.verb = string.Empty;
     this.noun = string.Empty;
     this.helpFilePath = string.Empty;
     this.verb = other.verb;
     this.noun = other.noun;
     this.implementingType = other.implementingType;
     this.helpFilePath = other.helpFilePath;
     this._PSSnapin = other._PSSnapin;
     this.options = ScopedItemOptions.ReadOnly;
 }
Ejemplo n.º 8
0
 public int CompareTo(PSSnapInInfo other)
 {
     if (!string.Equals(Name, other.Name, StringComparison.CurrentCultureIgnoreCase))
     {
         return Name.CompareTo(other.Name);
     }
     if (string.Equals(AssemblyName, other.AssemblyName, StringComparison.CurrentCultureIgnoreCase))
     {
         return 0;
     }
     return AssemblyName.CompareTo(other.AssemblyName);
 }
Ejemplo n.º 9
0
 internal RunspaceConfigurationEntry(string name, PSSnapInInfo psSnapin)
 {
     this._action = UpdateAction.None;
     if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(name.Trim()))
     {
         throw PSTraceSource.NewArgumentNullException("name");
     }
     this._name = name.Trim();
     if (psSnapin == null)
     {
         throw PSTraceSource.NewArgumentException("psSnapin");
     }
     this._PSSnapin = psSnapin;
 }
Ejemplo n.º 10
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo PSSnapin, ExecutionContext context)
     : base(name, CommandTypes.Cmdlet)
 {
     int i = name.IndexOf('-');
     if (i == -1)
     {
         throw new Exception("InvalidCmdletNameFormat " + name);
     }
     Verb = name.Substring(0, i);
     Noun = name.Substring(i + 1);
     ImplementingType = implementingType;
     HelpFile = helpFile;
     PSSnapIn = PSSnapin;
     _context = context;
     ParameterSets = GetParameterSetInfo(implementingType);
 }
Ejemplo n.º 11
0
 internal ProviderConfigurationEntry(string name, Type implementingType, string helpFileName, PSSnapInInfo psSnapinInfo) : base(name, psSnapinInfo)
 {
     if (implementingType == null)
     {
         throw PSTraceSource.NewArgumentNullException("implementingType");
     }
     this._type = implementingType;
     if (!string.IsNullOrEmpty(helpFileName))
     {
         this._helpFileName = helpFileName.Trim();
     }
     else
     {
         this._helpFileName = helpFileName;
     }
 }
Ejemplo n.º 12
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo PSSnapin, ExecutionContext context)
     : base(name, CommandTypes.Cmdlet)
 {
     int i = name.IndexOf('-');
     if (i == -1)
     {
         throw new Exception("InvalidCmdletNameFormat " + name);
     }
     ParameterInfoLookupTable = new Dictionary<string, CommandParameterInfo>(StringComparer.CurrentCultureIgnoreCase);
     Verb = name.Substring(0, i);
     Noun = name.Substring(i + 1);
     ImplementingType = implementingType;
     HelpFile = helpFile;
     PSSnapIn = PSSnapin;
     _validationException = null;
     GetParameterSetInfo(implementingType);
 }
Ejemplo n.º 13
0
 protected ProviderInfo(ProviderInfo providerInfo)
 {
     this.helpFile = "";
     if (providerInfo == null)
     {
         throw PSTraceSource.NewArgumentNullException("providerInfo");
     }
     this.name = providerInfo.Name;
     this.implementingType = providerInfo.ImplementingType;
     this.capabilities = providerInfo.capabilities;
     this.description = providerInfo.description;
     this.hiddenDrive = providerInfo.hiddenDrive;
     this.home = providerInfo.home;
     this.helpFile = providerInfo.helpFile;
     this.pssnapin = providerInfo.pssnapin;
     this.sessionState = providerInfo.sessionState;
 }
Ejemplo n.º 14
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo PSSnapin, System.Management.Automation.ExecutionContext context) : base(name, CommandTypes.Cmdlet, context)
 {
     this.verb         = string.Empty;
     this.noun         = string.Empty;
     this.helpFilePath = string.Empty;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     if (!SplitCmdletName(name, out this.verb, out this.noun))
     {
         throw PSTraceSource.NewArgumentException("name", "DiscoveryExceptions", "InvalidCmdletNameFormat", new object[] { name });
     }
     this.implementingType     = implementingType;
     this.helpFilePath         = helpFile;
     this._PSSnapin            = PSSnapin;
     this.options              = ScopedItemOptions.ReadOnly;
     base.DefiningLanguageMode = 0;
 }
Ejemplo n.º 15
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo PSSnapin, System.Management.Automation.ExecutionContext context) : base(name, CommandTypes.Cmdlet, context)
 {
     this.verb = string.Empty;
     this.noun = string.Empty;
     this.helpFilePath = string.Empty;
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     if (!SplitCmdletName(name, out this.verb, out this.noun))
     {
         throw PSTraceSource.NewArgumentException("name", "DiscoveryExceptions", "InvalidCmdletNameFormat", new object[] { name });
     }
     this.implementingType = implementingType;
     this.helpFilePath = helpFile;
     this._PSSnapin = PSSnapin;
     this.options = ScopedItemOptions.ReadOnly;
     base.DefiningLanguageMode = 0;
 }
Ejemplo n.º 16
0
        internal static PSSnapInInfo ReadCoreEngineSnapIn()
        {
            Version version;
            Version version2;
            string  publicKeyToken  = null;
            string  culture         = null;
            string  architecture    = null;
            string  applicationBase = null;

            ReadRegistryInfo(out version, out publicKeyToken, out culture, out architecture, out applicationBase, out version2);
            Collection <string> formats = new Collection <string>(new string[] { "Certificate.format.ps1xml", "DotNetTypes.format.ps1xml", "FileSystem.format.ps1xml", "Help.format.ps1xml", "HelpV3.format.ps1xml", "PowerShellCore.format.ps1xml", "PowerShellTrace.format.ps1xml", "Registry.format.ps1xml" });
            Collection <string> types   = new Collection <string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });
            string       assemblyName   = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}", new object[] { CoreSnapin.AssemblyName, version, culture, publicKeyToken, architecture });
            string       moduleName     = Path.Combine(applicationBase, CoreSnapin.AssemblyName + ".dll");
            PSSnapInInfo psSnapInInfo   = new PSSnapInInfo(CoreSnapin.PSSnapInName, true, applicationBase, assemblyName, moduleName, version2, version, types, formats, null, CoreSnapin.Description, CoreSnapin.DescriptionIndirect, null, null, CoreSnapin.VendorIndirect, null);

            SetSnapInLoggingInformation(psSnapInInfo);
            return(psSnapInInfo);
        }
Ejemplo n.º 17
0
        internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo PSSnapin, ExecutionContext context)
            : base(name, CommandTypes.Cmdlet)
        {
            int i = name.IndexOf('-');

            if (i == -1)
            {
                throw new Exception("InvalidCmdletNameFormat " + name);
            }
            UniqueSetParameters      = new Dictionary <string, string>();
            ParameterInfoLookupTable = new Dictionary <string, CommandParameterInfo>(StringComparer.CurrentCultureIgnoreCase);
            Verb                 = name.Substring(0, i);
            Noun                 = name.Substring(i + 1);
            ImplementingType     = implementingType;
            HelpFile             = helpFile;
            PSSnapIn             = PSSnapin;
            _validationException = null;
            GetParameterSetInfo(implementingType);
        }
Ejemplo n.º 18
0
        internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo snapin, PSModuleInfo module)
            : base(name, CommandTypes.Cmdlet)
        {
            int i = name.IndexOf('-');

            if (i == -1)
            {
                throw new Exception("InvalidCmdletNameFormat " + name);
            }
            ParameterInfoLookupTable = new Dictionary <string, CommandParameterInfo>(StringComparer.CurrentCultureIgnoreCase);
            Verb                 = name.Substring(0, i);
            Noun                 = name.Substring(i + 1);
            ImplementingType     = implementingType;
            HelpFile             = helpFile;
            _validationException = null;
            PSSnapIn             = snapin;
            Module               = module;
            GetParameterSetInfo(implementingType);
            GetOutputTypes(implementingType);
        }
Ejemplo n.º 19
0
        internal static Collection <PSSnapInInfo> ReadEnginePSSnapIns()
        {
            Version version;
            Version version2;
            string  publicKeyToken  = null;
            string  culture         = null;
            string  architecture    = null;
            string  applicationBase = null;

            ReadRegistryInfo(out version, out publicKeyToken, out culture, out architecture, out applicationBase, out version2);
            Collection <string>       collection  = new Collection <string>(new string[] { "Certificate.format.ps1xml", "DotNetTypes.format.ps1xml", "FileSystem.format.ps1xml", "Help.format.ps1xml", "HelpV3.format.ps1xml", "PowerShellCore.format.ps1xml", "PowerShellTrace.format.ps1xml", "Registry.format.ps1xml" });
            Collection <string>       collection2 = new Collection <string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });
            Collection <PSSnapInInfo> collection3 = new Collection <PSSnapInInfo>();

            for (int i = 0; i < DefaultMshSnapins.Count; i++)
            {
                DefaultPSSnapInInformation information = DefaultMshSnapins[i];
                string assemblyName         = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}", new object[] { information.AssemblyName, version.ToString(), culture, publicKeyToken, architecture });
                Collection <string> formats = null;
                Collection <string> types   = null;
                if (information.AssemblyName.Equals("System.Management.Automation", StringComparison.OrdinalIgnoreCase))
                {
                    formats = collection;
                    types   = collection2;
                }
                else if (information.AssemblyName.Equals("Microsoft.PowerShell.Commands.Diagnostics", StringComparison.OrdinalIgnoreCase))
                {
                    types   = new Collection <string>(new string[] { "GetEvent.types.ps1xml" });
                    formats = new Collection <string>(new string[] { "Event.Format.ps1xml", "Diagnostics.Format.ps1xml" });
                }
                else if (information.AssemblyName.Equals("Microsoft.WSMan.Management", StringComparison.OrdinalIgnoreCase))
                {
                    formats = new Collection <string>(new string[] { "WSMan.format.ps1xml" });
                }
                string       moduleName   = Path.Combine(applicationBase, information.AssemblyName + ".dll");
                PSSnapInInfo psSnapInInfo = new PSSnapInInfo(information.PSSnapInName, true, applicationBase, assemblyName, moduleName, version2, version, types, formats, null, information.Description, information.DescriptionIndirect, null, null, information.VendorIndirect, null);
                SetSnapInLoggingInformation(psSnapInInfo);
                collection3.Add(psSnapInInfo);
            }
            return(collection3);
        }
Ejemplo n.º 20
0
        private string FindHelpFile(CmdletInfo cmdletInfo)
        {
            if (cmdletInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("cmdletInfo");
            }
            string helpFile = cmdletInfo.HelpFile;

            if (string.IsNullOrEmpty(helpFile))
            {
                if ((cmdletInfo.Module != null) && InitialSessionState.IsEngineModule(cmdletInfo.Module.Name))
                {
                    return(Path.Combine(cmdletInfo.Module.ModuleBase, Thread.CurrentThread.CurrentCulture.Name, engineModuleHelpFileCache[cmdletInfo.Module.Name]));
                }
                return(helpFile);
            }
            string              file        = helpFile;
            PSSnapInInfo        pSSnapIn    = cmdletInfo.PSSnapIn;
            Collection <string> searchPaths = new Collection <string>();

            if (pSSnapIn != null)
            {
                file = Path.Combine(pSSnapIn.ApplicationBase, helpFile);
            }
            else if ((cmdletInfo.Module != null) && !string.IsNullOrEmpty(cmdletInfo.Module.Path))
            {
                file = Path.Combine(cmdletInfo.Module.ModuleBase, helpFile);
            }
            else
            {
                searchPaths.Add(base.GetDefaultShellSearchPath());
                searchPaths.Add(GetCmdletAssemblyPath(cmdletInfo));
            }
            string str3 = MUIFileSearcher.LocateFile(file, searchPaths);

            if (string.IsNullOrEmpty(str3))
            {
                tracer.WriteLine("Unable to load file {0}", new object[] { file });
            }
            return(str3);
        }
Ejemplo n.º 21
0
 private static void SetSnapInLoggingInformation(PSSnapInInfo psSnapInInfo, ModuleCmdletBase.ModuleLoggingGroupPolicyStatus status, IEnumerable <string> moduleOrSnapinNames)
 {
     if (((status & ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Enabled) != ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Undefined) && (moduleOrSnapinNames != null))
     {
         foreach (string str in moduleOrSnapinNames)
         {
             if (string.Equals(psSnapInInfo.Name, str, StringComparison.OrdinalIgnoreCase))
             {
                 psSnapInInfo.LogPipelineExecutionDetails = true;
             }
             else if (WildcardPattern.ContainsWildcardCharacters(str))
             {
                 WildcardPattern pattern = new WildcardPattern(str, WildcardOptions.IgnoreCase);
                 if (pattern.IsMatch(psSnapInInfo.Name))
                 {
                     psSnapInInfo.LogPipelineExecutionDetails = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 22
0
 internal CmdletInfo(
     string name,
     Type implementingType,
     string helpFile,
     PSSnapInInfo PSSnapin,
     ExecutionContext context)
     : base(name, CommandTypes.Cmdlet, context)
 {
     if (string.IsNullOrEmpty(name))
     {
         throw CmdletInfo.tracer.NewArgumentException(nameof(name));
     }
     if (implementingType == null)
     {
         throw CmdletInfo.tracer.NewArgumentNullException(nameof(implementingType));
     }
     if (!CmdletInfo.SplitCmdletName(name, out this.verb, out this.noun))
     {
         throw CmdletInfo.tracer.NewArgumentException(nameof(name), "DiscoveryExceptions", "InvalidCmdletNameFormat", (object)name);
     }
     this.implementingType = implementingType;
     this.helpFilePath     = helpFile;
     this._PSSnapin        = PSSnapin;
 }
Ejemplo n.º 23
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo snapin)
     : this(name, implementingType, helpFile, snapin, null)
 {
 }
Ejemplo n.º 24
0
 internal PSSnapInSpecification(string psSnapinName)
 {
     PSSnapInInfo.VerifyPSSnapInFormatThrowIfError(psSnapinName);
     Name    = psSnapinName;
     Version = null;
 }
Ejemplo n.º 25
0
        // TODO: separate providers from cmdlets
        internal Collection<CmdletInfo> LoadCmdletsFromPSSnapin(string strType, out Collection<SnapinProviderPair> providers)
        {
            Collection<CmdletInfo> collection = new Collection<CmdletInfo>();
            providers = new Collection<SnapinProviderPair>();

            try
            {
                Type snapinType = Type.GetType(strType, true);
                Assembly assembly = snapinType.Assembly;

                PSSnapIn snapin = Activator.CreateInstance(snapinType) as PSSnapIn;

                PSSnapInInfo snapinInfo = new PSSnapInInfo(snapin.Name, false, string.Empty, assembly.GetName().Name, string.Empty, new Version(1, 0), null, null, null, snapin.Description, snapin.Vendor);

                foreach (Type type in assembly.GetTypes())
                {
                    if (type.IsSubclassOf(typeof(Cmdlet)))
                    {
                        foreach (CmdletAttribute cmdletAttribute in type.GetCustomAttributes(typeof(CmdletAttribute), true))
                        {
                            CmdletInfo cmdletInfo =
                                new CmdletInfo(cmdletAttribute.ToString(), type, null, snapinInfo, _context);
                            collection.Add(cmdletInfo);
                        }
                        continue;
                    }

                    if (type.IsSubclassOf(typeof(CmdletProvider)))
                    {
                        foreach (CmdletProviderAttribute providerAttr in type.GetCustomAttributes(typeof(CmdletProviderAttribute), true))
                        {
                            providers.Add(new SnapinProviderPair()
                            {
                                snapinInfo = snapinInfo,
                                providerType = type,
                                providerAttr = providerAttr
                            });
                        }
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine(ex.ToString());
            }

            return collection;
        }
Ejemplo n.º 26
0
 private void LoadPSSnapIn(PSSnapInInfo snapinInfo, Assembly assembly)
 {
     var snapinName = snapinInfo.Name;
     try
     {
         _snapins.Add(snapinName, snapinInfo);
     }
     catch (ArgumentException)
     {
         throw new PSSnapInException(String.Format("The snapin '{0}' is already loaded!", snapinName));
     }
     LoadProvidersFromAssembly(assembly, snapinInfo);
     CommandManager.LoadCmdletsFromAssembly(assembly, snapinInfo);
 }
Ejemplo n.º 27
0
 private Collection<ProviderInfo> GetProvidersByPSSnapIn(PSSnapInInfo snapinInfo)
 {
     Collection<ProviderInfo> snapinProviders = new Collection<ProviderInfo>();
     foreach (var pair in _providers)
     {
         foreach (var provider in pair.Value)
         {
             if (provider.PSSnapIn.Equals(snapinInfo))
             {
                 snapinProviders.Add(provider);
             }
         }
     }
     return snapinProviders;
 }
Ejemplo n.º 28
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description,
                       string home, string helpFile, PSSnapInInfo psSnapIn)
     : this(sessionState, implementingType, name, description, home, helpFile, psSnapIn, null)
 {
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Enable Snapin logging based on group policy
 /// </summary>
 private static void SetSnapInLoggingInformation(PSSnapInInfo psSnapInInfo, ModuleCmdletBase.ModuleLoggingGroupPolicyStatus status, IEnumerable<string> moduleOrSnapinNames)
 {
     if (((status & ModuleCmdletBase.ModuleLoggingGroupPolicyStatus.Enabled) != 0) && moduleOrSnapinNames != null)
     {
         foreach (string currentGPModuleOrSnapinName in moduleOrSnapinNames)
         {
             if (string.Equals(psSnapInInfo.Name, currentGPModuleOrSnapinName, StringComparison.OrdinalIgnoreCase))
             {
                 psSnapInInfo.LogPipelineExecutionDetails = true;
             }
             else if (WildcardPattern.ContainsWildcardCharacters(currentGPModuleOrSnapinName))
             {
                 WildcardPattern wildcard = WildcardPattern.Get(currentGPModuleOrSnapinName, WildcardOptions.IgnoreCase);
                 if (wildcard.IsMatch(psSnapInInfo.Name))
                 {
                     psSnapInInfo.LogPipelineExecutionDetails = true;
                 }
             }
         }
     }
 }
Ejemplo n.º 30
0
        internal PSSnapInInfo Clone()
        {
            PSSnapInInfo cloned = new PSSnapInInfo(Name,
                IsDefault, ApplicationBase, AssemblyName,
                ModuleName, PSVersion, Version, new Collection<string>(Types),
                new Collection<string>(Formats), _description,
                _descriptionFallback, _descriptionIndirect, _vendor, _vendorFallback, _vendorIndirect,
                CustomPSSnapInType
                );

            return cloned;
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Reads the mshsnapin info for a specific key under specific monad version
        /// </summary>
        /// <remarks>
        /// ReadOne will never create a default PSSnapInInfo object.
        /// </remarks>
        /// <exception cref="SecurityException">
        /// The user does not have the permissions required to read the
        /// registry key for specified mshsnapin.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// 1) Specified mshsnapin is not installed.
        /// 2) Specified mshsnapin is not correctly installed.
        /// </exception>
        private static PSSnapInInfo ReadOne(RegistryKey mshSnapInRoot, string mshsnapinId)
        {
            Dbg.Assert(!string.IsNullOrEmpty(mshsnapinId), "caller should validate the parameter");
            Dbg.Assert(mshSnapInRoot != null, "caller should validate the parameter");

            RegistryKey mshsnapinKey;
            mshsnapinKey = mshSnapInRoot.OpenSubKey(mshsnapinId);
            if (mshsnapinKey == null)
            {
                s_mshsnapinTracer.TraceError("Error opening registry key {0}\\{1}.", mshSnapInRoot.Name, mshsnapinId);
                throw PSTraceSource.NewArgumentException("mshsnapinId", MshSnapinInfo.MshSnapinDoesNotExist, mshsnapinId);
            }

            string applicationBase = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_ApplicationBase, true);
            string assemblyName = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_AssemblyName, true);
            string moduleName = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_ModuleName, true);
            Version monadVersion = ReadVersionValue(mshsnapinKey, RegistryStrings.MshSnapin_MonadVersion, true);
            Version version = ReadVersionValue(mshsnapinKey, RegistryStrings.MshSnapin_Version, false);

            string description = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_Description, false);
            if (description == null)
            {
                s_mshsnapinTracer.WriteLine("No description is specified for mshsnapin {0}. Using empty string for description.", mshsnapinId);
                description = string.Empty;
            }
            string vendor = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_Vendor, false);
            if (vendor == null)
            {
                s_mshsnapinTracer.WriteLine("No vendor is specified for mshsnapin {0}. Using empty string for description.", mshsnapinId);
                vendor = string.Empty;
            }

            bool logPipelineExecutionDetails = false;
            string logPipelineExecutionDetailsStr = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_LogPipelineExecutionDetails, false);
            if (!String.IsNullOrEmpty(logPipelineExecutionDetailsStr))
            {
                if (String.Compare("1", logPipelineExecutionDetailsStr, StringComparison.OrdinalIgnoreCase) == 0)
                    logPipelineExecutionDetails = true;
            }

            string customPSSnapInType = ReadStringValue(mshsnapinKey, RegistryStrings.MshSnapin_CustomPSSnapInType, false);
            if (string.IsNullOrEmpty(customPSSnapInType))
            {
                customPSSnapInType = null;
            }

            Collection<string> types = ReadMultiStringValue(mshsnapinKey, RegistryStrings.MshSnapin_BuiltInTypes, false);
            Collection<string> formats = ReadMultiStringValue(mshsnapinKey, RegistryStrings.MshSnapin_BuiltInFormats, false);

            s_mshsnapinTracer.WriteLine("Successfully read registry values for mshsnapin {0}. Constructing PSSnapInInfo object.", mshsnapinId);
            PSSnapInInfo mshSnapinInfo = new PSSnapInInfo(mshsnapinId, false, applicationBase, assemblyName, moduleName, monadVersion, version, types, formats, description, vendor, customPSSnapInType);
            mshSnapinInfo.LogPipelineExecutionDetails = logPipelineExecutionDetails;

            return mshSnapinInfo;
        }
Ejemplo n.º 32
0
        /// <summary>
        /// Reads core snapin for monad engine
        /// </summary>
        /// <returns>
        /// A PSSnapInInfo object
        /// </returns>
        internal static PSSnapInInfo ReadCoreEngineSnapIn()
        {
            Version assemblyVersion, psVersion;
            string publicKeyToken = null;
            string culture = null;
            string architecture = null;
            string applicationBase = null;

            ReadRegistryInfo(out assemblyVersion, out publicKeyToken, out culture, out architecture, out applicationBase, out psVersion);

            // System.Management.Automation formats & types files
            Collection<string> types = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });
            Collection<string> formats = new Collection<string>(new string[]
                        {"Certificate.format.ps1xml","DotNetTypes.format.ps1xml","FileSystem.format.ps1xml",
                         "Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
                         "Registry.format.ps1xml"});

            string strongName = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}",
                s_coreSnapin.AssemblyName, assemblyVersion, culture, publicKeyToken, architecture);

            string moduleName = Path.Combine(applicationBase, s_coreSnapin.AssemblyName + ".dll");

            PSSnapInInfo coreMshSnapin = new PSSnapInInfo(s_coreSnapin.PSSnapInName, true, applicationBase,
                strongName, moduleName, psVersion, assemblyVersion, types, formats, null,
                s_coreSnapin.Description, s_coreSnapin.DescriptionIndirect, null, null,
                s_coreSnapin.VendorIndirect, null);
            SetSnapInLoggingInformation(coreMshSnapin);

            return coreMshSnapin;
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Reads all registered mshsnapins for currently executing monad engine
        /// </summary>
        /// <returns>
        /// A collection of PSSnapInInfo objects
        /// </returns>
        internal static Collection<PSSnapInInfo> ReadEnginePSSnapIns()
        {
            Version assemblyVersion, psVersion;
            string publicKeyToken = null;
            string culture = null;
            string architecture = null;
            string applicationBase = null;

            ReadRegistryInfo(out assemblyVersion, out publicKeyToken, out culture, out architecture, out applicationBase, out psVersion);

            // System.Management.Automation formats & types files
            Collection<string> smaFormats = new Collection<string>(new string[]
                        {"Certificate.format.ps1xml","DotNetTypes.format.ps1xml","FileSystem.format.ps1xml",
                         "Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
                         "Registry.format.ps1xml"});
            Collection<string> smaTypes = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });

            // create default mshsnapininfo objects..
            Collection<PSSnapInInfo> engineMshSnapins = new Collection<PSSnapInInfo>();

            for (int item = 0; item < DefaultMshSnapins.Count; item++)
            {
                DefaultPSSnapInInformation defaultMshSnapinInfo = DefaultMshSnapins[item];

                string strongName = string.Format(CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}",
                    defaultMshSnapinInfo.AssemblyName, assemblyVersion.ToString(), culture, publicKeyToken, architecture);

                Collection<string> formats = null;
                Collection<string> types = null;

                if (defaultMshSnapinInfo.AssemblyName.Equals("System.Management.Automation", StringComparison.OrdinalIgnoreCase))
                {
                    formats = smaFormats;
                    types = smaTypes;
                }
                else if (defaultMshSnapinInfo.AssemblyName.Equals("Microsoft.PowerShell.Commands.Diagnostics",
                    StringComparison.OrdinalIgnoreCase))
                {
                    types = new Collection<string>(new string[] { "GetEvent.types.ps1xml" });
                    formats = new Collection<string>(new string[] { "Event.format.ps1xml", "Diagnostics.format.ps1xml" });
                }
                else if (defaultMshSnapinInfo.AssemblyName.Equals("Microsoft.WSMan.Management", StringComparison.OrdinalIgnoreCase))
                {
                    formats = new Collection<string>(new string[] { "WSMan.format.ps1xml" });
                }

                string moduleName = Path.Combine(applicationBase, defaultMshSnapinInfo.AssemblyName + ".dll");

                if (File.Exists(moduleName))
                {
                    moduleName = Path.Combine(applicationBase, defaultMshSnapinInfo.AssemblyName + ".dll");
                }
                else
                {
                    moduleName = defaultMshSnapinInfo.AssemblyName;
                }

                PSSnapInInfo defaultMshSnapin = new PSSnapInInfo(defaultMshSnapinInfo.PSSnapInName, true, applicationBase,
                    strongName, moduleName, psVersion, assemblyVersion, types, formats, null,
                    defaultMshSnapinInfo.Description, defaultMshSnapinInfo.DescriptionIndirect, null, null,
                    defaultMshSnapinInfo.VendorIndirect, null);

                SetSnapInLoggingInformation(defaultMshSnapin);
                engineMshSnapins.Add(defaultMshSnapin);
            }

            return engineMshSnapins;
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Constructor for the ProviderInfo class.
        /// </summary>
        /// 
        /// <param name="sessionState">
        /// The instance of session state that the provider is being added to.
        /// </param>
        /// 
        /// <param name="implementingType">
        /// The type that implements the provider
        /// </param>
        /// 
        /// <param name="name">
        /// The alternate name to use for the provider instead of the one specified
        /// in the .cmdletprovider file.
        /// </param>
        /// 
        /// <param name="description">
        /// The description of the provider.
        /// </param>
        /// 
        /// <param name="home">
        /// The home path for the provider. This must be an MSH path.
        /// </param>
        /// 
        /// <param name="helpFile">
        /// The help file for the provider.
        /// </param>
        /// 
        /// <param name="psSnapIn">
        /// The Snap-In for the provider.
        /// </param>
        /// 
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="implementingType"/> or <paramref name="sessionState"/> is null.
        /// </exception>
        /// 
        /// <exception cref="ArgumentException">
        /// If <paramref name="name"/> is null or empty.
        /// </exception>
        /// 
        internal ProviderInfo(
            SessionState sessionState,
            Type implementingType,
            string name,
            string description,
            string home,
            string helpFile,
            PSSnapInInfo psSnapIn)
        {
            // Verify parameters
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

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

            if (String.IsNullOrEmpty(name))
            {
                throw PSTraceSource.NewArgumentException("name");
            }


            if (String.IsNullOrEmpty(name))
            {
                throw PSTraceSource.NewArgumentException("name");
            }

            _sessionState = sessionState;

            Name = name;
            Description = description;
            Home = home;
            ImplementingType = implementingType;
            HelpFile = helpFile;
            PSSnapIn = psSnapIn;

#if SUPPORTS_CMDLETPROVIDER_FILE
            LoadProviderFromPath(path);
#endif
            // Create the hidden drive. The name doesn't really
            // matter since we are not adding this drive to a scope.

            _hiddenDrive =
                new PSDriveInfo(
                    this.FullName,
                    this,
                    "",
                    "",
                    null);

            _hiddenDrive.Hidden = true;

            // TODO:PSL
            // this is probably not right here
            if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows)
            {
                VolumeSeparatedByColon = false;
            }
        }
Ejemplo n.º 35
0
        private ProviderInfo AddProvider(Type implementingType, string name, string helpFileName, PSSnapInInfo psSnapIn, PSModuleInfo module)
        {
            ProviderInfo provider = null;

            try
            {
                provider =
                    new ProviderInfo(
                        new SessionState(this),
                        implementingType,
                        name,
                        helpFileName,
                        psSnapIn);
                provider.SetModule(module);

                NewProvider(provider);

                // Log the provider start event

                MshLog.LogProviderLifecycleEvent(
                    this.ExecutionContext,
                    provider.Name,
                    ProviderState.Started);
            }
            catch (LoopFlowException)
            {
                throw;
            }
            catch (PipelineStoppedException)
            {
                throw;
            }
            catch (ActionPreferenceStopException)
            {
                throw;
            }
            catch (SessionStateException sessionStateException)
            {
                if (sessionStateException.GetType() == typeof(SessionStateException))
                {
                    throw;
                }
                else
                {
                    // NTRAID#Windows OS Bugs-1009281-2004/02/11-JeffJon
                    this.ExecutionContext.ReportEngineStartupError(sessionStateException);
                }
            }
            catch (Exception e) // Catch-all OK, 3rd party callout
            {
                CommandProcessorBase.CheckForSevereException(e);

                // NTRAID#Windows OS Bugs-1009281-2004/02/11-JeffJon
                this.ExecutionContext.ReportEngineStartupError(e);
            }
            return provider;
        }
Ejemplo n.º 36
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description, string home, string helpFile, PSSnapInInfo psSnapIn)
 {
     _sessionState    = sessionState;
     PSSnapIn         = psSnapIn;
     Name             = name;
     Description      = description;
     Home             = home;
     ImplementingType = implementingType;
     Capabilities     = GetCapabilities(implementingType);
     HelpFile         = helpFile;
 }
Ejemplo n.º 37
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string helpFile, PSSnapInInfo psSnapIn)
     : this(sessionState, implementingType, name, string.Empty, string.Empty, helpFile, psSnapIn)
 {
 }
Ejemplo n.º 38
0
        /// <summary>
        /// Load help file provided.
        /// </summary>
        /// <remarks>
        /// This will load providerHelpInfo from help file into help cache.
        /// </remarks>
        /// <param name="providerInfo">providerInfo for which to locate help.</param>
        private void LoadHelpFile(ProviderInfo providerInfo)
        {
            if (providerInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("providerInfo");
            }

            string helpFile = providerInfo.HelpFile;

            if (String.IsNullOrEmpty(helpFile) || _helpFiles.Contains(helpFile))
            {
                return;
            }

            string helpFileToLoad = helpFile;

            // Get the mshsnapinfo object for this cmdlet.
            PSSnapInInfo mshSnapInInfo = providerInfo.PSSnapIn;

            // Search fallback
            // 1. If PSSnapInInfo exists, then always look in the application base
            //    of the mshsnapin
            // Otherwise,
            //    Look in the default search path and cmdlet assembly path
            Collection <String> searchPaths = new Collection <String>();

            if (mshSnapInInfo != null)
            {
                Diagnostics.Assert(!string.IsNullOrEmpty(mshSnapInInfo.ApplicationBase),
                                   "Application Base is null or empty.");
                // not minishell case..
                // we have to search only in the application base for a mshsnapin...
                // if you create an absolute path for helpfile, then MUIFileSearcher
                // will look only in that path.
                helpFileToLoad = Path.Combine(mshSnapInInfo.ApplicationBase, helpFile);
            }
            else if ((providerInfo.Module != null) && (!string.IsNullOrEmpty(providerInfo.Module.Path)))
            {
                helpFileToLoad = Path.Combine(providerInfo.Module.ModuleBase, helpFile);
            }
            else
            {
                searchPaths.Add(GetDefaultShellSearchPath());
                searchPaths.Add(GetProviderAssemblyPath(providerInfo));
            }

            string location = MUIFileSearcher.LocateFile(helpFileToLoad, searchPaths);

            if (String.IsNullOrEmpty(location))
            {
                throw new FileNotFoundException(helpFile);
            }

            XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument(
                new FileInfo(location),
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */

            // Add this file into _helpFiles hashtable to prevent it to be loaded again.
            _helpFiles[helpFile] = 0;

            XmlNode helpItemsNode = null;

            if (doc.HasChildNodes)
            {
                for (int i = 0; i < doc.ChildNodes.Count; i++)
                {
                    XmlNode node = doc.ChildNodes[i];
                    if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                return;
            }

            using (this.HelpSystem.Trace(location))
            {
                if (helpItemsNode.HasChildNodes)
                {
                    for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++)
                    {
                        XmlNode node = helpItemsNode.ChildNodes[i];
                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = ProviderHelpInfo.Load(node);

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                // Add snapin qualified type name for this command..
                                // this will enable customizations of the help object.
                                helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture,
                                                                                    "ProviderHelpInfo#{0}#{1}", providerInfo.PSSnapInName, helpInfo.Name));

                                if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                                {
                                    helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn));
                                    helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture,
                                                                                        "ProviderHelpInfo#{0}", providerInfo.PSSnapInName));
                                }
                                AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 39
0
 // internals
 internal RunspaceConfigurationEntry(string name, PSSnapInInfo psSnapin)
 {
     Name = name;
     PSSnapIn = psSnapin;
 }
Ejemplo n.º 40
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string description, string home, string helpFile, PSSnapInInfo psSnapIn)
 {
     this.helpFile = "";
     if (sessionState == null)
     {
         throw PSTraceSource.NewArgumentNullException("sessionState");
     }
     if (implementingType == null)
     {
         throw PSTraceSource.NewArgumentNullException("implementingType");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     if (string.IsNullOrEmpty(name))
     {
         throw PSTraceSource.NewArgumentException("name");
     }
     this.sessionState       = sessionState;
     this.name               = name;
     this.description        = description;
     this.home               = home;
     this.implementingType   = implementingType;
     this.helpFile           = helpFile;
     this.pssnapin           = psSnapIn;
     this.hiddenDrive        = new PSDriveInfo(this.FullName, this, "", "", null);
     this.hiddenDrive.Hidden = true;
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Adds the PSSnapIn by name/path
 /// </summary>
 /// <exception cref="PSArgumentException">If loading the snapin fails (e.g. invalid name/path)</exception>
 /// <param name="name">Either the name of the registered snapin or a path to an assembly</param>
 /// <returns>The newly added PSSnapIn</returns>
 internal PSSnapInInfo AddPSSnapIn(string name)
 {
     // a slash is not part of a valid snapin name. If the name contains a slash (e.g. "./foobar") its likely
     // that the user wants to load an assembly directly
     Assembly assembly = null;
     if (name.Contains(PathIntrinsics.CorrectSlash) || name.Contains(PathIntrinsics.WrongSlash))
     {
         assembly = LoadAssemblyFromFile(name);
     }
     else
     {
         assembly = LoadRegisteredPSSnapInAssembly(name);
     }
     //load snapins from assembly and make sure it's only one snapin class defined in thwere
     var snapins = from Type type in assembly.GetTypes()
                   where type.IsSubclassOf(typeof(PSSnapIn))
                   select type;
     if (snapins.Count() != 1)
     {
         string errorMsg = "The assembly '{0}' contains either no or more than one PSSnapIn class!";
         throw new PSSnapInException(String.Format(errorMsg, assembly.FullName));
     }
     PSSnapIn snapin = (PSSnapIn) Activator.CreateInstance(snapins.First());
     //okay, we got the new snapin. now load it
     PSSnapInInfo snapinInfo = new PSSnapInInfo(snapin, assembly, false);
     LoadPSSnapIn(snapinInfo, assembly);
     return snapinInfo;
 }
Ejemplo n.º 42
0
 internal CmdletInfo(string name, Type implementingType, string helpFile, PSSnapInInfo snapin)
     : this(name, implementingType, helpFile, snapin, null)
 {
 }
Ejemplo n.º 43
0
        private void LoadProvidersFromAssembly(Assembly assembly, PSSnapInInfo snapinInfo)
        {
            // first get name and type of all providers in this assembly
            var providers = from Type type in assembly.GetTypes()
                where !type.IsSubclassOf(typeof(Cmdlet))
                    where type.IsSubclassOf(typeof(CmdletProvider))
                    from CmdletProviderAttribute providerAttr in
                    type.GetCustomAttributes(typeof(CmdletProviderAttribute), true)
                    select new KeyValuePair<string, Type>(providerAttr.ProviderName, type);
            // then initialize all providers
            foreach (var curPair in providers)
            {
                ProviderInfo providerInfo = new ProviderInfo(_executionContext.SessionState, curPair.Value,
                                                             curPair.Key, string.Empty, snapinInfo);
                CmdletProvider provider = AddProvider(providerInfo);
                InitializeProvider(provider, providerInfo);

                // Cache the provider's instance
                if (!_providerInstances.ContainsKey(providerInfo.Name))
                {
                    _providerInstances.Add(providerInfo.Name, new List<CmdletProvider>());
                }
                List<CmdletProvider> instanceList = _providerInstances[providerInfo.Name];
                instanceList.Add(provider);
            }
        }
Ejemplo n.º 44
0
        internal static Collection <PSSnapInInfo> ReadEnginePSSnapIns()
        {
            string   str1              = PSSnapInReader.ReadStringValue(PSSnapInReader.GetPSEngineKey(PSVersionInfo.RegistryVersionKey), "ApplicationBase", true);
            Version  psVersion         = PSVersionInfo.PSVersion;
            Assembly executingAssembly = Assembly.GetExecutingAssembly();
            Version  version           = executingAssembly.GetName().Version;

            byte[] publicKeyToken           = executingAssembly.GetName().GetPublicKeyToken();
            string str2                     = publicKeyToken.Length != 0 ? PSSnapInReader.ConvertByteArrayToString(publicKeyToken) : throw PSSnapInReader._tracer.NewArgumentException("PublicKeyToken", "MshSnapinInfo", "PublicKeyTokenAccessFailed");
            string str3                     = "neutral";
            string str4                     = executingAssembly.GetName().ProcessorArchitecture.ToString();
            Collection <string> collection1 = new Collection <string>((IList <string>) new string[7]
            {
                "Certificate.format.ps1xml",
                "DotNetTypes.format.ps1xml",
                "FileSystem.format.ps1xml",
                "Help.format.ps1xml",
                "PowerShellCore.format.ps1xml",
                "PowerShellTrace.format.ps1xml",
                "Registry.format.ps1xml"
            });
            Collection <string> collection2 = new Collection <string>((IList <string>) new string[1]
            {
                "types.ps1xml"
            });
            Collection <PSSnapInInfo> collection3 = new Collection <PSSnapInInfo>();

            for (int index = 0; index < PSSnapInReader._defaultMshSnapins.Length; ++index)
            {
                PSSnapInReader.DefaultPSSnapInInformation defaultMshSnapin = PSSnapInReader._defaultMshSnapins[index];
                string assemblyName         = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}, Version={1}, Culture={2}, PublicKeyToken={3}, ProcessorArchitecture={4}", (object)defaultMshSnapin.AssemblyName, (object)version.ToString(), (object)str3, (object)str2, (object)str4);
                Collection <string> formats = (Collection <string>)null;
                Collection <string> types   = (Collection <string>)null;
                if (defaultMshSnapin.AssemblyName.Equals("System.Management.Automation", StringComparison.OrdinalIgnoreCase))
                {
                    formats = collection1;
                    types   = collection2;
                }
                else if (defaultMshSnapin.AssemblyName.Equals("Microsoft.PowerShell.Commands.Diagnostics", StringComparison.OrdinalIgnoreCase))
                {
                    types = new Collection <string>((IList <string>) new string[1]
                    {
                        "GetEvent.types.ps1xml"
                    });
                    formats = new Collection <string>((IList <string>) new string[1]
                    {
                        "Diagnostics.Format.ps1xml"
                    });
                }
                else if (defaultMshSnapin.AssemblyName.Equals("Microsoft.WSMan.Management", StringComparison.OrdinalIgnoreCase))
                {
                    formats = new Collection <string>((IList <string>) new string[1]
                    {
                        "WSMan.format.ps1xml"
                    });
                }
                string       moduleName   = Path.Combine(str1, defaultMshSnapin.AssemblyName + ".dll");
                PSSnapInInfo psSnapInInfo = new PSSnapInInfo(defaultMshSnapin.PSSnapInName, true, str1, assemblyName, moduleName, psVersion, version, types, formats, (string)null, defaultMshSnapin.Description, defaultMshSnapin.DescriptionIndirect, (string)null, (string)null, defaultMshSnapin.VendorIndirect, (string)null);
                collection3.Add(psSnapInInfo);
                PSSnapInReader._tracer.WriteLine("Constructed PSSnapInInfo object for default mshsnapin {0}.", (object)defaultMshSnapin.PSSnapInName);
            }
            return(collection3);
        }
 internal void Load(Assembly assembly, ExecutionContext executionContext, PSSnapInInfo snapinInfo)
 {
     Load(assembly, executionContext, snapinInfo, null);
 }
Ejemplo n.º 46
0
 internal void SetPSSnapIn(PSSnapInInfo psSnapIn)
 {
     this._psSnapIn = psSnapIn;
 }
Ejemplo n.º 47
0
 private void LoadHelpFile(ProviderInfo providerInfo)
 {
     using (ProviderHelpProvider.tracer.TraceMethod())
     {
         string str1 = providerInfo != null ? providerInfo.HelpFile : throw ProviderHelpProvider.tracer.NewArgumentNullException(nameof(providerInfo));
         if (string.IsNullOrEmpty(str1) || this._helpFiles.Contains((object)str1))
         {
             return;
         }
         string              file        = str1;
         PSSnapInInfo        psSnapIn    = providerInfo.PSSnapIn;
         Collection <string> searchPaths = new Collection <string>();
         if (psSnapIn != null)
         {
             file = Path.Combine(psSnapIn.ApplicationBase, str1);
         }
         else if (providerInfo.Module != null && !string.IsNullOrEmpty(providerInfo.Module.Path))
         {
             file = Path.Combine(providerInfo.Module.ModuleBase, str1);
         }
         else
         {
             searchPaths.Add(this.GetDefaultShellSearchPath());
             searchPaths.Add(ProviderHelpProvider.GetProviderAssemblyPath(providerInfo));
         }
         string str2 = MUIFileSearcher.LocateFile(file, searchPaths);
         if (string.IsNullOrEmpty(str2))
         {
             throw new FileNotFoundException(str1);
         }
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(str2);
         this._helpFiles[(object)str1] = (object)0;
         XmlNode xmlNode = (XmlNode)null;
         if (xmlDocument.HasChildNodes)
         {
             for (int i = 0; i < xmlDocument.ChildNodes.Count; ++i)
             {
                 XmlNode childNode = xmlDocument.ChildNodes[i];
                 if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     xmlNode = childNode;
                     break;
                 }
             }
         }
         if (xmlNode == null)
         {
             return;
         }
         using (this.HelpSystem.Trace(str2))
         {
             if (!xmlNode.HasChildNodes)
             {
                 return;
             }
             for (int i = 0; i < xmlNode.ChildNodes.Count; ++i)
             {
                 XmlNode childNode = xmlNode.ChildNodes[i];
                 if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     HelpInfo helpInfo = (HelpInfo)ProviderHelpInfo.Load(childNode);
                     if (helpInfo != null)
                     {
                         this.HelpSystem.TraceErrors(helpInfo.Errors);
                         helpInfo.FullHelp.TypeNames.Insert(0, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}#{1}", (object)providerInfo.PSSnapInName, (object)helpInfo.Name));
                         if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                         {
                             helpInfo.FullHelp.Properties.Add((PSPropertyInfo) new PSNoteProperty("PSSnapIn", (object)providerInfo.PSSnapIn));
                             helpInfo.FullHelp.TypeNames.Insert(1, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}", (object)providerInfo.PSSnapInName));
                         }
                         this.AddCache(providerInfo.PSSnapInName + "\\" + helpInfo.Name, helpInfo);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 48
0
 internal ProviderInfo(SessionState sessionState, Type implementingType, string name, string helpFile, PSSnapInInfo psSnapIn)
     : this(sessionState, implementingType, name, string.Empty, string.Empty, helpFile, psSnapIn)
 {
 }
Ejemplo n.º 49
0
        private void LoadHelpFile(ProviderInfo providerInfo)
        {
            if (providerInfo == null)
            {
                throw PSTraceSource.NewArgumentNullException("providerInfo");
            }
            string helpFile = providerInfo.HelpFile;

            if (!string.IsNullOrEmpty(helpFile) && !this._helpFiles.Contains(helpFile))
            {
                string              file        = helpFile;
                PSSnapInInfo        pSSnapIn    = providerInfo.PSSnapIn;
                Collection <string> searchPaths = new Collection <string>();
                if (pSSnapIn != null)
                {
                    file = Path.Combine(pSSnapIn.ApplicationBase, helpFile);
                }
                else if ((providerInfo.Module != null) && !string.IsNullOrEmpty(providerInfo.Module.Path))
                {
                    file = Path.Combine(providerInfo.Module.ModuleBase, helpFile);
                }
                else
                {
                    searchPaths.Add(base.GetDefaultShellSearchPath());
                    searchPaths.Add(GetProviderAssemblyPath(providerInfo));
                }
                string str3 = MUIFileSearcher.LocateFile(file, searchPaths);
                if (string.IsNullOrEmpty(str3))
                {
                    throw new FileNotFoundException(helpFile);
                }
                XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(str3), false, null);
                this._helpFiles[helpFile] = 0;
                System.Xml.XmlNode node = null;
                if (document.HasChildNodes)
                {
                    for (int i = 0; i < document.ChildNodes.Count; i++)
                    {
                        System.Xml.XmlNode node2 = document.ChildNodes[i];
                        if ((node2.NodeType == XmlNodeType.Element) && (string.Compare(node2.Name, "helpItems", StringComparison.OrdinalIgnoreCase) == 0))
                        {
                            node = node2;
                            break;
                        }
                    }
                }
                if (node != null)
                {
                    using (base.HelpSystem.Trace(str3))
                    {
                        if (node.HasChildNodes)
                        {
                            for (int j = 0; j < node.ChildNodes.Count; j++)
                            {
                                System.Xml.XmlNode xmlNode = node.ChildNodes[j];
                                if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.Name, "providerHelp", StringComparison.OrdinalIgnoreCase) == 0))
                                {
                                    HelpInfo helpInfo = ProviderHelpInfo.Load(xmlNode);
                                    if (helpInfo != null)
                                    {
                                        base.HelpSystem.TraceErrors(helpInfo.Errors);
                                        helpInfo.FullHelp.TypeNames.Insert(0, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}#{1}", new object[] { providerInfo.PSSnapInName, helpInfo.Name }));
                                        if (!string.IsNullOrEmpty(providerInfo.PSSnapInName))
                                        {
                                            helpInfo.FullHelp.Properties.Add(new PSNoteProperty("PSSnapIn", providerInfo.PSSnapIn));
                                            helpInfo.FullHelp.TypeNames.Insert(1, string.Format(CultureInfo.InvariantCulture, "ProviderHelpInfo#{0}", new object[] { providerInfo.PSSnapInName }));
                                        }
                                        base.AddCache(providerInfo.PSSnapInName + @"\" + helpInfo.Name, helpInfo);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 50
0
        /// <summary>
        /// Constructor for the ProviderInfo class.
        /// </summary>
        ///
        /// <param name="sessionState">
        /// The instance of session state that the provider is being added to.
        /// </param>
        ///
        /// <param name="implementingType">
        /// The type that implements the provider
        /// </param>
        ///
        /// <param name="name">
        /// The alternate name to use for the provider instead of the one specified
        /// in the .cmdletprovider file.
        /// </param>
        ///
        /// <param name="description">
        /// The description of the provider.
        /// </param>
        ///
        /// <param name="home">
        /// The home path for the provider. This must be an MSH path.
        /// </param>
        ///
        /// <param name="helpFile">
        /// The help file for the provider.
        /// </param>
        ///
        /// <param name="psSnapIn">
        /// The Snap-In for the provider.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="implementingType"/> or <paramref name="sessionState"/> is null.
        /// </exception>
        ///
        /// <exception cref="ArgumentException">
        /// If <paramref name="name"/> is null or empty.
        /// </exception>
        ///
        internal ProviderInfo(
            SessionState sessionState,
            Type implementingType,
            string name,
            string description,
            string home,
            string helpFile,
            PSSnapInInfo psSnapIn)
        {
            // Verify parameters
            if (sessionState == null)
            {
                throw PSTraceSource.NewArgumentNullException("sessionState");
            }

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

            if (String.IsNullOrEmpty(name))
            {
                throw PSTraceSource.NewArgumentException("name");
            }


            if (String.IsNullOrEmpty(name))
            {
                throw PSTraceSource.NewArgumentException("name");
            }

            _sessionState = sessionState;

            Name = name;
            Description = description;
            Home = home;
            ImplementingType = implementingType;
            HelpFile = helpFile;
            PSSnapIn = psSnapIn;

#if SUPPORTS_CMDLETPROVIDER_FILE
            LoadProviderFromPath(path);
#endif
            // Create the hidden drive. The name doesn't really
            // matter since we are not adding this drive to a scope.

            _hiddenDrive =
                new PSDriveInfo(
                    this.FullName,
                    this,
                    "",
                    "",
                    null);

            _hiddenDrive.Hidden = true;

            // TODO:PSL
            // this is probably not right here
            if (implementingType == typeof(Microsoft.PowerShell.Commands.FileSystemProvider) && !Platform.IsWindows)
            {
                VolumeSeparatedByColon = false;
            }
        }