Lookup on known time servers

This commit is contained in:
Carsten Larsen 2016-12-14 21:06:14 +01:00
parent 938c24765e
commit cd2135aca1
5 changed files with 1588 additions and 3 deletions

File diff suppressed because it is too large Load Diff

View File

@ -39,6 +39,7 @@
<Compile Include="..\Shared\AssemblyInfo.cs" />
<Compile Include="Changes\Change03.cs" />
<Compile Include="DataFace.cs" />
<Compile Include="Import\TimerServers.cs" />
<Compile Include="Import\TimeServerImporter.cs" />
<Compile Include="Import\TimeServerLoader.cs" />
<Compile Include="Log\LogExtensions.cs" />

View File

@ -33,6 +33,6 @@ public Host(int id, string name, string ip, int? orgId, bool newObject = true)
public string Ip { get; }
public int? OrgId { get; }
public int? OrgId { get; set; }
}
}

View File

@ -195,6 +195,8 @@ private void InitializeData()
if (!config.Database.Initialize)
return;
var knownServers = TimeServers.List.ToDictionary(i => i.Value, i => i.Key);
try
{
// Initialize hosts
@ -212,10 +214,35 @@ private void InitializeData()
{
ip = IPAddress.None;
}
host = new Host(server.HostId, server.ServerName, ip.ToString(), null);
int? orgId = null;
if (knownServers.ContainsKey(server.ServerName))
{
orgId = knownServers[server.ServerName];
Log.KnownServer(orgId.Value, server.ServerName);
}
else if (!Equals(ip, IPAddress.None) && knownServers.ContainsKey(ip.ToString()))
{
orgId = knownServers[ip.ToString()];
Log.KnownServer(orgId.Value, ip.ToString());
}
host = new Host(server.HostId, server.ServerName, ip.ToString(), orgId);
DataFace.Instance.Hosts.Save(host);
Log.NewHost(server, ip);
}
else if (host.OrgId == null && knownServers.ContainsKey(host.Ip))
{
host.OrgId = knownServers[host.Ip];
Log.KnownServer(host.OrgId.Value, host.Ip);
DataFace.Instance.Hosts.Save(host);
}
else if (host.OrgId == null && knownServers.ContainsKey(host.Name))
{
host.OrgId = knownServers[host.Name];
Log.KnownServer(host.OrgId.Value, host.Name);
DataFace.Instance.Hosts.Save(host);
}
// Flush old association entries
DataFace.Instance.AssociationEntries.Delete(server.HostId);
@ -230,7 +257,15 @@ private void InitializeData()
if (peerList.Any())
continue;
var peer = new Peer(entry.Remote, entry.Remote, null);
TimeServer timeServer = null;
if (knownServers.ContainsKey(entry.Remote))
{
int orgId = knownServers[entry.Remote];
timeServer = DataFace.Instance.Servers[orgId];
Log.KnownServer(orgId, entry.Remote);
}
var peer = new Peer(entry.Remote, entry.Remote, timeServer);
DataFace.Instance.Peers.Save(peer);
Log.NewPeer(entry);
}

View File

@ -116,6 +116,13 @@ internal static void NewPeer(this LogBase log, AssociationEntry entry)
Severity.Info);
}
internal static void KnownServer(this LogBase log, int id, string name)
{
log.WriteLine(
$"Found known time server {name} with id {id} in list.",
Severity.Info);
}
internal static void NoConfig(this LogBase log, string file)
{
log.WriteLine($"Cannot find configuration file {file}", Severity.Error);