private void updateAvailableCheckerBackgroundWorker_DoWork(
            object sender,
            DoWorkEventArgs e)
        {
            try
            {
                Host.ApplyLanguageSettingsToCurrentThread();

                _updateCheckInfo =
                    new UpdateCheckInfo2
                {
                    ApiKey        = @"658b513f-8c69-482c-86ab-4be029377d18",
                    VersionNumber = FileHelper.GetAssemblyVersion(
                        Assembly.GetEntryAssembly().Location).ToString(),
                    VersionDate = File.GetLastWriteTime(
                        Assembly.GetEntryAssembly().Location),
                    Culture = CultureInfo.CurrentUICulture.LCID
                };

                var ws   = WebServiceManager.Current.UpdateCheckerWS;
                var info = ws.IsUpdateAvailable2(_updateCheckInfo);

                e.Result = info.IsPresent ? info : null;
            }
            catch (Exception x)
            {
                // Catch and forget.
                LogCentral.Current.LogError(
                    @"Error during checking for updates.", x);
            }
        }
Пример #2
0
        private void updateAvailableCheckerBackgroundWorker_RunWorkerCompleted(
            object sender,
            RunWorkerCompletedEventArgs e)
        {
            try
            {
                if (!e.Cancelled &&
                    e.Error == null &&
                    e.Result is UpdatePresentResult2 result)
                {
                    // Yes, we do have an update, pass the URL to the
                    // toolbar button and make it visible.

                    buttonUpdateAvailable.Tag     = result;
                    updateRibbonPageGroup.Visible = true;
                    updateAvailableBlinkTimer.Start();
                }
                else if (e.Error != null)
                {
                    _updateCheckInfo = null;
                    throw e.Error;
                }
            }
            catch (Exception x)
            {
                // Catch and forget.
                LogCentral.Current.LogError(
                    @"Error after checking for updates.", x);
            }
        }
	public UpdatePresentResult2 IsUpdateAvailable2(
		UpdateCheckInfo2 info )
	{
		try
		{
			CheckThrowApiKey(info.ApiKey);

			var v1 = new Version(info.VersionNumber);
			var v2 = availableVersion;

			var url = v1 >= v2 ? string.Empty : ConfigurationManager.AppSettings[@"updateChecker.downloadUrl"];
			var web = v1 >= v2 ? string.Empty : ConfigurationManager.AppSettings[@"updateChecker.websiteUrl"];

			var result =
				new UpdatePresentResult2
					{
						IsPresent = v1 < v2, 
						DownloadWebsiteUrl = web
					};

			LogCentral.Current.LogInfo(string.Format(@"Returning download URL '{0}'.", url));
			return result;
		}
		catch (Exception x)
		{
			LogCentral.Current.LogError(@"Error checking whether an update is available.", x);
			throw;
		}
	}
	public UpdateInformationResult2 DownloadUpdate2(
		UpdateCheckInfo2 info)
	{
		try
		{
			CheckThrowApiKey(info.ApiKey);

			LogCentral.Current.LogInfo(
				string.Format(
					@"Downloading Update for client with version '{0}', date '{1}'.",
					info.VersionNumber,
					info.VersionDate));

			var avail = IsUpdateAvailable2(info);

			var result =
				new UpdateInformationResult2
					{
						IsPresent = avail.IsPresent,
						AlternativeFallbackDownloadUrl = avail.DownloadWebsiteUrl,
						FileName = @"ZetaResourceEditor-setup.exe",
						FileContent = File.ReadAllBytes(getSetupExeFilePath())
					};

			return result;
		}
		catch (Exception x)
		{
			LogCentral.Current.LogError(@"Error downloading update .", x);
			throw;
		}
	}
    public UpdateInformationResult2 DownloadUpdate2(
        UpdateCheckInfo2 info)
    {
        try
        {
            CheckThrowApiKey(info.ApiKey);

            LogCentral.Current.LogInfo(
                string.Format(
                    @"Downloading Update for client with version '{0}', date '{1}'.",
                    info.VersionNumber,
                    info.VersionDate));

            var avail = IsUpdateAvailable2(info);

            var result =
                new UpdateInformationResult2
            {
                IsPresent = avail.IsPresent,
                AlternativeFallbackDownloadUrl = avail.DownloadWebsiteUrl,
                FileName    = @"ZetaResourceEditor-setup.exe",
                FileContent = File.ReadAllBytes(getSetupExeFilePath())
            };

            return(result);
        }
        catch (Exception x)
        {
            LogCentral.Current.LogError(@"Error downloading update .", x);
            throw;
        }
    }
    public UpdatePresentResult2 IsUpdateAvailable2(
        UpdateCheckInfo2 info)
    {
        try
        {
            CheckThrowApiKey(info.ApiKey);

            var v1 = new Version(info.VersionNumber);
            var v2 = availableVersion;

            var url = v1 >= v2 ? string.Empty : ConfigurationManager.AppSettings[@"updateChecker.downloadUrl"];
            var web = v1 >= v2 ? string.Empty : ConfigurationManager.AppSettings[@"updateChecker.websiteUrl"];

            var result =
                new UpdatePresentResult2
            {
                IsPresent          = v1 < v2,
                DownloadWebsiteUrl = web
            };

            LogCentral.Current.LogInfo(string.Format(@"Returning download URL '{0}'.", url));
            return(result);
        }
        catch (Exception x)
        {
            LogCentral.Current.LogError(@"Error checking whether an update is available.", x);
            throw;
        }
    }
        private void updateAvailableCheckerBackgroundWorker_RunWorkerCompleted(
            object sender,
            RunWorkerCompletedEventArgs e)
        {
            try
            {
                if (!e.Cancelled &&
                    e.Error == null &&
                    e.Result is UpdatePresentResult2)
                {
                    // Yes, we do have an update, pass the URL to the
                    // toolbar button and make it visible.

                    buttonUpdateAvailable.Tag     = e.Result as UpdatePresentResult2;
                    updateRibbonPageGroup.Visible = true;
                    updateAvailableBlinkTimer.Start();

                    //// Make more visible.
                    //updateAvailableToolStripButton.ForeColor = Color.Green;
                    //updateAvailableToolStripButton.BackColor = Color.Yellow;
                    //updateAvailableToolStripButton.Font =
                    //    new Font(
                    //        updateAvailableToolStripButton.Font,
                    //        FontStyle.Bold );
                }
                else if (e.Error != null)
                {
                    _updateCheckInfo = null;
                    throw e.Error;
                }
            }
            catch (Exception x)
            {
                // Catch and forget.
                LogCentral.Current.LogError(
                    @"Error after checking for updates.", x);
            }
        }
        public void DownloadAndRunSetup(
            IWin32Window owner,
            UpdateCheckInfo2 info,
            string downloadWebsiteUrl)
        {
            var    error     = false;
            string localPath = null;

            using (new BackgroundWorkerLongProgressGui(
                       delegate
            {
                try
                {
                    var res = _ws.DownloadUpdate2(info);

                    localPath =
                        PathHelper.Combine(
                            getTempPathIntelligent(),
                            Path.GetFileNameWithoutExtension(res.FileName) +
                            Guid.NewGuid() +
                            Path.GetExtension(res.FileName));

                    File.WriteAllBytes(localPath, res.FileContent);
                }
                catch (Exception x)
                {
                    LogCentral.Current.LogError(
                        @"Error downloading setup of new version.",
                        x);

                    error = true;
                }
            },
                       Resources.SetupDownloadController_DownloadAndRunSetup_Downloading_update__please_wait___,
                       BackgroundWorkerLongProgressGui.CancellationMode.NotCancelable,
                       owner))
            {
            }

            // --

            if (error)
            {
                // Failed, simply redirect.

                var url = downloadWebsiteUrl;

                LogCentral.Current.LogInfo(
                    string.Format(
                        @"About to redirect to update-web page at '{0}' " +
                        @"for client with version '{1}'.",
                        url,
                        info.VersionNumber));

                var si =
                    new ProcessStartInfo
                {
                    FileName = url,
                    //Arguments = @" /S",
                    UseShellExecute = true
                };

                Process.Start(si);
            }
            else
            {
                // Succeeded, run setup, from outside the background thread.

                var si =
                    new ProcessStartInfo
                {
                    FileName        = localPath,
                    Arguments       = @"/S",
                    UseShellExecute = true
                };

                Process.Start(si);

                // TODO: Some day, cleanup the downloaded file.
            }
        }
