private void LoadPropertyValue(SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite) { SettingsProperty prop = collection [element.Name]; if (prop == null) // see bug #343459 { prop = new SettingsProperty(element.Name); collection.Add(prop); } SettingsPropertyValue value = new SettingsPropertyValue(prop); value.IsDirty = false; value.SerializedValue = element.Value.ValueXml != null ? element.Value.ValueXml.InnerText : prop.DefaultValue; try { if (allowOverwrite) { values.Remove(element.Name); } values.Add(value); } catch (ArgumentException) { throw new ConfigurationErrorsException(); } }
private void LoadPropertyValue(SettingsPropertyCollection collection, SettingElement element, bool allowOverwrite) { SettingsProperty prop = collection [element.Name]; if (prop == null) // see bug #343459 { prop = new SettingsProperty(element.Name); collection.Add(prop); } SettingsPropertyValue value = new SettingsPropertyValue(prop); value.IsDirty = false; if (element.Value.ValueXml != null) { switch (value.Property.SerializeAs) { case SettingsSerializeAs.Xml: value.SerializedValue = element.Value.ValueXml.InnerXml; break; case SettingsSerializeAs.String: value.SerializedValue = element.Value.ValueXml.InnerText; break; case SettingsSerializeAs.Binary: value.SerializedValue = Convert.FromBase64String(element.Value.ValueXml.InnerText); break; } } else { value.SerializedValue = prop.DefaultValue; } try { if (allowOverwrite) { values.Remove(element.Name); } values.Add(value); } catch (ArgumentException ex) { throw new ConfigurationErrorsException(string.Format( CultureInfo.InvariantCulture, "Failed to load value for '{0}'.", element.Name), ex); } }
public void Remove () { SettingsPropertyValueCollection col = new SettingsPropertyValueCollection (); SettingsProperty test_prop = new SettingsProperty ("test_prop"); SettingsPropertyValue val = new SettingsPropertyValue (test_prop); col.Add (val); Assert.AreEqual (1, col.Count, "A1"); col.Remove ("test_prop"); Assert.AreEqual (0, col.Count, "A2"); }
private void GetProfileDataFromTable(SettingsPropertyCollection properties, SettingsPropertyValueCollection svc, string username, OleDbConnection conn) { List<ProfileColumnData> columnData = new List<ProfileColumnData>(properties.Count); StringBuilder commandText = new StringBuilder("SELECT u.MEMBER_ID"); OleDbCommand cmd = new OleDbCommand(String.Empty, conn); int columnCount = 0; foreach (SettingsProperty prop in properties) { SettingsPropertyValue value = new SettingsPropertyValue(prop); if (prop.PropertyType == typeof(List<SnitzLink>)) { prop.ThrowOnErrorDeserializing = true; prop.SerializeAs = SettingsSerializeAs.Xml; value.Deserialized = false; } svc.Add(value); string persistenceData = prop.Attributes["CustomProviderData"] as string; // If we can't find the table/column info we will ignore this data if (String.IsNullOrEmpty(persistenceData)) { // REVIEW: Perhaps we should throw instead? continue; } string[] chunk = persistenceData.Split(new char[] { ';' }); if (chunk.Length != 2) { // REVIEW: Perhaps we should throw instead? continue; } if (chunk[1].ToLower() == "int") chunk[1] = "integer"; string columnName = chunk[0]; // REVIEW: Should we ignore case? OleDbType datatype = (OleDbType)Enum.Parse(typeof(OleDbType), chunk[1], true); columnData.Add(new ProfileColumnData(columnName, prop, null /* not needed for get */, datatype)); commandText.Append(", "); commandText.Append("t." + columnName); ++columnCount; } commandText.AppendFormat(" FROM {0} t, {1}MEMBERS u WHERE ",TableName,Config.MemberTablePrefix).AppendLine(); commandText.Append("u.M_NAME = @Username AND t.UserID = u.MEMBER_ID"); cmd.CommandText = commandText.ToString(); cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("@Username", username); OleDbDataReader reader = null; try { reader = cmd.ExecuteReader(); //If no row exists in the database, then the default Profile values //from configuration are used. if (reader.Read()) { svc.Clear(); int userId = reader.GetInt32(0); for (int i = 0; i < columnData.Count; ++i) { object val = reader.GetValue(i + 1); ProfileColumnData colData = columnData[i]; SettingsPropertyValue propValue = new SettingsPropertyValue(colData.PropertyValue); //Only initialize a SettingsPropertyValue for non-null values //if (!(val is DBNull || val == null)) //{ propValue.IsDirty = false; if (propValue.Property.SerializeAs == SettingsSerializeAs.Xml) { propValue.Deserialized = false; object test = ""; if (!val.Equals(test)) propValue.SerializedValue = val; } else { propValue.PropertyValue = val; propValue.Deserialized = true; } svc.Add(propValue); //} } // need to close reader before we try to update the user if (reader != null) { reader.Close(); reader = null; } //UpdateLastActivityDate(conn, userId); } else { object val = GetBookMarkModValues(username); ProfileColumnData colData = columnData.Find(c => c.ColumnName == "BookMarks"); SettingsPropertyValue propValue = new SettingsPropertyValue(colData.PropertyValue); propValue.IsDirty = false; if (propValue.Property.SerializeAs == SettingsSerializeAs.Xml) { if (propValue.Name == "BookMarks") { svc.Remove("BookMarks"); propValue.Deserialized = false; object test = ""; if (!val.Equals(test)) propValue.SerializedValue = val; svc.Add(propValue); } } } } finally { if (reader != null) { reader.Close(); } } }
public void ReadOnly_Remove () { SettingsPropertyValueCollection col = new SettingsPropertyValueCollection (); SettingsProperty test_prop = new SettingsProperty ("test_prop"); SettingsPropertyValue val = new SettingsPropertyValue (test_prop); col.Add (val); col.SetReadOnly (); col.Remove ("test_prop"); }