2021-03-10 01:12:07 +08:00
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace PortProxyGUI.Data
|
|
|
|
|
{
|
|
|
|
|
public class Rule : IEquatable<Rule>
|
|
|
|
|
{
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
|
|
|
|
|
public string Type { get; set; }
|
|
|
|
|
public string ListenOn { get; set; }
|
|
|
|
|
public int ListenPort { get; set; }
|
|
|
|
|
public string ConnectTo { get; set; }
|
2022-02-17 16:31:03 +08:00
|
|
|
|
public int ConnectPort { get; set; }
|
2022-02-23 00:41:01 +08:00
|
|
|
|
public string Comment { get; set; }
|
2022-02-17 16:31:03 +08:00
|
|
|
|
public string Group { get; set; }
|
2021-03-10 01:12:07 +08:00
|
|
|
|
|
|
|
|
|
public bool Equals(Rule other)
|
|
|
|
|
{
|
|
|
|
|
return Id == other.Id
|
|
|
|
|
&& Type == other.Type
|
|
|
|
|
&& ListenOn == other.ListenOn
|
|
|
|
|
&& ListenPort == other.ListenPort
|
|
|
|
|
&& ConnectTo == other.ConnectTo
|
2022-02-17 16:31:03 +08:00
|
|
|
|
&& ConnectPort == other.ConnectPort
|
2022-02-23 00:41:01 +08:00
|
|
|
|
&& Comment == other.Comment
|
2022-02-17 16:31:03 +08:00
|
|
|
|
&& Group == other.Group;
|
2021-03-10 01:12:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool EqualsWithKeys(Rule other)
|
|
|
|
|
{
|
|
|
|
|
return Type == other.Type
|
|
|
|
|
&& ListenOn == other.ListenOn
|
|
|
|
|
&& ListenPort == other.ListenPort;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-17 16:31:03 +08:00
|
|
|
|
public static int ParsePort(string portString)
|
|
|
|
|
{
|
|
|
|
|
if (int.TryParse(portString, out var port) && 0 < port && port < 65536) return port;
|
|
|
|
|
else throw new NotSupportedException($"Invalid port string. ({portString})");
|
|
|
|
|
}
|
2021-03-10 01:12:07 +08:00
|
|
|
|
}
|
|
|
|
|
}
|