Пример #9
0
		private void updateAvailableCheckerBackgroundWorker_RunWorkerCompleted(
			object sender,
			RunWorkerCompletedEventArgs e)
		{
			try
			{
				if (!e.Cancelled &&
					e.Error == null &&
					e.Result is UpdatePresentResult2)
				{
					// Yes, we do have an update, pass the URL to the
					// toolbar button and make it visible.

					buttonUpdateAvailable.Tag = e.Result as UpdatePresentResult2;
					updateRibbonPageGroup.Visible = true;
					updateAvailableBlinkTimer.Start();

					//// Make more visible.
					//updateAvailableToolStripButton.ForeColor = Color.Green;
					//updateAvailableToolStripButton.BackColor = Color.Yellow;
					//updateAvailableToolStripButton.Font =
					//    new Font(
					//        updateAvailableToolStripButton.Font,
					//        FontStyle.Bold );
				}
				else if (e.Error != null)
				{
					_updateCheckInfo = null;
					throw e.Error;
				}
			}
			catch (Exception x)
			{
				// Catch and forget.
				LogCentral.Current.LogError(
					@"Error after checking for updates.", x);
			}
		}
Пример #10
0
		private void updateAvailableCheckerBackgroundWorker_DoWork(
			object sender,
			DoWorkEventArgs e)
		{
			try
			{
				Host.ApplyLanguageSettingsToCurrentThread();

				_updateCheckInfo =
					new UpdateCheckInfo2
						{
							ApiKey = @"658b513f-8c69-482c-86ab-4be029377d18",
							VersionNumber = FileHelper.GetAssemblyVersion(
								Assembly.GetEntryAssembly().Location).ToString(),
							VersionDate = File.GetLastWriteTime(
								Assembly.GetEntryAssembly().Location),
							Culture = CultureInfo.CurrentUICulture.LCID
						};

				var ws = WebServiceManager.Current.UpdateCheckerWS;
				var info = ws.IsUpdateAvailable2(_updateCheckInfo);

				e.Result = info.IsPresent ? info : null;
			}
			catch (Exception x)
			{
				// Catch and forget.
				LogCentral.Current.LogError(
					@"Error during checking for updates.", x);
			}
		}
		public void DownloadAndRunSetup(
			IWin32Window owner,
			UpdateCheckInfo2 info,
			string downloadWebsiteUrl)
		{
			var error = false;
			string localPath = null;

			using (new BackgroundWorkerLongProgressGui(
				delegate
				{
					try
					{
						var res = _ws.DownloadUpdate2(info);

						localPath =
							PathHelper.Combine(
								getTempPathIntelligent(),
								Path.GetFileNameWithoutExtension(res.FileName) +
								Guid.NewGuid() +
								Path.GetExtension(res.FileName));

						File.WriteAllBytes(localPath, res.FileContent);
					}
					catch (Exception x)
					{
						LogCentral.Current.LogError(
							@"Error downloading setup of new version.",
							x);

						error = true;
					}
				},
				Resources.SetupDownloadController_DownloadAndRunSetup_Downloading_update__please_wait___,
				BackgroundWorkerLongProgressGui.CancellationMode.NotCancelable,
				owner))
			{
			}

			// --

			if (error)
			{
				// Failed, simply redirect.

				var url = downloadWebsiteUrl;

				LogCentral.Current.LogInfo(
					string.Format(
						@"About to redirect to update-web page at '{0}' " +
							@"for client with version '{1}'.",
						url,
						info.VersionNumber));

				var si =
					new ProcessStartInfo
					{
						FileName = url,
						//Arguments = @" /S",
						UseShellExecute = true
					};

				Process.Start(si);
			}
			else
			{
				// Succeeded, run setup, from outside the background thread.

				var si =
					new ProcessStartInfo
					{
						FileName = localPath,
						Arguments = @"/S",
						UseShellExecute = true
					};

				Process.Start(si);

				// TODO: Some day, cleanup the downloaded file.
			}
		}