Пример #1
0
        //Changed to public so that we can use it in Test implmementation - mt 10/10/2012
        public MemberAccount(IMemberAccountData accountData)
        {
            String logMethodName = ".ctor(IMemberAccountData accountData) - ";

            _log.Debug(logMethodName + "Begin Method");

            Init();

            _membershipId = accountData.MemberId;

            _accountData       = (MemberAccountData)accountData;
            _accountDataLoaded = true;
            _isAnonymous       = false;

            _log.Debug(logMethodName + "End Method");
        }
Пример #2
0
        private void LoadData()
        {
            String logMethodName = ".LoadData() - ";

            _log.Debug(logMethodName + "Begin Method");

            if (!_accountDataLoaded)
            {
                _log.Debug(logMethodName + "Loading Member Account Data");

                IMemberAccountData accountData;
                try
                {
                    if (_membershipId == null)
                    {
                        _log.Debug(logMethodName + "Calling ISecurityAdapter.GetMember() - Attempting to get the currently logged member from the adapter");
                        accountData = _adapter.GetMember();
                    }
                    else
                    {
                        _log.Debug(logMethodName + "Calling ISecurityAdapter.GetMember(Object memberId) - Attempting to get the member based on provided ID");
                        accountData = _adapter.GetMember(_membershipId);
                    }
                }
                catch (Exception ex)
                {
                    _isAuthenticated = false;

                    String message = logMethodName + "Error getting account data";
                    _log.Error(message, ex);

                    throw new WtfException(message, ex);
                }

                if (accountData != null)
                {
                    _log.Debug(logMethodName + "Member Account Data loaded successfully");

                    _accountData = (MemberAccountData)accountData;

                    _isAnonymous = false;

                    //Membership ID is only set when the constructor that injects data is called.
                    //the default constructor will load the currently logged in user and does
                    //not set the _membershipId value.

                    //TODO: This pattern sucks, fix it -JFM
                    if (_membershipId == null)
                    {
                        _isAuthenticated = true;
                    }
                    else
                    {
                        _isAuthenticated = false;
                    }
                }
                else
                {
                    _log.Debug(logMethodName + "No user found, creating an anonymous context");

                    //NOTE: This is the beginning of having a real anonymous context. This can be expaned to allow for persistance
                    //for anonymons users for future features.

                    //We generate a unique ID for our anonmous user
                    //TODO: On first visit during session, set ID, RE-Use that ID throughout the anonymous user's session.
                    Guid anonId = Guid.NewGuid();

                    _accountData = new MemberAccountData
                    {
                        MemberId     = Guid.Empty,
                        Id           = anonId,
                        LastActivity =
                            DateTime.Now,
                        IsOnline   = false,
                        IsApproved = false,
                        Username   = "******"
                    };

                    _isAuthenticated = false;
                    _isAnonymous     = true;
                }

                _accountDataLoaded = true;
                _log.Debug(string.Format("About to set WTFSession.AccountId = {0}", _accountData.MemberId != null ? _accountData.MemberId : "NULL"));
                WTFSession.AccountId = _accountData.MemberId;
                _log.Debug(logMethodName + "Account Data loading complete");
            }
            else
            {
                _log.Debug(logMethodName + "Account Data is already loaded, skipping");
            }


            _log.Debug(logMethodName + "End Method");
        }