Example #1
0
        private static MainWindowViewModel Create(
            IEventAggregator eventAggregator         = null,
            IKataAttemptRepository attemptRepository = null,
            IGenerateAndLaunchKataCommand generateAndLaunchKataCommand = null,
            ISettingsManager settingsManager = null,
            IPlayerNotifier playerNotifier   = null,
            IKataraiApp kataraiApp           = null)
        {
            settingsManager = settingsManager ?? CreateSubstituteSettingsManager();
            var viewModel = new MainWindowViewModel(
                eventAggregator ?? Substitute.For <IEventAggregator>(),
                kataraiApp ?? Substitute.For <IKataraiApp>(),
                playerNotifier ?? Substitute.For <IPlayerNotifier>(),
                attemptRepository ?? Substitute.For <IKataAttemptRepository>(),
                generateAndLaunchKataCommand ?? Substitute.For <IGenerateAndLaunchKataCommand>(),
                Substitute.For <ISendFeedbackCommand>(),
                Substitute.For <IShowMainWindowCommand>(),
                Substitute.For <IHideMainWindowCommand>(),
                Substitute.For <IExitApplicationCommand>(),
                settingsManager,
                Substitute.For <IOpenKataSolutionCommand>(),
                Substitute.For <IShowReminderSettingsCommand>(),
                Substitute.For <IShowAttemptsCommand>(),
                Substitute.For <IShowCompletedKatasCommand>(),
                Substitute.For <IShowAttemptsPerWeekCommand>(),
                Substitute.For <IAbandonAttemptCommand>(),
                Substitute.For <IShowAboutWindowCommand>());

            viewModel.KataraiApp = new KataraiApp(settingsManager);
            return(viewModel);
        }
        public MainWindowViewModel(
            IEventAggregator eventAggregator,
            IKataraiApp kataraiApp,
            IPlayerNotifier playerNotifier,
            IKataAttemptRepository attemptRepository,
            IGenerateAndLaunchKataCommand generateKataCommand,
            ISendFeedbackCommand sendFeedbackCommand,
            IShowMainWindowCommand showMainWindowCommand,
            IHideMainWindowCommand hideMainWindowCommand,
            IExitApplicationCommand exitApplicationCommand,
            ISettingsManager settingsManager,
            IOpenKataSolutionCommand openKataSolutionCommand,
            IShowReminderSettingsCommand showReminderSettingsCommand,
            IShowAttemptsCommand showAttemptsCommand,
            IShowCompletedKatasCommand showCompletedKatasCommand,
            IShowAttemptsPerWeekCommand showAttemptsPerWeekCommand,
            IAbandonAttemptCommand abandonAttemptCommand,
            IShowAboutWindowCommand showAboutWindowCommand)
        {
            if (eventAggregator == null)
            {
                throw new ArgumentNullException(nameof(eventAggregator));
            }
            if (kataraiApp == null)
            {
                throw new ArgumentNullException(nameof(kataraiApp));
            }
            if (playerNotifier == null)
            {
                throw new ArgumentNullException(nameof(playerNotifier));
            }
            if (attemptRepository == null)
            {
                throw new ArgumentNullException(nameof(attemptRepository));
            }
            if (generateKataCommand == null)
            {
                throw new ArgumentNullException(nameof(generateKataCommand));
            }
            if (sendFeedbackCommand == null)
            {
                throw new ArgumentNullException(nameof(sendFeedbackCommand));
            }
            if (showMainWindowCommand == null)
            {
                throw new ArgumentNullException(nameof(showMainWindowCommand));
            }
            if (hideMainWindowCommand == null)
            {
                throw new ArgumentNullException(nameof(hideMainWindowCommand));
            }
            if (exitApplicationCommand == null)
            {
                throw new ArgumentNullException(nameof(exitApplicationCommand));
            }
            if (openKataSolutionCommand == null)
            {
                throw new ArgumentNullException(nameof(openKataSolutionCommand));
            }
            if (showReminderSettingsCommand == null)
            {
                throw new ArgumentNullException(nameof(showReminderSettingsCommand));
            }
            if (showAttemptsCommand == null)
            {
                throw new ArgumentNullException(nameof(showAttemptsCommand));
            }
            if (showCompletedKatasCommand == null)
            {
                throw new ArgumentNullException(nameof(showCompletedKatasCommand));
            }
            if (showAttemptsPerWeekCommand == null)
            {
                throw new ArgumentNullException(nameof(showAttemptsPerWeekCommand));
            }
            if (abandonAttemptCommand == null)
            {
                throw new ArgumentNullException(nameof(abandonAttemptCommand));
            }
            if (showAboutWindowCommand == null)
            {
                throw new ArgumentNullException(nameof(showAboutWindowCommand));
            }
            _eventAggregator            = eventAggregator;
            _kataraiApp                 = kataraiApp;
            _playerNotifier             = playerNotifier;
            _attemptRepository          = attemptRepository;
            _settingsManager            = settingsManager;
            ShowReminderSettingsCommand = WrapWithLogging(showReminderSettingsCommand);
            ShowAttemptsCommand         = WrapWithLogging(showAttemptsCommand);
            ShowCompletedKatasCommand   = WrapWithLogging(showCompletedKatasCommand);
            ShowAttemptsPerWeekCommand  = WrapWithLogging(showAttemptsPerWeekCommand);
            AbandonAttemptCommand       = WrapWithLogging(abandonAttemptCommand);
            GenerateKataSolution        = WrapWithLogging(generateKataCommand);
            RegisterNewKataAttemptEvent();
            SendFeedbackCommand     = sendFeedbackCommand;
            ShowWindowCommand       = WrapWithLogging(showMainWindowCommand);
            HideWindowCommand       = WrapWithLogging(hideMainWindowCommand);
            ExitApplicationCommand  = exitApplicationCommand;
            ShowAboutWindowCommand  = showAboutWindowCommand;
            OpenKataSolutionCommand = WrapWithLogging(openKataSolutionCommand);

            Katas = _attemptRepository.GetKataInfos();
            LoadSettings();
            IsAlwaysOnTop  = settingsManager.IsAlwaysOnTopOn();
            ShouldShowHint = settingsManager.IsShowHintOn();
            NotificationVisibilityTimeSeconds = settingsManager.GetNotificationVisibilityTime();
            RegisterAbandonAttemptEvent();

            Initialize();
            KataMenuItems = new ObservableCollection <MenuItem>();
            FeedbackItems = new ObservableCollection <string>();
            SetupKataMenuItems();
            _eventAggregator.Subscribe(this);
        }