Ejemplo n.º 1
0
        private IList <ProfileProperty> GetProperties(string userName)
        {
            if (string.IsNullOrEmpty(userName))
            {
                return(null);
            }

            IList <ProfileProperty> properties;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var         userStore = new ProfileUserDataStore(transaction);
                ProfileUser user      = userStore.FindByName(ApplicationName, userName);
                if (user == null)
                {
                    return(null);
                }

                var propStore = new ProfilePropertyDataStore(transaction);

                properties = propStore.FindByUser(user);

                //Update the last activity date
                user.LastActivityDate = DateTime.Now;

                transaction.Commit();
            }

            return(properties);
        }
        public ProfileProperty FindByPropertyName(ProfileUser user, string propertyName)
        {
            ICriteria criteria = CreateCriteria();

            criteria.CreateCriteria("User").Add(Expression.Eq("Id", user.Id));
            criteria.Add(Expression.Eq("Name", propertyName));

            return(FindUnique(criteria, null));
        }
        public IList <ProfileProperty> FindByUser(ProfileUser user)
        {
            ICriteria criteria = CreateCriteria();

            criteria.CreateCriteria("User").Add(Expression.Eq("Id", user.Id));
            criteria.AddOrder(Order.Desc("Name"));

            return(Find(criteria, null));
        }
Ejemplo n.º 4
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection properties)
        {
            var         username = (string)context[CONTEXT_USERNAME];
            ProfileType profileType;

            if ((bool)context[CONTEXT_ISAUTHENTICATED])
            {
                profileType = ProfileType.Authenticated;
            }
            else
            {
                profileType = ProfileType.Anonymous;
            }

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var propStore = new ProfilePropertyDataStore(transaction);
                var userStore = new ProfileUserDataStore(transaction);

                ProfileUser user = userStore.FindByName(ApplicationName, username);
                //Create the user if not exist
                if (user == null)
                {
                    user = new ProfileUser(ApplicationName, username, profileType);
                    userStore.Insert(user);
                }

                bool userChanged = false;

                foreach (SettingsPropertyValue propValue in properties)
                {
                    if (propValue.IsDirty)
                    {
                        if (profileType == ProfileType.Anonymous)
                        {
                            var allowAnonymous = (bool)propValue.Property.Attributes[PROP_ATTRIBUTE_ALLOWANONYMOUS];
                            if (!allowAnonymous)
                            {
                                continue;
                            }
                        }

                        userChanged = true;

                        ChangeProfileProperty(propStore, user, propValue);
                    }
                }

                user.LastActivityDate = DateTime.Now;
                if (userChanged)
                {
                    user.LastPropertyChangedDate = DateTime.Now;
                }

                transaction.Commit();
            }
        }
        public int DeleteByUser(ProfileUser user)
        {
            IList <ProfileProperty> properties = FindByUser(user);

            foreach (ProfileProperty prop in properties)
            {
                Delete(prop.Id);
            }

            return(properties.Count);
        }
Ejemplo n.º 6
0
        private void ChangeProfileProperty(ProfilePropertyDataStore propStore, ProfileUser user,
                                           SettingsPropertyValue propValue)
        {
            ProfileProperty dbProperty = propStore.FindByPropertyName(user, propValue.Name);

            if (dbProperty == null) //Create the property if not found
            {
                dbProperty = new ProfileProperty(user, propValue.Name);
                propStore.Insert(dbProperty);
            }

            //The property is already deserialized and is null
            if (propValue.Deserialized && propValue.PropertyValue == null)
            {
                dbProperty.SetNull();
            }
            else //Property is not null
            {
                object serializedVal = propValue.SerializedValue;

                if (serializedVal == null) //null
                {
                    dbProperty.SetNull();
                }
                else if (serializedVal is string) //string
                {
                    dbProperty.SetValue((string)serializedVal);
                }
                else if (serializedVal is byte[]) //binary
                {
                    dbProperty.SetValue((byte[])serializedVal);
                }
                else
                {
                    throw new ProfileValueNotSupportedException(propValue.Name);
                }
            }
        }
Ejemplo n.º 7
0
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            int profilesDeleted = 0;

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var profileStore = new ProfileUserDataStore(transaction);

                foreach (ProfileInfo profileInfo in profiles)
                {
                    ProfileUser user = profileStore.FindByName(ApplicationName, profileInfo.UserName);
                    if (user != null)
                    {
                        profileStore.Delete(user.Id);

                        profilesDeleted++;
                    }
                }

                transaction.Commit();
            }

            return(profilesDeleted);
        }