/// <summary> /// Raised by <see cref="updateCheck"/> when a new version has been /// made available. /// </summary> private void updateCheck_UpdateAvailable(object sender, UpdateEventArgs e) { this.updateEvent = e; this.buttonUpdate.Enabled = (e.UpdateUri != null) && e.UpdateUri.StartsWith("http"); this.labelUpdateTitle.Text = Resources.IntelStatus_VersionTitle; this.labelUpdate.Text = String.Format( CultureInfo.CurrentCulture, Resources.IntelStatus_Version, e.OldVersion, e.NewVersion, e.UpdateUri); this.UpdateStatus(); this.notifyIcon.ShowBalloonTip(10000, Resources.Update_NotificationTitle, Resources.Update_NotificationText, ToolTipIcon.Info); }
/// <summary> /// Called periodically by <see cref="timer"/> to download /// the version list and check for updates. /// </summary> private void timer_Elapsed(object sender, ElapsedEventArgs e) { var requestUri = this.CheckUri; if (String.IsNullOrEmpty(requestUri)) { return; } // Grab the assembly information var assemblyName = this.AssemblyName; var assemblyVersion = this.AssemblyVersion; if (assemblyName == null || assemblyVersion == null) { return; } try { // Figure out what the server has available var doc = XDocument.Load(requestUri); var newAssembly = doc.Root .Elements("assembly") .Select(x => new { Name = x.Attribute("name"), Version = x.Attribute("version"), UpdateUri = x.Attribute("update-uri") }) .Where(x => (x.Name != null) && (x.Name.Value == assemblyName) && (x.Version != null)) .Select(x => new { Version = new Version(x.Version.Value), UpdateUri = (x.UpdateUri != null) ? x.UpdateUri.Value : null }) .OrderBy(x => x.Version) .Last(); // Check if we have an update if (newAssembly.Version > assemblyVersion) { var handler = this.UpdateAvailable; if (handler != null) { var sync = this.SynchronizationObject; var args = new UpdateEventArgs( assemblyVersion, newAssembly.Version, newAssembly.UpdateUri); if ((sync != null) && sync.InvokeRequired) { sync.BeginInvoke(new Action(() => handler(this, args)), null); } else { ThreadPool.QueueUserWorkItem((state) => handler(this, args)); } } } } catch (WebException) { // Error downloading the document } catch (FormatException) { // The user's URI is invalid } catch (XmlException) { // Error parsing the XML } catch (InvalidOperationException) { // Our assembly isn't listed } }