private void LoadHelpFile(string helpFile, string helpFileIdentifier)
        {
            XmlDocument document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(helpFile), false, null);

            this._helpFiles[helpFile] = 0;
            System.Xml.XmlNode helpItemsNode = 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.LocalName, "helpItems", StringComparison.OrdinalIgnoreCase) == 0))
                    {
                        helpItemsNode = node2;
                        break;
                    }
                }
            }
            if (helpItemsNode == null)
            {
                tracer.WriteLine("Unable to find 'helpItems' element in file {0}", new object[] { helpFile });
            }
            else
            {
                bool flag = IsMamlHelp(helpFile, helpItemsNode);
                using (base.HelpSystem.Trace(helpFile))
                {
                    if (helpItemsNode.HasChildNodes)
                    {
                        for (int j = 0; j < helpItemsNode.ChildNodes.Count; j++)
                        {
                            System.Xml.XmlNode xmlNode = helpItemsNode.ChildNodes[j];
                            if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.LocalName, "command", StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                MamlCommandHelpInfo helpInfo = null;
                                if (flag)
                                {
                                    helpInfo = MamlCommandHelpInfo.Load(xmlNode, System.Management.Automation.HelpCategory.Cmdlet);
                                }
                                if (helpInfo != null)
                                {
                                    base.HelpSystem.TraceErrors(helpInfo.Errors);
                                    this.AddToCommandCache(helpFileIdentifier, helpInfo.Name, helpInfo);
                                }
                            }
                            if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.Name, "UserDefinedData", StringComparison.OrdinalIgnoreCase) == 0))
                            {
                                UserDefinedHelpData userDefinedHelpData = UserDefinedHelpData.Load(xmlNode);
                                this.ProcessUserDefineddHelpData(helpFileIdentifier, userDefinedHelpData);
                            }
                        }
                    }
                }
            }
        }
Beispiel #2
0
 internal static object DeserializeBoolean(InternalDeserializer deserializer)
 {
     object obj2;
     try
     {
         obj2 = XmlConvert.ToBoolean(deserializer._reader.ReadElementString());
     }
     catch (FormatException exception)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception, new object[] { typeof(bool).FullName });
     }
     return obj2;
 }
Beispiel #3
0
 internal Deserializer(XmlReader reader, DeserializationContext context)
 {
     this._reader       = reader != null ? reader : throw Deserializer._trace.NewArgumentNullException(nameof(reader));
     this._context      = context;
     this._deserializer = new InternalDeserializer(this._reader, this._context);
     try
     {
         this.Start();
     }
     catch (XmlException ex)
     {
         this.ReportExceptionForETW(ex);
         throw;
     }
 }
Beispiel #4
0
 internal static object DeserializeByte(InternalDeserializer deserializer)
 {
     Exception innerException = null;
     try
     {
         return XmlConvert.ToByte(deserializer._reader.ReadElementString());
     }
     catch (FormatException exception2)
     {
         innerException = exception2;
     }
     catch (OverflowException exception3)
     {
         innerException = exception3;
     }
     throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, innerException, new object[] { typeof(byte).FullName });
 }
Beispiel #5
0
 internal Deserializer(XmlReader reader, DeserializationContext context)
 {
     if (reader == null)
     {
         throw PSTraceSource.NewArgumentNullException("reader");
     }
     this._reader       = reader;
     this._context      = context;
     this._deserializer = new InternalDeserializer(this._reader, this._context);
     try
     {
         this.Start();
     }
     catch (XmlException exception)
     {
         ReportExceptionForETW(exception);
         throw;
     }
 }
Beispiel #6
0
 internal Deserializer(XmlReader reader, DeserializationContext context)
 {
     if (reader == null)
     {
         throw PSTraceSource.NewArgumentNullException("reader");
     }
     this._reader = reader;
     this._context = context;
     this._deserializer = new InternalDeserializer(this._reader, this._context);
     try
     {
         this.Start();
     }
     catch (XmlException exception)
     {
         ReportExceptionForETW(exception);
         throw;
     }
 }
Beispiel #7
0
 internal static object DeserializeUri(InternalDeserializer deserializer)
 {
     object obj2;
     try
     {
         obj2 = new Uri(deserializer.ReadDecodedElementString("URI"), UriKind.RelativeOrAbsolute);
     }
     catch (UriFormatException exception)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception, new object[] { typeof(Uri).FullName });
     }
     return obj2;
 }
