Example #1
0
        public MonitorViewModel(
            IDataSelectViewModel dataViewModel,
            ITrainingViewModel trainingViewModel,
            IFileMonitorFactory fileMonitorFactory,
            IFolderBrowserDialogService folderBrowserDialog)
            : base(new NullHandler <IFileMonitor>())
        {
            Guard.NotNull(() => trainingViewModel, trainingViewModel);
            Guard.NotNull(() => fileMonitorFactory, fileMonitorFactory);
            Guard.NotNull(() => dataViewModel, dataViewModel);
            this.dataViewModel      = dataViewModel;
            this.trainingViewModel  = trainingViewModel;
            this.fileMonitorFactory = fileMonitorFactory;
            Monitor     = new SelectableViewModel(folderBrowserDialog, this, Observable.Return(Settings.Default.MonitorPath));
            Destination = new SelectableViewModel(folderBrowserDialog, path: dataViewModel.Select.PathData);
            var canMonitor = this.WhenAny(x => x.Monitor.Path, y => y.Result, (x, y) => x.Value != null && Directory.Exists(x.Value) && y.Value == null);

            this.WhenAnyValue(x => x.Monitor.Path)
            .Where(x => x != Settings.Default.MonitorPath)
            .Subscribe(
                x =>
            {
                Settings.Default.MonitorPath = x;
                Settings.Default.Save();
            });

            var visibility = this.WhenAny(
                item => item.trainingViewModel.Result,
                item => item.dataViewModel.Result,
                (model1, model2) => model1.Value == null || model2.Value == null ? Visibility.Collapsed : Visibility.Visible);

            classes = this.WhenAny(item => item.trainingViewModel.Result, model => ((NominalHeader)model.Value?.DataSet?.Header?.Class)?.Nominals).ToProperty(this, model => model.Classes);

            InitMain(canMonitor, visibility);
            PendingFiles = resultList.CreateDerivedCollection(x => x, scheduler: RxApp.MainThreadScheduler);
            var selected = SelectedItems.CreateDerivedCollection(x => x);
            var canMove  = selected.Changed.StartWith().Select(_ => selected.Count > 0);

            Move = ReactiveCommand.Create(MoveSelected, canMove);
            Move.Subscribe(o => { MoveSelected(); });
            Move.ThrownExceptions.Subscribe(
                ex =>
            {
                MessageBox.Show("Move of some items failed", "Error", MessageBoxButton.OK);
            });
        }