Пример #1
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");
                }
Пример #2
0
        public async Task Deploy(Device device, bool autoDetect)
        {
            DisplayInfo();

            device = await GetDevice(device, autoDetect);

            try
            {
                Log.Information("Starting deployment for {Device}...", device);
                await woaDeployer.Deploy(device);

                Log.Information("Deployment finished");
            }
            catch (RequirementException re)
            {
                Log.Error($"The script requires the following variables to be defined:\n{string.Join("\n", re.Requirements.Select(s => "-" + s))}\n\nPlease, specify them using the --variables argument");
            }
        }