Beispiel #1
0
        internal UpdatableHelpVersionRange ParseManifestForApplicableUpdates(string xml, UpdatableHelpVersion currentVersion, int currentRevision)
        {
            UpdatableHelpVersionRange result = null;
            XmlDocument xmlDocument          = null;

            try
            {
                xmlDocument = this.CreateValidXmlDocument(xml, new ValidationEventHandler(this.ManifestValidationHandler), true);
            }
            catch (XmlException innerException)
            {
                throw new UpdatableExchangeHelpSystemException(UpdatableHelpStrings.UpdateManifestXmlValidationFailureErrorID, UpdatableHelpStrings.UpdateManifestXmlValidationFailure, ErrorCategory.InvalidData, null, innerException);
            }
            new SortedList <int, UpdatableHelpVersion>();
            XmlNodeList childNodes = xmlDocument["ExchangeHelpInfo"]["HelpVersions"].ChildNodes;

            foreach (object obj in childNodes)
            {
                XmlNode xmlNode = (XmlNode)obj;
                if (xmlNode.HasChildNodes)
                {
                    List <string> list       = new List <string>();
                    string        text       = string.Empty;
                    string        cabinetUrl = string.Empty;
                    int           num        = 0;
                    foreach (object obj2 in xmlNode.ChildNodes)
                    {
                        XmlNode xmlNode2 = (XmlNode)obj2;
                        string  name;
                        if ((name = xmlNode2.Name) != null)
                        {
                            if (!(name == "Version"))
                            {
                                if (!(name == "Revision"))
                                {
                                    if (!(name == "CulturesUpdated"))
                                    {
                                        if (name == "CabinetUrl")
                                        {
                                            cabinetUrl = xmlNode["CabinetUrl"].InnerText;
                                        }
                                    }
                                    else
                                    {
                                        text = xmlNode2.InnerText;
                                    }
                                }
                                else if (!int.TryParse(xmlNode2.InnerText, out num))
                                {
                                    throw new UpdatableExchangeHelpSystemException(UpdatableHelpStrings.UpdateInvalidVersionNumberErrorID, UpdatableHelpStrings.UpdateInvalidVersionNumber(xmlNode2.InnerText), ErrorCategory.InvalidData, null, null);
                                }
                            }
                            else
                            {
                                list.Add(xmlNode2.InnerText.Trim());
                            }
                        }
                    }
                    int newestRevisionFound = currentRevision;
                    if (list.Count > 0 && num > 0 && !string.IsNullOrEmpty(text) && !string.IsNullOrEmpty("CabinetUrl"))
                    {
                        foreach (string versionRange in list)
                        {
                            UpdatableHelpVersionRange updatableHelpVersionRange = new UpdatableHelpVersionRange(versionRange, num, text, cabinetUrl);
                            if (updatableHelpVersionRange.IsInRangeAndNewerThan(currentVersion, newestRevisionFound))
                            {
                                result = updatableHelpVersionRange;
                                newestRevisionFound = updatableHelpVersionRange.HelpRevision;
                            }
                        }
                    }
                }
            }
            return(result);
        }
