private void Update_Click(object sender, RoutedEventArgs e)
        {
            Button updateButton = sender as Button;

            updateButton.IsEnabled = false;

            // Create an update toast
            var toast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Info, new ErrorHandling.UserFacingMessage("update-update-started"), priority: UI.Components.Toast.Priority.Important);

            Manager.ToastManager.Show(toast);
            ErrorHandling.ErrorHandler.WriteToLog(Manager.TranslationService.GetString("update-update-started"), ErrorHandling.LogLevel.Info);

            var updateTask = Task.Run(async() =>
            {
                var success = await Update.Update.Run(ProductConstants.GetNumericVersion());
                if (!success)
                {
                    ErrorHandling.ErrorHandler.Handle(new ErrorHandling.UserFacingMessage("update-update-failed"), ErrorHandling.UserFacingErrorType.Toast, ErrorHandling.UserFacingSeverity.ShowError, ErrorHandling.LogLevel.Error);
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    updateButton.IsEnabled = true;
                });
            });
        }
Example #2
0
        private void Update_Click(object sender, RoutedEventArgs e)
        {
            Button updateButton = sender as Button;

            updateButton.IsEnabled = false;

            // Create an update toast
            var toast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Info, new ErrorHandling.UserFacingMessage("update-update-started"), priority: UI.Components.Toast.Priority.Important);

            Manager.ToastManager.Show(toast);
            ErrorHandling.ErrorHandler.WriteToLog(Manager.TranslationService.GetString("update-update-started"), ErrorHandling.LogLevel.Info);

            var updateTask = Task.Run(async() =>
            {
                var updateResult = await Update.Update.Run(ProductConstants.GetNumericVersion());

                switch (updateResult)
                {
                case Update.Update.UpdateResult.DisconnectTimeout:
                case Update.Update.UpdateResult.GeneralFailure:
                case Update.Update.UpdateResult.HttpError:
                case Update.Update.UpdateResult.InvalidSignature:
                case Update.Update.UpdateResult.SuccessNoUpdate:
                case Update.Update.UpdateResult.RunFailure:
                    ErrorHandling.ErrorHandler.Handle(new ErrorHandling.UserFacingMessage("update-update-failed"), ErrorHandling.UserFacingErrorType.Toast, ErrorHandling.UserFacingSeverity.ShowError, ErrorHandling.LogLevel.Error);
                    break;

                case Update.Update.UpdateResult.Georestricted:
                    ErrorHandling.ErrorHandler.Handle(new ErrorHandling.UserFacingMessage("update-update-failed-georestricted"), ErrorHandling.UserFacingErrorType.Toast, ErrorHandling.UserFacingSeverity.ShowError, ErrorHandling.LogLevel.Error);
                    break;
                }

                Application.Current.Dispatcher.Invoke(() =>
                {
                    updateButton.IsEnabled = true;
                });
            });
        }
        private async void UpdateVersionAsync(CancellationToken cancellationToken)
        {
            while (!cancellationToken.IsCancellationRequested)
            {
                JSONStructures.BalrogResponse balrogResponse;

                try
                {
                    balrogResponse = await Update.Balrog.QueryUpdate(ProductConstants.GetNumericVersion());
                }
                catch (Exception e)
                {
                    if (e is HttpRequestException)
                    {
                        cancellationToken.WaitHandle.WaitOne(TimeSpan.FromMinutes(5));
                        continue;
                    }
                    else
                    {
                        ErrorHandling.ErrorHandler.Handle(e, ErrorHandling.LogLevel.Error);
                        throw e;
                    }
                }

                if (balrogResponse != null)
                {
                    if (balrogResponse.Required)
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            var owner = Application.Current.MainWindow;
                            if (owner != null)
                            {
                                ((UI.MainWindow)owner).NavigateToView(new UI.UpdateView(), UI.MainWindow.SlideDirection.Right);
                                Manager.MustUpdate = true;
                            }
                        });
                    }
                    else
                    {
                        Application.Current.Dispatcher.Invoke(() =>
                        {
                            if (Manager.MainWindowViewModel.UpdateToast == null)
                            {
                                // Create an update toast
                                var message = new ErrorHandling.UserFacingMessage(
                                    "toast-update-version-message-1",
                                    new ErrorHandling.UserFacingMessage[] { new ErrorHandling.UserFacingMessage("toast-update-version-message-2", new List <Type>()
                                    {
                                        typeof(Underline), typeof(Bold)
                                    }) }
                                    );

                                var toast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Info, message, display: UI.Components.Toast.Display.Persistent, priority: UI.Components.Toast.Priority.Important)
                                {
                                    ClickEventHandler = (sender, e) =>
                                    {
                                        // Create an update toast
                                        var updateToast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Info, new ErrorHandling.UserFacingMessage("update-update-started"), priority: UI.Components.Toast.Priority.Important);
                                        Manager.ToastManager.Show(updateToast);
                                        ErrorHandling.ErrorHandler.WriteToLog(Manager.TranslationService.GetString("update-update-started"), ErrorHandling.LogLevel.Info);

                                        var updateTask = Task.Run(async() =>
                                        {
                                            var success = await Update.Update.Run(ProductConstants.GetNumericVersion());
                                            if (success)
                                            {
                                                // Dismiss the update toast
                                                Application.Current.Dispatcher.Invoke(() =>
                                                {
                                                    Manager.MainWindowViewModel.UpdateToast.Toast_Dismiss(null, null);
                                                });
                                            }
                                            else
                                            {
                                                ErrorHandling.ErrorHandler.Handle(new ErrorHandling.UserFacingMessage("update-update-failed"), ErrorHandling.UserFacingErrorType.Toast, ErrorHandling.UserFacingSeverity.ShowError, ErrorHandling.LogLevel.Error);
                                            }
                                        });
                                    },
                                };

                                Manager.MainWindowViewModel.UpdateToast = toast;
                            }

                            var owner = Application.Current.MainWindow;
                            if (owner != null)
                            {
                                // Show the update toast
                                Manager.ToastManager.Show(Manager.MainWindowViewModel.UpdateToast);
                            }
                        });
                    }
                }

                cancellationToken.WaitHandle.WaitOne(TimeSpan.FromHours(6));
            }
        }