コード例 #1
0
        public virtual CharacterMonthlyLogHeuristics GetForCharacter(CharacterName characterName)
        {
            if (characterName == null) throw new ArgumentNullException("characterName");

            CharacterMonthlyLogHeuristics heuristics;
            if (!cache.TryGetValue(characterName, out heuristics))
            {
                IPersistent<WurmCharacterLogsEntity> persistentData =
                    heuristicsPersistentCollection.GetObject<WurmCharacterLogsEntity>(characterName.Normalized);
                heuristics = new CharacterMonthlyLogHeuristics(
                    persistentData,
                    monthlyHeuristicsExtractorFactory,
                    wurmLogFiles.GetForCharacter(characterName));
                cache.Add(characterName, heuristics);
            }
            return heuristics;
        }
コード例 #2
0
        public virtual CharacterMonthlyLogHeuristics GetForCharacter(CharacterName characterName)
        {
            if (characterName == null)
            {
                throw new ArgumentNullException(nameof(characterName));
            }

            CharacterMonthlyLogHeuristics heuristics;

            if (!cache.TryGetValue(characterName, out heuristics))
            {
                IPersistent <WurmCharacterLogsEntity> persistentData =
                    heuristicsPersistentCollection.GetObject <WurmCharacterLogsEntity>(characterName.Normalized);
                heuristics = new CharacterMonthlyLogHeuristics(
                    persistentData,
                    monthlyHeuristicsExtractorFactory,
                    wurmLogFiles.GetForCharacter(characterName));
                cache.Add(characterName, heuristics);
            }
            return(heuristics);
        }
コード例 #3
0
ファイル: LogsScanner.cs プロジェクト: imtheman/WurmApi
        private IList<LogEntry> GetEntries(
            IEnumerable<LogFileInfo> logFileInfos,
            CharacterMonthlyLogHeuristics heuristicsFileMap)
        {
            var parsingHelper = logFileParserFactory.Create();

            List<LogEntry> result = new List<LogEntry>();
            IOrderedEnumerable<LogFileInfo> orderedLogFileInfos =
                logFileInfos.OrderBy(info => info.LogFileDate.DateTime);

            foreach (LogFileInfo logFileInfo in orderedLogFileInfos)
            {
                if (logFileInfo.LogFileDate.LogSavingType == LogSavingType.Monthly)
                {
                    ParseMonthlyFile(heuristicsFileMap, logFileInfo, result, parsingHelper);
                }
                else if (logFileInfo.LogFileDate.LogSavingType == LogSavingType.Daily)
                {
                    ParseDailyFile(logFileInfo, result, parsingHelper);
                }
                else
                {
                    logger.Log(
                        LogLevel.Warn,
                        string.Format(
                            "LogsScanner encountered and skipped file with unsupported saving type, type: {0}, file: {1}",
                            logFileInfo.LogFileDate.LogSavingType,
                            logFileInfo.FullPath),
                        this,
                        null);
                }

                cancellationManager.ThrowIfCancelled();
            }
            return result;
        }
コード例 #4
0
ファイル: LogsScanner.cs プロジェクト: imtheman/WurmApi
        private void ParseMonthlyFile(
            CharacterMonthlyLogHeuristics heuristicsFileMap,
            LogFileInfo logFileInfo,
            List<LogEntry> result,
            LogFileParser logFileParser)
        {
            var heuristics = heuristicsFileMap.GetFullHeuristicsForMonth(logFileInfo);
            var dayToSearchFrom = GetMinDayToSearchFrom(logSearchParameters.DateFrom, logFileInfo.LogFileDate.DateTime);
            var dayToSearchTo = GetMaxDayToSearchUpTo(logSearchParameters.DateTo, logFileInfo.LogFileDate.DateTime);
            LogFileStreamReader reader = null;
            try
            {
                for (int day = dayToSearchFrom; day <= dayToSearchTo; day++)
                {
                    var thisDayHeuristics = heuristics.GetForDay(day);

                    if (thisDayHeuristics.LinesLength == 0) continue;

                    if (reader == null)
                    {
                        if (heuristics.HasValidFilePositions)
                        {
                            reader = streamReaderFactory.Create(
                                logFileInfo.FullPath,
                                thisDayHeuristics.StartPositionInBytes);
                        }
                        else
                        {
                            reader = streamReaderFactory.CreateWithLineCountFastForward(
                                logFileInfo.FullPath,
                                thisDayHeuristics.TotalLinesSinceBeginFile);
                        }
                    }
                    var thisEntryDate = new DateTime(
                        logFileInfo.LogFileDate.DateTime.Year,
                        logFileInfo.LogFileDate.DateTime.Month,
                        day,
                        0,
                        0,
                        0);

                    int readLinesCount = 0;
                    List<string> allLines = new List<string>();

                    string currentLine;
                    while ((currentLine = reader.TryReadNextLine()) != null)
                    {
                        allLines.Add(currentLine);
                        readLinesCount++;
                        if (readLinesCount == thisDayHeuristics.LinesLength)
                        {
                            break;
                        }
                    }

                    IEnumerable<LogEntry> parsedLines = logFileParser.ParseLinesForDay(allLines,
                        thisEntryDate,
                        logFileInfo);
                    result.AddRange(parsedLines);

                    cancellationManager.ThrowIfCancelled();
                }
            }
            finally
            {
                if (reader != null) reader.Dispose();
            }
        }