123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- 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<T> : Configuration<T> 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<T>(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<string, T> LoadAll()
- {
- var results = new Dictionary<string, T>();
- 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<string, T> 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<T>(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;
- }
- }*/
- }
|