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;
                });
            });
        }
Beispiel #2
0
        /// <summary>
        /// Removes the next available ephemeral toast from the queue and signifies the the toast scheduler to display it.
        /// </summary>
        /// <returns>The dequeued ephemeral toast to be displayed.</returns>
        public UI.Components.Toast.Toast Dequeue()
        {
            var toast = ToastList.FirstOrDefault();

            if (toast != null)
            {
                ToastList.RemoveAt(0);
            }

            DisplayToast = toast;
            return(toast);
        }
Beispiel #3
0
        /// <summary>
        /// Adds the desired toast to the queue/list be scheduled for display.
        /// </summary>
        /// <param name="toast">Toast to be displayed.</param>
        public void Show(UI.Components.Toast.Toast toast)
        {
            switch (toast.Display)
            {
            case UI.Components.Toast.Display.Ephemeral:
                ephemeralToastQueue.Add(toast);
                break;

            case UI.Components.Toast.Display.Persistent:
                persistentToastList.Add(toast);
                break;

            default:
                break;
            }
        }
        private void UpdateSubscriptionStatusUI(bool newStatus)
        {
            if (newStatus)
            {
                viewModel.SubscriptionStatus = string.Format("Subscription: {0}", JSONStructures.SubscriptionStatus.Active);
            }
            else
            {
                viewModel.SubscriptionStatus = string.Format("Subscription: {0}", JSONStructures.SubscriptionStatus.Inactive);

                // Log the user out when their subscription is inactive
                Manager.Account.Logout(removeDevice: false);

                // Navigate the user to the sign in screen and display subscription expired toast
                Application.Current.Dispatcher.Invoke(() =>
                {
                    var owner = Application.Current.MainWindow;
                    if (owner != null)
                    {
                        ((UI.MainWindow)owner).NavigateToView(new UI.LinkAccountView(), UI.MainWindow.SlideDirection.Right);

                        // Create a subscription expired toast
                        var message = new ErrorHandling.UserFacingMessage(
                            "toast-no-subscription",
                            new ErrorHandling.UserFacingMessage[] { new ErrorHandling.UserFacingMessage("subscribe-url-title", new List <Type>()
                            {
                                typeof(Underline), typeof(Bold)
                            }) }
                            );

                        var toast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Info, message, priority: UI.Components.Toast.Priority.Important)
                        {
                            ClickEventHandler = (sender, e) =>
                            {
                                Process.Start(ProductConstants.SubscriptionUrl);
                            },
                        };

                        // Display the subscription expired toast
                        Manager.ToastManager.Show(toast);
                    }
                });
            }
        }
        /// <summary>
        /// Add a persistent toast to the list, reorders the toast list based on priority level, and displays when available.
        /// </summary>
        /// <param name="toast">The persistent toast to display.</param>
        public void Add(UI.Components.Toast.Toast toast)
        {
            ToastList.Add(toast);
            var newToastList = ToastList.OrderByDescending(x => x.Priority).Take(Size < Capacity ? Size : Capacity).ToList();

            // If at capacity, remove obsolete persistent toasts
            if (AtCapacity)
            {
                foreach (UI.Components.Toast.Toast existingToast in ToastList)
                {
                    if (!newToastList.Contains(existingToast))
                    {
                        existingToast.RemoveFromElement();
                    }
                }
            }

            ToastList = newToastList;
        }
Beispiel #6
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;
                });
            });
        }
Beispiel #7
0
        /// <summary>
        /// Shows a toast offering the user the chance to start the Broker service.
        /// </summary>
        public static void PromptRestartBrokerService()
        {
            Application.Current.Dispatcher.Invoke(() =>
            {
                var toast = new UI.Components.Toast.Toast(UI.Components.Toast.Style.Error, new ErrorHandling.UserFacingMessage("toast-service-communication-error"), priority: UI.Components.Toast.Priority.Important)
                {
                    ClickEventHandler = (sender, e) =>
                    {
                        Task.Run(() =>
                        {
                            // Get the broker service from the service controller
                            var brokerService = ServiceController.GetServices().Where(s => s.ServiceName == ProductConstants.BrokerServiceName).FirstOrDefault();

                            // Start a net process to restart the broker service
                            if (brokerService.Status == ServiceControllerStatus.Stopped)
                            {
                                ProcessStartInfo info = new ProcessStartInfo
                                {
                                    UseShellExecute = true,
                                    WindowStyle     = ProcessWindowStyle.Hidden,
                                    Verb            = "runas",
                                    FileName        = "net",
                                    Arguments       = string.Join(" ", new string[] { "start", ProductConstants.BrokerServiceName }),
                                };

                                try
                                {
                                    Process.Start(info);
                                }
                                catch (Exception)
                                {
                                    Application.Current.Dispatcher.Invoke(() =>
                                    {
                                        Manager.ToastManager.Show(new UI.Components.Toast.Toast(UI.Components.Toast.Style.Error, new ErrorHandling.UserFacingMessage("toast-service-restart-error"), duration: TimeSpan.FromSeconds(5), priority: UI.Components.Toast.Priority.Important));
                                    });
                                }
                            }

                            // Wait for the broker service to run
                            brokerService.WaitForStatus(ServiceControllerStatus.Running, BrokerServiceTimeout);

                            if (brokerService.Status == ServiceControllerStatus.Running)
                            {
                                Application.Current.Dispatcher.Invoke(() =>
                                {
                                    Manager.ToastManager.Show(new UI.Components.Toast.Toast(UI.Components.Toast.Style.Success, new ErrorHandling.UserFacingMessage("toast-service-restart-success"), duration: TimeSpan.FromSeconds(5), priority: UI.Components.Toast.Priority.Important));
                                });
                            }
                            else
                            {
                                Application.Current.Dispatcher.Invoke(() =>
                                {
                                    Manager.ToastManager.Show(new UI.Components.Toast.Toast(UI.Components.Toast.Style.Error, new ErrorHandling.UserFacingMessage("toast-service-restart-error"), duration: TimeSpan.FromSeconds(5), priority: UI.Components.Toast.Priority.Important));
                                });
                            }
                        });
                    },
                };

                Manager.ToastManager.Show(toast);
            });
        }
        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));
            }
        }
Beispiel #9
0
 /// <summary>
 /// Adds an ephemeral toast to the queue and reorders the queue based on priority level.
 /// </summary>
 /// <param name="toast">The ephemeral toast to add to the queue.</param>
 public void Add(UI.Components.Toast.Toast toast)
 {
     ToastList.Add(toast);
     ToastList = ToastList.OrderByDescending(x => x.Priority).Take(Size < Capacity ? Size : Capacity).ToList();
 }