/// <summary> /// Thread safe function for the thread DkimSignerAvailable /// </summary> private async void CheckDkimSignerAvailable() { this.cbxPrereleases.Enabled = false; List<Release> aoRelease = null; StringBuilder changelog = new StringBuilder("Couldn't get current version.\r\nCheck your Internet connection or restart the application."); // Check the lastest Release Exception ex = null; await Task.Run(() => { try { aoRelease = ApiWrapper.GetAllRelease(cbxPrereleases.Checked); } catch (Exception e) { ex = e; } }); if(ex != null) { changelog.Append("\r\nError: " + ex.Message); } this.dkimSignerAvailable = null; if (aoRelease != null) { changelog.Clear(); this.dkimSignerAvailable = aoRelease[0]; changelog.AppendLine(aoRelease[0].TagName + " (" + aoRelease[0].CreatedAt.Substring(0, 10) + ")\r\n\t" + aoRelease[0].Body.Replace("\r\n", "\r\n\t") + "\r\n"); for(int i = 1; i < aoRelease.Count; i++) { if (this.dkimSignerAvailable.Version < aoRelease[i].Version) { this.dkimSignerAvailable = aoRelease[i]; } // TAG (DATE)\r\nIndented Text changelog.AppendLine(aoRelease[i].TagName + " (" + aoRelease[i].CreatedAt.Substring(0, 10) + ")\r\n\t" + aoRelease[i].Body.Replace("\r\n", "\r\n\t") + "\r\n"); } } this.txtDkimSignerAvailable.Text = this.dkimSignerAvailable != null ? this.dkimSignerAvailable.Version.ToString() : "Unknown"; this.txtChangelog.Text = changelog.ToString(); this.SetUpgradeButton(); this.cbxPrereleases.Enabled = true; }
/// <summary> /// Set the value of txtDkimSignerAvailable from CheckDkimSignerAvailableSafe (use by thread DkimSignerAvailable) /// </summary> /// <param name="dkimSignerAvailable"></param> private void SetDkimSignerAvailable(Release oDkimSignerAvailable) { dkimSignerAvailable = oDkimSignerAvailable; if (oDkimSignerAvailable != null) { string version = oDkimSignerAvailable.Version.ToString(); Match match = Regex.Match(oDkimSignerAvailable.TagName, @"v?((?:\d+\.){0,3}\d+)(?:-(alpha|beta|rc)(?:\.(\d+))?)?", RegexOptions.IgnoreCase); if (match.Success) { if (match.Groups.Count > 2 && match.Groups[2].Value.Length > 0) { version += " (" + match.Groups[2].Value; if (match.Groups.Count > 3 && match.Groups[3].Value.Length > 0) { version += "." + match.Groups[3].Value; } version += ")"; } } this.txtDkimSignerAvailable.Text = version; this.txtChangelog.Text = oDkimSignerAvailable.Body; } else { this.txtDkimSignerAvailable.Text = "Unknown"; this.txtChangelog.Text = "Couldn't get current version.\r\nCheck your Internet connection or restart the application."; } setUpgradeButton(); }
/// <summary> /// Thread safe function for the thread DkimSignerAvailable /// </summary> private void CheckDkimSignerAvailableSafe() { try { dkimSignerAvailable = ApiWrapper.getNewestRelease(); } catch (Exception) { dkimSignerAvailable = null; } if (this.txtDkimSignerInstalled.InvokeRequired) { SetDkimSignerAvailableCallback d = new SetDkimSignerAvailableCallback(SetDkimSignerAvailable); this.Invoke(d); } else { SetDkimSignerAvailable(); } }