public static void Clean() { //PrimeDns.semaphore.Wait(); PrimeDns.Log._LogInformation("CLEANING UP Started", Logger.Logger.ConstStartUp, null); if (File.Exists(PrimeDns.Config.MapDatabasePath)) { File.Delete(PrimeDns.Config.MapDatabasePath); } if (File.Exists(PrimeDns.Config.StateDatabasePath)) { File.Delete(PrimeDns.Config.StateDatabasePath); } if (File.Exists(PrimeDns.Config.MapDatabaseJournalPath)) { File.Delete(PrimeDns.Config.MapDatabaseJournalPath); } PrimeDns.HostFileUpdater.RemoveOldPrimeDnsSectionEntries(PrimeDns.Config.HostFilePath); Helper.FileHelper.RemoveLineFromFile(PrimeDns.Config.HostFilePath, PrimeDns.Config.PrimeDnsSectionBeginString); Helper.FileHelper.RemoveLineFromFile(PrimeDns.Config.HostFilePath, PrimeDns.Config.PrimeDnsSectionEndString); MapUpdater.CreateAndInitializePrimeDnsState(0, 0, 0, 0, 0); //PrimeDns.semaphore.Release(); PrimeDns.Log._LogInformation("CLEANING UP Ended", Logger.Logger.ConstStartUp, null); }
// Gets called multiple times during the game... public BotMain() { this.CardsHandler = new CardsHandler(this); this.LastVisibleMapUpdater = new LastVisibleMapUpdater(this); this.StatelessFogRemover = new StatelessFogRemover(this); //this.FogRemover = new StatefulFogRemover(this); this.HistoryTracker = new HistoryTracker(this); this.MovesScheduler2 = new MovesScheduler(this); this.MovesCalculator = new MovesCalculator(this); this.DeleteBadMovesTask = new DeleteBadMovesTask(this); this.TerritoryValueCalculator = new TerritoryValueCalculator(this); this.ExpansionMapUpdater = new ExpansionMapUpdater(this); this.BreakTerritoryTask = new BreakTerritoryTask(this); this.BonusValueCalculator = new BonusValueCalculator(this); this.ExpansionTask = new ExpansionTask(this); this.BonusExpansionValueCalculator = new BonusExpansionValueCalculator(this); this.BonusPickValueCalculator = new BonusPickValueCalculator(this); this.DefendTerritoryTask = new DefendTerritoryTask(this); this.DefendTerritoriesTask = new DefendTerritoriesTask(this); this.MapUpdater = new MapUpdater(this); this.PreventOpponentExpandBonusTask = new PreventOpponentExpandBonusTask(this); this.TakeTerritoriesTaskCalculator = new TakeTerritoriesTaskCalculator(this); this.OpponentDeploymentGuesser = new OpponentDeploymentGuesser(this); this.PicksEvaluator = new PicksEvaluator(this); }
public void Initialize() { //todo needs alot of support for threadsafe. int num_threads = WorldConfig.GetIntValue(WorldCfg.Numthreads); // Start mtmaps if needed. if (num_threads > 0) { m_updater = new MapUpdater(WorldConfig.GetIntValue(WorldCfg.Numthreads)); } }
/* * 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(); }
/* * AddNewEntriesToPrimeDnsMap() goes through _criticalDomains, * for each domain name, it checks whether it still exists in IsDomainCritical Dictionary, * if yes and it's value is true, it means the domain name is not a new entry, so nothing to be done. * if yes and it's value is false, it is absurd as no function marks them false and hence this is logged. * if no, then it's a new entry, * if the Domain Name is valid, * DNS Resolver is called and the result is written to PrimeDNSMap, * isDomainCritical() updated. * if Domain Name is invalid, it's logged as a warning. */ private async Task AddNewEntriesToPrimeDnsMap() { var tasks = new List <Task <Tuple <PrimeDnsMapRow, bool> > >(); var source = new CancellationTokenSource(); PrimeDns.DnsResolverCancellationToken = source.Token; foreach (string domain in _criticalDomains) { try { var value = IsDomainCritical[domain]; if (!value) { PrimeDns.Log._LogInformation("Dictionary having a FALSE entry!!!!? " + domain, Logger.Logger.ConstDomainsWatcher, null); } } catch (KeyNotFoundException) { if (IsDomainNameValid(domain)) { var mapRow = new PrimeDnsMapRow(domain); tasks.Add(DoWorkAsync(mapRow, PrimeDns.DnsResolverCancellationToken)); } else { PrimeDns.Log._LogWarning("Invalid Domain Name Found in File!", Logger.Logger.ConstDomainsWatcher, null); Telemetry.Telemetry.PushDnsCallsData(domain, "Failure", "InvalidDomain", 0, 0, "INVALID-DOMAIN"); } /* * if (tasks.Count > PrimeDns.Config.ParallelDnsCallsLimit) * { * foreach (var task in await Task.WhenAll(tasks)) * { * if (task.Item2) * { * MapUpdater.WriteToPrimeDnsMap(task.Item1); * IsDomainCritical.Add(domain, true); * PrimeDns.Log._LogInformation("Added the New Domain to PrimeDNSMap " + domain, Logger.Logger.CDomainsWatcher, null); * //Console.WriteLine("Ending Dns Resolver {0}", task.Item1.HostName); * } * } * tasks.Clear(); * } */ } } if (tasks.Count > 0) { var isMapUpdated = false; foreach (var(item1, item2) in await Task.WhenAll(tasks)) { if (item2) { try { if (DomainYetToBeAddedToMap[item1.HostName]) { PrimeDns.Log._LogInformation(" New Domain successfully added to PrimeDNSMap " + item1.HostName, Logger.Logger.ConstDomainsWatcher, null); DomainYetToBeAddedToMap.Remove(item1.HostName); } } catch (KeyNotFoundException) { PrimeDns.Log._LogInformation("Added the New Domain to PrimeDNSMap " + item1.HostName, Logger.Logger.ConstDomainsWatcher, null); } MapUpdater.WriteToPrimeDnsMap(item1); IsDomainCritical.Add(item1.HostName, true); isMapUpdated = true; //Console.WriteLine("Ending Dns Resolver {0}", task.Item1.HostName); } else { PrimeDns.Log._LogInformation("Failure in adding New Domain to PrimeDNSMap " + item1.HostName, Logger.Logger.ConstDomainsWatcher, null); try { if (!DomainYetToBeAddedToMap[item1.HostName]) { DomainYetToBeAddedToMap[item1.HostName] = true; } } catch (KeyNotFoundException) { DomainYetToBeAddedToMap.Add(item1.HostName, true); } } } tasks.Clear(); if (isMapUpdated) { MapUpdater.UpdatePrimeDnsState(AppConfig.ConstPrimeDnsMapUpdated, 1); } } }
public MapUpdateRequest(Map m, MapUpdater u, uint d) { m_map = m; m_updater = u; m_diff = d; }
public static void CreateMap() { MapUpdater.CreatePrimeDnsMap().Wait(); }