public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection result = new SettingsPropertyValueCollection(); if (collection.Count < 1) return result; string userEmail = (string) context["UserName"]; //Эта строка мне пока не понятна if (string.IsNullOrEmpty(userEmail)) return result; var user = UserService.GetByEmail(userEmail); var profile = ProfileService.GetProfile(user); foreach (SettingsProperty prop in collection) { SettingsPropertyValue svp = new SettingsPropertyValue(prop) { PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null) }; result.Add(svp); } return result; }
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues (System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { XDocument xdoc = XDocument.Load(new StreamReader(HttpRuntime.BinDirectory + "app.config")); var settings = xdoc.Element("configuration").Element("userSettings") .Element("PartialAssociationRules.Domain.ApplicationSettings").Descendants("setting"); var result = new SettingsPropertyValueCollection(); foreach (SettingsProperty singleProperty in collection) { var value = settings .Where(x => x.Attribute("name").Value == singleProperty.Name) .Select(x => x.Element("value").Value).First().Replace('.', ','); result.Add( new SettingsPropertyValue(singleProperty) { PropertyValue = Convert.ChangeType(value, singleProperty.PropertyType) }); } return(result); }
///<summary> ///Returns the collection of settings property values for the specified application instance and settings property group. ///</summary> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { Type settingsClass = (Type)context["SettingsClassType"]; string settingsKey = (string)context["SettingsKey"]; string user = Thread.CurrentPrincipal.Identity.Name; // load settings from store Dictionary<string, string> storedValues = _store.GetSettingsValues( new SettingsGroupDescriptor(settingsClass), user, settingsKey); // Create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); // Iterate through the settings to be retrieved foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value value.SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null; values.Add(value); } return values; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Gets the property values from a config file. /// </summary> /// ------------------------------------------------------------------------------------ public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { // Set the config files var configMap = SetConfigFiles(); // Create new collection of values var values = new SettingsPropertyValueCollection(); ReadProperties(context, properties, configMap, ConfigurationUserLevel.None, values); ReadProperties(context, properties, configMap, ConfigurationUserLevel.PerUserRoamingAndLocal, values); ReadProperties(context, properties, configMap, ConfigurationUserLevel.PerUserRoaming, values); // save new user config file try { SetPropertyValues(context, values); } catch { } return values; }
/// <summary> /// Must override this, this is the bit that matches up the designer properties to the dictionary values /// </summary> /// <param name="context"></param> /// <param name="collection"></param> /// <returns></returns> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { //load the file if (!_loaded) { _loaded = true; LoadValuesFromFile(); } //collection that will be returned. SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); //itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary foreach (SettingsProperty setting in collection) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; //need the type of the value for the strong typing var t = Type.GetType(setting.PropertyType.FullName); if (SettingsDictionary.ContainsKey(setting.Name)) { value.SerializedValue = SettingsDictionary[setting.Name].value; value.PropertyValue = Convert.ChangeType(SettingsDictionary[setting.Name].value, t); } else //use defaults in the case where there are no settings yet { value.SerializedValue = setting.DefaultValue; value.PropertyValue = Convert.ChangeType(setting.DefaultValue, t); } values.Add(value); } return values; }
/// <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"/> containing the values for the specified settings property group. /// </returns> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use. /// </param><param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved. /// </param><filterpriority>2</filterpriority> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var username = (string) context["UserName"]; var isAuthenticated = (bool) context["IsAuthenticated"]; Profile profile = ProfileManager.Instance.GetCurrentUser(username); var svc = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { var pv = new SettingsPropertyValue(prop); switch (pv.Property.Name) { case _PROFILE_SHOPPINGCART: pv.PropertyValue = CartList.GetCart(profile.UniqueID, true); break; case _PROFILE_WISHLIST: pv.PropertyValue = CartList.GetCart(profile.UniqueID, false); break; case _PROFILE_ACCOUNT: if (isAuthenticated) pv.PropertyValue = new Address(profile); break; default: throw new ApplicationException(string.Format("{0} name.", _ERR_INVALID_PARAMETER)); } svc.Add(pv); } return svc; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { XmlSettingsFile localFile = XmlSettingsFile.GetLocalSettingsFile(GetTypeFromContext(context)); XmlSettingsFile roamingFile = XmlSettingsFile.GetRoamingSettingsFile(GetTypeFromContext(context)); SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; if (IsRoaming(setting)) { value.SerializedValue = roamingFile.GetValue(setting); } else { value.SerializedValue = localFile.GetValue(setting); } values.Add(value); } return values; }
public static SettingsPropertyValueCollection GetSharedPropertyValues(LocalFileSettingsProvider provider, SettingsContext context, SettingsPropertyCollection properties, string currentExeConfigFilename = null) { var settingsClass = (Type)context["SettingsClassType"]; var systemConfiguration = String.IsNullOrEmpty(currentExeConfigFilename) ? SystemConfigurationHelper.GetExeConfiguration() : SystemConfigurationHelper.GetExeConfiguration(currentExeConfigFilename); var storedValues = systemConfiguration.GetSettingsValues(settingsClass); // Create new collection of values var values = new SettingsPropertyValueCollection(); foreach (SettingsProperty setting in properties) { var value = new SettingsPropertyValue(setting) { SerializedValue = storedValues.ContainsKey(setting.Name) ? storedValues[setting.Name] : null, IsDirty = false }; // use the stored value, or set the SerializedValue to null, which tells .NET to use the default value values.Add(value); } return values; }
public SettingsPropertyValueCollection LoadValues(string userName, SettingsPropertyCollection props) { var svc = new SettingsPropertyValueCollection(); // holds sourcename->data pairs var loadedData = new Dictionary<string, IDictionary>(); foreach (SettingsProperty prop in props) { EnsureDataLoaded(userName, prop.Name, loadedData); var pv = new SettingsPropertyValue(prop); object value = null; // lets try to locate property value foreach (var src in Sources) if (src.FieldsMapping.ContainsKey(prop.Name)) { value = loadedData[src.SourceName][ ResolveFieldName(prop.Name,src) ]; break; } if (value == null || value == DBNull.Value) { // leave default value } else { pv.PropertyValue = value; pv.IsDirty = false; } svc.Add(pv); } return svc; }
public object Clone () { SettingsPropertyCollection col = new SettingsPropertyCollection (); col.items = (Hashtable)items.Clone (); return col; }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <param name="context">A System.Configuration.SettingsContext describing the current application use.</param> /// <param name="collection">A System.Configuration.SettingsPropertyCollection containing the settings property group whose values are to be retrieved.</param> /// <returns>A System.Configuration.SettingsPropertyValueCollection containing the values for the specified settings property group.</returns> public override SettingsPropertyValueCollection GetPropertyValues( SettingsContext context, SettingsPropertyCollection collection) { string username = (string)context["UserName"]; bool isAuthenticated = (bool) context["IsAuthenticated"]; SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue pv = new SettingsPropertyValue(prop); switch (pv.Property.Name) { case PROFILE_SHOPPINGCART: pv.PropertyValue = GetCartItems(username, true); break; case PROFILE_WISHLIST: pv.PropertyValue = GetCartItems(username, false); break; case PROFILE_ACCOUNT: if (isAuthenticated) pv.PropertyValue = GetAccountInfo(username); break; default: throw new ApplicationException(ERR_INVALID_PARAMETER + " name."); } svc.Add(pv); } return svc; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { // set all of the inherited default values first in case we have failure later SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue spv = new SettingsPropertyValue(prop); spv.SerializedValue = prop.DefaultValue; settings.Add(spv); } // now read in overridden user settings try { Configuration config = null; ClientSettingsSection clientSettings = GetUserSettings(out config, true); foreach (SettingsPropertyValue spv in settings) { DeserializeFromXmlElement(spv.Property, spv, clientSettings); } } catch { // suppress } return settings; }
private SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties, bool returnPrevious) { Type settingsClass = (Type)context["SettingsClassType"]; string settingsKey = (string)context["SettingsKey"]; string user = Thread.CurrentPrincipal.Identity.Name; var group = new SettingsGroupDescriptor(settingsClass); if (returnPrevious) group = _store.GetPreviousSettingsGroup(group); else if (AnyUserScoped(properties)) SettingsMigrator.MigrateUserSettings(group); var storedValues = new Dictionary<string, string>(); if (group != null) { foreach (var userDefault in _store.GetSettingsValues(group, null, settingsKey)) storedValues[userDefault.Key] = userDefault.Value; foreach (var userValue in _store.GetSettingsValues(group, user, settingsKey)) storedValues[userValue.Key] = userValue.Value; } return GetSettingsValues(properties, storedValues); }
/// <summary> /// Must override this, this is the bit that matches up the designer properties to the dictionary values /// </summary> /// <param name="context"></param> /// <param name="collection"></param> /// <returns></returns> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { //load the file if (!_loaded) { _loaded = true; LoadValuesFromFile(); } //collection that will be returned. SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); //itterate thought the properties we get from the designer, checking to see if the setting is in the dictionary foreach (SettingsProperty setting in collection) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; if (SettingsDictionary.ContainsKey(setting.Name)) { value.SerializedValue = SettingsDictionary[setting.Name].value; } else //use defaults in the case where there are no settings yet { value.SerializedValue = setting.DefaultValue == null ? string.Empty : setting.DefaultValue.ToString(); } values.Add(value); } return values; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var properties = new SettingsPropertyValueCollection(); if (collection.Count < 1) return properties; var username = (string) context["UserName"]; foreach (SettingsProperty property in collection) { properties.Add(new SettingsPropertyValue(property)); } var db = new MyLifeEntities(); var profile = db.tblProfiles.Where(item => item.UserName == username).FirstOrDefault(); if (profile != null) { var names = profile.PropertyNames.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries); var values = profile.PropertyValues.Split(new[] {";#"}, StringSplitOptions.RemoveEmptyEntries); if (names.Length > 0 && values.Length > 0) { for (var i = 0; i < names.Length; i++) { var property = properties[names[i]]; if (property == null) continue; property.PropertyValue = Base64Serializer.Deserialize(values[i]); } } } return properties; }
public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context, SettingsPropertyCollection properties) { #if SPEW Console.WriteLine (Environment.StackTrace); #endif return base.GetPropertyValues (context, properties); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection v = new SettingsPropertyValueCollection(); value = new SettingsPropertyValue(new SettingsProperty("Style")); value.PropertyValue = "null"; v.Add(value); return v; }
public void Initialize (SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) { this.context = context; this.properties = properties; this.providers = providers; // values do not seem to be reset here!! (otherwise one of the SettingsBaseTest will fail) }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var values = GetPropertyValues(context, collection, false); var settingsClass = (Type)context["SettingsClassType"]; TranslateValues(settingsClass,values); return values; }
public static SettingsPropertyCollection ToSettingsPropertyCollection(this IEnumerable<SettingsProperty> settingsProperties) { var c = new SettingsPropertyCollection(); foreach (var property in settingsProperties) { c.Add(property); } return c; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { return new SettingsPropertyValueCollection { new SettingsPropertyValue(new SettingsProperty("FriendlyName") { PropertyType = typeof(String) }) }; }
public void Add () { SettingsPropertyCollection col = new SettingsPropertyCollection (); SettingsProperty test_prop = new SettingsProperty ("test_prop"); Assert.AreEqual (0, col.Count, "A1"); col.Add (test_prop); Assert.AreEqual (1, col.Count, "A2"); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { var values = new SettingsPropertyValueCollection(); foreach (SettingsProperty property in props) { var value2 = new SettingsPropertyValue(property) { IsDirty = false, SerializedValue = GetValue(property) }; values.Add(value2); } return values; }
private static SettingsPropertyCollection GetPropertiesForProvider(ApplicationSettingsBase settings, SettingsProvider provider) { SettingsPropertyCollection properties = new SettingsPropertyCollection(); foreach (SettingsProperty property in settings.Properties) { if (property.Provider == provider) properties.Add(property); } return properties; }
public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context, SettingsPropertyCollection properties) { #if TARGET_JVM SettingsPropertyValueCollection pv = new SettingsPropertyValueCollection (); foreach (SettingsProperty prop in properties) pv.Add (new SettingsPropertyValue (prop)); return pv; #else return impl.GetPropertyValues (context, properties); #endif }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { SettingsPropertyValueCollection spCollection = new SettingsPropertyValueCollection(); foreach (SettingsProperty settingsProperty in collection) { SettingsPropertyValue spVal = new SettingsPropertyValue(settingsProperty); spVal.PropertyValue = String.Empty; spCollection.Add(spVal); } return spCollection; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var settingsPropertyValueCollection = new SettingsPropertyValueCollection(); if (collection.Count < 1) { return settingsPropertyValueCollection; } var username = (string)context["UserName"]; if (string.IsNullOrWhiteSpace(username)) { return settingsPropertyValueCollection; } var query = Query.And(Query.EQ("ApplicationName", ApplicationName), Query.EQ("Username", username)); var bsonDocument = mongoCollection.FindOneAs<BsonDocument>(query); if (bsonDocument == null) { return settingsPropertyValueCollection; } foreach (SettingsProperty settingsProperty in collection) { var settingsPropertyValue = new SettingsPropertyValue(settingsProperty); settingsPropertyValueCollection.Add(settingsPropertyValue); if (!bsonDocument.Contains(settingsPropertyValue.Name)) { continue; } var value = BsonTypeMapper.MapToDotNetValue(bsonDocument[settingsPropertyValue.Name]); if (value == null) { continue; } settingsPropertyValue.PropertyValue = value; settingsPropertyValue.IsDirty = false; settingsPropertyValue.Deserialized = true; } var update = Update.Set("LastActivityDate", DateTime.Now); mongoCollection.Update(query, update); return settingsPropertyValueCollection; }
static void InitProperties () { SettingsPropertyCollection properties = new SettingsPropertyCollection (); ProfileSection config = (ProfileSection) WebConfigurationManager.GetSection ("system.web/profile"); RootProfilePropertySettingsCollection ps = config.PropertySettings; for (int i = 0; i < ps.GroupSettings.Count; i++) { ProfileGroupSettings pgs = ps.GroupSettings [i]; ProfilePropertySettingsCollection ppsc = pgs.PropertySettings; for (int s = 0; s < ppsc.Count; s++) { SettingsProperty settingsProperty = CreateSettingsProperty (pgs, ppsc [s]); ValidateProperty (settingsProperty, ppsc [s].ElementInformation); properties.Add (settingsProperty); } } for (int s = 0; s < ps.Count; s++) { SettingsProperty settingsProperty = CreateSettingsProperty (null, ps [s]); ValidateProperty (settingsProperty, ps [s].ElementInformation); properties.Add (settingsProperty); } if (config.Inherits.Length > 0) { Type profileType = ProfileParser.GetProfileCommonType (HttpContext.Current); if (profileType != null) { Type properiesType = profileType.BaseType; for (; ; ) { PropertyInfo [] pi = properiesType.GetProperties (BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly); if (pi.Length > 0) for (int i = 0; i < pi.Length; i++) properties.Add (CreateSettingsProperty (pi [i])); if (properiesType.BaseType == null || properiesType.BaseType == typeof (ProfileBase)) break; properiesType = properiesType.BaseType; } } } properties.SetReadOnly (); lock (Profiles_SettingsPropertyCollection) { if (_properties == null) _properties = properties; } }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props) { //Create new collection of values SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); //Iterate through the settings to be retrieved foreach (SettingsProperty setting in props) { SettingsPropertyValue value = new SettingsPropertyValue(setting); value.IsDirty = false; value.SerializedValue = GetValue(setting); values.Add(value); } return values; }
public static SettingsPropertyCollection GetPropertyMetadata(string serviceUri) { CookieContainer cookies = null; IIdentity id = Thread.CurrentPrincipal.Identity; SettingsPropertyCollection retColl = new SettingsPropertyCollection(); if (id is ClientFormsIdentity) cookies = ((ClientFormsIdentity)id).AuthenticationCookies; if (serviceUri.EndsWith(".svc", StringComparison.OrdinalIgnoreCase)) { throw new NotImplementedException(); // CustomBinding binding = ProxyHelper.GetBinding(); // ChannelFactory<ProfileService> channelFactory = new ChannelFactory<ProfileService>(binding, new EndpointAddress(serviceUri)); // ProfilePropertyMetadata[] props = null; // ProfileService clientService = channelFactory.CreateChannel(); // using (new OperationContextScope((IContextChannel)clientService)) { // ProxyHelper.AddCookiesToWCF(cookies, serviceUri, id.Name, null, null); // props = clientService.GetPropertiesMetadata(); // ProxyHelper.GetCookiesFromWCF(cookies, serviceUri, id.Name, null, null); // } // if (props == null) // return retColl; // for(int iter=0; iter<props.Length; iter++) { // AddToColl(props[iter], retColl, id.IsAuthenticated); // } } else { object o = ProxyHelper.CreateWebRequestAndGetResponse(serviceUri + "/GetPropertiesMetadata", ref cookies, id.Name, null, null, null, null, typeof(Collection<ProfilePropertyMetadata>)); Collection<ProfilePropertyMetadata> props2 = (Collection<ProfilePropertyMetadata>) o; if (props2 != null) { foreach(ProfilePropertyMetadata p in props2) AddToColl(p, retColl, id.IsAuthenticated); } } return retColl; }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var settingsPropertyValueCollection = new SettingsPropertyValueCollection(); if (context == null || collection == null || collection.Count < 1) { return settingsPropertyValueCollection; } var username = (string)context["UserName"]; if(String.IsNullOrWhiteSpace(username)) { return settingsPropertyValueCollection; } var query = Query.And(Query.EQ("ApplicationName", this.ApplicationName), Query.EQ("Username", username)); var bsonDocument = this.mongoCollection.FindOneAs<BsonDocument>(query); foreach (SettingsProperty settingsProperty in collection) { var settingsPropertyValue = new SettingsPropertyValue(settingsProperty); settingsPropertyValueCollection.Add(settingsPropertyValue); if (bsonDocument == null) continue; BsonValue value; if (!bsonDocument.TryGetValue(settingsPropertyValue.Name, out value)) continue; //If our BsonValue is a document we already happen to know what type it is //so we'll just perform a quick deserialization and be on our way, happy as a clam //mmmmmmmm clams.... if (!value.IsBsonDocument) settingsPropertyValue.PropertyValue = value.RawValue; else settingsPropertyValue.PropertyValue = BsonSerializer.Deserialize(value.AsBsonDocument, settingsPropertyValue.Property.PropertyType); settingsPropertyValue.IsDirty = false; settingsPropertyValue.Deserialized = true; } var update = Update.Set("LastActivityDate", DateTime.Now); this.mongoCollection.Update(query, update); return settingsPropertyValueCollection; }
void CacheValuesByProvider(SettingsProvider provider) { SettingsPropertyCollection col = new SettingsPropertyCollection(); foreach (SettingsProperty p in Properties) { if (p.Provider == provider) { col.Add(p); } } if (col.Count > 0) { SettingsPropertyValueCollection vals = provider.GetPropertyValues(Context, col); PropertyValues.Add(vals); } OnSettingsLoaded(this, new SettingsLoadedEventArgs(provider)); }
/// <summary> /// Private version of upgrade that uses isRoaming to determine which config file to use. /// </summary> private void Upgrade(SettingsContext context, SettingsPropertyCollection properties, bool isRoaming) { string prevConfig = GetPreviousConfigFileName(isRoaming); if (!string.IsNullOrEmpty(prevConfig)) { //Filter the settings properties to exclude those that have a NoSettingsVersionUpgradeAttribute on them. SettingsPropertyCollection upgradeProperties = new SettingsPropertyCollection(); foreach (SettingsProperty sp in properties) { if (!(sp.Attributes[typeof(NoSettingsVersionUpgradeAttribute)] is NoSettingsVersionUpgradeAttribute)) { upgradeProperties.Add(sp); } } SettingsPropertyValueCollection values = GetSettingValuesFromFile(prevConfig, GetSectionName(context), true, upgradeProperties); SetPropertyValues(context, values); } }
private void LoadProperies(ExeConfigurationFileMap exeMap, SettingsPropertyCollection collection, ConfigurationUserLevel level, string sectionGroupName, bool allowOverwrite) { Configuration config = ConfigurationManager.OpenMappedExeConfiguration(exeMap, level); ConfigurationSectionGroup sectionGroup = config.GetSectionGroup(sectionGroupName); if (sectionGroup != null) { foreach (ConfigurationSection configSection in sectionGroup.Sections) { ClientSettingsSection clientSection = configSection as ClientSettingsSection; if (clientSection != null) { foreach (SettingElement element in clientSection.Settings) { LoadPropertyValue(collection, element, allowOverwrite); } } } } }
private void GetPropertiesFromProvider(SettingsProvider provider) { SettingsPropertyCollection collection = new SettingsPropertyCollection(); foreach (SettingsProperty property in this.Properties) { if (property.Provider == provider) { collection.Add(property); } } if (collection.Count > 0) { foreach (SettingsPropertyValue value2 in provider.GetPropertyValues(this.Context, collection)) { if (this._PropertyValues[value2.Name] == null) { this._PropertyValues.Add(value2); } } } }
private void EnsureInitialized() { if (!this._initialized) { this._initialized = true; Type type = base.GetType(); if (this._context == null) { this._context = new SettingsContext(); } this._context["GroupName"] = type.FullName; this._context["SettingsKey"] = this.SettingsKey; this._context["SettingsClassType"] = type; PropertyInfo[] infoArray = this.SettingsFilter(type.GetProperties(BindingFlags.Public | BindingFlags.Instance)); this._classAttributes = type.GetCustomAttributes(false); if (this._settings == null) { this._settings = new SettingsPropertyCollection(); } if (this._providers == null) { this._providers = new SettingsProviderCollection(); } for (int i = 0; i < infoArray.Length; i++) { SettingsProperty property = this.CreateSetting(infoArray[i]); if (property != null) { this._settings.Add(property); if ((property.Provider != null) && (this._providers[property.Provider.Name] == null)) { this._providers.Add(property.Provider); } } } } }
private void GetPropertiesFromProvider(SettingsProvider provider) { SettingsPropertyCollection ppc = new SettingsPropertyCollection(); foreach (SettingsProperty pp in Properties) { if (pp.Provider == provider) { ppc.Add(pp); } } if (ppc.Count > 0) { SettingsPropertyValueCollection ppcv = provider.GetPropertyValues(Context, ppc); foreach (SettingsPropertyValue p in ppcv) { if (_PropertyValues[p.Name] == null) { _PropertyValues.Add(p); } } } }
private SettingsPropertyValueCollection GetSettingValuesFromFile(string configFileName, string sectionName, bool userScoped, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); IDictionary dictionary = ClientSettingsStore.ReadSettingsFromFile(configFileName, sectionName, userScoped); foreach (SettingsProperty property in properties) { string name = property.Name; SettingsPropertyValue value2 = new SettingsPropertyValue(property); if (dictionary.Contains(name)) { StoredSetting setting = (StoredSetting)dictionary[name]; string innerXml = setting.Value.InnerXml; if (setting.SerializeAs == SettingsSerializeAs.String) { innerXml = this.Escaper.Unescape(innerXml); } value2.SerializedValue = innerXml; value2.IsDirty = true; values.Add(value2); } } return(values); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); string sectionName = this.GetSectionName(context); IDictionary dictionary = this.Store.ReadSettings(sectionName, false); IDictionary dictionary2 = this.Store.ReadSettings(sectionName, true); ConnectionStringSettingsCollection settingss = this.Store.ReadConnectionStrings(); foreach (SettingsProperty property in properties) { string name = property.Name; SettingsPropertyValue value2 = new SettingsPropertyValue(property); SpecialSettingAttribute attribute = property.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute; if ((attribute != null) ? (attribute.SpecialSetting == SpecialSetting.ConnectionString) : false) { string str3 = sectionName + "." + name; if ((settingss != null) && (settingss[str3] != null)) { value2.PropertyValue = settingss[str3].ConnectionString; } else if ((property.DefaultValue != null) && (property.DefaultValue is string)) { value2.PropertyValue = property.DefaultValue; } else { value2.PropertyValue = string.Empty; } value2.IsDirty = false; values.Add(value2); } else { bool flag2 = this.IsUserSetting(property); if (flag2 && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig) { throw new ConfigurationErrorsException(System.SR.GetString("UserSettingsNotSupported")); } IDictionary dictionary3 = flag2 ? dictionary2 : dictionary; if (dictionary3.Contains(name)) { StoredSetting setting = (StoredSetting)dictionary3[name]; string innerXml = setting.Value.InnerXml; if (setting.SerializeAs == SettingsSerializeAs.String) { innerXml = this.Escaper.Unescape(innerXml); } value2.SerializedValue = innerXml; } else if (property.DefaultValue != null) { value2.SerializedValue = property.DefaultValue; } else { value2.PropertyValue = null; } value2.IsDirty = false; values.Add(value2); } } return(values); }
/// <summary> /// Get the property values for the user profile. /// </summary> /// <param name="context">Application context.</param> /// <param name="settingsProperties">Profile property settings.</param> /// <returns>Property setting values.</returns> public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection settingsProperties) { IObjectScope objScope = ORM.GetNewObjectScope(); SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection(); string userName = GetUserName((string)context["UserName"]); EmployeeProfile ep = ResolveEmployeeProfileByName(objScope, userName); if (null == ep) { ep = new EmployeeProfile(); } foreach (SettingsProperty property in settingsProperties) { SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(property); switch (property.Name) { case "Language": settingsPropertyValue.PropertyValue = ep.Language; break; case "StyleTheme": settingsPropertyValue.PropertyValue = ep.StyleTheme; break; case "Factory_Name": settingsPropertyValue.PropertyValue = ep.Factory_Name; break; case "Operation_Name": settingsPropertyValue.PropertyValue = ep.Operation_Name; break; case "WorkCenter_Name": settingsPropertyValue.PropertyValue = ep.WorkCenter_Name; break; default: throw new ProviderException("Unsupported property."); } settingsValues.Add(settingsPropertyValue); } return(settingsValues); }
/// <summary> /// Retrieves the values of settings from the given config file (as opposed to using /// the configuration for the current context) /// </summary> private SettingsPropertyValueCollection GetSettingValuesFromFile(string configFileName, string sectionName, bool userScoped, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); IDictionary settings = ClientSettingsStore.ReadSettingsFromFile(configFileName, sectionName, userScoped); // Map each SettingProperty to the right StoredSetting and deserialize the value if found. foreach (SettingsProperty setting in properties) { string settingName = setting.Name; SettingsPropertyValue value = new SettingsPropertyValue(setting); if (settings.Contains(settingName)) { StoredSetting ss = (StoredSetting)settings[settingName]; string valueString = ss.Value.InnerXml; // We need to un-escape string serialized values if (ss.SerializeAs == SettingsSerializeAs.String) { valueString = Escaper.Unescape(valueString); } value.SerializedValue = valueString; value.IsDirty = true; values.Add(value); } } return(values); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { CreateExeMap(); if (values == null) { values = new SettingsPropertyValueCollection(); LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false); LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false); LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true); LoadProperies(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true); // create default values if not exist foreach (SettingsProperty p in collection) { if (values [p.Name] == null) { values.Add(new SettingsPropertyValue(p)); } } } return(values); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { throw new NotImplementedException(); }
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { throw new Exception("Cannot get user profile from PSU Passport because of no password"); /* * https://msdn.microsoft.com/en-us/library/aa479025.aspx * The context parameter passed to GetPropertyValues is a dictionary of key/value pairs containing information about the context * in which GetPropertyValues was called. It contains the following keys: * 1. UserName—User name or user ID of the profile to read * 2. IsAuthenticated—Indicates whether the requestor is authenticated */ string userName = (string)context["UserName"]; bool isAuthenticated = (bool)context["IsAuthenticated"]; string connectionStringName = "LDAP://dc.phuket.psu.ac.th/dc=psu,dc=ac,dc=th"; //string domain = "psu\\"; //string attributeMapUsername = "******"; //AuthenticationTypes connectionProtection = AuthenticationTypes.None; DirectoryEntry root = new DirectoryEntry(connectionStringName); DirectorySearcher searcher = new DirectorySearcher(root); searcher.Filter = "&(objectClass=user)"; // SearchResult result = searcher.FindOne(); SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection(); foreach (SettingsProperty prop in collection) { SettingsPropertyValue pv = new SettingsPropertyValue(prop); if (prop.PropertyType == typeof(Model.PSUUserInfo)) { //Get UserDetails from PSU Passport Service pv.PropertyValue = new Model.PSUUserInfo("Uname") { FirstName = "F1", LastName = "L1", StaffCode = "Code1" }; svc.Add(pv); } else { throw new ProviderException("Unsupported Property."); } } UpdateActivityDates(Name, true, true); return(svc); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="collection"></param> /// <returns></returns> public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { string userName = (string)context["UserName"]; bool isAnonymous = !(bool)context["IsAuthenticated"]; SettingsPropertyValueCollection propertyValues = new SettingsPropertyValueCollection(); using (var dataStore = new ProductStore(SqlHelper.Current.GetConnection(_connectionString))) { bool retry = true; int retryCount = 0; while (retry && retryCount < 2) { retryCount++; var profile = (from p in dataStore.Profile join d in dataStore.ProfileData on p.Id equals d.ProfileId where p.ApplicationName == ApplicationName && p.Username == userName select new { Profile = p, Data = d }).FirstOrDefault(); if (profile == null) { retry = true; CreateProfile(dataStore, userName); dataStore.SubmitChanges(); } else { retry = false; foreach (var property in collection) { SettingsProperty settingsProperty = property as SettingsProperty; SettingsPropertyValue propertyValue = new SettingsPropertyValue(settingsProperty); switch (settingsProperty.Name) { case "FirstName": propertyValue.PropertyValue = profile.Data.FirstName; break; case "LastName": propertyValue.PropertyValue = profile.Data.LastName; break; case "Phone": propertyValue.PropertyValue = profile.Data.Phone; break; } propertyValues.Add(propertyValue); profile.Profile.LastActivity = DateTime.Now; } dataStore.SubmitChanges(); } } } return(propertyValues); }
/// <summary> /// Retrieve settings from the configuration file. /// </summary> /// <param name="sContext">Provides contextual information that the provider can use when persisting settings.</param> /// <param name="settingsColl">Contains a collection of <see cref="SettingsProperty"/> objects.</param> /// <returns>A collection of settings property values that map <see cref="SettingsProperty"/> objects to <see cref="SettingsPropertyValue"/> objects.</returns> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sContext, SettingsPropertyCollection settingsColl) { // Create a collection of values to return SettingsPropertyValueCollection retValues = new SettingsPropertyValueCollection(); // Create a temporary SettingsPropertyValue to reuse SettingsPropertyValue setVal; // Loop through the list of settings that the application has requested and add them // to our collection of return values. foreach (SettingsProperty sProp in settingsColl) { setVal = new SettingsPropertyValue(sProp); setVal.IsDirty = false; setVal.SerializedValue = GetSetting(sProp); retValues.Add(setVal); } return(retValues); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { return(impl.GetPropertyValues(context, properties)); }
void InitializeSettings(SettingsPropertyCollection settings) { }
void CreateSettingsProperty(PropertyInfo prop, SettingsPropertyCollection properties, ref SettingsProvider local_provider) { SettingsAttributeDictionary dict = new SettingsAttributeDictionary(); SettingsProvider provider = null; object defaultValue = null; SettingsSerializeAs serializeAs = SettingsSerializeAs.String; bool explicitSerializeAs = false; foreach (Attribute a in prop.GetCustomAttributes(false)) { /* the attributes we handle natively here */ if (a is SettingsProviderAttribute) { var providerTypeName = ((SettingsProviderAttribute)a).ProviderTypeName; Type provider_type = Type.GetType(providerTypeName); if (provider_type == null) // Type failed to find the type by name { var typeNameParts = providerTypeName.Split('.'); if (typeNameParts.Length > 1) //Load the assembly that providerTypeName claims { var assy = Assembly.Load(typeNameParts[0]); if (assy != null) { provider_type = assy.GetType(providerTypeName); //try to get the type from that Assembly } } } provider = (SettingsProvider)Activator.CreateInstance(provider_type); provider.Initialize(null, null); } else if (a is DefaultSettingValueAttribute) { defaultValue = ((DefaultSettingValueAttribute)a).Value; } else if (a is SettingsSerializeAsAttribute) { serializeAs = ((SettingsSerializeAsAttribute)a).SerializeAs; explicitSerializeAs = true; } else if (a is ApplicationScopedSettingAttribute || a is UserScopedSettingAttribute) { dict.Add(a.GetType(), a); } else { dict.Add(a.GetType(), a); } } if (!explicitSerializeAs) { // DefaultValue is a string and if we can't convert from string to the // property type then the only other option left is for the string to // be XML. // TypeConverter converter = TypeDescriptor.GetConverter(prop.PropertyType); if (converter != null && (!converter.CanConvertFrom(typeof(string)) || !converter.CanConvertTo(typeof(string)))) { serializeAs = SettingsSerializeAs.Xml; } } SettingsProperty setting = new SettingsProperty(prop.Name, prop.PropertyType, provider, false /* XXX */, defaultValue /* XXX always a string? */, serializeAs, dict, false, false); if (providerService != null) { setting.Provider = providerService.GetSettingsProvider(setting); } if (provider == null) { if (local_provider == null) { local_provider = new LocalFileSettingsProvider() as SettingsProvider; local_provider.Initialize(null, null); } setting.Provider = local_provider; // .NET ends up to set this to providers. provider = local_provider; } if (provider != null) { /* make sure we're using the same instance of a * given provider across multiple properties */ SettingsProvider p = Providers[provider.Name]; if (p != null) { setting.Provider = p; } } properties.Add(setting); if (setting.Provider != null && Providers [setting.Provider.Name] == null) { Providers.Add(setting.Provider); } }
// FIXME: implement public void Upgrade(SettingsContext context, SettingsPropertyCollection properties) { }
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection(); string username = Convert.ToString(context["UserName"]); Member member = null; Role guest = new Role() { Name = "Guest", Description = "Guest user", }; ICollection <Role> guestRoles = new List <Role>(); guestRoles.Add(guest); if (Convert.ToBoolean(context["IsAuthenticated"]) && !String.IsNullOrEmpty(username)) { Login login = _dataService.GetLoginByUsername(username); if (login != null) { member = _dataService.GetMemberByLoginId(login.Id); } foreach (SettingsProperty item in collection) { SettingsPropertyValue value = new SettingsPropertyValue(item); switch (item.Name) { case "LoginId": value.PropertyValue = login != null ? login.Id : 0; break; case "MemberId": value.PropertyValue = member != null ? member.Id : 0; break; case "FirstName": value.PropertyValue = member != null ? member.FirstName : string.Empty; break; case "LastName": value.PropertyValue = member != null ? member.LastName : string.Empty; break; case "PrimaryEmail": value.PropertyValue = member != null ? member.Login.Email : string.Empty; break; case "Roles": value.PropertyValue = member != null ? member.Roles : guestRoles; break; } svc.Add(value); } } return(svc); }
/// <summary> /// Gets the property values. /// </summary> /// <param name="context">The context.</param> /// <param name="ppc">The PPC.</param> /// <returns></returns> public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection ppc) { MongoServer server = MongoServer.Create(connectionString); // connect to the mongoDB url. MongoDatabase ProviderDB = server.GetDatabase(pMongoProviderDatabaseName, SafeMode.True); MongoCollection <BsonDocument> profiles = ProviderDB.GetCollection(pMongoProviderProfileCollectionName); string username = (string)context["UserName"]; bool isAuthenticated = (bool)context["IsAuthenticated"]; // The serializeAs attribute is ignored in this provider implementation. SettingsPropertyValueCollection svc = new SettingsPropertyValueCollection(); try { foreach (SettingsProperty prop in ppc) { SettingsPropertyValue pv = new SettingsPropertyValue(prop); var query = Query.And(Query.EQ("UsernameLowerCase", username.ToLower()), Query.EQ("ApplicationNameLowerCase", pApplicationName.ToLower()), Query.EQ("IsAnonymous", !isAuthenticated)); var profile = profiles.FindOne(query); if (profile != null) { BsonValue obj = BsonNull.Value; // Make sure the element exists (In case of changes to the object, the element would not exist on old documents.) if (profile.Contains(prop.Name)) { obj = profile[prop.Name]; } else { obj = BsonNull.Value; } object returnValue; switch (obj.BsonType) { case BsonType.Binary: returnValue = obj.AsByteArray; break; case BsonType.Boolean: returnValue = obj.AsBoolean; break; case BsonType.DateTime: returnValue = obj.AsDateTime; break; case BsonType.Double: returnValue = obj.AsDouble; break; case BsonType.Int32: returnValue = obj.AsInt32; break; case BsonType.Int64: returnValue = obj.AsInt64; break; case BsonType.Null: returnValue = null; break; case BsonType.String: returnValue = obj.AsString; break; case BsonType.Array: #warning To Do: Better handle the arrays. // Assumes array of strings. List <String> values = new List <string>(); foreach (BsonValue val in obj.AsBsonArray) { values.Add(val.AsString); } returnValue = values.ToArray(); break; case BsonType.Undefined: throw new ProviderException("Unsupported Property"); default: goto case BsonType.Undefined; } pv.PropertyValue = returnValue; } svc.Add(pv); } } catch (ApplicationException e) { if (WriteExceptionsToEventLog) { WriteToEventLog(e, "GetPropertyValues"); } } UpdateActivityDates(username, isAuthenticated, true); return(svc); }
/// <summary> /// Abstract SettingsProvider method /// </summary> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) { SettingsPropertyValueCollection values = new SettingsPropertyValueCollection(); string sectionName = GetSectionName(context); // Look for this section in both applicationSettingsGroup and userSettingsGroup IDictionary appSettings = Store.ReadSettings(sectionName, false); IDictionary userSettings = Store.ReadSettings(sectionName, true); ConnectionStringSettingsCollection connStrings = Store.ReadConnectionStrings(); // Now map each SettingProperty to the right StoredSetting and deserialize the value if found. foreach (SettingsProperty setting in properties) { string settingName = setting.Name; SettingsPropertyValue value = new SettingsPropertyValue(setting); // First look for and handle "special" settings SpecialSettingAttribute attr = setting.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute; bool isConnString = (attr != null) ? (attr.SpecialSetting == SpecialSetting.ConnectionString) : false; if (isConnString) { string connStringName = sectionName + "." + settingName; if (connStrings != null && connStrings[connStringName] != null) { value.PropertyValue = connStrings[connStringName].ConnectionString; } else if (setting.DefaultValue != null && setting.DefaultValue is string) { value.PropertyValue = setting.DefaultValue; } else { //No value found and no default specified value.PropertyValue = string.Empty; } value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called values.Add(value); continue; } // Not a "special" setting bool isUserSetting = IsUserSetting(setting); if (isUserSetting && !ConfigurationManagerInternalFactory.Instance.SupportsUserConfig) { // We encountered a user setting, but the current configuration system does not support // user settings. throw new ConfigurationErrorsException(SR.UserSettingsNotSupported); } IDictionary settings = isUserSetting ? userSettings : appSettings; if (settings.Contains(settingName)) { StoredSetting ss = (StoredSetting)settings[settingName]; string valueString = ss.Value.InnerXml; // We need to un-escape string serialized values if (ss.SerializeAs == SettingsSerializeAs.String) { valueString = Escaper.Unescape(valueString); } value.SerializedValue = valueString; } else if (setting.DefaultValue != null) { value.SerializedValue = setting.DefaultValue; } else { //No value found and no default specified value.PropertyValue = null; } value.IsDirty = false; //reset IsDirty so that it is correct when SetPropertyValues is called values.Add(value); } return(values); }
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { using (UsersContext db = new UsersContext()) { SettingsPropertyValueCollection settings = new SettingsPropertyValueCollection(); string userName = context["UserName"].ToString(); UserProfile userProfile = db.UsersProfiles.Find(userName); if (userProfile == null) { foreach (SettingsProperty profileProperty in collection) { SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]); value.PropertyValue = null; settings.Add(value); } } else { foreach (SettingsProperty profileProperty in collection) { SettingsPropertyValue value = new SettingsPropertyValue(collection[profileProperty.Name]); value.PropertyValue = userProfile.GetType().GetProperty(profileProperty.Name).GetValue(userProfile, null); settings.Add(value); } } return(settings); } }
public void Upgrade(SettingsContext context, SettingsPropertyCollection properties) { throw new NotImplementedException(); }
public void Initialize(SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) { throw new NotImplementedException(); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { CreateExeMap(); if (values == null) { values = new SettingsPropertyValueCollection(); string groupName = context ["GroupName"] as string; groupName = NormalizeInvalidXmlChars(groupName); // we likely saved the element removing the non valid xml chars. LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.None, "applicationSettings", false, groupName); LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.None, "userSettings", false, groupName); LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoaming, "userSettings", true, groupName); LoadProperties(exeMapCurrent, collection, ConfigurationUserLevel.PerUserRoamingAndLocal, "userSettings", true, groupName); // create default values if not exist foreach (SettingsProperty p in collection) { if (values [p.Name] == null) { values.Add(new SettingsPropertyValue(p)); } } } return(values); }
public void Initialize(SettingsContext context, SettingsPropertyCollection properties, SettingsProviderCollection providers) { this._Context = context; this._Properties = properties; this._Providers = providers; }
public abstract SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection);
public override System.Configuration.SettingsPropertyValueCollection GetPropertyValues(System.Configuration.SettingsContext context, System.Configuration.SettingsPropertyCollection collection) { throw new NotImplementedException(); }