/// <summary> /// Initialize the object. /// </summary> public WpMagDirOutputViewModel() : base("Water Profile Direction and Magnitude Data Output") { base.DisplayName = "Data Output"; // Subscribe to receive ensembles _eventAggregator = IoC.Get <IEventAggregator>(); _eventAggregator.Subscribe(this); // Get PulseManager _pm = IoC.Get <PulseManager>(); _fileSizeMonitor = 0; // Get the options from the database GetOptionsFromDatabase(); FormatList = new List <string>(); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_SHIP); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_EARTH); FormatList.Add(WpMagDirOutputViewOptions.TRANSFORM_INSTRUMENT); HeadingSourceList = Enum.GetValues(typeof(Transform.HeadingSource)).Cast <Transform.HeadingSource>().ToList(); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; DataOutput = ""; // Scan for ADCP command ScanCommand = ReactiveUI.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
public ConnectionInfoManagementViewModel() { AddNewItemCommand = IsItemEditing.Inverse().ToReactiveCommand(); AddNewItemCommand.Subscribe(() => { SelectedItem.Value = null; EditingItem.Value = new T(); if (IsGroupSelected?.Value == true) { EditingItem.Value.GroupName = SelectedGroup.Value?.Name; } IsItemEditing.Value = true; }).AddTo(Disposable); ConnectCommand.Subscribe(async item => await ConfirmConnect(item)).AddTo(Disposable); IsItemSelected = SelectedItem.Select(x => x != null).ToReadOnlyReactiveProperty(); IsNotItemEditing = IsItemEditing.Inverse().ToReadOnlyReactiveProperty(); SelectedItem.Subscribe(x => { EditingItem.Value = SelectedItem.Value; IsItemEditing.Value = false; }).AddTo(Disposable); StartEditCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToReactiveCommand(); StartEditCommand.Subscribe(() => { EditingItem.Value = SelectedItem.Value.CloneDeep(); IsItemEditing.Value = true; }).AddTo(Disposable); ReplicateCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToReactiveCommand(); ReplicateCommand.Subscribe(() => { var replicated = SelectedItem.Value.CloneDeep(); replicated.Id = -1; SelectedItem.Value = null; EditingItem.Value = replicated; IsItemEditing.Value = true; }).AddTo(Disposable); RemoveCommand = IsItemSelected .CombineLatest(IsItemEditing.Inverse(), (a, b) => a && b) .ToAsyncReactiveCommand(); RemoveCommand.Subscribe(async() => { if (await Remove(SelectedItem.Value)) { Items.Remove(SelectedItem.Value); // Renew Windows JumpList JumpListHelper.RenewJumpList(await MainWindow.DbContext.EnumerateAllConnectionInfos()); } }).AddTo(Disposable); DiscardChangesCommand = IsItemEditing.ToReactiveCommand(); DiscardChangesCommand.Subscribe(() => { EditingItem.Value = SelectedItem.Value ?? new T(); IsItemEditing.Value = false; }).AddTo(Disposable); SaveChangesCommand = IsItemEditing.ToReactiveCommand(); SaveChangesCommand.Subscribe(async() => { var selectedItem = SelectedItem.Value; var item = EditingItem.Value; try { var(result, resultItem) = await Save(item); if (resultItem == null) { return; // FAILED } item = resultItem; // Replace with the saved item if (result) // ADDED { Items.Add(item); } else // UPDATED { var oldItem = Items.FirstOrDefault(x => x.Id == item.Id); if (oldItem != null) { var index = Items.IndexOf(oldItem); if (index >= 0) { Items.RemoveAt(index); Items.Insert(index, item); } } } // Renew Windows JumpList JumpListHelper.RenewJumpList(await MainWindow.DbContext.EnumerateAllConnectionInfos()); } catch (OperationCanceledException) // User manually canceled { return; } SelectedItem.Value = item; IsItemEditing.Value = false; }).AddTo(Disposable); // Connection info filterings FilterText .Throttle(TimeSpan.FromMilliseconds(500)) .ObserveOnDispatcher() .Subscribe(_ => RefreshCollectionView()) .AddTo(Disposable); SelectedGroup .ObserveOnDispatcher() .Subscribe(_ => RefreshCollectionView()) .AddTo(Disposable); // If any group is selected or not (except for "All") IsGroupSelected = SelectedGroup .Select(x => x?.Name != AllGroupName) .ToReadOnlyReactivePropertySlim() .AddTo(Disposable); // Group list extraction on connection info events Observable.CombineLatest( // When Add, Remove or Update Items.CollectionChangedAsObservable() .Select(_ => Unit.Default) .StartWith(Unit.Default), // When GroupName property in each element changed Items.ObserveElementPropertyChanged() .Where(x => x.EventArgs.PropertyName == nameof(ConnectionInfoBase.GroupName)) .Select(_ => Unit.Default) .StartWith(Unit.Default) ) .Throttle(TimeSpan.FromMilliseconds(500)) // Once 500 ms .ObserveOnDispatcher() .Subscribe(_ => { var selectedGroup = SelectedGroup.Value; // Reload group list Groups.Clear(); EnumerateGroups().ToList().ForEach(Groups.Add); // Reset selected group SelectedGroup.Value = (selectedGroup is null) ? Groups.FirstOrDefault() : selectedGroup; }) .AddTo(Disposable); }
/// <summary> /// Initialize the view model. /// </summary> public OutputDataViewModel(string name) { base.DisplayName = name; NumBinsSelected = 4; MinBin = 1; MaxBin = 200; SelectedFormat = ENCODING_PD6_PD13; FormatList = new List <string>(); FormatList.Add(ENCODING_Binary_ENS); FormatList.Add(ENCODING_PD0); FormatList.Add(ENCODING_PD6_PD13); FormatList.Add(ENCODING_VMDAS); //FormatList.Add(ENCODING_PD0); //FormatList.Add(ENCODING_RETRANSFORM_PD6); SelectedCoordTransform = PD0.CoordinateTransforms.Coord_Earth; CoordinateTransformList = new List <PD0.CoordinateTransforms>(); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Beam); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Instrument); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Ship); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Earth); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; _SelectedBaud = 115200; IsRetransformData = true; IsRecording = false; IsUseGpsHeading = true; HeadingOffset = 0.0f; ShipXdcrOffset = 0.0f; DataOutput = ""; _codecVmDas = new VmDasAsciiCodec(); _codecPd6_13 = new EnsToPd6_13Codec(); // Bin List BinList = new List <int>(); for (int x = 1; x <= 200; x++) { BinList.Add(x); } // Scan for ADCP command ScanCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.Legacy.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
/// <summary> /// Initialize the object. /// </summary> public DataOutputViewModel() : base("Data Output") { base.DisplayName = "Data Output"; // Subscribe to receive ensembles _eventAggregator = IoC.Get <IEventAggregator>(); _eventAggregator.Subscribe(this); // Get PulseManager _pm = IoC.Get <PulseManager>(); // Get the options from the database GetOptionsFromDatabase(); NumBinsSelected = 4; FormatList = new List <string>(); FormatList.Add(DataOutputViewOptions.ENCODING_Binary_ENS); FormatList.Add(DataOutputViewOptions.ENCODING_PD0); FormatList.Add(DataOutputViewOptions.ENCODING_PD6_PD13); FormatList.Add(DataOutputViewOptions.ENCODING_VMDAS); //FormatList.Add(ENCODING_PD0); //FormatList.Add(ENCODING_RETRANSFORM_PD6); CoordinateTransformList = new List <PD0.CoordinateTransforms>(); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Beam); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Instrument); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Ship); CoordinateTransformList.Add(PD0.CoordinateTransforms.Coord_Earth); HeadingSourceList = Enum.GetValues(typeof(Transform.HeadingSource)).Cast <Transform.HeadingSource>().ToList(); _serialOptions = new SerialOptions(); CommPortList = SerialOptions.PortOptions; BaudRateList = SerialOptions.BaudRateOptions; _manualWT = new VesselMount.VmManualWaterTrack(); NumBins = 200; DataOutput = ""; _codecVmDas = new VmDasAsciiCodec(); _codecPd6_13 = new EnsToPd6_13Codec(); // Bin List BinList = new List <int>(); for (int x = 1; x <= 200; x++) { BinList.Add(x); } // Scan for ADCP command ScanCommand = ReactiveUI.ReactiveCommand.Create(); ScanCommand.Subscribe(_ => ScanForSerialPorts()); // Disconnect Serial ConnectCommand = ReactiveUI.ReactiveCommand.Create(); ConnectCommand.Subscribe(_ => ConnectAdcpSerial()); // Disconnect Serial DisconnectCommand = ReactiveUI.ReactiveCommand.Create(); DisconnectCommand.Subscribe(_ => DisconnectSerial()); }
public MainWindowViewModel() { Op = new Operation( //new MockWorker() ?? //new NetshWorker() ?? new NativeWifiWorker() as IWlanWorker); this.Profiles = Op.Profiles.ToReadOnlyReactiveCollection(x => new ProfileItemViewModel(x)); #region AutoReloadEnabled/Suspended/ConfigMode IsAutoReloadEnabled = Op .ToReactivePropertyAsSynchronized(x => x.IsAutoReloadEnabled); IsSuspended = Op .ToReactivePropertyAsSynchronized(x => x.IsSuspended); IsConfigMode = new ReactiveProperty <bool>(); IsAutoReloadEnabled .Merge(IsSuspended) .Where(x => x) .Subscribe(_ => IsConfigMode.Value = false); IsConfigMode .Where(x => x) .Subscribe(_ => IsAutoReloadEnabled.Value = false); #endregion #region Load IsLoading = Op.IsLoading .Where(_ => !Op.IsWorking.Value) //.Select(x => Observable.Empty<bool>() // .Delay(TimeSpan.FromMilliseconds(10)) // .StartWith(x)) //.Concat() .ObserveOnUIDispatcher() .ToReadOnlyReactiveProperty(); ReloadCommand = IsLoading .Select(x => !x) .ToReactiveCommand(); ReloadCommand .Subscribe(async _ => await Op.LoadProfilesAsync(true)); Profiles .ObserveElementObservableProperty(x => x.Position) .Throttle(TimeSpan.FromMilliseconds(10)) .ObserveOn(SynchronizationContext.Current) .Subscribe(_ => ProfilesView.Refresh()); // ListCollectionView.Refresh method seems not thread-safe. #endregion #region Work IsNotWorking = Op.IsWorking .Select(x => !x) .StartWith(true) // This is necessary for initial query. .ObserveOnUIDispatcher() .ToReadOnlyReactiveProperty(); // Query for a profile which is selected. var querySelectedProfiles = Profiles .ObserveElementObservableProperty(x => x.IsSelected) .Where(x => x.Value) .Select(x => x.Instance) .Publish(); // Query for the selected profile which is connected or disconnected. var queryConnectedProfiles = Profiles .ObserveElementObservableProperty(x => x.IsConnected) .Where(x => x.Instance.IsSelected.Value) .Select(x => x.Instance) .Publish(); // Query for the selected profile which changes to be available or unavailable. var queryAvailableProfiles = Profiles .ObserveElementObservableProperty(x => x.IsAvailable) .Where(x => x.Instance.IsSelected.Value) .Select(x => x.Instance) .Publish(); #region MoveUp var queryMoveUp = querySelectedProfiles .Select(x => x.Position.Value > 0); MoveUpCommand = new[] { IsNotWorking, queryMoveUp } .CombineLatestValuesAreAllTrue() .ToReactiveCommand(); MoveUpCommand .Subscribe(async _ => await Op.MoveUpProfileAsync()); #endregion #region MoveDown var queryMoveDown = querySelectedProfiles .Select(x => x.Position.Value < x.PositionCount.Value - 1); MoveDownCommand = new[] { IsNotWorking, queryMoveDown } .CombineLatestValuesAreAllTrue() .ToReactiveCommand(); MoveDownCommand .Subscribe(async _ => await Op.MoveDownProfileAsync()); #endregion #region Delete DeleteCommand = IsNotWorking .ToReactiveCommand(); DeleteCommand .Subscribe(async _ => await Op.DeleteProfileAsync()); #endregion #region Connect var queryConnect = Observable.Merge(querySelectedProfiles, queryConnectedProfiles, queryAvailableProfiles) .Select(x => !x.IsConnected.Value && x.IsAvailable.Value); ConnectCommand = new[] { IsNotWorking, queryConnect } .CombineLatestValuesAreAllTrue() .ToReactiveCommand(); ConnectCommand .Subscribe(async _ => await Op.ConnectNetworkAsync()); #endregion #region Disconnect var queryDisconnect = Observable.Merge(querySelectedProfiles, queryConnectedProfiles) .Select(x => x.IsConnected.Value); DisconnectCommand = new[] { IsNotWorking, queryDisconnect } .CombineLatestValuesAreAllTrue() .ToReactiveCommand(); DisconnectCommand .Subscribe(async _ => await Op.DisconnectNetworkAsync()); #endregion querySelectedProfiles.Connect(); queryConnectedProfiles.Connect(); queryAvailableProfiles.Connect(); #endregion }
public MainViewModel() { // ファイルから読む体で userDict.Add("111", new UserModel("111", "社会人P") { Color = Colors.LightGreen }); userDict.Add("222", new UserModel("222", "八百屋")); Comments = model.Comments.ToReadOnlyReactiveCollection(comment => { if (!userDict.TryGetValue(comment.ID, out var user)) { user = new UserModel(comment.ID); userDict.Add(user.ID, user); } return(new CommentViewModel(comment, user)); }).AddTo(disposable); #region Command NameChangeCommand.Subscribe(obj => { var menuItem = obj as MenuItem; var comment = menuItem.DataContext as CommentViewModel; var ib = new InputBox { DataContext = comment, Text = comment.Name.Value, }; if (ib.ShowDialog() == true) { comment.Name.Value = ib.Text; } }); ColorChangeCommand.Subscribe(obj => { var menuItem = obj as MenuItem; var comment = menuItem.DataContext as CommentViewModel; comment.Color.Value = (Color)menuItem.Tag; }); ConnectCommand = IsRunning.Select(x => !x).ToAsyncReactiveCommand(); ConnectCommand.Subscribe(async _ => { await model.ConnectAsync("lv1234567"); IsRunning.Value = true; }).AddTo(disposable); DisconnectCommand = IsRunning.ToReactiveCommand(); DisconnectCommand.Subscribe(_ => { model.Disconnect(); IsRunning.Value = false; }).AddTo(disposable); #endregion ConnectCommand.Execute(); }
public MainWindowViewModel() { _commandService = new PaletteCommandService(); CommandPaletteCommand = new ReactiveCommand(); CommandPaletteCommand.Subscribe( _ => { if (!IsCommandPaletteOpen.Value) { IsCommandPaletteOpen.Value = true; } else { IsCommandPaletteOpen.Value = false; } }); IsCommandPaletteOpen = new ReactiveProperty <bool>(); State = new ReactiveProperty <TargetState>(); TargetList = new ReactiveCollection <string>(); TargetList.Add(new string("default")); TargetList.Add(new string("TargetA")); TargetList.Add(new string("TargetB")); TargetList.Add(new string("TargetC")); ConnectCommand = State .Select(x => x == TargetState.NotConnected) .ToReactiveCommand <string>() .AddTo(Disposable); ConnectCommand.Subscribe( (target) => { State.Value = TargetState.Connected; }); var targetItemList = new List <IPaletteSearchItem>(); foreach (var target in TargetList) { var targetItem = PaletteParameterFactory.CreateSearchItem(target, target.ToString()); targetItemList.Add(targetItem); } var targetParameter = PaletteParameterFactory.CreateSearchParameter(targetItemList, "Target", "接続先を指定してください"); _commandService.AddCommand(ConnectCommand, nameof(ConnectCommand), "ターゲットと接続します", (paramList) => { return(paramList.First()); }, targetParameter); DisconnectCommand = State .Select(x => x != TargetState.NotConnected) .ToReactiveCommand() .AddTo(Disposable); DisconnectCommand.Subscribe( _ => { State.Value = TargetState.NotConnected; }); _commandService.AddCommand(DisconnectCommand, nameof(DisconnectCommand), "ターゲットとの接続を切断します"); Volume = new ReactiveProperty <float>().AddTo(Disposable); Volume.Value = 0.5f; ChangeVolumeCommand = new ReactiveCommand <float>(); ChangeVolumeCommand.Subscribe((volume) => { Volume.Value = volume; }); var volumeParameter = PaletteParameterFactory.CreateMinMaxParameter(0.0f, 1.0f, "Volume", "ボリュームを変更します (0.0 - 1.0)"); _commandService.AddCommand(ChangeVolumeCommand, nameof(ChangeVolumeCommand), "プレイバックボリュームを変更します", (paramList) => { return(paramList.First()); }, volumeParameter); RecordingDirectory = new ReactiveProperty <string>().AddTo(Disposable); SelectRecordingDirectoryCommand = State .Select(x => x != TargetState.Recording) .ToReactiveCommand() .AddTo(Disposable); SelectRecordingDirectoryCommand.Subscribe( _ => { MessageBox.Show("SelectCommand"); }); _commandService.AddCommand(SelectRecordingDirectoryCommand, nameof(SelectRecordingDirectoryCommand), "録音の保存先を選択します"); StartRecordingCommand = State .Select(x => x == TargetState.Connected) .ToReactiveCommand() .AddTo(Disposable); StartRecordingCommand.Subscribe( _ => { State.Value = TargetState.Recording; }); _commandService.AddCommand(StartRecordingCommand, nameof(StartRecordingCommand), "録音を開始します"); StopRecordingCommand = State .Select(x => x == TargetState.Recording) .ToReactiveCommand() .AddTo(Disposable); StopRecordingCommand.Subscribe( _ => { State.Value = TargetState.Connected; }); _commandService.AddCommand(StopRecordingCommand, nameof(StopRecordingCommand), "録音を終了します"); }