-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConfigEntry.cs
61 lines (50 loc) · 1.92 KB
/
ConfigEntry.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using System.Collections.Generic;
using System.Linq;
namespace SSHMan {
public struct ConfigEntry : IEquatable<ConfigEntry> {
public string Host { get; set; }
public Dictionary<string, string> Data { get; private set; }
const string CfgKeyHost = "HOSTNAME";
const string CfgKeyPort = "PORT";
public static ConfigEntry Create (string host, string port) {
return new ConfigEntry () {
Host = host,
Data = new Dictionary<string, string> () { { CfgKeyHost, host }, { CfgKeyPort, port },
}
};
}
public static ConfigEntry Create () {
return new ConfigEntry () {
Host = "Unknown",
Data = new Dictionary<string, string> () { { CfgKeyHost, "Unknown" } }
};
}
public override int GetHashCode () {
return HashCode.Combine (Host, Data);
}
public SSHHostEntry ToEntry () {
var ip = Data.Keys.Contains (CfgKeyHost) ? Data[CfgKeyHost] : "-";
var port = Data.Keys.Contains (CfgKeyPort) ? Data[CfgKeyPort] : "22";
return new SSHHostEntry () {
Name = Host,
Address = $"{ip}:{port}"
};
}
public static bool operator == (ConfigEntry left, ConfigEntry right) {
return left.Equals (right);
}
public static bool operator != (ConfigEntry left, ConfigEntry right) {
return !(left == right);
}
public bool Equals (ConfigEntry other) {
return other is ConfigEntry entry &&
Host == entry.Host &&
EqualityComparer<Dictionary<string, string>>.Default.Equals (Data, entry.Data);
}
public override bool Equals(object obj)
{
return obj is ConfigEntry entry && Equals(entry);
}
}
}