RemoteInterfaceConfig.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Text.Json.Serialization;
  2. namespace NetworkTool.Client.Models;
  3. public sealed class RemoteInterfaceAddressConfig
  4. {
  5. [JsonPropertyName("ip")]
  6. public string IP { get; init; } = string.Empty;
  7. [JsonPropertyName("prefix")]
  8. public int Prefix { get; init; }
  9. }
  10. public sealed class RemoteInterfaceRouteConfig
  11. {
  12. [JsonPropertyName("to")]
  13. public string To { get; init; } = string.Empty;
  14. [JsonPropertyName("via")]
  15. public string Via { get; init; } = string.Empty;
  16. }
  17. public sealed class RemoteInterfaceConfig
  18. {
  19. [JsonPropertyName("interface")]
  20. public string Interface { get; init; } = string.Empty;
  21. [JsonPropertyName("dhcp4")]
  22. public bool Dhcp4 { get; init; }
  23. [JsonPropertyName("addresses")]
  24. public IReadOnlyList<RemoteInterfaceAddressConfig> Addresses { get; init; } = [];
  25. [JsonPropertyName("routes")]
  26. public IReadOnlyList<RemoteInterfaceRouteConfig> Routes { get; init; } = [];
  27. [JsonPropertyName("dns")]
  28. public IReadOnlyList<string> Dns { get; init; } = [];
  29. [JsonPropertyName("ip")]
  30. public string IP { get; init; } = string.Empty;
  31. [JsonPropertyName("prefix")]
  32. public int Prefix { get; init; }
  33. [JsonPropertyName("gateway")]
  34. public string Gateway { get; init; } = string.Empty;
  35. [JsonIgnore]
  36. public string DnsSummary => Dns is null || Dns.Count == 0 ? "无" : string.Join(Environment.NewLine, Dns);
  37. [JsonIgnore]
  38. public IReadOnlyList<RemoteInterfaceAddressConfig> EffectiveAddresses => Addresses.Count > 0
  39. ? Addresses
  40. : string.IsNullOrWhiteSpace(IP) ? [] : [new RemoteInterfaceAddressConfig { IP = IP, Prefix = Prefix }];
  41. [JsonIgnore]
  42. public IReadOnlyList<RemoteInterfaceRouteConfig> EffectiveRoutes => Routes.Count > 0
  43. ? Routes
  44. : string.IsNullOrWhiteSpace(Gateway) ? [] : [new RemoteInterfaceRouteConfig { To = "default", Via = Gateway }];
  45. }
  46. public sealed class RemoteInterfaceConfigsRequest
  47. {
  48. [JsonPropertyName("configs")]
  49. public IReadOnlyList<RemoteInterfaceConfig> Configs { get; init; } = [];
  50. }
  51. public sealed class RemoteInterfaceConfigsResponse
  52. {
  53. [JsonPropertyName("configs")]
  54. public IReadOnlyList<RemoteInterfaceConfig> Configs { get; init; } = [];
  55. [JsonPropertyName("errors")]
  56. public IReadOnlyList<RemoteInterfaceConfigError> Errors { get; init; } = [];
  57. }
  58. public sealed class RemoteInterfaceConfigError
  59. {
  60. [JsonPropertyName("interface")]
  61. public string Interface { get; init; } = string.Empty;
  62. [JsonPropertyName("message")]
  63. public string Message { get; init; } = string.Empty;
  64. }