Пример #1
0
        public WoaDeployerConsole(WoaDeployer woaDeployer, IEnumerable <IDetector> detectors,
                                  Func <ConsoleProgressUpdater> progressUpdater, IEnumerable <IFunction> functions)
        {
            this.woaDeployer = woaDeployer;
            this.detectors   = detectors;
            this.functions   = functions;
            updater          = progressUpdater();
            woaDeployer.Messages.Subscribe(Log.Information).DisposeWith(disposables);

            ConfigureLogging();
        }
Пример #2
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);
        }
Пример #3
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");
                }
Пример #4
0
        public OperationProgressViewModel(WoaDeployer deployer, IOperationProgress progress)
        {
            this.deployer = deployer;

            message = deployer.Messages.ToProperty(this, x => x.Message);

            this.progress = progress.Percentage
                            .Where(d => !double.IsNaN(d))
                            .ToProperty(this, model => model.Progress);

            isProgressVisible = progress.Percentage
                                .Select(d => !double.IsNaN(d))
                                .ToProperty(this, x => x.IsProgressVisible);

            isProgressIndeterminate = progress.Percentage
                                      .Select(double.IsPositiveInfinity)
                                      .ToProperty(this, x => x.IsProgressIndeterminate);

            downloaded = progress.Value
                         .Select(x => ByteSize.FromBytes(x))
                         .Sample(TimeSpan.FromSeconds(1))
                         .ToProperty(this, model => model.Downloaded);
        }