Esempio n. 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="TestRunnerControlViewModel" /> class.
        /// </summary>
        public TestRunnerControlViewModel()
        {
            BrowseCommand = ReactiveCommand.Create(
                () =>
            {
                var vistaOpenFileDialog = new VistaOpenFileDialog
                {
                    Multiselect = true,
                    Filter      = "DLL files (*.dll)|*.dll"
                };

                if (!_lastSelectedFolder.IsNullOrWhiteSpace())
                {
                    vistaOpenFileDialog.InitialDirectory = _lastSelectedFolder;
                }

                var result = vistaOpenFileDialog.ShowDialog();

                if (result != true)
                {
                    return;
                }

                _lastSelectedFolder = Path.GetDirectoryName(vistaOpenFileDialog.FileName);

                foreach (var fileName in vistaOpenFileDialog.FileNames)
                {
                    if (!SelectedAssemblies.Contains(fileName))
                    {
                        SelectedAssemblies.Add(fileName);
                    }
                }
            });

            var canRemove = this.WhenAnyValue(x => x.SelectedAssembly, assembly => !assembly.IsNullOrWhiteSpace()).ObserveOnDispatcher();

            RemoveCommand = ReactiveCommand.Create(
                () =>
            {
                SelectedAssemblies.Remove(SelectedAssembly);
            },
                canRemove);

            CancelCommand = ReactiveCommand.Create((Window window) =>
            {
                window.DialogResult = false;
                window.Close();
            });

            var canExecute = this.WhenAnyObservable(x => x.SelectedAssemblies.CountChanged).ObserveOnDispatcher().Select(count => count > 0);

            ExecuteCommand = ReactiveCommand.Create(
                (Window window) =>
            {
                window.DialogResult = true;
                window.Close();
            }, canExecute);
        }
        /// <summary>
        ///     Initializes a new instance of the <see cref="TestRunnerControlViewModel" /> class.
        /// </summary>
        /// <param name="scheduler">The scheduler</param>
        public TestRunnerControlViewModel([NotNull] IScheduler scheduler)
        {
            if (scheduler == null)
            {
                throw new ArgumentNullException(nameof(scheduler));
            }

            BrowseCommand = ReactiveCommand.Create(
                () =>
            {
                var vistaOpenFileDialog = new VistaOpenFileDialog
                {
                    Multiselect = true,
                    Filter      = "DLL files (*.dll)|*.dll"
                };

                if (!_lastSelectedFolder.IsNullOrWhiteSpace())
                {
                    vistaOpenFileDialog.InitialDirectory = _lastSelectedFolder;
                }

                var result = vistaOpenFileDialog.ShowDialog();

                if (result != true)
                {
                    return;
                }

                _lastSelectedFolder = Path.GetDirectoryName(vistaOpenFileDialog.FileName);

                foreach (var fileName in vistaOpenFileDialog.FileNames)
                {
                    if (!SelectedAssemblies.Contains(fileName))
                    {
                        SelectedAssemblies.Add(fileName);
                    }
                }
            });

            var canRemove = this.WhenAnyValue(x => x.SelectedAssembly, assembly => !assembly.IsNullOrWhiteSpace()).ObserveOn(scheduler);

            RemoveCommand = ReactiveCommand.Create(
                () => { SelectedAssemblies.Remove(SelectedAssembly); },
                canRemove);

            CancelCommand = ReactiveCommand.Create(
                (Window window) =>
            {
                window.DialogResult = false;
                window.Close();
            });

            var canExecute = this.WhenAnyObservable(x => x.SelectedAssemblies.CountChanged).ObserveOn(scheduler).Select(count => count > 0);

            ExecuteCommand = ReactiveCommand.Create(
                (Window window) =>
            {
                window.DialogResult = true;
                window.Close();
            },
                canExecute);

            this.WhenAnyValue(x => x.AllowCommandDataAccess).ToProperty(this, x => x.IsCopyDllsToNewFolderEnabled, out _isCopyDllsToNewFolderEnabled);

            this.WhenAnyValue(x => x.IsCopyDllsToNewFolderEnabled).Subscribe(
                b =>
            {
                if (!b)
                {
                    CopyDllsToNewFolder = false;
                }
            });
        }