Пример #1
0
        public void HandleNewLiveData()
        {
            var newData = liveLogsDataQueue.Consume();

            foreach (var data in newData)
            {
                if (data.Uptime != null)
                {
                    var serverName = wurmServerHistory.TryGetServer(data.Character, data.Uptime.Stamp.DateTime);
                    if (serverName != null)
                    {
                        TimeDetails details;
                        if (!latestData.TryGetValue(serverName, out details))
                        {
                            details = new TimeDetails();
                            latestData.Add(serverName, details);
                        }

                        if (details.ServerUptime.Stamp < data.Uptime.Stamp)
                        {
                            details.ServerUptime = new ServerUptimeStamped()
                            {
                                Uptime = data.Uptime.Uptime,
                                Stamp  = data.Uptime.Stamp
                            };
                        }
                    }
                }
                if (data.WurmDateTime != null)
                {
                    var serverName = wurmServerHistory.TryGetServer(data.Character, data.WurmDateTime.Stamp.DateTime);
                    if (serverName != null)
                    {
                        TimeDetails details;
                        if (!latestData.TryGetValue(serverName, out details))
                        {
                            details = new TimeDetails();
                            latestData.Add(serverName, details);
                        }

                        if (details.ServerDate.Stamp < data.WurmDateTime.Stamp)
                        {
                            details.ServerDate = new ServerDateStamped()
                            {
                                WurmDateTime = data.WurmDateTime.WurmDateTime,
                                Stamp        = data.WurmDateTime.Stamp
                            };
                        }
                    }
                }
            }
        }
Пример #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;
        }