Exemple #1
0
        public MainViewModel(TaskExecutionService taskExecutionService, HistoryService historyService, WindowService windowService)
        {
            // Commands
            WindowShownCommand = new RelayCommand <Window>(w =>
            {
                _taskbarIcon = (w as MainWindow)?.MainTaskbarIcon; // HACK: slightly MVVM breaking
                Locator.StartServicesAsync().Forget();             // Start services after the main window is loaded
            });
            WindowClosingCommand = new RelayCommand <CancelEventArgs>(args =>
            {
                args.Cancel = true;
                windowService.MainWindowHide();
            });

            ShowHideWindowCommand  = new RelayCommand(windowService.MainWindowToggleShowHide);
            ShowAboutCommand       = new RelayCommand(async() => await windowService.ShowAboutWindowAsync());
            ShowHelpCommand        = new RelayCommand(ShowHelp);
            SubmitBugReportCommand = new RelayCommand(async() => await windowService.ShowBugReportWindowAsync());
            ExitComand             = new RelayCommand(() => Application.Current.ShutdownSafe(ExitCode.UserExit));

            // Events
            taskExecutionService.TaskAddedToQueue += (sender, args) => windowService.MainWindowShow();
            historyService.HistoryEntryRecorded   += (sender, args) =>
            {
                if (!Settings.ShowNotifications)
                {
                    return;
                }
                _taskbarIcon?.ShowBalloonTip("Modboy", Localization.Localize(args.Entry),
                                             args.Entry.Success ? BalloonIcon.Info : BalloonIcon.Error);
            };
        }
        public OverviewViewModel(TaskExecutionService taskExecutionService, PersistenceService persistenceService, WindowService windowService)
        {
            _taskExecutionService = taskExecutionService;
            _persistenceService   = persistenceService;
            _windowService        = windowService;

            // Setup collection view
            _collectionView = CollectionViewSource.GetDefaultView(Mods);

            // Commands
            ToggleExpandCommand = new RelayCommand <ModStatus>(ToggleExpand);
            ExpandCommand       = new RelayCommand <ModStatus>(Expand);
            UnexpandCommand     = new RelayCommand <ModStatus>(Unexpand);
            ClearFilters        = new RelayCommand(() => NameFilter = GameFilter = null,
                                                   () => NameFilter.IsNotBlank() || GameFilter.IsNotBlank());
            AbortCommand       = new RelayCommand <string>(Abort);
            OpenModPageCommand = new RelayCommand <string>(OpenModPage);
            VerifyCommand      = new RelayCommand <string>(Verify);
            ReinstallCommand   = new RelayCommand <string>(Reinstall);
            UninstallCommand   = new RelayCommand <string>(Uninstall);

            // Events
            Localization.PropertyChanged += (sender, args) =>
            {
                UpdateLocalization();
                PopulateAll();
            };
            _taskExecutionService.TaskAddedToQueue += (sender, args) => PopulateEnqueuedMods();
            _taskExecutionService.TaskStateChanged += (sender, args) => PopulateCurrent();
            _taskExecutionService.TaskEnded        += (sender, args) =>
            {
                // If it was a verification task - notify of the result
                if (args.Task.Type == TaskType.Verify)
                {
                    if (args.Success)
                    {
                        _windowService.ShowNotificationWindowAsync(Localization.Overview_VerifySuccessfulNotification).GetResult();
                    }
                    else
                    {
                        _windowService.ShowErrorWindowAsync(Localization.Overview_VerifyUnsuccessfulNotification).GetResult();
                    }
                }

                RemoveModStatus(args.Task.ModID);
                PopulateInstalledMod(args.Task.ModID);
            };
            _taskExecutionService.TaskAborted += (sender, args) =>
            {
                RemoveModStatus(args.Task.ModID);
                PopulateInstalledMod(args.Task.ModID);
            };
            _taskExecutionService.TaskRemovedFromQueue += (sender, args) =>
            {
                RemoveModStatus(args.Task.ModID);
                PopulateInstalledMod(args.Task.ModID);
            };

            // Initial population
            UpdateLocalization();
            PopulateAll();
        }