コード例 #1
0
 public MainWindowViewModel()
 {
     CompositeDisposable.Add(_backstageViewModel  = new BackstageViewModel());
     CompositeDisposable.Add(this._inputViewModel = new InputViewModel());
     CompositeDisposable.Add(_mainAreaViewModel   = new MainAreaViewModel());
     CompositeDisposable.Add(_globalAccountSelectionFlipViewModel = new AccountSelectionFlipViewModel());
     CompositeDisposable.Add(_settingFlipViewModel          = new SettingFlipViewModel(this));
     CompositeDisposable.Add(_tabConfigurationFlipViewModel = new TabConfigurationFlipViewModel());
     CompositeDisposable.Add(_searchFlipViewModel           = new SearchFlipViewModel());
     CompositeDisposable.Add(Observable
                             .FromEvent <FocusRequest>(
                                 h => MainWindowModel.FocusRequested += h,
                                 h => MainWindowModel.FocusRequested -= h)
                             .Subscribe(SetFocus));
     CompositeDisposable.Add(Observable
                             .FromEvent <bool>(
                                 h => MainWindowModel.BackstageTransitionRequested += h,
                                 h => MainWindowModel.BackstageTransitionRequested -= h)
                             .Subscribe(this.TransitionBackstage));
     CompositeDisposable.Add(Setting.BackgroundImagePath.ListenValueChanged(
                                 _ =>
     {
         RaisePropertyChanged(() => BackgroundImageUri);
         RaisePropertyChanged(() => BackgroundImage);
     }));
     CompositeDisposable.Add(Setting.BackgroundImageTransparency.ListenValueChanged(
                                 _ => RaisePropertyChanged(() => BackgroundImageOpacity)));
     CompositeDisposable.Add(Setting.RotateWindowContent.ListenValueChanged(
                                 _ => RaisePropertyChanged(() => RotateWindowContent)));
     this._backstageViewModel.Initialize();
 }
コード例 #2
0
        public void GivenViewModel_WhenExecutingSetSelectedViewModelCommandAndSetToSameViewModel_ThenNothingHappens(
            Func <BackstageViewModel, IBackstagePageViewModel> getBackstagePageViewModelFunc,
            bool infoSelected, bool openSelected, bool aboutSelected)
        {
            // Given
            var viewModel = new BackstageViewModel(new GuiCoreSettings(), "1.0");
            IBackstagePageViewModel backstagePageViewModel = getBackstagePageViewModelFunc(viewModel);

            viewModel.SelectedViewModel = backstagePageViewModel;

            // Precondition
            Assert.AreSame(backstagePageViewModel, viewModel.SelectedViewModel);
            Assert.AreEqual(infoSelected, viewModel.InfoSelected);
            Assert.AreEqual(aboutSelected, viewModel.AboutSelected);
            Assert.AreEqual(openSelected, viewModel.SupportSelected);

            var propertyChangedCount = 0;

            viewModel.PropertyChanged += (sender, args) => propertyChangedCount++;

            // When
            viewModel.SetSelectedViewModelCommand.Execute(backstagePageViewModel);

            // Then
            Assert.AreSame(backstagePageViewModel, viewModel.SelectedViewModel);
            Assert.AreEqual(infoSelected, viewModel.InfoSelected);
            Assert.AreEqual(aboutSelected, viewModel.AboutSelected);
            Assert.AreEqual(openSelected, viewModel.SupportSelected);
            Assert.AreEqual(0, propertyChangedCount);
        }
コード例 #3
0
 public BackstageAccountViewModel(BackstageViewModel parent, BackstageAccountModel model)
 {
     _parent = parent;
     _model = model;
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.ConnectionStateChanged += h,
             h => _model.ConnectionStateChanged -= h)
                   .Subscribe(_ => ConnectionStateChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.TwitterUserChanged += h,
             h => _model.TwitterUserChanged -= h)
                   .Subscribe(_ => UserChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.FallbackStateUpdated += h,
             h => _model.FallbackStateUpdated -= h)
                   .Subscribe(_ => this.FallbackStateUpdated()));
     this.CompositeDisposable.Add(
         Observable.Interval(TimeSpan.FromSeconds(5))
                   .Subscribe(_ =>
                   {
                       var count = PostLimitPredictionService.GetCurrentWindowCount(model.Account.Id);
                       MaxUpdate = Setting.PostLimitPerWindow.Value;
                       RemainUpdate = MaxUpdate - count;
                       this.RaisePropertyChanged(() => RemainUpdate);
                       this.RaisePropertyChanged(() => MaxUpdate);
                       this.RaisePropertyChanged(() => IsWarningPostLimit);
                   }));
 }
コード例 #4
0
 public BackstageAccountViewModel(BackstageViewModel parent, BackstageAccountModel model)
 {
     _parent = parent;
     _model  = model;
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.ConnectionStateChanged += h,
             h => _model.ConnectionStateChanged -= h)
         .Subscribe(_ => ConnectionStateChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.TwitterUserChanged += h,
             h => _model.TwitterUserChanged -= h)
         .Subscribe(_ => UserChanged()));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => _model.FallbackStateUpdated += h,
             h => _model.FallbackStateUpdated -= h)
         .Subscribe(_ => this.FallbackStateUpdated()));
     this.CompositeDisposable.Add(
         Observable.Interval(TimeSpan.FromSeconds(5))
         .Subscribe(_ =>
     {
         var count    = PostLimitPredictionService.GetCurrentWindowCount(model.Account.Id);
         MaxUpdate    = Setting.PostLimitPerWindow.Value;
         RemainUpdate = MaxUpdate - count;
         this.RaisePropertyChanged(() => RemainUpdate);
         this.RaisePropertyChanged(() => MaxUpdate);
         this.RaisePropertyChanged(() => IsWarningPostLimit);
     }));
 }