Beispiel #8
0
 internal static object DeserializeString(InternalDeserializer deserializer)
 {
     return deserializer.ReadDecodedElementString("S");
 }
Beispiel #9
0
 internal static object DeserializeSecureString(InternalDeserializer deserializer)
 {
     return deserializer.ReadSecureString();
 }
Beispiel #10
0
 internal static object DeserializeScriptBlock(InternalDeserializer deserializer)
 {
     string script = deserializer.ReadDecodedElementString("SBK");
     if (DeserializationOptions.DeserializeScriptBlocks == (deserializer._context.options & DeserializationOptions.DeserializeScriptBlocks))
     {
         return ScriptBlock.Create(script);
     }
     return script;
 }
        /// <summary>
        /// Get provider specific help info.
        /// </summary>
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            if (InternalTestHooks.BypassOnlineHelpRetrieval)
            {
                // By returning null, we force get-help to return generic help
                // which includes a helpUri that points to the fwlink defined in the cmdlet code.
                return(null);
            }

            // Get the provider.
            ProviderInfo          providerInfo          = null;
            PSDriveInfo           driveInfo             = null;
            string                resolvedProviderPath  = null;
            CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext);

            try
            {
                string psPath = _requestedPath;
                if (string.IsNullOrEmpty(_requestedPath))
                {
                    psPath = _pathIntrinsics.CurrentLocation.Path;
                }

                resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath(
                    psPath,
                    cmdletProviderContext,
                    out providerInfo,
                    out driveInfo);
            }
            // ignore exceptions caused by provider resolution
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }

            if (providerInfo == null)
            {
                return(null);
            }

            // Does the provider know how to generate MAML.
            CmdletProvider cmdletProvider        = providerInfo.CreateInstance();
            ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp;

            // Under JEA sessions the resolvedProviderPath will be null, we should allow get-help to continue.
            if (provider == null)
            {
                return(null);
            }

            bool isJEASession = false;

            if (this._executionContext.InitialSessionState != null && this._executionContext.InitialSessionState.Providers != null && providerInfo != null)
            {
                foreach (
                    Runspaces.SessionStateProviderEntry sessionStateProvider in
                    this._executionContext.InitialSessionState.Providers[providerInfo.Name])
                {
                    if (sessionStateProvider.Visibility == SessionStateEntryVisibility.Private)
                    {
                        isJEASession = true;
                        break;
                    }
                }
            }

            if (resolvedProviderPath == null)
            {
                if (isJEASession)
                {
                    return(null);
                }
                else
                {
                    throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
                }
            }

            // ok we have path and valid provider that supplys content..initialize the provider
            // and get the help content for the path.
            cmdletProvider.Start(providerInfo, cmdletProviderContext);
            // There should be exactly one resolved path.
            string providerPath = resolvedProviderPath;
            // Get the MAML help info. Don't catch exceptions thrown by provider.
            string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath);

            if (string.IsNullOrEmpty(mamlXmlString))
            {
                return(null);
            }
            // process the MAML content only if it is non-empty.
            XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument(
                mamlXmlString,
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */
            MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider);

            return(providerSpecificHelpInfo);
        }
