Пример #1
0
        /// <summary> Check if a region has updated. Keep in mind that this is limited by RepoApi to 1 request per second! </summary>
        private async Task <bool> Updated(Region region)
        {
            var lastUpdate = await api.LastUpdateFor(region.Name);

            var startOfThisUpdate =
                nextUpdateIsMajor ? TimeUtil.UnixNextMajorStart() : TimeUtil.UnixNextMinorStart();

            return(lastUpdate > startOfThisUpdate);
        }
Пример #2
0
        /// <summary> Generate a report of likely military operations during the last (major or minor) update </summary>
        public async Task Run(string userAgent, Dictionary <string, string> userTags, bool interactiveLog = false)
        {
            Console.Write("Compiling operations report... \n");

            api     = RepoApi.Api(userAgent);
            regions = await RepoRegionDump.Dump(userAgent, userTags).Regions();

            // Start and end of last (major or minor) update
            var updateStart = StartOfLastUpdate();
            var updateEnd   = await api.LastUpdateFor(regions.Last().Name);

            // Get happenings
            var delegateChangeHappenings = await api.DelegateChangesFrom(updateStart, updateEnd);

            // Parse each happening to the DelegacyChange DTO
            var delegacyChanges = DelegacyChanges(delegateChangeHappenings);

            // Filter out the suspicious changes from among the (supposedly) legitimate changes
            var ops = await FilterOps(delegacyChanges, updateEnd - 43200, userTags, interactiveLog);

            if (interactiveLog)
            {
                Console.Write("Saving to report... ");
            }

            // Generate report
            ops = ops.OrderBy(o => o.ChangeTimeStamp).ToList();
            var report = Report(ops);

            // Save
            var date = TimeUtil.DateForPath();

            Directory.CreateDirectory(date);
            await File.WriteAllTextAsync($"{date}/Kronos-Ops_{date}.md", report);

            if (interactiveLog)
            {
                Console.Write("[done].\n");
            }
        }