Update: Configuration Framework +CallerMemberName

Simplified creation of configuration modules; Scope is obtained from
abstract, Property names become keys (via CallerMemberName); Simple
generic Get/Set methods are used; Helpers for Obsfucation and Json are
available.
This commit is contained in:
Gary Sharp
2013-05-03 20:48:15 +10:00
parent d19ad7d0dc
commit 8533ec2fe0
23 changed files with 545 additions and 684 deletions
@@ -3,43 +3,21 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Disco.Models.Repository;
using Disco.Data.Repository;
namespace Disco.Data.Configuration.Modules
{
public class DeviceProfilesConfiguration : ConfigurationBase
{
// Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3.
//private Dictionary<int, DeviceProfileConfiguration> deviceProfileConfigurations;
public DeviceProfilesConfiguration(DiscoDataContext dbContext) : base(dbContext) { }
public DeviceProfilesConfiguration(ConfigurationContext Context)
: base(Context)
{
// Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3.
//this.deviceProfileConfigurations = new Dictionary<int, DeviceProfileConfiguration>();
}
public override string Scope
{
get { return "DeviceProfiles"; }
}
// Removed 2012-06-14 G# - Properties moved to DeviceProfile model & DB Migrated in DBv3.
//public DeviceProfileConfiguration DeviceProfile(DeviceProfile Profile)
//{
// DeviceProfileConfiguration dpc = default(DeviceProfileConfiguration);
// if (!this.deviceProfileConfigurations.TryGetValue(Profile.Id, out dpc))
// {
// dpc = new DeviceProfileConfiguration(this.Context, Profile);
// this.deviceProfileConfigurations[Profile.Id] = dpc;
// }
// return dpc;
//}
public override string Scope { get { return "DeviceProfiles"; } }
public int DefaultDeviceProfileId
{
get
{
var v = this.GetValue("DefaultDeviceProfileId", 1);
var v = this.Get(1);
if (v > 0)
return v;
else
@@ -49,20 +27,22 @@ namespace Disco.Data.Configuration.Modules
{
if (value < 1)
throw new ArgumentOutOfRangeException("value", "Expected >= 1");
this.SetValue("DefaultDeviceProfileId", value);
this.Set(value);
}
}
public int DefaultAddDeviceOfflineDeviceProfileId
{
get
{
return this.GetValue("DefaultAddDeviceOfflineDeviceProfileId", 0);
return this.Get(0);
}
set
{
if (value < 0)
throw new ArgumentOutOfRangeException("value", "Expected >= 0");
this.SetValue("DefaultAddDeviceOfflineDeviceProfileId", value);
this.Set(value);
}
}