ServerSettings.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. case ServerType.HTTPProxy:
  47. return Serialization.Deserialize<HTTPDatabaseProxyProperties>(Properties);
  48. case ServerType.WebSocketProxy:
  49. return Serialization.Deserialize<WebSocketDatabaseProxyProperties>(Properties);
  50. case ServerType.PipeProxy:
  51. return Serialization.Deserialize<PipeDatabaseProxyProperties>(Properties);
  52. default:
  53. return null;
  54. }
  55. }
  56. /*public override void Load(RegistryKey key)
  57. {
  58. Type = (ServerType)Enum.Parse(typeof(ServerType), key.GetValue("Type") as string);
  59. Properties = key.GetValue("Properties") as string;
  60. }
  61. public override void Save(RegistryKey key)
  62. {
  63. key.SetValue("Type", Type.ToString());
  64. key.SetValue("Properties", Properties);
  65. }*/
  66. }
  67. }