Exemplo n.º 1
0
        internal bool IsNewerVersion(UpdatableHelpInfo helpInfo, CultureInfo culture)
        {
            Version cultureVersion = helpInfo.GetCultureVersion(culture);
            Version version2       = this.GetCultureVersion(culture);

            return((version2 == null) || (cultureVersion > version2));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Checks if the other HelpInfo has a newer version
        /// </summary>
        /// <param name="helpInfo">HelpInfo object to check</param>
        /// <param name="culture">culture to check</param>
        /// <returns>true if the other HelpInfo is newer, false if not</returns>
        internal bool IsNewerVersion(UpdatableHelpInfo helpInfo, CultureInfo culture)
        {
            Debug.Assert(helpInfo != null);

            Version v1 = helpInfo.GetCultureVersion(culture);
            Version v2 = GetCultureVersion(culture);

            Debug.Assert(v1 != null);

            if (v2 == null)
            {
                return(true);
            }

            return(v1 > v2);;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if the other HelpInfo has a newer version
        /// </summary>
        /// <param name="helpInfo">HelpInfo object to check</param>
        /// <param name="culture">culture to check</param>
        /// <returns>true if the other HelpInfo is newer, false if not</returns>
        internal bool IsNewerVersion(UpdatableHelpInfo helpInfo, CultureInfo culture)
        {
            Debug.Assert(helpInfo != null);

            Version v1 = helpInfo.GetCultureVersion(culture);
            Version v2 = GetCultureVersion(culture);

            Debug.Assert(v1 != null);

            if (v2 == null)
            {
                return true;
            }

            return v1 > v2; ;
        }
Exemplo n.º 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);
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
0
 internal bool IsNewerVersion(UpdatableHelpInfo helpInfo, CultureInfo culture)
 {
     Version cultureVersion = helpInfo.GetCultureVersion(culture);
     Version version2 = this.GetCultureVersion(culture);
     return ((version2 == null) || (cultureVersion > version2));
 }
Exemplo n.º 8
0
 internal void GenerateHelpInfo(string moduleName, Guid moduleGuid, string contentUri, string culture, Version version, string destPath, string fileName, bool force)
 {
     if (!this._stopping)
     {
         string path = Path.Combine(destPath, fileName);
         if (force)
         {
             this.RemoveReadOnly(path);
         }
         UpdatableHelpInfo info = null;
         string            xml  = LoadStringFromPath(this._cmdlet, path, null);
         if (xml != null)
         {
             info = this.CreateHelpInfo(xml, moduleName, moduleGuid, null, null, false);
         }
         using (FileStream stream = new FileStream(path, FileMode.Create, FileAccess.Write))
         {
             XmlTextWriter writer = new XmlTextWriter(stream, Encoding.UTF8)
             {
                 Formatting  = Formatting.Indented,
                 Indentation = 2
             };
             try
             {
                 writer.WriteStartDocument();
                 writer.WriteStartElement("HelpInfo", "http://schemas.microsoft.com/powershell/help/2010/05");
                 writer.WriteStartElement("HelpContentURI");
                 writer.WriteValue(contentUri);
                 writer.WriteEndElement();
                 writer.WriteStartElement("SupportedUICultures");
                 bool flag = false;
                 if (info != null)
                 {
                     foreach (CultureSpecificUpdatableHelp help in info.UpdatableHelpItems)
                     {
                         if (help.Culture.Name.Equals(culture, StringComparison.OrdinalIgnoreCase))
                         {
                             if (help.Version.Equals(version))
                             {
                                 writer.WriteStartElement("UICulture");
                                 writer.WriteStartElement("UICultureName");
                                 writer.WriteValue(help.Culture.Name);
                                 writer.WriteEndElement();
                                 writer.WriteStartElement("UICultureVersion");
                                 writer.WriteValue(help.Version.ToString());
                                 writer.WriteEndElement();
                                 writer.WriteEndElement();
                             }
                             else
                             {
                                 writer.WriteStartElement("UICulture");
                                 writer.WriteStartElement("UICultureName");
                                 writer.WriteValue(culture);
                                 writer.WriteEndElement();
                                 writer.WriteStartElement("UICultureVersion");
                                 writer.WriteValue(version.ToString());
                                 writer.WriteEndElement();
                                 writer.WriteEndElement();
                             }
                             flag = true;
                         }
                         else
                         {
                             writer.WriteStartElement("UICulture");
                             writer.WriteStartElement("UICultureName");
                             writer.WriteValue(help.Culture.Name);
                             writer.WriteEndElement();
                             writer.WriteStartElement("UICultureVersion");
                             writer.WriteValue(help.Version.ToString());
                             writer.WriteEndElement();
                             writer.WriteEndElement();
                         }
                     }
                 }
                 if (!flag)
                 {
                     writer.WriteStartElement("UICulture");
                     writer.WriteStartElement("UICultureName");
                     writer.WriteValue(culture);
                     writer.WriteEndElement();
                     writer.WriteStartElement("UICultureVersion");
                     writer.WriteValue(version.ToString());
                     writer.WriteEndElement();
                     writer.WriteEndElement();
                 }
                 writer.WriteEndElement();
                 writer.WriteEndDocument();
             }
             finally
             {
                 writer.Close();
             }
         }
     }
 }
Exemplo n.º 9
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;
 }