public static void Update()
        {
            int num = 25;

            for (int index = 0; index < AutoUpdatables._updateables.Count; ++index)
            {
                if (AutoUpdatables._updateables[index] == null)
                {
                    if (num > 0)
                    {
                        AutoUpdatables._updateables.RemoveAt(index);
                        --index;
                        --num;
                    }
                }
                else
                {
                    IAutoUpdate target = AutoUpdatables._updateables[index].Target as IAutoUpdate;
                    if (!AutoUpdatables._updateables[index].IsAlive || target == null)
                    {
                        AutoUpdatables._updateables[index] = (WeakReference)null;
                    }
                    else
                    {
                        target.Update();
                    }
                }
            }
        }
Example #2
0
        public void ReleaseChannel_CanBeOverriddenInConstructor()
        {
            const ReleaseChannel testReleaseChannel = ReleaseChannel.Insider;
            IAutoUpdate          update             = BuildAutoUpdate(releaseChannel: testReleaseChannel);

            Assert.AreEqual(testReleaseChannel.ToString(), update.ReleaseChannel);
        }
        private static void PublishTelemetryEventAsync(IAutoUpdate autoUpdate, Stopwatch updateOptionStopwatch, bool timeOutOccurred)
        {
            Task.Run(() =>
            {
                try
                {
                    var updateOption = autoUpdate.UpdateOptionAsync.Result;
                    if (timeOutOccurred)
                    {
                        updateOptionStopwatch.Stop();
                    }
                    Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_GetUpgradeOption, new Dictionary <TelemetryProperty, string>
                    {
                        { TelemetryProperty.UpdateInitializationTime, GetTimeSpanTelemetryString(autoUpdate.GetInitializationTime()) },
                        { TelemetryProperty.UpdateOptionWaitTime, GetTimeSpanTelemetryString(updateOptionStopwatch.Elapsed) },
                        { TelemetryProperty.UpdateOption, updateOption.ToString() },
                        { TelemetryProperty.UpdateTimedOut, timeOutOccurred.ToString(CultureInfo.InvariantCulture) }
                    });
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception e)
                {
                    e.ReportException();
                    System.Diagnostics.Trace.WriteLine($"Unable to send telemetry at {e.Message}");
                }
#pragma warning restore CA1031 // Do not catch general exception types
            });
        }
Example #4
0
 public void AutoUpdate_ExtensionsExist_ReturnsCorrectType()
 {
     using (Container container = new Container(ExtensionsExistSearchPattern))
     {
         IAutoUpdate autoUpdate = container.AutoUpdate;
         Assert.IsNotNull(autoUpdate);
         Assert.IsInstanceOfType(autoUpdate, typeof(DummyAutoUpdate));
     }
 }
Example #5
0
        public override void Init()
        {
            IAutoUpdate autoUpdata = application.Make <IAutoUpdate>();

            if (autoUpdata is IEvent)
            {
                (autoUpdata as IEvent).Event.One(CAutoUpdate.Events.ON_UPDATE_COMPLETE, (sender, e) =>
                {
                    (application.Make <ILua>() as CLua).LoadHotFix();
                });
            }
        }
        /// <summary>
        /// Download the upgrade installer and close the app depending on if it is successful or not
        /// </summary>
        private async void DownLoadInstaller(IAutoUpdate autoUpdate, AutoUpdateOption updateOption)
        {
            UpdateResult result = UpdateResult.Unknown;

            // If the window is topmost, the UAC prompt from the version switcher will appear behind the main window.
            // To prevent this, save the previous topmost state, ensure that the main window is not topmost when the
            // UAC prompt will display, then restore the previous topmost state.
            bool previousTopmostSetting = Topmost;

            try
            {
                ctrlProgressRing.Activate();
                Topmost = false;
                result  = await autoUpdate.UpdateAsync().ConfigureAwait(true);

                Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_DoInstallation, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.UpdateInstallerUpdateTime, GetTimeSpanTelemetryString(autoUpdate.GetUpdateTime()) },
                    { TelemetryProperty.UpdateResult, updateOption.ToString() },
                });
                if (result == UpdateResult.Success)
                {
                    this.Close();
                    return;
                }
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception e)
            {
                e.ReportException();
            };
#pragma warning restore CA1031 // Do not catch general exception types

            Topmost = previousTopmostSetting;
            ctrlProgressRing.Deactivate();
            Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_InstallationError, TelemetryProperty.Error, result.ToString());

            string message = updateOption == AutoUpdateOption.RequiredUpgrade
                ? GetMessageForRequiredUpdateFailure() : GetMessageForOptionalUpdateFailure();

            MessageDialog.Show(message);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }
        /// <summary>
        /// Retrieve the upgrade decision status, if yes, use autoUpdateOption to update, otherwise, no need to upgrade the app
        /// </summary>
        private static bool ShouldUserUpgrade(IAutoUpdate autoUpdate, out AutoUpdateOption autoUpdateOption)
        {
            if (autoUpdate == null)
            {
                autoUpdateOption = AutoUpdateOption.Unknown;
                return(false);
            }

            AutoUpdateOption updateOption;
            Stopwatch        updateOptionStopwatch = Stopwatch.StartNew();
            bool             timeOutOccurred       = false;

            try
            {
                var t = autoUpdate.UpdateOptionAsync;
                if (!t.Wait(2000))
                {
                    timeOutOccurred  = true;
                    autoUpdateOption = AutoUpdateOption.Unknown;
                    return(false);
                }
                updateOptionStopwatch.Stop();
                updateOption = t.Result;
            }
            catch (AggregateException e)
            {
                e.ReportException();
                updateOption = AutoUpdateOption.Unknown;
            }
            finally
            {
                PublishTelemetryEventAsync(autoUpdate, updateOptionStopwatch, timeOutOccurred);
            }

            autoUpdateOption = updateOption;
            if (autoUpdateOption == AutoUpdateOption.Current || autoUpdateOption == AutoUpdateOption.Unknown)
            {
                return(false);
            }
            return(true);
        }
        private static void PublishTelemetryEventAsync(IAutoUpdate autoUpdate, Stopwatch updateOptionStopwatch, bool timeOutOccurred)
        {
            Task.Run(() =>
            {
                try
                {
                    var updateOption = autoUpdate.UpdateOptionAsync.Result;
                    if (timeOutOccurred)
                    {
                        updateOptionStopwatch.Stop();
                    }
                    Logger.PublishTelemetryEvent(TelemetryEventFactory.ForGetUpgradeOption(autoUpdate.GetInitializationTime(),
                                                                                           updateOptionStopwatch.Elapsed, updateOption.ToString(), timeOutOccurred));
                }
#pragma warning disable CA1031 // Do not catch general exception types
                catch (Exception e)
                {
                    e.ReportException();
                    System.Diagnostics.Trace.WriteLine($"Unable to send telemetry at {e.Message}");
                }
#pragma warning restore CA1031 // Do not catch general exception types
            });
        }
        /// <summary>
        /// Download the upgrade installer and close the app depending on if it is successful or not
        /// </summary>
        private async void DownLoadInstaller(IAutoUpdate autoUpdate, AutoUpdateOption updateOption)
        {
            UpdateResult result = UpdateResult.Unknown;

            try
            {
                ctrlProgressRing.Activate();
                result = await autoUpdate.UpdateAsync().ConfigureAwait(true);

                Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_DoInstallation, new Dictionary <TelemetryProperty, string>
                {
                    { TelemetryProperty.UpdateInstallerDownloadTime, GetTimeSpanTelemetryString(autoUpdate.GetInstallerDownloadTime()) },
                    { TelemetryProperty.UpdateInstallerVerificationTime, GetTimeSpanTelemetryString(autoUpdate.GetInstallerVerificationTime()) },
                    { TelemetryProperty.UpdateResult, updateOption.ToString() },
                });
                if (result == UpdateResult.Success)
                {
                    this.Close();
                    return;
                }
            }
            catch (Exception) { };

            ctrlProgressRing.Deactivate();
            Logger.PublishTelemetryEvent(TelemetryAction.Upgrade_InstallationError, TelemetryProperty.Error, result.ToString());

            string message = updateOption == AutoUpdateOption.RequiredUpgrade
                ? GetMessageForRequiredUpdateFailure(result) : GetMessageForOptionalUpdateFailure(result);

            MessageBox.Show(message);

            if (updateOption == AutoUpdateOption.RequiredUpgrade)
            {
                this.Close();
                return;
            }
        }
 public static void Add(IAutoUpdate update) => AutoUpdatables._updateables.Add(new WeakReference((object)update));
Example #11
0
 public AutoUpdater(IAutoUpdate autoUpdateComponent)
 {
     _AutoUpdateComponent = autoUpdateComponent;
     _executable          = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) ? $"{AUTOUPDATER_PROCESS_EXEC_BASE}.exe" : AUTOUPDATER_PROCESS_EXEC_BASE;
 }
Example #12
0
        public void ReleaseChannel_DefaultsToExpectedValue()
        {
            IAutoUpdate update = BuildAutoUpdate();

            Assert.AreEqual(DefaultReleaseChannel.ToString(), update.ReleaseChannel);
        }
Example #13
0
 public AutoUpdate(IAutoUpdate autoUpdateComponent)
 {
     _AutoUpdateComponent = autoUpdateComponent;
 }