public void Logoff()
        {
            if (_currentUser.Id == UserInfo.GuestID)
            {
                throw new Exception("无法注销Guest用户。");
            }

            // 发布用户将要切换事件。
            GlobalMessageBus.PublishUserChanging(new EventArgs());

            // 切换用户。
            _currentUser.Name = "Guest";
            _currentUser.Id   = UserInfo.GuestID;
            _currentUser.Privileges.Clear();

            // 发布用户切换事件。
            GlobalMessageBus.PublishUserChanged(new EventArgs());
        }
        public void LogOn(string userName, byte[] pwdActual)
        {
            if (string.Equals(userName, _currentUser.Name, StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception("用户名相同,无需切换。");
            }

            //
            var theUser = _userMgr.GetUser(userName);

            if (theUser == null)
            {
                throw new Exception("指定的用户不存在。");
            }

            if (!HelperTool.BytesEquals(theUser.Password, pwdActual))
            {
                throw new Exception("密码不正确。");
            }

            // 发布用户将要切换事件。
            GlobalMessageBus.PublishUserChanging(new EventArgs());

            // 更新用户。
            _currentUser.Id   = theUser.Code;
            _currentUser.Name = theUser.Name;
            if (theUser.Privileges != null)
            {
                _currentUser.Privileges = theUser.Privileges.ToList();
            }
            else
            {
                _currentUser.Privileges.Clear();
            }

            // 发布用户切换事件。
            GlobalMessageBus.PublishUserChanged(new EventArgs());
        }