Beispiel #12
0
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            ProviderInfo          info    = null;
            PSDriveInfo           drive   = null;
            string                str     = null;
            CmdletProviderContext context = new CmdletProviderContext(this._executionContext);

            try
            {
                string str2 = this._requestedPath;
                if (string.IsNullOrEmpty(this._requestedPath))
                {
                    str2 = this._pathIntrinsics.CurrentLocation.Path;
                }
                str = this._executionContext.LocationGlobber.GetProviderPath(str2, context, out info, out drive);
            }
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }
            if (info == null)
            {
                return(null);
            }
            CmdletProvider provider          = info.CreateInstance();
            ICmdletProviderSupportsHelp help = provider as ICmdletProviderSupportsHelp;

            if (help == null)
            {
                return(null);
            }
            if (str == null)
            {
                throw new ItemNotFoundException(this._requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
            }
            provider.Start(info, context);
            string path     = str;
            string helpMaml = help.GetHelpMaml(helpItemName, path);

            if (string.IsNullOrEmpty(helpMaml))
            {
                return(null);
            }
            return(MamlCommandHelpInfo.Load(InternalDeserializer.LoadUnsafeXmlDocument(helpMaml, false, null).DocumentElement, HelpCategory.Provider));
        }
        /// <summary>
        /// Get provider specific help info.
        /// </summary>
        internal MamlCommandHelpInfo GetProviderSpecificHelpInfo(string helpItemName)
        {
            // Get the provider.
            ProviderInfo          providerInfo          = null;
            PSDriveInfo           driveInfo             = null;
            string                resolvedProviderPath  = null;
            CmdletProviderContext cmdletProviderContext = new CmdletProviderContext(_executionContext);

            try
            {
                string psPath = _requestedPath;
                if (string.IsNullOrEmpty(_requestedPath))
                {
                    psPath = _pathIntrinsics.CurrentLocation.Path;
                }

                resolvedProviderPath = _executionContext.LocationGlobber.GetProviderPath(
                    psPath,
                    cmdletProviderContext,
                    out providerInfo,
                    out driveInfo);
            }
            // ignore exceptions caused by provider resolution
            catch (ArgumentNullException)
            {
            }
            catch (ProviderNotFoundException)
            {
            }
            catch (DriveNotFoundException)
            {
            }
            catch (ProviderInvocationException)
            {
            }
            catch (NotSupportedException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            catch (ItemNotFoundException)
            {
            }

            if (providerInfo == null)
            {
                return(null);
            }

            // Does the provider know how to generate MAML.
            CmdletProvider cmdletProvider        = providerInfo.CreateInstance();
            ICmdletProviderSupportsHelp provider = cmdletProvider as ICmdletProviderSupportsHelp;

            if (provider == null)
            {
                return(null);
            }

            if (resolvedProviderPath == null)
            {
                throw new ItemNotFoundException(_requestedPath, "PathNotFound", SessionStateStrings.PathNotFound);
            }

            // ok we have path and valid provider that supplys content..initialize the provider
            // and get the help content for the path.
            cmdletProvider.Start(providerInfo, cmdletProviderContext);
            // There should be exactly one resolved path.
            string providerPath = resolvedProviderPath;
            // Get the MAML help info. Don't catch exceptions thrown by provider.
            string mamlXmlString = provider.GetHelpMaml(helpItemName, providerPath);

            if (string.IsNullOrEmpty(mamlXmlString))
            {
                return(null);
            }
            // process the MAML content only if it is non-empty.
            XmlDocument mamlDoc = InternalDeserializer.LoadUnsafeXmlDocument(
                mamlXmlString,
                false, /* ignore whitespace, comments, etc. */
                null); /* default maxCharactersInDocument */
            MamlCommandHelpInfo providerSpecificHelpInfo = MamlCommandHelpInfo.Load(mamlDoc.DocumentElement, HelpCategory.Provider);

            return(providerSpecificHelpInfo);
        }
Beispiel #14
0
        /// <summary>
        /// Load help file for HelpInfo objects. The HelpInfo objects will be
        /// put into help cache.
        /// </summary>
        /// <remarks>
        /// 1. Needs to pay special attention about error handling in this function.
        /// Common errors include: file not found and invalid xml. None of these error
        /// should cause help search to stop.
        /// </remarks>
        /// <param name="helpFile"></param>
        private void LoadHelpFile(string helpFile)
        {
            if (String.IsNullOrEmpty(helpFile))
            {
                return;
            }

            XmlDocument doc;

            try
            {
                doc = InternalDeserializer.LoadUnsafeXmlDocument(
                    new FileInfo(helpFile),
                    false, /* ignore whitespace, comments, etc. */
                    null); /* default maxCharactersInDocument */
            }
            catch (IOException ioException)
            {
                ErrorRecord errorRecord = new ErrorRecord(ioException, "HelpFileLoadFailure", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileLoadFailure", helpFile, ioException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (System.Security.SecurityException securityException)
            {
                ErrorRecord errorRecord = new ErrorRecord(securityException, "HelpFileNotAccessible", ErrorCategory.OpenError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotAccessible", helpFile, securityException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }
            catch (XmlException xmlException)
            {
                ErrorRecord errorRecord = new ErrorRecord(xmlException, "HelpFileNotValid", ErrorCategory.SyntaxError, null);
                errorRecord.ErrorDetails = new ErrorDetails(typeof(FaqHelpProvider).GetTypeInfo().Assembly, "HelpErrors", "HelpFileNotValid", helpFile, xmlException.Message);
                this.HelpSystem.LastErrors.Add(errorRecord);
                return;
            }

            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, "faq", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                return;
            }

            using (this.HelpSystem.Trace(helpFile))
            {
                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, "faqEntry", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = null;

                            helpInfo = FaqHelpInfo.Load(node);

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                AddCache(helpInfo.Name, helpInfo);
                            }
                            continue;
                        }

                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "faqDiv", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            LoadFaqDiv(node);
                        }
                    }
                }
            }
        }
