//Could be serialized to a class that binds to the UI //Could use a json instad than XML private void DownloadUpdateComplete(object sender, DownloadStringCompletedEventArgs e) { try { if (e.Error == null) { var document = XDocument.Parse(e.Result); string version = document.Element("Bcfier").Element("Version").Value; if (System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.CompareTo(Version.Parse(version)) < 0) { var dialog = new NewVersion(); dialog.Description.Text = "Version " + version + " is available,\ndo you want to check it out now?"; dialog.NewFeatures.Text = document.Element("Bcfier").Element("Changelog").Element("NewFeatures").Value; dialog.BugFixes.Text = document.Element("Bcfier").Element("Changelog").Element("BugFixes").Value; dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.ShowDialog(); if(dialog.DialogResult.HasValue && dialog.DialogResult.Value) Process.Start(document.Element("Bcfier").Element("URL").Value); } } } catch (System.Exception ex1) { //warning suppressed Console.WriteLine("exception: " + ex1); } }
//check github API for new release private void CheckUpdates() { Task.Run(() => { try { var release = GitHubRest.GetLatestRelease(); if (release == null) return; string version = release.tag_name.Replace("v", ""); var mine = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; var online = Version.Parse(version); if (mine.CompareTo(online) < 0 && release.assets.Any()) { Application.Current.Dispatcher.Invoke((Action)delegate { var dialog = new NewVersion(); dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.Description.Text = release.name + " has been released on " + release.published_at.ToLongDateString() + "\ndo you want to check it out now?"; //dialog.NewFeatures.Text = document.Element("Bcfier").Element("Changelog").Element("NewFeatures").Value; //dialog.BugFixes.Text = document.Element("Bcfier").Element("Changelog").Element("BugFixes").Value; //dialog.WindowStartupLocation = WindowStartupLocation.CenterScreen; dialog.ShowDialog(); if (dialog.DialogResult.HasValue && dialog.DialogResult.Value) Process.Start(release.assets.First().browser_download_url); }); } } catch (System.Exception ex1) { //warning suppressed Console.WriteLine("exception: " + ex1); } }); }