Exemple #1
0
        public SiteMember GetMember(object membershipId)
        {
            const string logMethodName = ".GetMember(object membershipId)";

            _log.Debug(logMethodName + " - Begin Method");
            IMemberAccountData accountData = null;
            IMemberProfileData profileData = null;

            try
            {
                _log.Debug(logMethodName + " - Calling ISecurityAdapter.GetMember(membershipId)");

                accountData = _adapter.GetMember(membershipId);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + " - Error retrieving member accound data from Security Adapter " + _adapter.GetType().FullName);

                throw new WtfException(logMethodName + " - Error retrieving member accound data from Security Adapter" + _adapter.GetType().FullName, ex);
            }

            try
            {
                _log.Debug(logMethodName + " - Calling IContextDataAdapter.GetMemberProfile(membershipId)");

                profileData = _provider.GetMemberProfile(accountData.MemberId);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + " - Error retrieving member accound data from Data Provider" + _provider.GetType().FullName, ex);

                throw new WtfException(logMethodName + " - Error retrieving member accound data from Data Provider " + _provider.GetType().FullName, ex);
            }

            SiteMember siteMember = null;

            try
            {
                siteMember = new SiteMember(accountData, profileData);
            }
            catch (Exception ex)
            {
                _log.Error(logMethodName + " - Unable to create SiteMember(MemberAccountData, MemberProfileData) instance", ex);

                throw new WtfException(logMethodName + " - Unable to create SiteMember(MemberAccountData, MemberProfileData) instance", ex);
            }

            _log.Debug(logMethodName + " - End Method");
            return(siteMember);
        }
Exemple #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");
        }