PortStatus.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using InABox.Core;
  2. using InABox.Rpc;
  3. namespace PRSServer
  4. {
  5. public enum PortState
  6. {
  7. Unavailable,
  8. Available,
  9. Secure,
  10. }
  11. public enum PortType
  12. {
  13. None,
  14. Database,
  15. Session,
  16. Web,
  17. GPS,
  18. Sigfox,
  19. Certificate
  20. }
  21. public class PortStatus
  22. {
  23. public int Port { get; set; }
  24. public PortType Type { get; set; }
  25. public PortState State { get; set; }
  26. public PortStatus(int port, PortType type, PortState state)
  27. {
  28. Port = port;
  29. Type = type;
  30. State = state;
  31. }
  32. public PortStatus()
  33. {
  34. Port = 0;
  35. Type = PortType.None;
  36. State = PortState.Unavailable;
  37. }
  38. }
  39. //public class PortStatus[] : List<PortStatus> { }
  40. public class PortStatusCommand : IRpcCommand<PortStatusParameters, PortStatusResult>
  41. {
  42. public bool Log => false;
  43. }
  44. public class PortStatusParameters : IRpcCommandParameters
  45. {
  46. public void SerializeBinary(CoreBinaryWriter writer)
  47. {throw new System.NotImplementedException();
  48. }
  49. public void DeserializeBinary(CoreBinaryReader reader)
  50. {
  51. throw new System.NotImplementedException();
  52. }
  53. public string? FullDescription() => null;
  54. public string? ShortDescription() => null;
  55. }
  56. public class PortStatusResult : IRpcCommandResult
  57. {
  58. public PortStatus[] Ports { get; set; }
  59. public PortStatusResult()
  60. {
  61. Ports = new PortStatus[] { };
  62. }
  63. public void SerializeBinary(CoreBinaryWriter writer)
  64. {
  65. writer.WriteBinaryValue(Ports);
  66. }
  67. public void DeserializeBinary(CoreBinaryReader reader)
  68. {
  69. Ports = reader.ReadBinaryValue<PortStatus[]>();
  70. }
  71. public string? FullDescription() => null;
  72. }
  73. public class PortStatusHandler : RpcCommandHandler<IEngine, PortStatusCommand, PortStatusParameters, PortStatusResult>
  74. {
  75. protected override PortStatusResult Execute(IRpcSession session, PortStatusParameters? parameters)
  76. => new() { Ports = Sender.PortStatusList() };
  77. public PortStatusHandler(IEngine sender) : base(sender)
  78. {
  79. }
  80. }
  81. }