示例#1
0
        /// <summary>
        ///     Returns the collection of settings property values for the specified application instance and settings property
        ///     group.
        /// </summary>
        /// <returns>
        ///     A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> containing the values for the specified
        ///     settings property group.
        /// </returns>
        /// <param name="context">
        ///     A <see cref="T:System.Configuration.SettingsContext"></see> describing the current application use.
        /// </param>
        /// <param name="collection">
        ///     A <see cref="T:System.Configuration.SettingsPropertyCollection"></see> containing the settings property group whose
        ///     values are to be retrieved.
        /// </param>
        /// <filterpriority>2</filterpriority>
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context,
                                                                          SettingsPropertyCollection collection)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            IUserProfileDao profileDao = MemberShipFactory.CreateProfileDao();

            try
            {
                var result = new SettingsPropertyValueCollection();
                Dictionary <string, object> persisteProfileValue = null;
                string       userName     = LoginId(context);
                ProfileValue profileValue = profileDao.FindByLoginId(userName);
                if (profileValue != null)
                {
                    persisteProfileValue = profileValue.Properities;
                }
                foreach (SettingsProperty property in collection)
                {
                    var item = new SettingsPropertyValue(property);
                    if (persisteProfileValue != null && persisteProfileValue.ContainsKey(item.Name))
                    {
                        item.PropertyValue = persisteProfileValue[item.Name];
                    }
                    result.Add(item);
                }
                sessionWrapper.Commit();
                return(result);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
示例#2
0
        private void Profile_MigrateAnonymous(object sender, ProfileMigrateEventArgs args)
        {
            SessionWrapper wrapper = SessionManager.GetSessionWrapper();

            try
            {
                IUserProfileDao profileDao = OrnamentContext.DaoFactory.MemberShipFactory.CreateProfileDao();
                ProfileValue    anonymous  = profileDao.FindByLoginId(args.AnonymousID);
                if (anonymous != null)
                {
                    //合并anonymous profile
                    ProfileBase currenProfile = HttpContext.Current.Profile;
                    foreach (string key in anonymous.Properities.Keys)
                    {
                        currenProfile.SetPropertyValue(key, anonymous.Properities[key]);
                    }
                    profileDao.Delete(anonymous);
                    currenProfile.Save();
                    AnonymousIdentificationModule.ClearAnonymousIdentifier();
                }


                //最后,一更新Multi-lang的cookie,因此使用Profile的语言。
                OrnamentContext.MemberShip.SwitchLanguage(OrnamentContext.MemberShip.CurrentUser().GetLanguage());
                wrapper.Commit();
            }
            catch (Exception ex)
            {
                ILog log = LogManager.GetLogger(typeof(GlobalContext));
                log.Error(ex.Message, ex);
            }
            finally
            {
                wrapper.Close();
            }
        }
示例#3
0
        /// <summary>
        ///     Sets the values of the specified group of property settings.
        /// </summary>
        /// <param name="context">
        ///     A <see cref="T:System.Configuration.SettingsContext"></see> describing the current application usage.
        /// </param>
        /// <param name="collection">
        ///     A <see cref="T:System.Configuration.SettingsPropertyValueCollection"></see> representing the group of property
        ///     settings to set.
        /// </param>
        /// <filterpriority>2</filterpriority>
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                string          userName   = LoginId(context);
                IUserProfileDao profileDao = MemberShipFactory.CreateProfileDao();


                ProfileValue profileValue = profileDao.FindByLoginId(userName) ??
                                            new ProfileValue
                {
                    LastActivityDate = DateTime.Now,
                    IsAnonymous      = !userIsAuthenticated(context),
                    LoginId          = userName
                };
                foreach (SettingsPropertyValue settingsPropertyValue in collection)
                {
                    if (profileValue.Properities.ContainsKey(settingsPropertyValue.Name))
                    {
                        profileValue.Properities[settingsPropertyValue.Name] = settingsPropertyValue.PropertyValue;
                    }
                    else
                    {
                        profileValue.Properities.Add(settingsPropertyValue.Name, settingsPropertyValue.PropertyValue);
                    }
                }
                profileDao.SaveOrUpdate(profileValue);
                sessionWrapper.Commit();
            }
            finally
            {
                sessionWrapper.Close();
            }
        }