Exemplo n.º 1
0
        private static void UpdateMostRecentlyInstalledVersionInAppConfig(UpdaterManifest updaterManifest)
        {
            // This doesn't work when running within the VS debugger. This is because VS updates the vshost.exe.config.

            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            config.AppSettings.Settings["MostRecentlyInstalledVersion"].Value = updaterManifest.Version;

            config.Save(ConfigurationSaveMode.Modified);

            ConfigurationManager.RefreshSection("appSettings");
        }
Exemplo n.º 2
0
        private bool VersionHasBeenInstalled(UpdaterManifest updaterManifest)
        {
            string mostRecentlyInstalledVersion = ConfigurationManager.AppSettings["MostRecentlyInstalledVersion"];

            if (updaterManifest.Version != mostRecentlyInstalledVersion)
            {
                Logger.LogInformation(string.Format(CultureInfo.CurrentCulture,
                                                    "New version ({0}) of {1} detected. Old version was {2}. App will be updated and restarted.",
                                                    updaterManifest.Version,
                                                    this._appName,
                                                    mostRecentlyInstalledVersion));

                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        private void Process(object stateInfo)
        {
            if (!Monitor.TryEnter(_locker))
            {
                return;
            }

            try
            {
                // Check for new binaries. If new, copy the files and restart the app domain.
                UpdaterManifest updaterManifest = GetUpdaterManifest();

                if (updaterManifest == null)
                {
                    return;
                }

                if (VersionHasBeenInstalled(updaterManifest))
                {
                    IfAppNotRunningThenRunApp();
                    return;
                }

                DeleteFiles();
                CopyFiles();

                UpdateMostRecentlyInstalledVersionInAppConfig(updaterManifest);
                this._initialRunningOfAppOccurred = true;
                RestartAppDomain();
            }
            catch (Exception ex)
            {
                // Just log and keep trying to process (ie: don't stop timer).
                Logger.LogException(ex);
            }
            finally
            {
                Monitor.Exit(_locker);
            }
        }