Ejemplo n.º 1
0
        /// <devdoc>
        ///    Raises the ValidatingPropertiesEvent if atleast one handler is assigned.
        /// </devdoc>
        private void OnValidatingProperties(ValidatingPropertiesEventArgs e)
        {
            EventHandler <ValidatingPropertiesEventArgs> handler = _validatingProperties;

            if (null != handler)
            {
                handler(this, e);
            }
        }
Ejemplo n.º 2
0
 /// <devdoc>
 ///    Raises the ValidatingPropertiesEvent if atleast one handler is assigned.
 /// </devdoc>
 private void OnValidatingProperties(ValidatingPropertiesEventArgs e) {
     EventHandler<ValidatingPropertiesEventArgs> handler = _validatingProperties;
     if (null != handler) {
         handler(this, e);
     }
 }
Ejemplo n.º 3
0
        public Collection<string> SetPropertiesForCurrentUser(IDictionary<string, object> values, bool authenticatedUserOnly) {
            if (values == null) {
                throw new ArgumentNullException("values");
            }

            ApplicationServiceHelper.EnsureProfileServiceEnabled();

            if (authenticatedUserOnly) {
                ApplicationServiceHelper.EnsureAuthenticated(HttpContext.Current);
            }

            Collection<string> sc = new Collection<string>();
            try {
                ValidatingPropertiesEventArgs vp = new ValidatingPropertiesEventArgs(values);
                OnValidatingProperties(vp);

                Dictionary<string, object> allowedSet = ApplicationServiceHelper.ProfileAllowedSet;
                ProfileBase pb = GetProfileForCurrentUser(authenticatedUserOnly);
                foreach (KeyValuePair<string, object> kvp in values) {
                    string propertyName = kvp.Key;

                    if (pb == null) {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (vp.FailedProperties.Contains(propertyName)) {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (allowedSet == null) {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (!allowedSet.ContainsKey(propertyName)) {
                        sc.Add(propertyName);
                        continue;
                    }
                    
                    SettingsProperty settingProperty = ProfileBase.Properties[propertyName];
                    if (settingProperty == null) {
                        // property not found 
                        sc.Add(propertyName);
                        continue;
                    }
                    if (settingProperty.IsReadOnly || (pb.IsAnonymous && !(bool)settingProperty.Attributes["AllowAnonymous"])) {
                        // property is readonly, or the profile is anonymous and the property isn't enabled for anonymous access
                        sc.Add(propertyName);
                        continue;
                    }

                    SettingsPropertyValue value = GetPropertyValue(pb, kvp.Key);
                    if (value == null) { // property not found 
                        sc.Add(propertyName);
                        continue;
                    }
                    else {
                        try {
                            pb[propertyName] = kvp.Value;
                        }
                        catch (System.Configuration.Provider.ProviderException) {
                            // provider specific error
                            sc.Add(propertyName);
                        }
                        catch (System.Configuration.SettingsPropertyNotFoundException) {
                            sc.Add(propertyName);
                        }
                        catch (System.Configuration.SettingsPropertyWrongTypeException) {
                            sc.Add(propertyName);
                        }
                    }
                }
                pb.Save();
            }
            catch (Exception e) {
                LogException(e);
                throw;
            }
            return sc;
        }
Ejemplo n.º 4
0
        public Collection <string> SetPropertiesForCurrentUser(IDictionary <string, object> values, bool authenticatedUserOnly)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values");
            }

            ApplicationServiceHelper.EnsureProfileServiceEnabled();

            if (authenticatedUserOnly)
            {
                ApplicationServiceHelper.EnsureAuthenticated(HttpContext.Current);
            }

            Collection <string> sc = new Collection <string>();

            try {
                ValidatingPropertiesEventArgs vp = new ValidatingPropertiesEventArgs(values);
                OnValidatingProperties(vp);

                Dictionary <string, object> allowedSet = ApplicationServiceHelper.ProfileAllowedSet;
                ProfileBase pb = GetProfileForCurrentUser(authenticatedUserOnly);
                foreach (KeyValuePair <string, object> kvp in values)
                {
                    string propertyName = kvp.Key;

                    if (pb == null)
                    {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (vp.FailedProperties.Contains(propertyName))
                    {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (allowedSet == null)
                    {
                        sc.Add(propertyName);
                        continue;
                    }
                    if (!allowedSet.ContainsKey(propertyName))
                    {
                        sc.Add(propertyName);
                        continue;
                    }

                    SettingsProperty settingProperty = ProfileBase.Properties[propertyName];
                    if (settingProperty == null)
                    {
                        // property not found
                        sc.Add(propertyName);
                        continue;
                    }
                    if (settingProperty.IsReadOnly || (pb.IsAnonymous && !(bool)settingProperty.Attributes["AllowAnonymous"]))
                    {
                        // property is readonly, or the profile is anonymous and the property isn't enabled for anonymous access
                        sc.Add(propertyName);
                        continue;
                    }

                    SettingsPropertyValue value = GetPropertyValue(pb, kvp.Key);
                    if (value == null)   // property not found
                    {
                        sc.Add(propertyName);
                        continue;
                    }
                    else
                    {
                        try {
                            pb[propertyName] = kvp.Value;
                        }
                        catch (System.Configuration.Provider.ProviderException) {
                            // provider specific error
                            sc.Add(propertyName);
                        }
                        catch (System.Configuration.SettingsPropertyNotFoundException) {
                            sc.Add(propertyName);
                        }
                        catch (System.Configuration.SettingsPropertyWrongTypeException) {
                            sc.Add(propertyName);
                        }
                    }
                }
                pb.Save();
            }
            catch (Exception e) {
                LogException(e);
                throw;
            }
            return(sc);
        }