| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- using System.Text.Json.Serialization;
- namespace NetworkTool.Client.Models;
- public sealed class RemoteInterfaceAddressConfig
- {
- [JsonPropertyName("ip")]
- public string IP { get; init; } = string.Empty;
- [JsonPropertyName("prefix")]
- public int Prefix { get; init; }
- }
- public sealed class RemoteInterfaceRouteConfig
- {
- [JsonPropertyName("to")]
- public string To { get; init; } = string.Empty;
- [JsonPropertyName("via")]
- public string Via { get; init; } = string.Empty;
- }
- public sealed class RemoteInterfaceConfig
- {
- [JsonPropertyName("interface")]
- public string Interface { get; init; } = string.Empty;
- [JsonPropertyName("dhcp4")]
- public bool Dhcp4 { get; init; }
- [JsonPropertyName("addresses")]
- public IReadOnlyList<RemoteInterfaceAddressConfig> Addresses { get; init; } = [];
- [JsonPropertyName("routes")]
- public IReadOnlyList<RemoteInterfaceRouteConfig> Routes { get; init; } = [];
- [JsonPropertyName("dns")]
- public IReadOnlyList<string> Dns { get; init; } = [];
- [JsonPropertyName("ip")]
- public string IP { get; init; } = string.Empty;
- [JsonPropertyName("prefix")]
- public int Prefix { get; init; }
- [JsonPropertyName("gateway")]
- public string Gateway { get; init; } = string.Empty;
- [JsonIgnore]
- public string DnsSummary => Dns is null || Dns.Count == 0 ? "无" : string.Join(Environment.NewLine, Dns);
- [JsonIgnore]
- public IReadOnlyList<RemoteInterfaceAddressConfig> EffectiveAddresses => Addresses.Count > 0
- ? Addresses
- : string.IsNullOrWhiteSpace(IP) ? [] : [new RemoteInterfaceAddressConfig { IP = IP, Prefix = Prefix }];
- [JsonIgnore]
- public IReadOnlyList<RemoteInterfaceRouteConfig> EffectiveRoutes => Routes.Count > 0
- ? Routes
- : string.IsNullOrWhiteSpace(Gateway) ? [] : [new RemoteInterfaceRouteConfig { To = "default", Via = Gateway }];
- }
- public sealed class RemoteInterfaceConfigsRequest
- {
- [JsonPropertyName("configs")]
- public IReadOnlyList<RemoteInterfaceConfig> Configs { get; init; } = [];
- }
- public sealed class RemoteInterfaceConfigsResponse
- {
- [JsonPropertyName("configs")]
- public IReadOnlyList<RemoteInterfaceConfig> Configs { get; init; } = [];
- [JsonPropertyName("errors")]
- public IReadOnlyList<RemoteInterfaceConfigError> Errors { get; init; } = [];
- }
- public sealed class RemoteInterfaceConfigError
- {
- [JsonPropertyName("interface")]
- public string Interface { get; init; } = string.Empty;
- [JsonPropertyName("message")]
- public string Message { get; init; } = string.Empty;
- }
|