/// <summary> /// Initialize the view model. /// </summary> public AdcpConfigurationViewModel() : base("Adcp Configuration") { // Initialize values _events = IoC.Get <IEventAggregator>(); _pm = IoC.Get <PulseManager>(); _adcpConnection = IoC.Get <AdcpConnection>(); SubsystemConfigList = new ReactiveList <AdcpSubsystemConfigurationViewModel>(); BatteryTypeList = DeploymentOptions.GetBatteryList(); // Initialize the values InitializeValues(); // Scan ADCP command ScanAdcpCommand = ReactiveCommand.CreateAsyncTask(_ => ScanConfiguration()); // Add Subsystem Configuration AddSubsystemCommand = ReactiveCommand.Create(); AddSubsystemCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.FrequencyView))); // Next command NextCommand = ReactiveCommand.Create(this.WhenAny(x => x.IsScanning, x => !x.Value)); NextCommand.Subscribe(_ => NextPage()); // Back coommand BackCommand = ReactiveCommand.Create(); BackCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.Back))); // Exit coommand ExitCommand = ReactiveCommand.Create(); ExitCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.HomeView))); // Compass Cal coommand CompassCalCommand = ReactiveCommand.Create(); CompassCalCommand.Subscribe(_ => _events.PublishOnUIThread(new ViewNavEvent(ViewNavEvent.ViewId.CompassCalView))); // Edit the configuration command EditCommand = ReactiveCommand.Create(); EditCommand.Subscribe(param => OnEditCommand(param)); // Save the commands to a text file SaveCmdsCommand = ReactiveCommand.CreateAsyncTask(_ => SaveCommandsToFile()); // Get the configuration from the project GetConfiguation(); // Update the deployment duration to include all the new configurations // The duration needs to be divided amoung all the configuration UpdateDeploymentDuration(); // Update the properites UpdateProperties(); }
public ManagedEmployeeListViewModel(IHumanResourcesService humanResourcesService, IRegionManager regionManager) { _humanResourcesService = humanResourcesService; _regionManager = regionManager; PopCommand = new DelegateCommand(() => Pop(_regionManager)); EditCommand = this.ObserveProperty(x => x.IsReadOnly).ToReactiveCommand(); EditCommand.Subscribe(() => IsReadOnly = false); SaveCommand = this.ObserveProperty(x => x.IsReadOnly).Select(x => !x).ToReactiveCommand(); SaveCommand.Subscribe(OnSave); }
// コンストラクタ public SupplyData(DateTime time, int value, Action1 action1, Action2 action2) { // 数値を記録する oldTime = Utility.GetTimeStrSQLite(time); Time = new ReactiveProperty <string>(oldTime); oldValue = value; Value = new ReactiveProperty <int>(oldValue); // コマンドを作成する // つまり、「Time != oldTime または Value != oldValue」なら // EditCommandが有効になる EditCommand = Time.Select(x => (x != oldTime)).CombineLatest( Value.Select(y => (y != oldValue)), (x, y) => x | y).ToReactiveCommand(); // コマンドを登録する EditCommand.Subscribe(_ => action1(oldTime, oldValue, Time.Value, Value.Value)); DeleteCommand.Subscribe(_ => action2(oldTime, oldValue)); }
public CollectionViewModel(TProperty property, ViewModelFactory factory) : base(property) { Collection = property.Collection.ToReadOnlyReactiveCollection(x => { IPropertyViewModel vm = null; try { vm = factory.Create(x); } catch (Exception e) { OnErrorSubject.OnNext(e); return(null); } vm.OnChanged.Subscribe(y => OnChangedSubject.OnNext(Unit.Default)); vm.OnError.Subscribe(e => OnErrorSubject.OnNext(e)); return(vm); }); FormatedString = Property.Count.Select(x => $"Count = {x}") .ToReactiveProperty(mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe); AddCommand.Subscribe(x => { try { Property.AddNewElement(); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); RemoveCommand.Subscribe(x => { try { Property.RemoveElementAt(x); } catch (Exception e) { OnErrorSubject.OnNext(e); } OnChangedSubject.OnNext(Unit.Default); }); EditCommand.Subscribe(x => ShowDetailSubject.OnNext(this)); UpCommand.Subscribe(x => { Property.Move(x - 1, x); SelectedIndex.Value = x - 1; }); DownCommand.Subscribe(x => { Property.Move(x + 1, x); SelectedIndex.Value = x; }); DuplicateCommand.Subscribe(x => { Property.Duplicate(x, x + 1); }); }