using System.Collections.Generic; using System.IO; using System.Reflection; using InABox.Configuration; using Microsoft.Win32; namespace PRS.Shared { /*public abstract class RegistryConfigurationSettings : IConfigurationSettings { public abstract void Load(RegistryKey key); public abstract void Save(RegistryKey key); } public class RegistryConfiguration : Configuration where T : RegistryConfigurationSettings, new() { private readonly RegistryKey _key; public RegistryConfiguration(string section = "") : base(section) { _key = Registry.LocalMachine.OpenSubKey("Software"); _key = OpenOrCreate(_key, "PRS"); _key = OpenOrCreate(_key, Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)); if (string.IsNullOrWhiteSpace(section)) _key = OpenOrCreate(_key, section); } public override T Load() { var cached = ConfigurationCache.Check(ConfigurationCacheType.Local, Section); if (cached != null) //Logger.Send(LogType.Information, "", "Local Config: Returning Cached Configuration Data"); return cached; //Logger.Send(LogType.Information, "", "Local Config: Creating "+typeof(T).EntityName().Split('.').Last()); var result = new T(); result.Load(_key); //Logger.Send(LogType.Information, "", "Local Config: Adding Configuration to Cache"); ConfigurationCache.Add(ConfigurationCacheType.Local, Section, result); return result; } public override Dictionary LoadAll() { var results = new Dictionary(); var sections = _key.GetSubKeyNames(); foreach (var section in sections) { var _subkey = _key.OpenSubKey(section, true); var result = new T(); result.Load(_subkey); results[section] = result; } return results; } public override void Save(T obj) { obj.Save(_key); ConfigurationCache.Add(ConfigurationCacheType.Local, Section, obj); } public override void SaveAll(Dictionary objs) { throw new System.NotImplementedException(); } public override void Delete() { var key = GetParent(); if (string.IsNullOrWhiteSpace(Section)) key.DeleteSubKeyTree(Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)); else key.DeleteSubKeyTree(Section); ConfigurationCache.Clear(ConfigurationCacheType.Local, Section); } public override string[] Sections() { return _key.GetSubKeyNames(); } public RegistryKey GetParent() { var result = Registry.LocalMachine.OpenSubKey("Software"); result = OpenOrCreate(result, "PRS"); if (!string.IsNullOrWhiteSpace(Section)) result = OpenOrCreate(result, Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location)); return result; } private RegistryKey OpenOrCreate(RegistryKey key, string name) { var result = key.OpenSubKey(name, true); if (result == null) result = key.CreateSubKey(name, true); return result; } }*/ }