public GeometryViewModel() { Geometries = AUTDSettings.Instance.GeometriesReactive; Current = new ReactivePropertySlim <GeometrySettingReactive?>(); AddItem = new ReactiveCommand(); RemoveItem = Current.Select(c => c != null).ToReactiveCommand(); UpItem = Current.Select(c => c != null && c.No.Value != 0).ToReactiveCommand(); DownItem = Current.Select(c => c != null && c.No.Value != Geometries.Count - 1).ToReactiveCommand(); AddItem.Subscribe(_ => { var item = new GeometrySettingReactive(Geometries.Count); Geometries.Add(item); Current.Value = item; }); RemoveItem.Subscribe(_ => { if (Current.Value == null) { return; } var delNo = Current.Value.No.Value; Geometries.RemoveAt(delNo); ResetNo(); Current.Value = Geometries.Count > delNo ? Geometries[delNo] : Geometries.Count > 0 ? Geometries[delNo - 1] : null; }); UpItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var up = Geometries[cNo - 1]; Geometries.Insert(cNo - 1, Current.Value); Geometries.RemoveAt(cNo); Geometries[cNo] = up; ResetNo(); Current.Value = Geometries[cNo - 1]; }); DownItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var down = Geometries[cNo + 1]; Geometries.RemoveAt(cNo + 1); Geometries.Insert(cNo + 1, Current.Value); Geometries[cNo] = down; ResetNo(); Current.Value = Geometries[cNo + 1]; }); }
public MainWindowVm(string directory, VirtualCollectionSource <FileModel, FileViewModel> virtualSource) { Directory = directory; VirtualSource = virtualSource; FilterName = new ReactivePropertySlim <string>().AddTo(Disposables); FilterExtension = new ReactivePropertySlim <string>().AddTo(Disposables); CollectedSize = new ReactivePropertySlim <int>().AddTo(Disposables); StagedSize = new ReactivePropertySlim <int>().AddTo(Disposables); VirtualProxySize = new ReactivePropertySlim <int>().AddTo(Disposables); LowerFilterName = FilterName.Select(x => x?.ToLower()).ToReadOnlyReactivePropertySlim().AddTo(Disposables); LowerFilterExtension = FilterExtension.Select(x => x?.ToLower()).ToReadOnlyReactivePropertySlim().AddTo(Disposables); // 仮想Cコンテナにフィルター関数を設定します。 virtualSource.SetFilter( x => x.Filter(LowerFilterName.Value, LowerFilterExtension.Value) ); // 検索ボックスの入力からトリガしてフィルターを実行します。 FilterName .Merge(FilterExtension) .Throttle(TimeSpan.FromMilliseconds(200), UIDispatcherScheduler.Default) .Subscribe(async _ => await VirtualSource.ResetCollection()) .AddTo(Disposables); // 画面表示用に定期更新します Observable.Interval(TimeSpan.FromMilliseconds(100), UIDispatcherScheduler.Default) .Subscribe(_ => { CollectedSize.Value = VirtualSource.SourceSize; StagedSize.Value = VirtualSource.Items.Count; VirtualProxySize.Value = VirtualSource.ProxySize; }).AddTo(Disposables); }
public FpsCounterViewModel() { MouseDownUnit = new ReactivePropertySlim <Unit>(mode: ReactivePropertyMode.None).AddTo(CompositeDisposable); // http://reactivex.io/documentation/operators/buffer.html // Buffer(count, skip) : count個のデータが溜まったら、skip個ごとに count個をまとめた List<T> を流します // Buffer(count) : countの倍数で、count個をまとめた List<T> を流します。 FpsCounter1 = MouseDownUnit .Select(_ => DateTime.Now) .Pairwise() .Select(dateTime => dateTime.NewItem - dateTime.OldItem) .Buffer(count: _bufferLength, skip: 1) .Select(tss => 1000d / tss.Select(ts => ts.TotalMilliseconds).Average()) .ToReadOnlyReactivePropertySlim() .AddTo(CompositeDisposable); FpsCounter2 = MouseDownUnit .TimeInterval() .Buffer(count: _bufferLength, skip: 1) .Select(xs => 1000d / xs.Select(x => x.Interval.Milliseconds).Average()) .ToReadOnlyReactivePropertySlim() .AddTo(CompositeDisposable); FpsCounter3 = MouseDownUnit .Framerate(_bufferLength) .ToReadOnlyReactivePropertySlim() .AddTo(CompositeDisposable); }
public MainPageViewModel(DocumentManager documentManager, IAppCenterLogger appCenterLogger, IEventAggregator eventAggregator) { this.DocumentManager = documentManager; this.AppCenterLogger = appCenterLogger; this.EventAggregator = eventAggregator; Documents = DocumentManager.Documents .ToReadOnlyReactiveCollectionForCurrentContext(); NewDocumentTitle = new ReactivePropertySlim<string>(); AddDocumentCommand = NewDocumentTitle .Select(x => !string.IsNullOrEmpty(x)) .ToReactiveCommand() .WithSubscribe(() => { if (NewDocumentTitle.Value == "野菜") { throw new InvalidOperationException("野菜 is invalid"); } DocumentManager.AddDocument(NewDocumentTitle.Value); AppCenterLogger.TrackEvent("Document created", ("name", NewDocumentTitle.Value)); NewDocumentTitle.Value = ""; }); SelectedDocument = new ReactivePropertySlim<Document>(); IsEditorBladeOpen = SelectedDocument .Select(x => x != null) .ToReadOnlyReactivePropertySlim(); BladeMode = DocumentManager.DocumentEditMode .Select(x => x == DocumentEditMode.Normal ? Microsoft.Toolkit.Uwp.UI.Controls.BladeMode.Normal : Microsoft.Toolkit.Uwp.UI.Controls.BladeMode.Fullscreen) .ToReadOnlyReactivePropertySlim(); PreviewMarkdownText = SelectedDocument .SelectMany(x => x?.Content ?? Observable.Return("")) .Throttle(TimeSpan.FromSeconds(1)) .ObserveOnUIDispatcher() .ToReadOnlyReactivePropertySlim(); IsPreviewOpen = IsPreviewOpenNotifier.ToReadOnlyReactivePropertySlim(); SwitchPreviewCommand = new ReactiveCommand() .WithSubscribe(() => IsPreviewOpenNotifier.SwitchValue()); RemoveDocumentCommand = new ReactiveCommand<Document>() .WithSubscribe(x => { DocumentManager.RemoveDocument(x.Id.Value); AppCenterLogger.TrackEvent("Document removed", ("name", x.Title.Value), ("content", x.Content.Value)); IsPreviewOpenNotifier.TurnOff(); EventAggregator.GetEvent<NotifyEvent>() .Publish($"{x.Title.Value} を削除しました。"); }); }
public DeployToOpenShiftViewModel() { Masters = model.Masters.ToReadOnlyReactiveCollection(m => new OpenShiftMasterViewModel(m)); SelectedMaster = new ReactivePropertySlim <OpenShiftMasterViewModel>(); SelectedMaster .Where(x => x != null) .Subscribe(x => model.SelectedMaster.Value = x.Model) .AddTo(Disposable); Projects = model.Projects.ToReadOnlyReactiveCollection(); SelectedNameSpace = model.SelectedProject.ToReactivePropertyAsSynchronized(x => x.Value); Name = model.Name .ToReactiveProperty() .SetValidateAttribute(() => Name) .AddTo(Disposable); Host = model.Host .ToReactiveProperty() .SetValidateAttribute(() => Host) .AddTo(Disposable); MemoryLimit = model.MemoryLimit .ToReactiveProperty() .SetValidateAttribute(() => MemoryLimit) .AddTo(Disposable); GitSource = model.GitSource .ToReactiveProperty() .SetValidateAttribute(() => GitSource) .AddTo(Disposable); GitRef = model.GitRef .ToReactiveProperty() .SetValidateAttribute(() => GitRef) .AddTo(Disposable); StartupProject = model.StartupProject .ToReactiveProperty() .SetValidateAttribute(() => StartupProject) .AddTo(Disposable); IsDeploying = model.IsDeploying.ToReadOnlyReactivePropertySlim(); Message = model.Message.ToReadOnlyReactivePropertySlim(); DeployCommand = SelectedMaster.Select(s => s != null) .ToReactiveCommand() .WithSubscribe(() => { model.StartDeploy(); }); }
public RenbanVm(RenbanDownLoader renbanDownLoader) { _renbanDownLoader = renbanDownLoader; Address = new ReactiveProperty <string>(string.Empty); UrlsPreview = new ReactivePropertySlim <string>(string.Empty).AddTo(Disposables); TextInput = new ReactiveProperty <string>(string.Empty).AddTo(Disposables); // ダウンロードコマンド { DownLoadCommand = UrlsPreview .Select(x => ToUrls()) .Select(urls => urls.Any() && urls.All(url => Uri.TryCreate(url, UriKind.Absolute, out _))) .ToAsyncReactiveCommand(); DownLoadCommand.Subscribe(async() => { DownloadLogInfo.Value = string.Empty; await _renbanDownLoader.DownLoad(ToUrls()); }) .AddTo(Disposables); } // Vmの入力を RenbanDownloaderで処理し、データを加工する Address.Throttle(TimeSpan.FromMilliseconds(100), UIDispatcherScheduler.Default) .Subscribe(x => { _renbanDownLoader.SetAddressWithAutoUpdateProperties(x); Address.Value = renbanDownLoader.Address.Value; }) .AddTo(Disposables); // 各パラメータの更新に併せてダウンロード候補一覧表示を更新する Observable.Merge(Address.ToUnit(), TextInput.ToUnit(), Start.ToUnit(), End.ToUnit(), FillZero.ToUnit()) .Throttle(TimeSpan.FromMilliseconds(250), UIDispatcherScheduler.Default) .Select(_ => CreateDownloadCandidate()) .Subscribe(x => UrlsPreview.Value = x).AddTo(Disposables); UrlsPreview.Throttle(TimeSpan.FromMilliseconds(500), UIDispatcherScheduler.Default) .Subscribe(async _ => await CreatePreviewThumbnailsAsync()).AddTo(Disposables); }
private ReactivePropertySlim <CultureInfo> CreateAppLanguageRp() { //Model側から変更されることは無いはずなので、初期値のみ読込 //リストにない言語の場合は、Autoに設定する var modelCultureInfo = CultureInfo.GetCultureInfo(setting.AppLanguageCode.Value); if (!this.AvailableLanguages.Contains(modelCultureInfo)) { modelCultureInfo = CultureInfo.InvariantCulture; } var rp = new ReactivePropertySlim <CultureInfo>(modelCultureInfo); rp.Select(c => (c == null || c == CultureInfo.InvariantCulture) ? "" : c.Name) .Subscribe(c => setting.AppLanguageCode.Value = c); return(rp); }
/// <summary> /// コンストラクタ /// </summary> public DataExportViewModel(string inDirPath, string outFilePath) { InDirPath = new ReactiveProperty <string>(inDirPath, mode: ReactivePropertyMode.RaiseLatestValueOnSubscribe); _UnableToGetLanguages = new ReactivePropertySlim <bool>(false); InDirPath.SetValidateNotifyError( _ => _UnableToGetLanguages.Select(isError => isError ? "Error" : null)); _OutFilePath = outFilePath; Languages = new ReactiveCollection <LangComboboxItem>(); SelectedLanguage = new ReactivePropertySlim <LangComboboxItem?>(); MaxSteps = new ReactivePropertySlim <int>(1); CurrentStep = new ReactivePropertySlim <int>(0); CanOperation = _BusyNotifier.Inverse().ToReadOnlyReactivePropertySlim(); // 操作可能かつ入力項目に不備がない場合に true にする var canExport = new[] { CanOperation, InDirPath.Select(p => !string.IsNullOrEmpty(p)), SelectedLanguage.Select(l => l != null), }.CombineLatestValuesAreAllTrue(); SelectInDirCommand = new ReactiveCommand(CanOperation).WithSubscribe(SelectInDir); ExportCommand = new AsyncReactiveCommand(canExport).WithSubscribe(Export); ClosingCommand = new ReactiveCommand <CancelEventArgs>().WithSubscribe(Closing); // 入力元フォルダパスに値が代入された時、言語一覧を更新する InDirPath.ObserveOn(ThreadPoolScheduler.Instance).Subscribe(path => { using var _ = _BusyNotifier.ProcessStart(); _UnableToGetLanguages.Value = false; Languages.ClearOnScheduler(); var(success, languages) = _Model.GetLanguages(path); _UnableToGetLanguages.Value = !success; Languages.AddRangeOnScheduler(languages); }); }
public TodoItemDetailPageViewModel(INavigationService navigationService, IPageDialogService pageDialogService) : base(navigationService) { _pageDialogService = pageDialogService; Title = "Todo Item"; _id.Where(id => id != null) .SelectMany(id => CrossCloudFirestore.Current.Instance.GetDocument($"{TodoItem.CollectionPath}/{id}").GetDocumentAsync()) .Where(document => document != null) .Select(document => document.ToObject <TodoItem>()) .Subscribe(todoItem => { if (_todoItem != null) { _todoItem.Value = todoItem; Name.Value = todoItem.Name; Notes.Value = todoItem.Notes; } }, ex => System.Diagnostics.Debug.WriteLine(ex)); UpdateCommand = new[] { _todoItem.Select(x => x == null), Name.Select(x => string.IsNullOrEmpty(x)) }.CombineLatestValuesAreAllFalse() .ObserveOn(SynchronizationContext.Current) .ToAsyncReactiveCommand(); UpdateCommand.Subscribe(async() => { var todoItem = _todoItem.Value; todoItem.Name = Name.Value; todoItem.Notes = Notes.Value; CrossCloudFirestore.Current.Instance.GetDocument($"{TodoItem.CollectionPath}/{todoItem.Id}") .UpdateData(todoItem, (error) => { if (error != null) { System.Diagnostics.Debug.WriteLine(error); } }); await navigationService.GoBackAsync(); }); DeleteCommand = new[] { _todoItem.Select(x => x == null) }.CombineLatestValuesAreAllFalse() .ObserveOn(SynchronizationContext.Current) .ToAsyncReactiveCommand(); DeleteCommand.Subscribe(async() => { var ok = await _pageDialogService.DisplayAlertAsync("Are you sure you want to delete this?", _todoItem.Value.Name, "Ok", "Cancel"); if (ok) { CrossCloudFirestore.Current .Instance .GetDocument($"{TodoItem.CollectionPath}/{_todoItem.Value.Id}") .DeleteDocument((error) => { if (error != null) { System.Diagnostics.Debug.WriteLine(error); } }); await NavigationService.GoBackAsync(); } }); }
public HoloViewModel() { Holo = AUTDSettings.Instance.ToReactivePropertySlimAsSynchronized(i => i.Holo); HoloSettings = AUTDSettings.Instance.Holo.HoloSettingsReactive; Current = new ReactivePropertySlim <HoloSettingReactive?>(); AddItem = new ReactiveCommand(); RemoveItem = Current.Select(c => c != null).ToReactiveCommand(); UpItem = Current.Select(c => c != null && c.No.Value != 0).ToReactiveCommand(); DownItem = Current.Select(c => c != null && c.No.Value != HoloSettings.Count - 1).ToReactiveCommand(); AddItem.Subscribe(_ => { var item = new HoloSettingReactive(HoloSettings.Count); HoloSettings.Add(item); Current.Value = item; }); RemoveItem.Subscribe(_ => { if (Current.Value == null) { return; } var delNo = Current.Value.No.Value; HoloSettings.RemoveAt(delNo); ResetNo(); Current.Value = HoloSettings.Count > delNo ? HoloSettings[delNo] : HoloSettings.Count > 0 ? HoloSettings[delNo - 1] : null; }); UpItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var up = HoloSettings[cNo - 1]; HoloSettings.Insert(cNo - 1, Current.Value); HoloSettings.RemoveAt(cNo); HoloSettings[cNo] = up; ResetNo(); Current.Value = HoloSettings[cNo - 1]; }); DownItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var down = HoloSettings[cNo + 1]; HoloSettings.RemoveAt(cNo + 1); HoloSettings.Insert(cNo + 1, Current.Value); HoloSettings[cNo] = down; ResetNo(); Current.Value = HoloSettings[cNo + 1]; }); }
public SeqViewModel() { Seq = AUTDSettings.Instance.ToReactivePropertySlimAsSynchronized(i => i.Seq); Points = AUTDSettings.Instance.Seq.PointsReactive; SendSeqCommand = AUTDHandler.Instance.IsOpen.Select(b => b).ToReactiveCommand(); SendSeqCommand.Subscribe(_ => { if (Points.Count == 0) { return; } AUTDHandler.Instance.SendSeq(); }); Current = new ReactivePropertySlim <Vector3Reactive?>(); AddItem = new ReactiveCommand(); RemoveItem = Current.Select(c => c != null).ToReactiveCommand(); UpItem = Current.Select(c => c != null && c.No.Value != 0).ToReactiveCommand(); DownItem = Current.Select(c => c != null && c.No.Value != Points.Count - 1).ToReactiveCommand(); AddItem.Subscribe(_ => { var item = new Vector3Reactive(Points.Count); Points.Add(item); Current.Value = item; }); RemoveItem.Subscribe(_ => { if (Current.Value == null) { return; } var delNo = Current.Value.No.Value; Points.RemoveAt(delNo); ResetNo(); Current.Value = Points.Count > delNo ? Points[delNo] : Points.Count > 0 ? Points[delNo - 1] : null; }); UpItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var up = Points[cNo - 1]; Points.Insert(cNo - 1, Current.Value); Points.RemoveAt(cNo); Points[cNo] = up; ResetNo(); Current.Value = Points[cNo - 1]; }); DownItem.Subscribe(_ => { if (Current.Value == null) { return; } var cNo = Current.Value.No.Value; var down = Points[cNo + 1]; Points.RemoveAt(cNo + 1); Points.Insert(cNo + 1, Current.Value); Points[cNo] = down; ResetNo(); Current.Value = Points[cNo + 1]; }); }