Ejemplo n.º 1
0
 private void LoadGlossaryDiv(XmlNode xmlNode)
 {
     if (xmlNode == null)
     {
         return;
     }
     for (int i = 0; i < xmlNode.ChildNodes.Count; ++i)
     {
         XmlNode childNode = xmlNode.ChildNodes[i];
         if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0)
         {
             HelpInfo helpInfo = (HelpInfo)GlossaryHelpInfo.Load(childNode);
             if (helpInfo != null)
             {
                 this.HelpSystem.TraceErrors(helpInfo.Errors);
                 this.AddCache(helpInfo.Name, helpInfo);
             }
         }
     }
 }
Ejemplo n.º 2
0
 private void LoadGlossaryDiv(System.Xml.XmlNode xmlNode)
 {
     if (xmlNode != null)
     {
         for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
         {
             System.Xml.XmlNode node = xmlNode.ChildNodes[i];
             if ((node.NodeType == XmlNodeType.Element) && (string.Compare(node.Name, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0))
             {
                 HelpInfo helpInfo = null;
                 helpInfo = GlossaryHelpInfo.Load(node);
                 if (helpInfo != null)
                 {
                     base.HelpSystem.TraceErrors(helpInfo.Errors);
                     base.AddCache(helpInfo.Name, helpInfo);
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
 private void LoadHelpFile(string helpFile)
 {
     using (GlossaryHelpProvider.tracer.TraceMethod())
     {
         if (string.IsNullOrEmpty(helpFile))
         {
             return;
         }
         XmlDocument xmlDocument = new XmlDocument();
         try
         {
             xmlDocument.Load(helpFile);
         }
         catch (IOException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileLoadFailure", ErrorCategory.OpenError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileLoadFailure", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         catch (SecurityException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileNotAccessible", ErrorCategory.OpenError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotAccessible", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         catch (XmlException ex)
         {
             this.HelpSystem.LastErrors.Add(new ErrorRecord((Exception)ex, "HelpFileNotValid", ErrorCategory.SyntaxError, (object)null)
             {
                 ErrorDetails = new ErrorDetails(Assembly.GetExecutingAssembly(), "HelpErrors", "HelpFileNotValid", new object[2]
                 {
                     (object)helpFile,
                     (object)ex.Message
                 })
             });
             return;
         }
         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, "glossary", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     xmlNode = childNode;
                     break;
                 }
             }
         }
         if (xmlNode == null)
         {
             return;
         }
         using (this.HelpSystem.Trace(helpFile))
         {
             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, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     HelpInfo helpInfo = (HelpInfo)GlossaryHelpInfo.Load(childNode);
                     if (helpInfo != null)
                     {
                         this.HelpSystem.TraceErrors(helpInfo.Errors);
                         this.AddCache(helpInfo.Name, helpInfo);
                     }
                 }
                 else if (childNode.NodeType == XmlNodeType.Element && string.Compare(childNode.Name, "glossaryDiv", StringComparison.OrdinalIgnoreCase) == 0)
                 {
                     this.LoadGlossaryDiv(childNode);
                 }
             }
         }
     }
 }
Ejemplo n.º 4
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, "glossary", 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, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0))
                         {
                             HelpInfo helpInfo = null;
                             helpInfo = GlossaryHelpInfo.Load(xmlNode);
                             if (helpInfo != null)
                             {
                                 base.HelpSystem.TraceErrors(helpInfo.Errors);
                                 base.AddCache(helpInfo.Name, helpInfo);
                             }
                         }
                         else if ((xmlNode.NodeType == XmlNodeType.Element) && (string.Compare(xmlNode.Name, "glossaryDiv", StringComparison.OrdinalIgnoreCase) == 0))
                         {
                             this.LoadGlossaryDiv(xmlNode);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
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(GlossaryHelpProvider).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(GlossaryHelpProvider).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(GlossaryHelpProvider).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, "glossary", 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, "glossaryEntry", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            HelpInfo helpInfo = null;

                            helpInfo = GlossaryHelpInfo.Load(node);

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

                        if (node.NodeType == XmlNodeType.Element && String.Compare(node.Name, "glossaryDiv", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            LoadGlossaryDiv(node);
                        }
                    }
                }
            }
        }