Esempio n. 1
0
        protected override void Update()
        {
            if (IsUserLoggedIn && UserSettingStorage.AutoLogoutEnabled && CheckIfIdle())
            {
                // Logout inactive user
                LogoutUser();
                return;
            }

            // Update login mode
            if (EnableUserLogin != UserSettingStorage.UserLoginEnabled)
            {
                EnableUserLoginProperty.SetValue(UserSettingStorage.UserLoginEnabled);
            }

            // Client login retry
            if (CurrentUser == UserManagement.UNKNOWN_USER)
            {
                SetCurrentUser().TryWait();
            }

            // Update user
            IUserManagement userManagement = ServiceRegistration.Get <IUserManagement>();

            if (userManagement?.CurrentUser?.Name != CurrentUser?.Name)
            {
                CurrentUserProperty.SetValue(userManagement.CurrentUser);
                CurrentUserProperty.Fire(null);
            }
        }
Esempio n. 2
0
        private async Task SetCurrentUser(UserProfile userProfile = null)
        {
            bool            refreshHome = false;
            IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();

            if (userProfile == null)
            {
                if (UserSettingStorage.AutoLoginUser != Guid.Empty && _firstLogin)
                {
                    if (userProfileDataManagement.UserProfileDataManagement != null)
                    {
                        var result = await userProfileDataManagement.UserProfileDataManagement.GetProfileAsync(UserSettingStorage.AutoLoginUser);

                        if (result.Success)
                        {
                            userProfile = userProfileDataManagement.CurrentUser = result.Result;
                            _firstLogin = false;
                            refreshHome = true;
                        }
                    }
                }
                if (userProfile == null)
                {
                    // Init with system default
                    userProfileDataManagement.CurrentUser = null;
                    userProfile = userProfileDataManagement.CurrentUser;
                }
            }
            else
            {
                userProfileDataManagement.CurrentUser = userProfile;
            }
            CurrentUserProperty.SetValue(userProfile);

            if (userProfile != UserManagement.UNKNOWN_USER)
            {
                if (userProfileDataManagement.UserProfileDataManagement != null)
                {
                    await userProfileDataManagement.UserProfileDataManagement.LoginProfileAsync(userProfile.ProfileId);
                }
                _lastActivity  = DateTime.Now;
                IsUserLoggedIn = !userProfile.Name.Equals(System.Windows.Forms.SystemInformation.ComputerName, StringComparison.InvariantCultureIgnoreCase) ||
                                 userProfile.ProfileType != UserProfileType.ClientProfile;
            }
            else
            {
                IsUserLoggedIn = false;
            }
            if (refreshHome)
            {
                ShowHomeScreen(true);
            }
        }