/* * UpdateMap() is straight forward to understand. */ internal static void UpdateMap(DateTimeOffset time) { PrimeDns.Log._LogInformation("Map Updater Started at Time : " + time.ToString(), Logger.ConstStartUp, null); Telemetry.Telemetry.PushStatusOfThread("MapUpdater", "Started"); if (!SqliteConnect.CheckPrimeDnsState(AppConfig.ConstPrimeDnsMapCreated)) { CreatePrimeDnsMap().Wait(); } var t = new Task[2] { UpdatePrimeDnsMap(), Task.Delay(new TimeSpan(0, 0, 300)) }; var index = Task.WaitAny(t); if (index == 1) { var source = new CancellationTokenSource(); PrimeDns.DnsResolverCancellationToken = source.Token; source.Cancel(); t[0].Wait(); } Telemetry.Telemetry.PushStatusOfThread("MapUpdater", "Ended"); PrimeDns.Log._LogInformation("Map Updater Exited at Time : " + time.ToString(), Logger.ConstStartUp, null); }
/* * UpdateHostfile() - calls various other functions that have comments on them, so should be understandable. */ internal void UpdateHostfile(DateTimeOffset time) { PrimeDns.Log._LogInformation("Host File Updater Started at Time : " + time.ToString(), Logger.ConstStartUp, null); Telemetry.Telemetry.PushStatusOfThread("HostFileUpdater", "Started"); if (!SqliteConnect.CheckPrimeDnsState(AppConfig.ConstPrimeDnsSectionCreated)) { CreatePrimeDnsSection(); Telemetry.Telemetry.PushHostfileWrites(); MapUpdater.UpdatePrimeDnsState(AppConfig.ConstPrimeDnsSectionCreated, 1); } var isPrimeDnsSectionOkay = IntegrityChecker.CheckPrimeDnsSectionIntegrity(PrimeDns.Config.HostFilePath); var isMapUpdated = SqliteConnect.CheckPrimeDnsState(AppConfig.ConstPrimeDnsMapUpdated); var isHostFileUpdatedFromOutside = SqliteConnect.CheckPrimeDnsState(AppConfig.ConstPrimeDnsHostFileUpdatedFromOutside); if (isPrimeDnsSectionOkay && (isMapUpdated || isHostFileUpdatedFromOutside)) { try { var newPrimeDnsSectionEntries = GetPrimeDnsSectionEntries(); var hostfilePath = PrimeDns.Config.HostFilePath; RemoveOldPrimeDnsSectionEntries(hostfilePath); FindPrimeDnsSectionBegin(hostfilePath); if (PrimeDnsBeginLine >= 0) { FileHelper.InsertIntoFile(hostfilePath, newPrimeDnsSectionEntries, PrimeDnsBeginLine + 1); } MapUpdater.UpdatePrimeDnsState(AppConfig.ConstPrimeDnsMapUpdated, 0); MapUpdater.UpdatePrimeDnsState(AppConfig.ConstPrimeDnsHostFileUpdatedFromOutside, 0); Telemetry.Telemetry.PushHostfileWrites(); } catch (IOException ioe) { PrimeDns.Log._LogError("Aggregate Exception occured while updating Hostfile - ", Logger.ConstHostFileIntegrity, ioe); Telemetry.Telemetry.PushStatusOfThread("HostFileUpdater", "Failed"); } } else if (!isPrimeDnsSectionOkay) { FileHelper.RemoveLineFromFile(PrimeDns.Config.HostFilePath, PrimeDns.Config.PrimeDnsSectionBeginString); FileHelper.RemoveLineFromFile(PrimeDns.Config.HostFilePath, PrimeDns.Config.PrimeDnsSectionEndString); CreatePrimeDnsSection(); Telemetry.Telemetry.PushHostfileWrites(); MapUpdater.UpdatePrimeDnsState(AppConfig.ConstPrimeDnsHostFileUpdatedFromOutside, 1); PrimeDns.Log._LogWarning("CheckPrimeDnsSectionIntegrity FAILED!!, Continuing..", Logger.ConstHostFileIntegrity, null); } Telemetry.Telemetry.PushStatusOfThread("HostFileUpdater", "Ended"); PrimeDns.Log._LogInformation("Host File Updater Ended at Time : " + time.ToString(), Logger.ConstStartUp, null); GC.Collect(); GC.WaitForPendingFinalizers(); }