Пример #1
0
        /// <summary>
        /// Checks if it is necessary to update help
        /// </summary>
        /// <param name="module">ModuleInfo</param>
        /// <param name="currentHelpInfo">current HelpInfo.xml</param>
        /// <param name="newHelpInfo">new HelpInfo.xml</param>
        /// <param name="culture">current culture</param>
        /// <param name="force">force update</param>
        /// <returns>true if it is necessary to update help, false if not</returns>
        internal bool IsUpdateNecessary(UpdatableHelpModuleInfo module, UpdatableHelpInfo currentHelpInfo,
            UpdatableHelpInfo newHelpInfo, CultureInfo culture, bool force)
        {
            Debug.Assert(module != null);

            if (newHelpInfo == null)
            {
                throw new UpdatableHelpSystemException("UnableToRetrieveHelpInfoXml",
                    StringUtil.Format(HelpDisplayStrings.UnableToRetrieveHelpInfoXml, culture.Name), ErrorCategory.ResourceUnavailable,
                    null, null);
            }

            // Culture check
            if (!newHelpInfo.IsCultureSupported(culture))
            {
                throw new UpdatableHelpSystemException("HelpCultureNotSupported",
                    StringUtil.Format(HelpDisplayStrings.HelpCultureNotSupported,
                    culture.Name, newHelpInfo.GetSupportedCultures()), ErrorCategory.InvalidOperation, null, null);
            }

            // Version check
            if (!force && currentHelpInfo != null && !currentHelpInfo.IsNewerVersion(newHelpInfo, culture))
            {
                return false;
            }

            return true;
        }
Пример #2
0
        internal UpdatableHelpInfo CreateHelpInfo(string xml, string moduleName, Guid moduleGuid, string currentCulture, string pathOverride, bool verbose)
        {
            XmlDocument document = null;

            try
            {
                document = this.CreateValidXmlDocument(xml, HelpInfoXmlNamespace, HelpInfoXmlSchema, new ValidationEventHandler(this.HelpInfoValidationHandler), true);
            }
            catch (XmlException exception)
            {
                throw new UpdatableHelpSystemException("HelpInfoXmlValidationFailure", exception.Message, ErrorCategory.InvalidData, null, exception);
            }
            string resolvedUri = pathOverride;
            string innerText   = document["HelpInfo"]["HelpContentURI"].InnerText;

            if (string.IsNullOrEmpty(pathOverride))
            {
                resolvedUri = this.ResolveUri(innerText, verbose);
            }
            XmlNodeList childNodes = document["HelpInfo"]["SupportedUICultures"].ChildNodes;

            CultureSpecificUpdatableHelp[] cultures = new CultureSpecificUpdatableHelp[childNodes.Count];
            for (int i = 0; i < childNodes.Count; i++)
            {
                cultures[i] = new CultureSpecificUpdatableHelp(new CultureInfo(childNodes[i]["UICultureName"].InnerText), new Version(childNodes[i]["UICultureVersion"].InnerText));
            }
            UpdatableHelpInfo info = new UpdatableHelpInfo(innerText, cultures);

            if (!string.IsNullOrEmpty(currentCulture))
            {
                WildcardOptions options = WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase;
                IEnumerable <WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(new string[] { currentCulture }, options);
                for (int j = 0; j < cultures.Length; j++)
                {
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(cultures[j].Culture.Name, patterns, true))
                    {
                        info.HelpContentUriCollection.Add(new UpdatableHelpUri(moduleName, moduleGuid, cultures[j].Culture, resolvedUri));
                    }
                }
            }
            if (!string.IsNullOrEmpty(currentCulture) && (info.HelpContentUriCollection.Count == 0))
            {
                throw new UpdatableHelpSystemException("HelpCultureNotSupported", StringUtil.Format(HelpDisplayStrings.HelpCultureNotSupported, currentCulture, info.GetSupportedCultures()), ErrorCategory.InvalidOperation, null, null);
            }
            return(info);
        }
