/// <summary> /// Stores the value of a Setting. /// </summary> /// <param name="name">The name of the Setting.</param> /// <param name="value">The value of the Setting. Value cannot contain CR and LF characters, which will be removed.</param> /// <returns>True if the Setting is stored, false otherwise.</returns> /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception> public bool SetSetting(string name, string value) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("name"); } _settingsDictionary = null; // Nulls are converted to empty strings if (value == null) { value = ""; } GlobalSettingsEntity settingsEntity = GetGlobalSettingsEntity(name); CloudTable table = _cloudTableClient.GetTableReference(GlobalSettingsTable); var batchOperation = new TableBatchOperation(); if (settingsEntity == null) { settingsEntity = new GlobalSettingsEntity() { PartitionKey = "0", RowKey = name, Value = value }; batchOperation.Insert(settingsEntity); } else { settingsEntity.Value = value; batchOperation.Replace(settingsEntity); } table.ExecuteBatch(batchOperation); return(true); }
/// <summary> /// Stores the value of a Setting. /// </summary> /// <param name="name">The name of the Setting.</param> /// <param name="value">The value of the Setting. Value cannot contain CR and LF characters, which will be removed.</param> /// <returns>True if the Setting is stored, false otherwise.</returns> /// <exception cref="ArgumentNullException">If <paramref name="name"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">If <paramref name="name"/> is empty.</exception> public bool SetSetting(string name, string value) { if (name == null) { throw new ArgumentNullException("name"); } if (name.Length == 0) { throw new ArgumentException("name"); } _settingsDictionary = null; // Nulls are converted to empty strings if (value == null) { value = ""; } GlobalSettingsEntity settingsEntity = GetGlobalSettingsEntity(name); if (settingsEntity == null) { settingsEntity = new GlobalSettingsEntity() { PartitionKey = "0", RowKey = name, Value = value }; _context.AddObject(GlobalSettingsTable, settingsEntity); } else { settingsEntity.Value = value; _context.UpdateObject(settingsEntity); } _context.SaveChangesStandard(); return(true); }