Beispiel #2
0
        internal UpdatableExchangeHelpSystemException UpdateHelp()
        {
            double num = 90.0;
            UpdatableExchangeHelpSystemException result = null;

            this.ProgressNumerator = 0.0;
            if (!this.Cmdlet.Force)
            {
                if (!this.DownloadThrottleExpired())
                {
                    this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateUseForceToUpdateHelp(this.ThrottlingPeriodHours));
                    return(result);
                }
            }
            try
            {
                this.UpdateProgress(UpdatePhase.Checking, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                string path = this.LocalTempBase + "UpdateHelp.$$$\\";
                this.CleanDirectory(path);
                this.EnsureDirectory(path);
                HelpDownloader helpDownloader = new HelpDownloader(this);
                helpDownloader.DownloadManifest();
                if (!this.Cmdlet.Abort)
                {
                    UpdatableHelpVersionRange updatableHelpVersionRange = helpDownloader.SearchManifestForApplicableUpdates(this.CurrentHelpVersion, this.CurrentHelpRevision);
                    if (updatableHelpVersionRange != null)
                    {
                        double num2 = 20.0;
                        this.ProgressNumerator = 10.0;
                        this.UpdateProgress(UpdatePhase.Downloading, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                        string[] array = this.EnumerateAffectedCultures(updatableHelpVersionRange.CulturesAffected);
                        if (array.Length > 0)
                        {
                            this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateApplyingRevision(updatableHelpVersionRange.HelpRevision, string.Join(", ", array)));
                            helpDownloader.DownloadPackage(updatableHelpVersionRange.CabinetUrl);
                            if (this.Cmdlet.Abort)
                            {
                                return(result);
                            }
                            this.ProgressNumerator += num2;
                            this.UpdateProgress(UpdatePhase.Extracting, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                            HelpInstaller helpInstaller = new HelpInstaller(this, array, num);
                            helpInstaller.ExtractToTemp();
                            if (this.Cmdlet.Abort)
                            {
                                return(result);
                            }
                            this.ProgressNumerator += num2;
                            this.UpdateProgress(UpdatePhase.Validating, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                            Dictionary <string, LocalizedString> dictionary = helpInstaller.ValidateFiles();
                            if (this.Cmdlet.Abort)
                            {
                                return(result);
                            }
                            if (dictionary != null && dictionary.Count > 0)
                            {
                                this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateInvalidHelpFiles);
                                foreach (KeyValuePair <string, LocalizedString> keyValuePair in dictionary)
                                {
                                    this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateInvalidFileDescription(keyValuePair.Key, keyValuePair.Value));
                                }
                                throw new UpdatableExchangeHelpSystemException(UpdatableHelpStrings.UpdateContentXmlValidationFailureErrorID, UpdatableHelpStrings.UpdateContentXmlValidationFailure, ErrorCategory.NotInstalled, null, null);
                            }
                            this.ProgressNumerator += num2;
                            this.UpdateProgress(UpdatePhase.Installing, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                            if (!helpInstaller.AtomicInstallFiles())
                            {
                                throw new UpdatableExchangeHelpSystemException(UpdatableHelpStrings.UpdateInstallFilesExceptionErrorID, UpdatableHelpStrings.UpdateInstallFilesException, ErrorCategory.NotInstalled, null, null);
                            }
                        }
                        else
                        {
                            this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateSkipRevision(updatableHelpVersionRange.HelpRevision));
                        }
                        this.UpdateCurrentVersionInRegistry(updatableHelpVersionRange.HelpRevision);
                        this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateRevisionApplied(updatableHelpVersionRange.HelpRevision));
                        this.ProgressNumerator += num2;
                    }
                    else
                    {
                        this.Cmdlet.WriteVerbose(UpdatableHelpStrings.UpdateNoApplicableUpdates);
                    }
                    this.ProgressNumerator = num;
                    this.UpdateProgress(UpdatePhase.Finalizing, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
                    try
                    {
                        this.CleanDirectory(path);
                        if (Directory.Exists(path))
                        {
                            Directory.Delete(path);
                        }
                    }
                    catch
                    {
                    }
                    this.UpdateLastSuccessfulCheckTimestamp(DateTime.UtcNow);
                }
            }
            catch (Exception ex)
            {
                if (ex.GetType() == typeof(UpdatableExchangeHelpSystemException))
                {
                    result = (UpdatableExchangeHelpSystemException)ex;
                }
                else
                {
                    result = new UpdatableExchangeHelpSystemException(UpdatableHelpStrings.UpdateInstallFilesExceptionErrorID, UpdatableHelpStrings.UpdateInstallFilesException, ErrorCategory.InvalidOperation, null, ex);
                }
            }
            this.ProgressNumerator = 100.0;
            this.UpdateProgress(UpdatePhase.Finalizing, LocalizedString.Empty, (int)this.ProgressNumerator, 100);
            return(result);
        }