private void OnCheckForUpdateFinished(object sender, CheckForNewerReleaseCompletedEventArgs e)
        {
            try
            {
                if (e.Cancelled)
                {
                    this.runUpdate.Text = "Check for updates was cancelled.";
                    return;
                }

                if (e.Error != null)
                {
                    this.runUpdate.Text = "Error checking for updates";
                    return;
                }

                Version currentVersion = AssemblyInfo.Default.Version;
                if (e.Result == null || e.Result.Version <= currentVersion)
                {
                    this.runUpdate.Text          = "XML Explorer is up to date";
                    this.runUpdateHyperlink.Text = null;
                    this.imageCheck.Visibility   = System.Windows.Visibility.Visible;
                    return;
                }

                this.runUpdate.Text = "An update is available: ";
                this.hyperlinkUpdate.NavigateUri = new Uri(e.Result.Url);
                this.runUpdateHyperlink.Text     = e.Result.Version.ToString();
            }
            catch (Exception ex)
            {
                App.HandleException(ex);
            }
        }
Ejemplo n.º 2
0
        static void OnDownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            EventHandler <CheckForNewerReleaseCompletedEventArgs> onFinished = e.UserState as EventHandler <CheckForNewerReleaseCompletedEventArgs>;

            if (onFinished == null)
            {
                return;
            }

            Exception error     = null;
            bool      cancelled = e.Cancelled;
            Release   result    = null;

            if (!cancelled)
            {
                error = e.Error;

                if (error == null)
                {
                    string rss = e.Result;

                    XDocument document = XDocument.Parse(rss);

                    var releases = ParseReleases(document);

                    Version currentVersion = AssemblyInfo.Default.Version;

                    DevelopmentStatus desiredDevelopmentStatus = Properties.Settings.Default.DevelopmentStatus;

                    Release latestRelease = null;

                    foreach (var release in releases)
                    {
                        if (release.DevelopmentStatus >= desiredDevelopmentStatus)
                        {
                            if (latestRelease == null || release.Version > latestRelease.Version)
                            {
                                latestRelease = release;
                            }
                        }
                    }

                    if (latestRelease.Version > currentVersion)
                    {
                        result = latestRelease;
                    }
                }
            }

            CheckForNewerReleaseCompletedEventArgs args = new CheckForNewerReleaseCompletedEventArgs(error, cancelled, result);

            onFinished(null, args);
        }
        private void OnCheckForUpdateFinished(object sender, CheckForNewerReleaseCompletedEventArgs e)
        {
            try
            {
                if (e.Cancelled)
                {
                    return;
                }

                if (e.Error != null)
                {
                    if (this.IsCheckForUpdatesUserInitiated)
                    {
                        App.HandleException(e.Error);
                    }
                    return;
                }

                Version currentVersion = AssemblyInfo.Default.Version;
                if (e.Result == null || e.Result.Version <= currentVersion)
                {
                    if (this.IsCheckForUpdatesUserInitiated)
                    {
                        MessageBox.Show(string.Format("XML Explorer is up to date ({0})", currentVersion));
                    }
                    return;
                }

                AboutWindow aboutWindow = new AboutWindow();
                aboutWindow.Owner = this;
                aboutWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                App.HandleException(ex);
            }
        }