Example #1
0
        public void ProfileValueEquality()
        {
            string msg;

            debug.WriteLine("ProfileNodeCompare:");
            ProfileValue p1 = new ProfileValue("ptest ")
            {
                ParentProfileNodeId = 13
            };
            ProfileValue p2 = new ProfileValue("PTest")
            {
                ParentProfileNodeId = p1.ParentProfileNodeId
            };

            msg = $"[TEST Keys Compare]: '[{p1?.ParentProfileNodeId}]{p1?.Key}' == '[{p2?.ParentProfileNodeId}]{p2?.Key}'";
            debug.WriteLine(msg);
            Assert.IsTrue(p1.Equals(p2), msg);
            p2.ParentProfileNodeId++;
            msg = $"[TEST Keys Compare]: '[{p1?.ParentProfileNodeId}]{p1?.Key}' == '[{p2?.ParentProfileNodeId}]{p2?.Key}'";
            debug.WriteLine(msg);
            Assert.IsTrue(!p1.Equals(p2), msg);
            p2.ParentProfileNodeId--;
            p2.Key = "not same ";
            msg    = $"[TEST Keys Compare]: '[{p1?.ParentProfileNodeId}]{p1?.Key}' == '[{p2?.ParentProfileNodeId}]{p2?.Key}'";
            debug.WriteLine(msg);
            Assert.IsTrue(!p1.Equals(p2), msg);
        }
Example #2
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();
            }
        }
Example #3
0
        public void ProfileValueCompare()
        {
            string msg;

            debug.WriteLine("ProfileValueCompare:");
            ProfileValue p1 = new ProfileValue("ptest ");
            ProfileValue p2 = new ProfileValue("PTest");

            msg = $"[TEST Keys Compare]: '{p1?.Key}' < '{p2?.Key}'";
            debug.WriteLine(msg);
            Assert.IsTrue(p1 < p2, msg);
        }
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = (DistributionPeriod != null ? DistributionPeriod.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ Occurrence;
         hashCode = (hashCode * 397) ^ (Period != null ? Period.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ (PeriodType != null ? PeriodType.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ PeriodYear;
         hashCode = (hashCode * 397) ^ ProfileValue.GetHashCode();
         return(hashCode);
     }
 }
Example #5
0
        private static ProfileInfo ToProfileInfo(ProfileValue profileValue)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                var reuslt =
                    new ProfileInfo(profileValue.LoginId, profileValue.IsAnonymous, profileValue.LastActivityDate.Value,
                                    profileValue.LastActivityDate.Value,
                                    0);
                return(reuslt);
            }
            finally
            {
                sessionWrapper.Close();
            }
        }
Example #6
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();
            }
        }
Example #7
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();
            }
        }
Example #8
0
 public decimal GetProfileValue() => ProfileValue.GetValueOrDefault();
        private static ProfileInfo ToProfileInfo(ProfileValue profileValue)
        {
            SessionWrapper sessionWrapper = SessionManager.GetSessionWrapper();

            try
            {
                var reuslt =
                    new ProfileInfo(profileValue.LoginId, profileValue.IsAnonymous, profileValue.LastActivityDate.Value,
                        profileValue.LastActivityDate.Value,
                        0);
                return reuslt;
            }
            finally
            {
                sessionWrapper.Close();
            }
        }