public AboutPageViewModel(INavigationService navigationService, IOperatingSystemVersionProvider operatingSystemVersionProvider, IUpdateService updateService, ICacheManager cacheManager, IDialogService dialogService ) : base(navigationService, dialogService) { _operatingSystemVersionProvider = operatingSystemVersionProvider; _updateService = updateService; _cacheManager = cacheManager; Title = "关于我们"; this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { var version = await _updateService.GetCurrentVersionAsync(); if (version != null && version != null) { var curVersion = _operatingSystemVersionProvider.GetVersion(); CurrentVersion = curVersion; LatestVersion = version.Version; } })); BindBusyCommand(Load); }
private async void OnActiveTabChangedAsync() { if (IsActive) { Updatetxt = "更新"; var version = await _updateService.GetCurrentVersion(); var curVersion = _operatingSystemVersionProvider.GetVersion(); IsNew = true; if (!string.IsNullOrEmpty(curVersion)) { if (version != null) { if (version.Version == curVersion) { IsNew = false; } Updatetxt = "Version " + version.Version; } } Version = IsNew ? string.Format("最新版本:{0}", version.Version) : "已经是最新版本了"; IsActive = false; } }
public UpdatePageViewModel(INavigationService navigationService, IOperatingSystemVersionProvider operatingSystemVersionProvider, IUpdateService updateService, IDialogService dialogService ) : base(navigationService, dialogService) { _operatingSystemVersionProvider = operatingSystemVersionProvider; _updateService = updateService; Title = "版本更新"; this.WhenAnyValue(x => x.IsUpdating) .Select(x => x ? "下载更新" : "已经是最新版了") .Subscribe(x => { this.DownloadInfoText = x; }).DisposeWith(DeactivateWith); this.Load = ReactiveCommand.CreateFromTask(() => Task.Run(async() => { try { var curVersion = _operatingSystemVersionProvider.GetVersion(); if (!string.IsNullOrEmpty(curVersion)) { this.CurrentVersion = curVersion; } var version = await _updateService.GetCurrentVersionAsync(); if (version != null) { var checkNew = _operatingSystemVersionProvider.CheckNewVersion(version); this.CurrentUpdateInfo = version; this.LatestVersion = version.Version; this.IsEnabled = version.Enable; this.IsUpdating = checkNew; } } catch (Exception) { } })); //检查更新 this.UpdateCommand = ReactiveCommand.Create(() => { try { if (CurrentUpdateInfo == null) { _dialogService.ShortAlert("请确保MainActivity已经初始化配置AutoUpdate."); return; } _operatingSystemVersionProvider.Check(CurrentUpdateInfo); } catch (Exception ex) { IsActive = true; Crashes.TrackError(ex); } }); this.BindBusyCommand(Load); }
public LoginPageViewModel(INavigationService navigationService, IAuthenticationService authenticationService, IOperatingSystemVersionProvider operatingSystemVersionProvider, IDialogService dialogService) : base(navigationService, dialogService) { Title = "登录"; _authenticationService = authenticationService; _operatingSystemVersionProvider = operatingSystemVersionProvider; this.WhenAnyValue( x => x.UserName, x => x.Password, (u, p) => !string.IsNullOrEmpty(u) && !string.IsNullOrEmpty(p)) .Select(x => x) .Subscribe(x => this.IsEnabled = x).DisposeWith(DeactivateWith); #if DEBUG //13883655199 //13379270266 //15139466658 //15332249255 //13379270266 //18191173366 //15319386295 UserName = "******"; Password = "******"; #endif var name = this .WhenAnyValue(x => x.UserName) .Select(x => x == null || CommonHelper.IsPhoneNo(x, true)); var password = this .WhenAnyValue(x => x.Password) .Select(x => x == null || x?.Length >= 6); var agreemented = this .WhenAnyValue(x => x.Agreemented) .Select(x => x); this.AgreementedRule = this.ValidationRule(vm => vm.Agreemented, agreemented, "是否同意并接受云销管理服务协议条款?"); this.NameRule = this.ValidationRule(vm => vm.UserName, name, "用户名不能为空,且必须为手机号."); this.PasswordRule = this.ValidationRule(vm => vm.Password, password, "必须指定一个长度超过6个符号的有效密码."); //检查版本 this.Load = ReactiveCommand.Create(() => { try { CurrentAppVersion = _operatingSystemVersionProvider.GetVersion(); } catch (Exception) { } }); //登录 this.PerformLogin = ReactiveCommand.CreateFromTask <string>(async arg => { if (!AgreementedRule.IsValid) { _dialogService.ShortAlert(AgreementedRule.Message[0]); return; } if (!NameRule.IsValid) { _dialogService.ShortAlert(NameRule.Message[0]); return; } if (!PasswordRule.IsValid) { _dialogService.ShortAlert(PasswordRule.Message[0]); return; } bool isAuthenticated = false; using (var dig = UserDialogs.Instance.Loading("登录中...")) { try { Settings.IsInitData = false; var rcode = await _authenticationService.LoginAsync(UserName, Password); if (rcode == 1) { isAuthenticated = true; Settings.IsAuthenticated = true; } } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { dig.Hide(); await ShowAlert(false, "认证失败,网络异常!"); return; } catch (Exception) { dig.Hide(); await ShowAlert(false, "认证失败,网络异常!"); return; } //认证成功 if (isAuthenticated) { await this.NavigateAsync($"{nameof(MainLayoutPage)}"); } else { dig.Hide(); await ShowAlert(false, "认证失败,无效账户或错误凭证!"); return; } } }); //免责 this.AgreementedCmd = ReactiveCommand.Create(async() => { await CrossDiaglogKit.Current.PopViewAsync("免责申明", GlobalSettings.AgreementText); }); this.BindBusyCommand(Load); }