Beispiel #1
0
        public TaskBoardViewModel(IRepositoryProvider repositoryProvider, IEventAggregator bus, ICommandResolver commandResolver)
        {
            _repositoryProvider = repositoryProvider;
            _bus = bus;
            _commandResolver = commandResolver;

            Tasks = new SortableReactiveCollection<TaskViewModel>();

            Tasks.ItemChanged
                .Throttle(TimeSpan.FromSeconds(5))
                .Select(c => c.Sender)
                .Where(c =>  _repository != null)
                .Where(task => !task.IsEditing)
                .SubscribeOn(RxApp.DeferredScheduler)
                .Subscribe(_ => OnSaveAllTasks(null));

            Tasks.ItemChanged
                .Where(c => c.PropertyName == "IsSelected")
                .SubscribeOn(RxApp.DeferredScheduler)
                .Select(c => c.Sender)
                .Subscribe(IsSelectedChanged);

            Tasks.ItemChanged
                .Where(c => c.PropertyName == "State")
                .SubscribeOn(RxApp.DeferredScheduler)
                .Select(c => c.Sender)
                .Subscribe(StateChanged);

            Tasks.ChangeTrackingEnabled = true;

            _bus.ListenOnScheduler<DatabaseChanged>(OnDatabaseChanged);
            _bus.ListenOnScheduler<CreateNewTask>(OnCreateNewTask);
            _bus.ListenOnScheduler<CreateNewSubTask>(OnCreateNewSubTask);
            _bus.ListenOnScheduler<SaveAllTasks>(OnSaveAllTasks);
            _bus.ListenOnScheduler<ReloadAllTasks>(evt => Reload());
            _bus.ListenOnScheduler<ReSort>(evt => Reorder());
            _bus.ListenOnScheduler<CollapseAll>(evt => OnCollapseAll());

            _bus.AddSource(Tasks.PropertyOnAnyChanged(vm => vm.State)
                .Select(_ => new TaskStateChanged()));

            DragCommand = new ReactiveCommand();

            DragCommand.OfType<DragCommandArgs>().Subscribe(OnNext);
        }