Example #1
0
 private void EventHandler(object sender, LogsMonitorEventArgs logsMonitorEventArgs)
 {
     if (logsMonitorEventArgs.LogType == LogType.Event)
     {
         foreach (var wurmLogEntry in logsMonitorEventArgs.WurmLogEntries)
         {
             var uptime = logEntriesParser.TryParseUptime(wurmLogEntry);
             if (uptime != null)
             {
                 Add(logsMonitorEventArgs.CharacterName, uptime);
             }
             else
             {
                 var datetime = logEntriesParser.TryParseWurmDateTime(wurmLogEntry);
                 if (datetime != null)
                 {
                     Add(logsMonitorEventArgs.CharacterName, datetime);
                 }
             }
         }
     }
 }
Example #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;
        }