private void Initialize(AppContextService appService) { appService?.KeyDetectedAsObservable() .Where(_ => this.IsVisibledNotifier.Value) .Where(e => KeyMapping.KeyCharacterFingerMapping.Keys.Any(key => key == e.Key) || e.Key == Key.Escape) .Subscribe(async e => await this.SubscribeKeyDetectedAsync(e)) .AddTo(this.Disposables); }
private void Initialize(AppContextService appService) { appService?.KeyDetectedAsObservable() .Where(_ => this.IsVisibledNotifier.Value) .Where(e => e.Key == Key.Space) .Subscribe(async e => await this.SubscribeKeyDetectedAsync(e)) .AddTo(this.Disposables); }
public static IObservable <EventArgs> PracticeRestartingAsObservable(this AppContextService self) { return(self == null ? Observable.Empty <EventArgs>() : Observable.FromEvent <EventHandler, EventArgs>( onNext => (sender, args) => onNext(args), handler => self.PracticeRestarting += handler, handler => self.PracticeRestarting -= handler)); }
public static IObservable <KeyEventArgs> KeyDetectedAsObservable(this AppContextService self) { return(self == null ? Observable.Empty <KeyEventArgs>() : Observable.FromEvent <EventHandler <KeyEventArgs>, KeyEventArgs>( onNext => (sender, args) => onNext(args), handler => self.KeyDetected += handler, handler => self.KeyDetected -= handler)); }
public TypingResultContentViewModel(AppContextService appService) : base(appService) { this.PracticeResultItems = new ReactiveCollection <PracticeResultItem>(); this.PracticeResultSummaries = new ReactiveCollection <PracticeResultSummary>(); this.PracticeRestartingCommand = new ReactiveCommand().AddTo(this.Disposables); this.PracticeRestartingCommand.Subscribe(() => this.AppService?.PublishPracticeRestarting()).AddTo(this.Disposables); }
private void Initialize(AppContextService appService) { this.ToggleThemeCommand.Subscribe(() => ThemeHelper.ApplyBase(this.IsDark.Value)).AddTo(this.Disposables); this.ContentsIndex.Subscribe(index => DebugLog.Print($"{this.GetType().Name}.{nameof(this.ContentsIndex)}: {index}")).AddTo(this.Disposables); this.KeyUpCommand .Where(_ => !this.IsDialogOpen.Value) .Subscribe(e => appService?.PublishKeyDetected(e)).AddTo(this.Disposables); appService?.PracticeStartedAsObservable().Subscribe(_ => this.SubscribePracticeStarted()).AddTo(this.Disposables); appService?.PracticeItemResultedAsObservable().Subscribe(this.SubscribePracticeItemResulted).AddTo(this.Disposables); appService?.PracticeRestartingAsObservable().Subscribe(_ => this.SubscribePracticeRestarting()).AddTo(this.Disposables); }
/// <summary> /// 判断是否有权限 /// </summary> /// <param name="userId">The user identifier.</param> /// <param name="privilegeCode">The privilege code.</param> /// <returns> /// <c>true</c> if the specified privilege code has right; otherwise, <c>false</c>. /// </returns> public static bool HasPrivilege(string userId, string privilegeCode) { if (AppConfig.IsDebugMode) { return(true); } else { return(AppContextService.HasPrivilege(userId, privilegeCode)); } }
public TypingConfirmContentViewModel(AppContextService appService) : base(appService) { this.cts = new CancellationTokenSource(); this.cts.AddTo(this.Disposables); this.busyNotifier = new BusyNotifier(); this.DialogViewModel = new ReactivePropertySlim <StartingPracticeDialogViewModel>().AddTo(this.Disposables); this.IsDialogOpen = new ReactivePropertySlim <bool>().AddTo(this.Disposables); this.Initialize(appService); }
private void checkPermissions(NavigatingCancelEventArgs e) { //اینجا بهترین مکان برای اعمال مباحث اعتبار سنجی ورود به صفحات است //چون قبل از بارگذاری صفحه اعمال میشود var attribute = PageAuthorizationScanner.GetPageAuthorizationAttribute(e.Uri); if (!AppContextService.CanCurrentUserNavigateTo(attribute)) { e.Cancel = true; //صفحه نمایش داده نشود Redirect.ToLoginFailedPage(); } }
public PracticeKeyInfoViewModel(AppContextService appService, char expectedKey, bool isCurrent) : base(appService) { this.ExpectedKey = new ReactivePropertySlim <char>(expectedKey).ToReadOnlyReactivePropertySlim().AddTo(this.Disposables); this.InputtedKey = new ReactivePropertySlim <char?>().AddTo(this.Disposables); this.IsCurrent = new ReactivePropertySlim <bool>(isCurrent).AddTo(this.Disposables); this.IsInputted = this.InputtedKey.Select(actual => actual.HasValue).ToReadOnlyReactivePropertySlim().AddTo(this.Disposables); this.IsMatch = this.ExpectedKey .CombineLatest(this.InputtedKey.Where(actual => actual.HasValue), (expect, actual) => (bool?)Nullable.Equals(expect, actual)) .ToReadOnlyReactivePropertySlim() .AddTo(this.Disposables); this.KeyInputtedCount = new ReactivePropertySlim <int>().AddTo(this.Disposables); this.KeyMistakedCount = new ReactivePropertySlim <int>().AddTo(this.Disposables); }
public TypingPracticeItemContentViewModel(AppContextService appService) : base(appService) { this.practiceKeyInfoViewModelsDisposable = new CompositeDisposable().AddTo(this.Disposables); this.notMatchedKeyNotifier = new BooleanNotifier(); this.keyMissingNotifier = new BooleanNotifier(); this.OdaiText = new ReactivePropertySlim <string>().AddTo(this.Disposables); this.YomiText = new ReactivePropertySlim <string>().AddTo(this.Disposables); this.PracticeKeyInfoViewModels = new ReactiveCollection <PracticeKeyInfoViewModel>().AddTo(this.Disposables); this.CurrentExpectedKey = new ReactivePropertySlim <Key>().AddTo(this.Disposables); this.IsNotMatched = this.notMatchedKeyNotifier.ToReadOnlyReactivePropertySlim().AddTo(this.Disposables); this.IsKeyMissing = this.keyMissingNotifier.ToReadOnlyReactivePropertySlim().AddTo(this.Disposables); this.Initialize(appService); }
public MainWindowViewModel(AppContextService appService) : base(appService) { this.booleanNotifier = new BooleanNotifier(); this.serialDisposable = new SerialDisposable().AddTo(this.Disposables); this.IsDark = new ReactivePropertySlim <bool>().AddTo(this.Disposables); this.ToggleThemeCommand = new ReactiveCommand().AddTo(this.Disposables); this.ContentsIndex = new ReactivePropertySlim <int>().AddTo(this.Disposables); this.KeyUpCommand = new ReactiveCommand <KeyEventArgs>().AddTo(this.Disposables); this.DialogViewModel = new ReactivePropertySlim <object>().AddTo(this.Disposables); this.IsDialogOpen = new ReactivePropertySlim <bool>().AddTo(this.Disposables); this.CurrentConfirmContentViewModel = new TypingConfirmContentViewModel(appService).AddTo(this.Disposables); this.CurrentPracticeItemContentViewModel = new TypingPracticeItemContentViewModel(appService).AddTo(this.Disposables); this.CurrentResultContentViewModel = new TypingResultContentViewModel(appService).AddTo(this.Disposables); this.Initialize(appService); }
internal async Task <bool> SetInputtedKeyAsync(Key actualKey, BooleanNotifier notMatchedKeyNotifier, BooleanNotifier keyMissingNotifier) { if (actualKey.TryToChar(out var actualChar)) { this.KeyInputtedCount.Value++; this.InputtedKey.Value = actualChar; if (actualKey == this.ExpectedKey.Value.ToKey()) { notMatchedKeyNotifier.TurnOff(); return(true); } this.KeyMistakedCount.Value++; notMatchedKeyNotifier.TurnOn(); keyMissingNotifier.TurnOn(); var task1 = AppContextService.BeepAsync(); var task2 = Task.Delay(TimeSpan.FromSeconds(0.2)); await Task.WhenAny(task1, task2); keyMissingNotifier.TurnOff(); } return(false); }
public static IObservable <PracticeResultItem> PracticeItemResultedAsObservable(this AppContextService self) { return(self == null ? Observable.Empty <PracticeResultItem>() : Observable.FromEvent <Action <PracticeResultItem>, PracticeResultItem>( onNext => onNext, handler => self.PracticeItemResulted += handler, handler => self.PracticeItemResulted -= handler)); }
protected ViewModelDependencyBase(AppContextService appService) { this.AppService = appService; }