public MainViewModel(IObservable <LogEvent> events, ICollection <DeployerItem> deployersItems, IPackageImporterFactory importerFactory, UIServices uiServices, ISettingsService settingsService, Func <Task <Phone> > getPhoneFunc) { DualBootViewModel = new DualBootViewModel(uiServices.DialogService, getPhoneFunc); DeployersItems = deployersItems; this.importerFactory = importerFactory; this.uiServices = uiServices; this.settingsService = settingsService; this.getPhoneFunc = getPhoneFunc; ShowWarningCommand = ReactiveCommand.CreateFromTask(() => uiServices.DialogService.ShowAlert(this, Resources.TermsOfUseTitle, Resources.WarningNotice)); SetupPickWimCommand(); var isDeployerSelected = this.WhenAnyValue(model => model.SelectedDeployerItem, (DeployerItem x) => x != null); var isSelectedWim = this.WhenAnyObservable(x => x.WimMetadata.SelectedImageObs) .Select(metadata => metadata != null); var canDeploy = isSelectedWim.CombineLatest(isDeployerSelected, (hasWim, hasDeployer) => hasWim && hasDeployer); FullInstallWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(DeployUefiAndWindows, canDeploy), uiServices.DialogService); WindowsInstallWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(DeployWindows, canDeploy), uiServices.DialogService); InjectDriversWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(InjectPostOobeDrivers, isDeployerSelected), uiServices.DialogService); ImportDriverPackageWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(ImportDriverPackage), uiServices.DialogService); var isBusyObs = Observable.Merge(FullInstallWrapper.Command.IsExecuting, WindowsInstallWrapper.Command.IsExecuting, InjectDriversWrapper.Command.IsExecuting, ImportDriverPackageWrapper.Command.IsExecuting); var dualBootIsBusyObs = DualBootViewModel.IsBusyObs; isBusyHelper = Observable.Merge(isBusyObs, dualBootIsBusyObs) .ToProperty(this, model => model.IsBusy); progressHelper = progressSubject .Where(d => !double.IsNaN(d)) .ObserveOn(SynchronizationContext.Current) .ToProperty(this, model => model.Progress); isProgressVisibleHelper = progressSubject .Select(d => !double.IsNaN(d)) .ToProperty(this, x => x.IsProgressVisible); SetupLogging(events); hasWimHelper = this.WhenAnyValue(model => model.WimMetadata, (WimMetadataViewModel x) => x != null) .ToProperty(this, x => x.HasWim); }
public MainViewModel(IObservable <LogEvent> events, IDeployer <RaspberryPi> deployer, IPackageImporterFactory importerFactory, DiskService diskService, UIServices uiServices, ISettingsService settingsService) { this.deployer = deployer; this.importerFactory = importerFactory; this.uiServices = uiServices; this.settingsService = settingsService; RefreshDisksCommmandWrapper = new CommandWrapper <Unit, ICollection <Disk> >(this, ReactiveCommand.CreateFromTask(diskService.GetDisks), uiServices.DialogService); disksHelper = RefreshDisksCommmandWrapper.Command .Select(x => x .Where(y => !y.IsBoot && !y.IsSystem && !y.IsOffline) .Select(disk => new DiskViewModel(disk))) .ToProperty(this, x => x.Disks); ShowWarningCommand = ReactiveCommand.CreateFromTask(() => uiServices.DialogService.ShowAlert(this, Resources.TermsOfUseTitle, Resources.WarningNotice)); ImportDriverPackageWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(ImportDriverPackage), uiServices.DialogService); SetupPickWimCommand(); var whenAnyValue = this.WhenAnyValue(x => x.SelectedDisk, (DiskViewModel disk) => disk != null); var canDeploy = this.WhenAnyObservable(x => x.WimMetadata.SelectedImageObs) .Select(metadata => metadata != null) .CombineLatest(whenAnyValue, (isWimSelected, isDiskSelected) => isDiskSelected && isWimSelected); FullInstallWrapper = new CommandWrapper <Unit, Unit>(this, ReactiveCommand.CreateFromTask(DeployUefiAndWindows, canDeploy), uiServices.DialogService); var isBusyObs = FullInstallWrapper.Command.IsExecuting; isBusyHelper = isBusyObs.ToProperty(this, model => model.IsBusy); progressHelper = progressSubject .Where(d => !double.IsNaN(d)) .ObserveOn(SynchronizationContext.Current) .ToProperty(this, model => model.Progress); isProgressVisibleHelper = progressSubject .Select(d => !double.IsNaN(d)) .ToProperty(this, x => x.IsProgressVisible); SetupLogging(events); hasWimHelper = this.WhenAnyValue(model => model.WimMetadata, (WimMetadataViewModel x) => x != null) .ToProperty(this, x => x.HasWim); DonateCommand = ReactiveCommand.Create(() => { Process.Start(DonationLink); }); }