ServerSettings.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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, */ILocalConfigurationSettings
  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. switch (Type)
  33. {
  34. case ServerType.Database:
  35. return Serialization.Deserialize<DatabaseServerProperties>(Properties);
  36. case ServerType.GPS:
  37. return Serialization.Deserialize<GPSServerProperties>(Properties);
  38. case ServerType.AutoDiscovery:
  39. return Serialization.Deserialize<AutoDiscoveryServerProperties>(Properties);
  40. case ServerType.Schedule:
  41. return Serialization.Deserialize<ScheduleServerProperties>(Properties);
  42. case ServerType.Web:
  43. return Serialization.Deserialize<WebServerProperties>(Properties);
  44. case ServerType.Certificate:
  45. return Serialization.Deserialize<CertificateEngineProperties>(Properties);
  46. default:
  47. return null;
  48. }
  49. }
  50. /*public override void Load(RegistryKey key)
  51. {
  52. Type = (ServerType)Enum.Parse(typeof(ServerType), key.GetValue("Type") as string);
  53. Properties = key.GetValue("Properties") as string;
  54. }
  55. public override void Save(RegistryKey key)
  56. {
  57. key.SetValue("Type", Type.ToString());
  58. key.SetValue("Properties", Properties);
  59. }*/
  60. }
  61. }