Beispiel #15
0
 private void LoadHelpFile(string helpFile)
 {
     if (!string.IsNullOrEmpty(helpFile))
     {
         XmlDocument document;
         try
         {
             document = InternalDeserializer.LoadUnsafeXmlDocument(new FileInfo(helpFile), false, null);
         }
         catch (IOException exception)
         {
             ErrorRecord item = new ErrorRecord(exception, "HelpFileLoadFailure", ErrorCategory.OpenError, null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileLoadFailure", new object[] { helpFile, exception.Message })
             };
             base.HelpSystem.LastErrors.Add(item);
             return;
         }
         catch (SecurityException exception2)
         {
             ErrorRecord record2 = new ErrorRecord(exception2, "HelpFileNotAccessible", ErrorCategory.OpenError, null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotAccessible", new object[] { helpFile, exception2.Message })
             };
             base.HelpSystem.LastErrors.Add(record2);
             return;
         }
         catch (XmlException exception3)
         {
             ErrorRecord record3 = new ErrorRecord(exception3, "HelpFileNotValid", ErrorCategory.SyntaxError, null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotValid", new object[] { helpFile, exception3.Message })
             };
             base.HelpSystem.LastErrors.Add(record3);
             return;
         }
         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, "conceptuals", StringComparison.OrdinalIgnoreCase) == 0))
                 {
                     node = node2;
                     break;
                 }
             }
         }
         if (node != null)
         {
             using (base.HelpSystem.Trace(helpFile))
             {
                 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, "conceptual", StringComparison.OrdinalIgnoreCase) == 0))
                         {
                             HelpInfo helpInfo = null;
                             helpInfo = GeneralHelpInfo.Load(xmlNode);
                             if (helpInfo != null)
                             {
                                 base.HelpSystem.TraceErrors(helpInfo.Errors);
                                 base.AddCache(helpInfo.Name, helpInfo);
                             }
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #16
0
 internal static object DeserializeXmlDocument(InternalDeserializer deserializer)
 {
     object obj2;
     string xmlContents = deserializer.ReadDecodedElementString("XD");
     try
     {
         int? maxCharactersInDocument = null;
         if (deserializer._context.MaximumAllowedMemory.HasValue)
         {
             maxCharactersInDocument = new int?(deserializer._context.MaximumAllowedMemory.Value / 2);
         }
         XmlDocument document = LoadUnsafeXmlDocument(xmlContents, true, maxCharactersInDocument);
         deserializer._context.LogExtraMemoryUsage((xmlContents.Length - document.OuterXml.Length) * 2);
         obj2 = document;
     }
     catch (XmlException exception)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception, new object[] { typeof(XmlDocument).FullName });
     }
     return obj2;
 }
Beispiel #17
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);
                            }
                        }
                    }
                }
            }
        }
Beispiel #18
0
 internal static object DeserializeDateTime(InternalDeserializer deserializer)
 {
     object obj2;
     try
     {
         obj2 = XmlConvert.ToDateTime(deserializer._reader.ReadElementString(), XmlDateTimeSerializationMode.RoundtripKind);
     }
     catch (FormatException exception)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception, new object[] { typeof(DateTime).FullName });
     }
     return obj2;
 }
Beispiel #19
0
 internal static object DeserializeByteArray(InternalDeserializer deserializer)
 {
     object obj2;
     try
     {
         obj2 = Convert.FromBase64String(deserializer._reader.ReadElementString());
     }
     catch (FormatException exception)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception, new object[] { typeof(byte[]).FullName });
     }
     return obj2;
 }
