本文整理汇总了C#中System.Configuration.SettingsPropertyValueCollection.Add方法的典型用法代码示例。如果您正苦于以下问题:C# SettingsPropertyValueCollection.Add方法的具体用法?C# SettingsPropertyValueCollection.Add怎么用?C# SettingsPropertyValueCollection.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Configuration.SettingsPropertyValueCollection
的用法示例。
在下文中一共展示了SettingsPropertyValueCollection.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddDuplicate
public void AddDuplicate ()
{
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.Add (val);
Assert.AreEqual (1, col.Count, "A2");
}
示例2: GetPropertyValues
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;
}
示例3: GetPropertyValues
/// <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;
}
示例4: GetPropertyValues
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;
}
示例5: GetPropertyValues
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;
}
示例6: GetPropertyValues
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;
}
示例7: SetSharedPropertyValues
private static void SetSharedPropertyValues(ApplicationSettingsBase settings, Dictionary<string, string> values)
{
foreach (SettingsProvider provider in settings.Providers)
{
ISharedApplicationSettingsProvider sharedSettingsProvider = GetSharedSettingsProvider(provider);
if (sharedSettingsProvider == null)
throw new NotSupportedException("Setting shared values is not supported.");
var properties = GetPropertiesForProvider(settings, provider);
SettingsPropertyValueCollection settingsValues = new SettingsPropertyValueCollection();
foreach (var value in values)
{
SettingsProperty property = properties[value.Key];
if (property == null)
continue;
settingsValues.Add(new SettingsPropertyValue(property) { SerializedValue = value.Value, IsDirty = true });
}
sharedSettingsProvider.SetSharedPropertyValues(settings.Context, settingsValues);
}
SaveIfDirty(settings);
settings.Reload();
}
示例8: GetPropertyValues
/// <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;
}
示例9: SettingValuesCreatesAnAppAndUserId
public void SettingValuesCreatesAnAppAndUserId()
{
MySQLProfileProvider provider = InitProfileProvider();
SettingsContext ctx = new SettingsContext();
ctx.Add("IsAuthenticated", false);
ctx.Add("UserName", "user1");
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
SettingsProperty property1 = new SettingsProperty("color");
property1.PropertyType = typeof(string);
property1.Attributes["AllowAnonymous"] = true;
SettingsPropertyValue value = new SettingsPropertyValue(property1);
value.PropertyValue = "blue";
values.Add(value);
provider.SetPropertyValues(ctx, values);
DataTable dt = FillTable("SELECT * FROM my_aspnet_applications");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_users");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_profiles");
Assert.AreEqual(1, dt.Rows.Count);
values["color"].PropertyValue = "green";
provider.SetPropertyValues(ctx, values);
dt = FillTable("SELECT * FROM my_aspnet_applications");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_users");
Assert.AreEqual(1, dt.Rows.Count);
dt = FillTable("SELECT * FROM my_aspnet_profiles");
Assert.AreEqual(1, dt.Rows.Count);
}
示例10: GetPropertyValues
/// <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;
}
示例11: GetPropertyValues
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;
}
示例12: ToSettingsPropertyValueCollection
public static SettingsPropertyValueCollection ToSettingsPropertyValueCollection(this IEnumerable<SettingsPropertyValue> values)
{
var c = new SettingsPropertyValueCollection();
foreach (var value in values)
{
c.Add(value);
}
return c;
}
示例13: GetPropertyValues
/// <summary>
/// Loads the settings from the database. This is only called when a propery in the Settings object
/// is used the first time, each time after that the assembly uses it's local cache
/// </summary>
/// <param name="context"></param>
/// <param name="properties"></param>
/// <returns>The requested settings</returns>
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection properties) {
SettingsPropertyValueCollection values = new SettingsPropertyValueCollection();
string section = GetSectionName(context);
settings = SnapShot.GetFor(section);
foreach (SettingsProperty property in properties) {
SpecialSettingAttribute attribute = property.Attributes[typeof(SpecialSettingAttribute)] as SpecialSettingAttribute;
if (attribute != null && (attribute.SpecialSetting == SpecialSetting.ConnectionString))
values.Add(GetConnectionStringValue(section, property));
else if (IsApplicationSetting(property))
values.Add(GetApplcationSetting(property));
else
throw new ConfigurationErrorsException("User settings are not supported in this provider");
}
return values;
}
示例14: GetPropertyValues
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
{
// коллекция, которая возвращает значения свойств профиля
var result = new SettingsPropertyValueCollection();
if (collection == null || collection.Count < 1 || context == null)
{
return result;
}
// получаем из контекста имя пользователя - логин в системе
var username = (string)context["UserName"];
if (String.IsNullOrEmpty(username)) return result;
// получаем id пользователя из таблицы Users по логину
var firstOrDefault = userService.GetUserEntityByEmail(username);
if (firstOrDefault != null)
{
int userId = firstOrDefault.Id;
// по этому id извлекаем профиль из таблицы профилей
ProfileEntity profile = profileService.GetProfileByUserId(userId);
if (profile != null)
{
foreach (SettingsProperty prop in collection)
{
var spv = new SettingsPropertyValue(prop)
{
PropertyValue = profile.GetType().GetProperty(prop.Name).GetValue(profile, null)
};
result.Add(spv);
}
}
else
{
foreach (SettingsProperty prop in collection)
{
var svp = new SettingsPropertyValue(prop) { PropertyValue = null };
result.Add(svp);
}
}
}
return result;
}
示例15: GetPropertyValues
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;
}