Пример #3
0
        /// <summary>
        /// Creates a HelpInfo object
        /// </summary>
        /// <param name="xml">XML text</param>
        /// <param name="moduleName">module name</param>
        /// <param name="moduleGuid">module GUID</param>
        /// <param name="currentCulture">current UI cultures</param>
        /// <param name="pathOverride">overrides the path contained within HelpInfo.xml</param>
        /// <param name="verbose"></param>
        /// <param name="shouldResolveUri">
        /// Resolve the uri retrieved from the <paramref name="xml"/> content. The uri is resolved
        /// to handle redirections if any.
        /// </param>
        /// <param name="ignoreValidationException">ignore the xsd validation exception and return null in such case</param>
        /// <returns>HelpInfo object</returns>
        internal UpdatableHelpInfo CreateHelpInfo(string xml, string moduleName, Guid moduleGuid,
            string currentCulture, string pathOverride, bool verbose, bool shouldResolveUri, bool ignoreValidationException)
        {
            XmlDocument document = null;
            try
            {
                document = CreateValidXmlDocument(xml, HelpInfoXmlNamespace, HelpInfoXmlSchema,
#if !CORECLR
                    new ValidationEventHandler(HelpInfoValidationHandler),
#endif
                    true);
            }
            catch (UpdatableHelpSystemException e)
            {
                if (ignoreValidationException && HelpInfoXmlValidationFailure.Equals(e.FullyQualifiedErrorId, StringComparison.Ordinal))
                {
                    return null;
                }

                throw;
            }
            catch (XmlException e)
            {
                if (ignoreValidationException) { return null; }

                throw new UpdatableHelpSystemException(HelpInfoXmlValidationFailure,
                    e.Message, ErrorCategory.InvalidData, null, e);
            }

            string uri = pathOverride;
            string unresolvedUri = document["HelpInfo"]["HelpContentURI"].InnerText;

            if (String.IsNullOrEmpty(pathOverride))
            {
                if (shouldResolveUri)
                {
                    uri = ResolveUri(unresolvedUri, verbose);
                }
                else
                {
                    uri = unresolvedUri;
                }
            }

            XmlNodeList cultures = document["HelpInfo"]["SupportedUICultures"].ChildNodes;

            CultureSpecificUpdatableHelp[] updatableHelpItem = new CultureSpecificUpdatableHelp[cultures.Count];

            for (int i = 0; i < cultures.Count; i++)
            {
                updatableHelpItem[i] = new CultureSpecificUpdatableHelp(
                    new CultureInfo(cultures[i]["UICultureName"].InnerText),
                    new Version(cultures[i]["UICultureVersion"].InnerText));
            }

            UpdatableHelpInfo helpInfo = new UpdatableHelpInfo(unresolvedUri, updatableHelpItem);

            if (!String.IsNullOrEmpty(currentCulture))
            {
                WildcardOptions wildcardOptions = WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant;
                IEnumerable<WildcardPattern> patternList = SessionStateUtilities.CreateWildcardsFromStrings(new string[1] { currentCulture }, wildcardOptions);

                for (int i = 0; i < updatableHelpItem.Length; i++)
                {
                    if (SessionStateUtilities.MatchesAnyWildcardPattern(updatableHelpItem[i].Culture.Name, patternList, true))
                    {
                        helpInfo.HelpContentUriCollection.Add(new UpdatableHelpUri(moduleName, moduleGuid, updatableHelpItem[i].Culture, uri));
                    }
                }
            }


            if (!String.IsNullOrEmpty(currentCulture) && helpInfo.HelpContentUriCollection.Count == 0)
            {
                // throw exception
                throw new UpdatableHelpSystemException("HelpCultureNotSupported",
                    StringUtil.Format(HelpDisplayStrings.HelpCultureNotSupported,
                        currentCulture, helpInfo.GetSupportedCultures()), ErrorCategory.InvalidOperation, null, null);
            }

            return helpInfo;
        }
Пример #4
0
 internal UpdatableHelpInfo CreateHelpInfo(string xml, string moduleName, Guid moduleGuid, string currentCulture, string pathOverride, bool verbose)
 {
     XmlDocument document = null;
     try
     {
         document = this.CreateValidXmlDocument(xml, HelpInfoXmlNamespace, HelpInfoXmlSchema, new ValidationEventHandler(this.HelpInfoValidationHandler), true);
     }
     catch (XmlException exception)
     {
         throw new UpdatableHelpSystemException("HelpInfoXmlValidationFailure", exception.Message, ErrorCategory.InvalidData, null, exception);
     }
     string resolvedUri = pathOverride;
     string innerText = document["HelpInfo"]["HelpContentURI"].InnerText;
     if (string.IsNullOrEmpty(pathOverride))
     {
         resolvedUri = this.ResolveUri(innerText, verbose);
     }
     XmlNodeList childNodes = document["HelpInfo"]["SupportedUICultures"].ChildNodes;
     CultureSpecificUpdatableHelp[] cultures = new CultureSpecificUpdatableHelp[childNodes.Count];
     for (int i = 0; i < childNodes.Count; i++)
     {
         cultures[i] = new CultureSpecificUpdatableHelp(new CultureInfo(childNodes[i]["UICultureName"].InnerText), new Version(childNodes[i]["UICultureVersion"].InnerText));
     }
     UpdatableHelpInfo info = new UpdatableHelpInfo(innerText, cultures);
     if (!string.IsNullOrEmpty(currentCulture))
     {
         WildcardOptions options = WildcardOptions.CultureInvariant | WildcardOptions.IgnoreCase;
         IEnumerable<WildcardPattern> patterns = SessionStateUtilities.CreateWildcardsFromStrings(new string[] { currentCulture }, options);
         for (int j = 0; j < cultures.Length; j++)
         {
             if (SessionStateUtilities.MatchesAnyWildcardPattern(cultures[j].Culture.Name, patterns, true))
             {
                 info.HelpContentUriCollection.Add(new UpdatableHelpUri(moduleName, moduleGuid, cultures[j].Culture, resolvedUri));
             }
         }
     }
     if (!string.IsNullOrEmpty(currentCulture) && (info.HelpContentUriCollection.Count == 0))
     {
         throw new UpdatableHelpSystemException("HelpCultureNotSupported", StringUtil.Format(HelpDisplayStrings.HelpCultureNotSupported, currentCulture, info.GetSupportedCultures()), ErrorCategory.InvalidOperation, null, null);
     }
     return info;
 }