namespace CodexPlugin.OverwatchSupport { public class IdentityMap { private readonly List nodes = new List(); private readonly Dictionary nameIndexMap = new Dictionary(); private readonly Dictionary shortToLong = new Dictionary(); public void Add(string name, string peerId, string nodeId) { Add(new CodexNodeIdentity { Name = name, PeerId = peerId, NodeId = nodeId }); nameIndexMap.Add(name, nameIndexMap.Count); } public void Add(CodexNodeIdentity identity) { if (string.IsNullOrWhiteSpace(identity.Name)) throw new Exception("Name required"); if (string.IsNullOrWhiteSpace(identity.PeerId) || identity.PeerId.Length < 11) throw new Exception("PeerId invalid"); if (string.IsNullOrWhiteSpace(identity.NodeId) || identity.NodeId.Length < 11) throw new Exception("NodeId invalid"); nodes.Add(identity); shortToLong.Add(CodexUtils.ToShortId(identity.PeerId), identity.PeerId); shortToLong.Add(CodexUtils.ToShortId(identity.NodeId), identity.NodeId); } public CodexNodeIdentity[] Get() { return nodes.ToArray(); } public int GetIndex(string name) { return nameIndexMap[name]; } public CodexNodeIdentity GetId(string name) { return nodes.Single(n => n.Name == name); } public string ReplaceShortIds(string value) { var result = value; foreach (var pair in shortToLong) { result = result.Replace(pair.Key, pair.Value); } return result; } public int Size { get { return nodes.Count; } } } }