Exemplo n.º 1
0
        private AddingTimePointViewModel GetAddingTimePointViewModel()
        {
            _mockCommand = _mockPresetViewModel.As <ICommand>();
            //_mockCommand.Setup(c => c.Execute(It.IsAny<Object>())).Callback(() => { });
            //_mockCommand.Setup(c => c.CanExecute(It.IsAny<Object>())).Callback(() => { });

            _mockPresetViewModel.Setup(c => c.AddTimePointCommand).Returns(_mockCommand.Object);

            var atpvm = new AddingTimePointViewModel(_mockPresetViewModel.Object);

            return(atpvm);
        }
Exemplo n.º 2
0
        public PresetViewModel(Preset preset, IMainViewModel mainViewModel)
        {
            #region local functions

            void LoadTimePointViewModelCollection()
            {
                if (Preset.TimePointCollection.Count > 0)
                {
                    foreach (var point in Preset.TimePointCollection)
                    {
                        _timePointVmCollection.Add(GetTimePointViewModel(point));

                        if (!_settedLoopNumbers.Contains(point.LoopNumber))
                        {
                            AddVisualBounds(point.LoopNumber);
                        }
                    }
                }
            }

            void SetupTimePointVmCollectionView()
            {
                ICollectionView view = CollectionViewSource.GetDefaultView(TimePointVmCollection);

                view.SortDescriptions.Clear();
                view.SortDescriptions.Add(new SortDescription("LoopNumber", ListSortDirection.Ascending));
                view.SortDescriptions.Add(new SortDescription("Id", ListSortDirection.Ascending));
            }

            void SetupCanBellOnStartTime()
            {
                if (Preset.Tag is string str)
                {
                    if (str == "true")
                    {
                        CanBellOnStartTime = true;
                    }
                    else if (str == "false")
                    {
                        CanBellOnStartTime = false;
                    }
                }
            }

            AddingTimePointViewModel GetAddingTimePointViewModel()
            {
                var addingTimePoint = new AddingTimePointViewModel(this);

                addingTimePoint.Reset();

                ((INotifyPropertyChanged)addingTimePoint).PropertyChanged += OnTimePropertyChanged;

                return(addingTimePoint);
            }

            #endregion


            Preset         = preset ?? throw new ArgumentNullException(nameof(preset));
            _mainViewModel = mainViewModel ?? throw new ArgumentNullException(nameof(mainViewModel));

            _settedLoopNumbers = new HashSet <int>();

            _timePointVmCollection = new ObservableCollection <TimePointViewModelBase>();
            LoadTimePointViewModelCollection();

            TimePointVmCollection = new ReadOnlyObservableCollection <TimePointViewModelBase>(_timePointVmCollection);

            SetupTimePointVmCollectionView();
            SetupCanBellOnStartTime();

            AddingTimePoint = GetAddingTimePointViewModel();

            ((INotifyCollectionChanged)Preset.TimePointCollection).CollectionChanged += OnTimePointCollectionChanged;

            _dispatcher = Application.Current?.Dispatcher;
        }