PortStatus.cs 2.0 KB

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