/// <summary>
        /// Initializes a new instance of the <see cref="ReqIfExportDialogViewModel"/> class
        /// </summary>
        /// <param name="sessions">The list of <see cref="ISession"/> available</param>
        /// <param name="iterations">The list of <see cref="Iteration"/> available</param>
        /// <param name="fileDialogService">The <see cref="IOpenSaveFileDialogService"/></param>
        /// <param name="serializer">The <see cref="IReqIFSerializer"/></param>
        public ReqIfExportDialogViewModel(IEnumerable <ISession> sessions, IEnumerable <Iteration> iterations, IOpenSaveFileDialogService fileDialogService, IReqIFSerializer serializer)
        {
            if (sessions == null)
            {
                throw new ArgumentNullException("sessions");
            }

            if (iterations == null)
            {
                throw new ArgumentNullException("iterations");
            }

            if (fileDialogService == null)
            {
                throw new ArgumentNullException("fileDialogService");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            this.Sessions          = sessions.ToList();
            this.Iterations        = new ReactiveList <ReqIfExportIterationRowViewModel>();
            this.fileDialogService = fileDialogService;
            this.serializer        = serializer;

            foreach (var iteration in iterations)
            {
                this.Iterations.Add(new ReqIfExportIterationRowViewModel(iteration));
            }

            var canOk = this.WhenAnyValue(
                vm => vm.Path,
                vm => vm.SelectedIteration,
                (path, iteration) => iteration != null && !string.IsNullOrEmpty(path));

            this.OkCommand = ReactiveCommand.CreateAsyncTask(canOk, async x => await this.ExecuteOk(), RxApp.MainThreadScheduler);

            this.OkCommand.ThrownExceptions.Select(ex => ex).Subscribe(x =>
            {
                this.ErrorMessage = x.Message;
            });

            this.BrowseCommand = ReactiveCommand.Create();
            this.BrowseCommand.Subscribe(_ => this.ExecuteBrowse());

            this.CancelCommand = ReactiveCommand.Create();
            this.CancelCommand.Subscribe(_ => this.ExecuteCancel());

            this.OnClosingCommand = ReactiveCommand.CreateAsyncTask(this.OnClosing, RxApp.MainThreadScheduler);

            this.CancelReqIfCommand = ReactiveCommand.Create();

            this.CancelReqIfCommand.Subscribe(_ =>
            {
                this.cancellationTokenSource?.Cancel();
                this.LoadingMessage = "Cancelling...";
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ReqIfExportDialogViewModel"/> class
        /// </summary>
        /// <param name="sessions">The list of <see cref="ISession"/> available</param>
        /// <param name="iterations">The list of <see cref="Iteration"/> available</param>
        /// <param name="fileDialogService">The <see cref="IOpenSaveFileDialogService"/></param>
        /// <param name="serializer">The <see cref="IReqIFSerializer"/></param>
        public ReqIfExportDialogViewModel(IEnumerable <ISession> sessions, IEnumerable <Iteration> iterations, IOpenSaveFileDialogService fileDialogService, IReqIFSerializer serializer)
        {
            if (sessions == null)
            {
                throw new ArgumentNullException("sessions");
            }

            if (iterations == null)
            {
                throw new ArgumentNullException("iterations");
            }

            if (fileDialogService == null)
            {
                throw new ArgumentNullException("fileDialogService");
            }

            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            this.Sessions          = sessions.ToList();
            this.Iterations        = new ReactiveList <ReqIfExportIterationRowViewModel>();
            this.fileDialogService = fileDialogService;
            this.serializer        = serializer;

            foreach (var iteration in iterations)
            {
                this.Iterations.Add(new ReqIfExportIterationRowViewModel(iteration));
            }

            var canOk = this.WhenAnyValue(
                vm => vm.Path,
                vm => vm.SelectedIteration,
                (path, iteration) => iteration != null && !string.IsNullOrEmpty(path));

            this.OkCommand = ReactiveCommand.Create(canOk);
            this.OkCommand.Subscribe(_ => this.ExecuteOk());

            this.BrowseCommand = ReactiveCommand.Create();
            this.BrowseCommand.Subscribe(_ => this.ExecuteBrowse());

            this.CancelCommand = ReactiveCommand.Create();
            this.CancelCommand.Subscribe(_ => this.ExecuteCancel());
        }