Beispiel #1
0
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            //Get the user name
            string userName = context["UserName"] as string;

            //Get the DirectoryEntry for the user name
            using (DirectoryEntry userEntry = GetUserEntryByUserName(userName))
            {
                //Get each property
                IEnumerator en = collection.GetEnumerator();
                while (en.MoveNext())
                {
                    SettingsPropertyValue spv = (en.Current as SettingsPropertyValue);

                    //The name of the property
                    string propertyToSet = spv.Name;

                    //The AttributeMapping associated with the property
                    AttributeMapping am = AttributeList[propertyToSet];
                    //if no such key exists, simply continue;

                    //Set properties recursievly because it might be a complex object
                    SetPropertyRecursively(userEntry, spv.Deserialized ? spv.PropertyValue : spv.SerializedValue, !spv.Deserialized, am);
                }

                //Set last actvity date
                if (LastActivityDateAttribute != null)
                {
                    userEntry.InvokeSet(LastActivityDateAttribute, DateTime.Now);
                }
                //Set last update date
                if (LastUpdateDateAttribute != null)
                {
                    userEntry.InvokeSet(LastUpdateDateAttribute, DateTime.Now);
                }

                //Commit changes
                userEntry.CommitChanges();
            }
        }