/// <summary>
        /// True if any data found
        /// </summary>
        private bool SearchLogsForwards(DateTime datetimeFrom, JobCancellationManager jobCancellationManager)
        {
            var dateFrom = datetimeFrom;
            var dateTo   = datetimeFrom + TimeSpan.FromDays(30);

            var  timeNow = Time.Get.LocalNow;
            bool end     = false;

            if (dateTo > timeNow)
            {
                dateTo = timeNow;
                end    = true;
            }

            var results = logsSearcher.Scan(
                new LogSearchParameters()
            {
                CharacterName = characterName.Normalized,
                MinDate       = dateFrom,
                MaxDate       = dateTo,
                LogType       = LogType.Event
            }, jobCancellationManager.GetLinkedToken());

            UpdateEntity(dateFrom, dateTo);

            var found = ParseForServerInfo(results);

            if (found)
            {
                return(true);
            }
            if (end)
            {
                return(false);
            }

            return(SearchLogsForwards(dateTo, jobCancellationManager));
        }
Ejemplo n.º 2
0
        void EnsureScanned()
        {
            if (scanned)
            {
                return;
            }

            var maxScanSince  = Time.Get.LocalNowOffset.AddDays(-30);
            var lastScanSince = logHistorySaved.LastScanDate.AddDaysSnapToMinMax(-1);
            var scanSince     = lastScanSince < maxScanSince ? maxScanSince : lastScanSince;

            var allChars = wurmCharacterDirectories.GetAllCharacters();

            foreach (var characterName in allChars)
            {
                var searchResults = wurmLogsHistory.Scan(
                    new LogSearchParameters()
                {
                    CharacterName = characterName.Normalized,
                    MinDate       = scanSince.DateTime,
                    MaxDate       = Time.Get.LocalNow,
                    LogType       = LogType.Event
                });
                foreach (var searchResult in searchResults)
                {
                    var upt = parser.TryParseUptime(searchResult);
                    if (upt != null)
                    {
                        var server = wurmServerHistory.TryGetServer(characterName, searchResult.Timestamp);
                        if (server != null)
                        {
                            logHistorySaved.UpdateHistoric(server, upt);
                        }
                        else
                        {
                            wurmApiLogger.Log(LogLevel.Info,
                                              string.Format("Server not found for character {0} at timestamp {1}",
                                                            characterName,
                                                            searchResult.Timestamp),
                                              this,
                                              null);
                        }
                    }
                    var wdt = parser.TryParseWurmDateTime(searchResult);
                    if (wdt != null)
                    {
                        var server = wurmServerHistory.TryGetServer(characterName, searchResult.Timestamp);
                        if (server != null)
                        {
                            logHistorySaved.UpdateHistoric(server, wdt);
                        }
                        else
                        {
                            wurmApiLogger.Log(LogLevel.Info,
                                              string.Format("Server not found for character {0} at timestamp {1}",
                                                            characterName,
                                                            searchResult.Timestamp),
                                              this,
                                              null);
                        }
                    }
                }
            }

            scanned = true;
        }