Example #1
0
        private void Send(AppVersionInfo versionInfo, string recipients)
        {
            string body    = EmbeddedResourceProvider.GetResourceString("NewVersionAvailableEmail.html", "EmbeddedResources.Templates");
            string subject = GetSubjectLine(body) ?? "New version available";

            Dictionary <string, string> tokens = new Dictionary <string, string>()
            {
                { "{url}", versionInfo.UpdateUrl },
                { "{version}", versionInfo.AvailableVersion.ToString() },
                { "{releaseNotes}", versionInfo.ReleaseNotes },
            };

            body    = TokenReplacer.ReplaceAsHtml(tokens, body);
            subject = TokenReplacer.ReplaceAsPlainText(tokens, subject);

            this.smtpProvider.SendEmail(recipients, subject, body);
        }
Example #2
0
        public async Task <AppVersionInfo> GetVersionInfo()
        {
            AppVersionInfo appVersionInfo = new AppVersionInfo();

            appVersionInfo.Status = VersionInfoStatus.Unknown;

            try
            {
                appVersionInfo.CurrentVersion = Assembly.GetEntryAssembly()?.GetName()?.Version;

                string appdata = await DownloadFile(UrlProductVersionInfo);

                if (appdata == null)
                {
                    this.logger.LogTrace("Version check response data from URL {url} was null", UrlProductVersionInfo);
                    return(appVersionInfo);
                }

                PublishedVersionInfo versionInfo = JsonConvert.DeserializeObject <PublishedVersionInfo>(appdata);
                appVersionInfo.AvailableVersion = Version.Parse(versionInfo.CurrentVersion);
                appVersionInfo.UpdateUrl        = versionInfo.UserUrl;
                appVersionInfo.ReleaseNotes     = versionInfo.ReleaseNotes;

                if (appVersionInfo.AvailableVersion > appVersionInfo.CurrentVersion)
                {
                    appVersionInfo.Status = VersionInfoStatus.UpdateAvailable;
                }
                else
                {
                    appVersionInfo.Status = VersionInfoStatus.Current;
                }
            }
            catch (Exception ex)
            {
                logger.LogWarning(EventIDs.UIGenericWarning, ex, "Could not get version update");
                appVersionInfo.Status = VersionInfoStatus.Failed;
            }

            this.logger.LogTrace("Update check returned {result}", appVersionInfo);

            return(appVersionInfo);
        }