Ejemplo n.º 1
0
        public MainViewModel(ICollection <IDetector> detectors, WoaDeployer deployer, IDialogService dialogService,
                             IFilePicker filePicker, OperationProgressViewModel operationProgress)
        {
            this.detectors     = detectors;
            this.deployer      = deployer;
            this.dialogService = dialogService;
            this.filePicker    = filePicker;
            OperationProgress  = operationProgress;

            ConfigureCommands();

            isDeploying = Deploy.IsExecuting.Merge(RunScript.IsExecuting).ToProperty(this, x => x.IsBusy);
        }
Ejemplo n.º 2
0
        public MainViewModel(ICollection <IDetector> detectors, WoaDeployer deployer, IDialogService dialogService, IFilePicker filePicker, OperationProgressViewModel operationProgress)
        {
            OperationProgress = operationProgress;
            Detect            = ReactiveCommand.CreateFromTask(async() =>
            {
                var detections = await Task.WhenAll(detectors.Select(d => d.Detect()));
                return(detections.FirstOrDefault(d => d != null));
            });

            var hasDevice = this.WhenAnyValue(model => model.Device).Select(d => d != null);

            Detect.Subscribe(detected =>
            {
                Device = detected;
            }).DisposeWith(disposables);

            Detect.SelectMany(async d =>
            {
                if (d == null)
                {
                    await dialogService.Notice("Cannot autodetect any device",
                                               "Cannot detect any device. Please, select your device manually");
                }

                return(Unit.Default);
            })
            .Subscribe()
            .DisposeWith(disposables);

            GetRequirements = ReactiveCommand.CreateFromTask(() => deployer.GetRequirements(Device), hasDevice);
            requirements    = GetRequirements.ToProperty(this, model => model.Requirements);
            Deploy          = ReactiveCommand.CreateFromTask(() => deployer.Deploy(Device), hasDevice);

            RunScript = ReactiveCommand.CreateFromObservable(() =>
            {
                var filter = new FileTypeFilter("Deployer Script", new[] { "*.ds", "*.txt" });
                return(filePicker
                       .Open("Select a script", new[] { filter })
                       .Where(x => x != null)
                       .SelectMany(file => Observable.FromAsync(() => deployer.RunScript(file.Source.LocalPath))));
            });

            dialogService.HandleExceptionsFromCommand(RunScript);
            dialogService.HandleExceptionsFromCommand(Deploy, exception =>
            {
                Log.Error(exception, exception.Message);

                if (exception is DeploymentCancelledException)
                {
                    return("Deployment cancelled", "Deployment cancelled");
                }