コード例 #5
0
 /// <summary>
 /// Creates a new Viewmodel.
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="EditMode">If set to to true, the fields contains values from the current company</param>
 public EditCompanyViewModel(BackstageViewModel parent, bool EditMode)
 {
     ParentViewModel = parent;
     this.EditMode = EditMode;
     if (EditMode)
         BackstageTabItem = new EditContentTabItem() { DataContext = this };
     else
         BackstageTabItem = new ContentTabItem() { DataContext = this };
     CompanyInformation = new Core.Models.CompanyInformation();
     CompanySettings = new Core.Models.CompanySettings();
 }
コード例 #6
0
        public MainWindowViewModel()
        {
            Globals.Model   = new Model(Settings.Default.User);
            _home           = new HomeViewModel(Navigate, null);
            _home.Backstage = _backstage = new BackstageViewModel(Navigate, _home);
            if (!Globals.Model.Assets.Exists("BasinShapefile"))
            {
                SelectedViewModel = new SplashViewModel(Navigate, _backstage, _home);
            }
            else
            {
                SelectedViewModel = _home;
            }

            RaisePropertyChanged(nameof(Title));
            _home.PropertyChanged      += (sender, args) => RaisePropertyChanged(nameof(Title));
            _backstage.PropertyChanged += (sender, args) => RaisePropertyChanged(nameof(Title));
        }
コード例 #7
0
        public void GivenViewModelWithSettingsWithOrWithoutUserManualPathSet_WhenCanExecuteOpenUserManualCommand_ThenExpectedValue(
            bool userManualPresent)
        {
            // Given
            string path = Uri.UnescapeDataString(new UriBuilder(Assembly.GetExecutingAssembly().CodeBase).Path);

            var settings = new GuiCoreSettings
            {
                ManualFilePath = userManualPresent ? path : null
            };

            var viewModel = new BackstageViewModel(settings, "1.0");

            // When
            bool canExecute = viewModel.OpenUserManualCommand.CanExecute(null);

            // Then
            Assert.AreEqual(userManualPresent, canExecute);
        }
コード例 #8
0
        public void GivenViewModel_WhenExecutingSetSelectedViewModelCommand_ThenExpectedValuesSetAndPropertyChangedEventsFired(
            Func <BackstageViewModel, IBackstagePageViewModel> getBackstagePageViewModelFunc,
            bool infoSelected, bool openSelected, bool aboutSelected)
        {
            // Given
            var viewModel = new BackstageViewModel(new GuiCoreSettings(), "1.0");
            IBackstagePageViewModel backstagePageViewModel = getBackstagePageViewModelFunc(viewModel);

            if (backstagePageViewModel is InfoViewModel)
            {
                viewModel.SelectedViewModel = viewModel.AboutViewModel;
            }

            var propertyNames = new List <string>();

            viewModel.PropertyChanged += (sender, args) =>
            {
                propertyNames.Add(args.PropertyName);
            };

            // When
            viewModel.SetSelectedViewModelCommand.Execute(backstagePageViewModel);

            // Then
            Assert.AreSame(backstagePageViewModel, viewModel.SelectedViewModel);
            Assert.AreEqual(infoSelected, viewModel.InfoSelected);
            Assert.AreEqual(aboutSelected, viewModel.AboutSelected);
            Assert.AreEqual(openSelected, viewModel.SupportSelected);
            CollectionAssert.AreEqual(new[]
            {
                nameof(viewModel.SelectedViewModel),
                nameof(viewModel.InfoSelected),
                nameof(viewModel.AboutSelected),
                nameof(viewModel.SupportSelected)
            }, propertyNames);
        }
コード例 #9
0
        public void Constructor_ExpectedValues()
        {
            // Setup
            var settings = new GuiCoreSettings
            {
                ApplicationName = "Test application",
                SupportHeader   = "Support",
                SupportText     = "Some text"
            };
            const string version = "1.0";

            // Call
            var viewModel = new BackstageViewModel(settings, version);

            // Assert
            Assert.IsInstanceOf <INotifyPropertyChanged>(viewModel);

            Assert.IsNotNull(viewModel.InfoViewModel);
            Assert.IsNull(viewModel.InfoViewModel.ProjectName);

            Assert.IsNotNull(viewModel.AboutViewModel);
            Assert.AreEqual(settings.ApplicationName, viewModel.AboutViewModel.ApplicationName);
            Assert.AreEqual(version, viewModel.AboutViewModel.Version);

            Assert.IsNotNull(viewModel.SupportViewModel);
            Assert.AreEqual(settings.SupportHeader, viewModel.SupportViewModel.SupportHeader);
            Assert.AreEqual(settings.SupportText, viewModel.SupportViewModel.SupportText);

            Assert.IsNotNull(viewModel.OpenUserManualCommand);
            Assert.IsNotNull(viewModel.SetSelectedViewModelCommand);

            Assert.AreSame(viewModel.InfoViewModel, viewModel.SelectedViewModel);
            Assert.IsTrue(viewModel.InfoSelected);
            Assert.IsFalse(viewModel.AboutSelected);
            Assert.IsFalse(viewModel.SupportSelected);
        }
コード例 #10
0
 public ChangeCompanyViewModel(BackstageViewModel parent)
 {
     ParentViewModel = parent;
     BackstageTabItem = new ContentTabItem() { DataContext = this };
     AllCompanies = new ObservableCollection<CompanyInformation>();
 }