コード例 #1
0
 public UserService(ICreditUtility credit, IEncryptUtility encrypt, IAuthorityUtility authority, IDatabaseModelManager database, ILogManagerFactory loggerFactory)
 {
     this.credit    = credit;
     this.encrypt   = encrypt;
     this.authority = authority;
     this.database  = database;
     logger         = loggerFactory.CreateManager <UserService>();
 }
コード例 #2
0
        public UserInfoViewModel(IUserService userService, ICreditUtility creditUtility, IAuthorityUtility authorityUtility, ILogManagerFactory loggerFactory)
        {
            this.userService      = userService;
            this.creditUtility    = creditUtility;
            this.authorityUtility = authorityUtility;
            logger = loggerFactory.CreateManager <UserInfoViewModel>();

            LoggedOut = new Interaction <Unit, Unit>();
            Activator = new ViewModelActivator();
            this.WhenActivated(disposableRegistration =>
            {
                userName = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "游小客" : account.UserName)
                           .ToProperty(this, vm => vm.UserName)
                           .DisposeWith(disposableRegistration);
                name = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "游客" : account.Name)
                       .ToProperty(this, vm => vm.Name)
                       .DisposeWith(disposableRegistration);
                nationalIdentificationNumber = this.WhenAnyValue <UserInfoViewModel, string, User>(vm => vm.ParentViewModel.Account, account => account == null ? "---" : account.NationalIdentificationNumber)
                                               .ToProperty(this, vm => vm.NationalIdentificationNumber)
                                               .DisposeWith(disposableRegistration);
                creditValue = this.WhenAnyValue <UserInfoViewModel, int, User>(vm => vm.ParentViewModel.Account, account => account == null ? -1 : account.CreditValue)
                              .ToProperty(this, vm => vm.CreditValue)
                              .DisposeWith(disposableRegistration);
                accreditedDays = this.WhenAnyValue(vm => vm.ParentViewModel.Account, account => this.creditUtility.GetAccreditedDays(account))
                                 .ToProperty(this, vm => vm.AccreditedDays)
                                 .DisposeWith(disposableRegistration);
                authorityLevel = this.WhenAnyValue(vm => vm.ParentViewModel.Account, account => this.authorityUtility.GetLevel(account))
                                 .Select(al =>
                {
                    return(al switch
                    {
                        Utilities.AuthorityLevel.Visitor => "游客",
                        Utilities.AuthorityLevel.Member => "会员",
                        Utilities.AuthorityLevel.Administrator => "管理员",
                        _ => "外星人",
                    });
                })
                                 .ToProperty(this, vm => vm.AuthorityLevel)
                                 .DisposeWith(disposableRegistration);
                RefreshCommand = ReactiveCommand.CreateFromTask(RefreshAsync, outputScheduler: RxApp.MainThreadScheduler)
                                 .DisposeWith(disposableRegistration);
                RefreshCommand.BindTo(ParentViewModel, pvm => pvm.Account);
                RefreshCommand.ThrownExceptions.Subscribe(ex => logger.Error(ex, "查询账户信息时出错"));
                LogoutCommand = ReactiveCommand.Create <User>(() => null)
                                .DisposeWith(disposableRegistration);
                LogoutCommand.Subscribe(u =>
                {
                    ParentViewModel.Account = u;
                    LoggedOut.Handle(Unit.Default).Subscribe();
                });
                LogoutCommand.ThrownExceptions.Subscribe(ex => logger.Error(ex, "退出账户时出错"));
            });