public ServerName TryGetAtTimestamp(DateTime timestamp, JobCancellationManager jobCancellationManager)
        {
            ParsePendingLiveLogEvents();

            var timeNow         = Time.Get.LocalNow;
            var time12MonthsAgo = timeNow.AddMonths(-12);

            // a cheap hack to reset history if its very outdated
            if (persistentData.Entity.SearchedFrom < time12MonthsAgo &&
                persistentData.Entity.SearchedTo < time12MonthsAgo)
            {
                persistentData.Entity.Reset();
            }

            if (persistentData.Entity.AnySearchCompleted &&
                timestamp >= persistentData.Entity.SearchedFrom &&
                timestamp <= persistentData.Entity.SearchedTo)
            {
                // within already scanned period
                ServerName serverName = sortedServerHistory.TryGetServerAtStamp(timestamp);
                if (serverName != null)
                {
                    // we have data, return
                    return(serverName);
                }
                // no data, we should continue
            }

            jobCancellationManager.ThrowIfCancelled();

            bool found = false;

            if (persistentData.Entity.AnySearchCompleted)
            {
                if (timestamp > persistentData.Entity.SearchedTo)
                {
                    found = SearchLogsForwards(persistentData.Entity.SearchedTo, jobCancellationManager);
                }

                if (!found || timestamp < persistentData.Entity.SearchedFrom)
                {
                    SearchLogsBackwards(persistentData.Entity.SearchedFrom, jobCancellationManager);
                }
            }
            else
            {
                found = SearchLogsForwards(timestamp, jobCancellationManager);
                if (!found)
                {
                    SearchLogsBackwards(timestamp, jobCancellationManager);
                }
                persistentData.Entity.AnySearchCompleted = true;
            }

            persistentData.FlagAsChanged();

            return(sortedServerHistory.TryGetServerAtStamp(timestamp));
        }
Ejemplo n.º 2
0
        public void UpdateHistoric(ServerName serverName, ServerDateStamped date)
        {
            ServerData data = GetServerData(serverName);

            if (data.LogHistory.ServerDate.Stamp < date.Stamp)
            {
                data.LogHistory.ServerDate = date;
                persistenceManager.FlagAsChanged();
            }
        }
        WurmLogMonthlyFile GetEntityForFile(LogFileInfo logFileInfo)
        {
            WurmLogMonthlyFile fileData;
            bool isNewFile   = false;
            bool needsSaving = false;

            if (!persistentData.Entity.WurmLogFiles.TryGetValue(logFileInfo.FileNameNormalized, out fileData))
            {
                fileData = new WurmLogMonthlyFile {
                    FileName = logFileInfo.FileNameNormalized
                };
                isNewFile   = true;
                needsSaving = true;
            }

            FileInfo fileInfo   = new FileInfo(logFileInfo.FullPath);
            var      fileLength = fileInfo.Length;

            if (fileData.LastKnownSizeInBytes < fileLength)
            {
                var extractor = monthlyHeuristicsExtractorFactory.Create(logFileInfo);
                var results   = extractor.ExtractDayToPositionMap();
                fileData.LogDate               = results.LogDate;
                fileData.DayToHeuristicsMap    = results.Heuristics;
                fileData.HasValidBytePositions = results.HasValidBytePositions;
                fileData.LastKnownSizeInBytes  = fileLength;
                needsSaving = true;
            }
            fileData.LastUpdated = Time.Get.LocalNowOffset;

            if (isNewFile)
            {
                persistentData.Entity.WurmLogFiles.Add(fileData.FileName, fileData);
            }
            if (needsSaving)
            {
                persistentData.FlagAsChanged();
            }
            return(fileData);
        }
Ejemplo n.º 4
0
 protected void FlagAsChanged()
 {
     persistent.FlagAsChanged();
 }