Beispiel #20
0
 internal static object DeserializeProgressRecord(InternalDeserializer deserializer)
 {
     ProgressRecordType type;
     object obj3;
     deserializer.ReadStartElement("PR");
     string activity = null;
     string str2 = null;
     string str3 = null;
     string statusDescription = null;
     int activityId = 0;
     int num2 = 0;
     int num3 = 0;
     int num4 = 0;
     Exception innerException = null;
     try
     {
         activity = deserializer.ReadDecodedElementString("AV");
         activityId = int.Parse(deserializer.ReadDecodedElementString("AI"), CultureInfo.InvariantCulture);
         object obj2 = deserializer.ReadOneObject();
         str2 = (obj2 == null) ? null : obj2.ToString();
         num2 = int.Parse(deserializer.ReadDecodedElementString("PI"), CultureInfo.InvariantCulture);
         num3 = int.Parse(deserializer.ReadDecodedElementString("PC"), CultureInfo.InvariantCulture);
         str3 = deserializer.ReadDecodedElementString("T");
         num4 = int.Parse(deserializer.ReadDecodedElementString("SR"), CultureInfo.InvariantCulture);
         statusDescription = deserializer.ReadDecodedElementString("SD");
     }
     catch (FormatException exception2)
     {
         innerException = exception2;
     }
     catch (OverflowException exception3)
     {
         innerException = exception3;
     }
     if (innerException != null)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, innerException, new object[] { typeof(ulong).FullName });
     }
     deserializer.ReadEndElement();
     try
     {
         type = (ProgressRecordType) Enum.Parse(typeof(ProgressRecordType), str3, true);
     }
     catch (ArgumentException exception4)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception4, new object[] { typeof(ProgressRecord).FullName });
     }
     try
     {
         ProgressRecord record = new ProgressRecord(activityId, activity, statusDescription);
         if (!string.IsNullOrEmpty(str2))
         {
             record.CurrentOperation = str2;
         }
         record.ParentActivityId = num2;
         record.PercentComplete = num3;
         record.RecordType = type;
         record.SecondsRemaining = num4;
         obj3 = record;
     }
     catch (ArgumentException exception5)
     {
         throw deserializer.NewXmlException(Serialization.InvalidPrimitiveType, exception5, new object[] { typeof(ProgressRecord).FullName });
     }
     return obj3;
 }
Beispiel #21
0
        /// <summary>
        /// Load help file for HelpInfo objects. The HelpInfo objects will be
        /// put into help cache.
        /// </summary>
        /// <remarks>
        /// 1. Needs to pay special attention about error handling in this function.
        /// Common errors include: file not found and invalid xml. None of these error
        /// should cause help search to stop.
        /// 2. a helpfile cache is used to avoid same file got loaded again and again.
        /// </remarks>
        private void LoadHelpFile(string helpFile, string helpFileIdentifier)
        {
            Dbg.Assert(!string.IsNullOrEmpty(helpFile), "HelpFile cannot be null or empty.");
            Dbg.Assert(!string.IsNullOrEmpty(helpFileIdentifier), "helpFileIdentifier cannot be null or empty.");

            XmlDocument doc = InternalDeserializer.LoadUnsafeXmlDocument(
                new FileInfo(helpFile),
                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.Equals(node.LocalName, "helpItems", StringComparison.OrdinalIgnoreCase))
                    {
                        helpItemsNode = node;
                        break;
                    }
                }
            }

            if (helpItemsNode == null)
            {
                s_tracer.WriteLine("Unable to find 'helpItems' element in file {0}", helpFile);
                return;
            }

            bool isMaml = IsMamlHelp(helpFile, helpItemsNode);

            using (this.HelpSystem.Trace(helpFile))
            {
                if (helpItemsNode.HasChildNodes)
                {
                    for (int i = 0; i < helpItemsNode.ChildNodes.Count; i++)
                    {
                        XmlNode node = helpItemsNode.ChildNodes[i];

                        string nodeLocalName = node.LocalName;

                        bool isClass = (string.Equals(nodeLocalName, "class", StringComparison.OrdinalIgnoreCase));

                        if (node.NodeType == XmlNodeType.Element && isClass)
                        {
                            MamlClassHelpInfo helpInfo = null;

                            if (isMaml)
                            {
                                if (isClass)
                                {
                                    helpInfo = MamlClassHelpInfo.Load(node, HelpCategory.Class);
                                }
                            }

                            if (helpInfo != null)
                            {
                                this.HelpSystem.TraceErrors(helpInfo.Errors);
                                AddCache(helpFileIdentifier, helpInfo);
                            }
                        }
                    }
                }
            }
        }
Beispiel #22
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);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }