Esempio n. 1
1
        public WaUpdaterViewModel(BuildType buildType)
        {
            if (buildType == BuildType.Stable)
            {
                manager = new StableWaUpdateManager();
            }
            else if (buildType == BuildType.Beta)
            {
                manager = new BetaWaUpdateManager();
            }
            else
            {
                throw new LauncherException("Unknown build type");
            }

            Settings = App.PersistentFactory.Create<UpdaterSettings>("UpdaterSettings" + buildType);
            Settings.Data.PropertyChanged += (sender, args) =>
                Settings.RequireSave();
            Application.Current.Exit += (sender, args) =>
                Settings.Save();

            UpdateCommand = new AwaitableDelegateCommand(async () =>
            {
                try
                {
                    await manager.UpdateAsync();
                    NewVersionAvailable = false;
                    nextUpdateCheck = DateTime.Now;
                }
                catch (Exception exception)
                {
                    App.Logger.LogError("update error", this, exception);
                    ErrorManager.ShowWarning("update error: " + exception.Message, exception);
                }
                manager.StatusReset();
            }, () => !UpdateInProgress);

            ReinstallCommand = new AwaitableDelegateCommand(async () =>
            {
                try
                {
                    manager.StatusReset();
                    AvailabilityStatus = string.Empty;
                    await manager.UninstallAsync();
                    await UpdateCommand.ExecuteAsync(null);
                }
                catch (Exception exception)
                {
                    App.Logger.LogError("reinstall error", this, exception);
                    ErrorManager.ShowWarning("reinstall error: " + exception.Message, exception);
                }
            });

            manager.UpdateStatusChanged += (sender, args) =>
            {
                UpdateStatus = args.Status;
                UpdateInProgress = args.IsRunning;
                UpdateProgressIndeterminate = args.ProgressIndeterminate;
                UpdateProgress = args.Progress;
            };

            AvailabilityStatus = "Checking for updates...";

            timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(1) };

            timer.Tick += async (s, a) =>
            {
                timer.Interval = TimeSpan.FromSeconds(10);

                if (!initialNewsLoad)
                {
                    initialNewsLoad = true;
                    RefreshWaNews();
                }

                Settings.Update();
                if (!UpdateInProgress && DateTime.Now > nextUpdateCheck)
                {
                    nextUpdateCheck = DateTime.Now + TimeSpan.FromHours(6);

                    try
                    {
                        CheckingVersion = true;
                        AvailabilityStatus = "Checking for updates...";
                        await CheckForNewVersion();
                        CheckingVersion = false;

                        if (newVersionAvailable)
                        {
                            RefreshWaNews();
                            manager.StatusReset();
                            AvailabilityStatus = string.Empty;
                            // run auto update if applicable
                            if (Settings.Data.NotifyOnNewVersion)
                            {
                                // todo show baloon, max once each 16 hours
                                if (DateTime.Now > nextUpdateReminder)
                                {
                                    var message = string.Format("New {0} Wurm Assistant version is available!", buildType);
                                    App.LauncherTaskbarIcon.ShowBalloonTip("Rejoice!", message, BalloonIcon.Info);
                                    nextUpdateReminder = DateTime.Now + TimeSpan.FromHours(16);
                                }
                            }
                            if (Settings.Data.AutoUpdate)
                            {
                                try
                                {
                                    await manager.UpdateAsync();
                                    NewVersionAvailable = false;
                                    nextUpdateCheck = DateTime.Now;
                                    var message =
                                        string.Format("{0} Wurm Assistant has just been updated to new version!",
                                            buildType);
                                    // show tray pop
                                    App.LauncherTaskbarIcon.ShowBalloonTip("Rejoice!", message, BalloonIcon.Info);
                                }
                                catch (Exception exception)
                                {
                                    // handle exceptions silently
                                    App.Logger.LogError("auto update failed, " + buildType, this, exception);
                                }
                                manager.StatusReset();
                            }
                        }
                        else
                        {
                            manager.StatusReset();
                            AvailabilityStatus = "WA-" + buildType + " is up to date";
                        }
                    }
                    catch (Exception exception)
                    {
                        App.Logger.LogError("Update error", this, exception);
                        AvailabilityStatus = "Error: " + exception.Message +
                            ". Try checking internet connection, firewall settings or restarting the launcher."
                            + " Version check will retry in 5 minutes.";
                        nextUpdateCheck = DateTime.Now + TimeSpan.FromMinutes(5);
                    }
                }
            };
        }
 public async Task TestCommand() {
     testCount = 0;
     var testIncrement = new Func<Task>(async () => { await Task.Run(() => { testCount++; }); });
     var command = new AwaitableDelegateCommand(testIncrement);
     for (int i = 0; i < 10; i++) {
         await command.ExecuteAsync();
     }
     Assert.AreEqual(10, testCount, "testCount hat nicht den erwarteten Wert!");
 }
        public async Task TaskCalculateParallelWhenAllShouldReturnSquares(int anzahl)
        {
            _testee.Anzahl = anzahl;

            AwaitableDelegateCommand command = _testee.CalculateParallelWhenAllCommand;
            await command.ExecuteAsync(null);

            _testee.ResultOutput.Should().Be(GetSquares(0, anzahl - 1));
        }
        public async Task CalculateMultiAsyncResultShouldBeVisible()
        {
            _testee.Anzahl = 3;

            AwaitableDelegateCommand command = _testee.CalculateMultiAsyncCommand;
            await command.ExecuteAsync(null);

            _testee.IsResultVisible.Should().Be(true);
        }
        public async Task CalculateMultiAsyncShouldReturnSquares()
        {
            _testee.Anzahl = 10;

            AwaitableDelegateCommand command = _testee.CalculateMultiAsyncCommand;
            await command.ExecuteAsync(null);

            _testee.ResultOutput.Should().Be(GetSquares(0, 9));
        }
Esempio n. 6
0
        public async Task TestCommand()
        {
            testCount = 0;
            var testIncrement = new Func <Task>(async() => { await Task.Run(() => { testCount++; }); });
            var command       = new AwaitableDelegateCommand(testIncrement);

            for (int i = 0; i < 10; i++)
            {
                await command.ExecuteAsync();
            }
            Assert.AreEqual(10, testCount, "testCount hat nicht den erwarteten Wert!");
        }