ServerSettings.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using InABox.Configuration;
  3. using InABox.Core;
  4. using Microsoft.Win32;
  5. using PRS.Shared;
  6. using PRSClasses;
  7. using PRSServer;
  8. namespace PRSServer
  9. {
  10. public class ServerSettings : /*RegistryConfigurationSettings, */LocalConfigurationSettings
  11. {
  12. //public long Sequence { get; set; }
  13. public ServerType Type { get; set; }
  14. public string Properties { get; set; }
  15. public Server CreateServer(string key)
  16. {
  17. var result = new Server();
  18. result.Key = key;
  19. result.Type = Type;
  20. //result.Sequence = Sequence == 0 ? DateTime.Now.Ticks : Sequence;
  21. var properties = DeserializeServerProperties();
  22. if (properties != null)
  23. {
  24. result.Properties = properties;
  25. result.Name = result.Properties.Name;
  26. }
  27. result.CommitChanges();
  28. return result;
  29. }
  30. public ServerProperties? DeserializeServerProperties()
  31. {
  32. if (Type == ServerType.Database)
  33. return Serialization.Deserialize<DatabaseServerProperties>(Properties);
  34. if (Type == ServerType.GPS)
  35. return Serialization.Deserialize<GPSServerProperties>(Properties);
  36. if (Type == ServerType.AutoDiscovery)
  37. return Serialization.Deserialize<AutoDiscoveryServerProperties>(Properties);
  38. if (Type == ServerType.Schedule)
  39. return Serialization.Deserialize<ScheduleServerProperties>(Properties);
  40. if (Type == ServerType.Web)
  41. return Serialization.Deserialize<WebServerProperties>(Properties);
  42. if (Type == ServerType.Certificate)
  43. return Serialization.Deserialize<CertificateEngineProperties>(Properties);
  44. return null;
  45. }
  46. /*public override void Load(RegistryKey key)
  47. {
  48. Type = (ServerType)Enum.Parse(typeof(ServerType), key.GetValue("Type") as string);
  49. Properties = key.GetValue("Properties") as string;
  50. }
  51. public override void Save(RegistryKey key)
  52. {
  53. key.SetValue("Type", Type.ToString());
  54. key.SetValue("Properties", Properties);
  55. }*/
  56. }
  57. }