Exemplo n.º 1
0
        public override ScanResult Execute(LogSearchParameters logSearchParameters, JobCancellationManager jobCancellationManager)
        {
            try
            {
                var scanner = logsScannerFactory.Create(logSearchParameters, jobCancellationManager);
                var results = scanner.Scan();

                try
                {
                    persistentLibrary.SaveChanged();
                }
                catch (Exception exception)
                {
                    logger.Log(LogLevel.Error, "Error at saving persistent data for WurmLogsHistory", this, exception);
                }

                return(results);
            }
            catch (Exception exception)
            {
                var canceledException = exception as OperationCanceledException;
                if (canceledException == null)
                {
                    logger.Log(LogLevel.Error,
                               string.Format("Error during scan job execution, search params: {0}", logSearchParameters),
                               this,
                               exception);
                }
                throw;
            }
        }
Exemplo n.º 2
0
 public LogsScanner(
     [NotNull] LogSearchParameters logSearchParameters, 
     [NotNull] JobCancellationManager cancellationManager,
     [NotNull] IWurmLogFiles wurmLogFiles,
     [NotNull] MonthlyLogFilesHeuristics monthlyHeuristics,
     [NotNull] LogFileStreamReaderFactory streamReaderFactory,
     [NotNull] ILogger logger,
     [NotNull] LogFileParserFactory logFileParserFactory, 
     [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logSearchParameters == null) throw new ArgumentNullException("logSearchParameters");
     if (cancellationManager == null) throw new ArgumentNullException("cancellationManager");
     if (wurmLogFiles == null) throw new ArgumentNullException("wurmLogFiles");
     if (monthlyHeuristics == null) throw new ArgumentNullException("monthlyHeuristics");
     if (streamReaderFactory == null) throw new ArgumentNullException("streamReaderFactory");
     if (logger == null) throw new ArgumentNullException("logger");
     if (logFileParserFactory == null) throw new ArgumentNullException("logFileParserFactory");
     if (wurmApiConfig == null) throw new ArgumentNullException("wurmApiConfig");
     this.logSearchParameters = logSearchParameters;
     this.cancellationManager = cancellationManager;
     this.wurmLogFiles = wurmLogFiles;
     this.monthlyHeuristics = monthlyHeuristics;
     this.streamReaderFactory = streamReaderFactory;
     this.logger = logger;
     this.logFileParserFactory = logFileParserFactory;
     this.wurmApiConfig = wurmApiConfig;
 }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Extracts all lines matching scan parameters.
 /// </summary>
 /// <returns></returns>
 public LogsScanner Create(LogSearchParameters logSearchParameters, JobCancellationManager cancellationManager)
 {
     return new LogsScanner(
         logSearchParameters,
         cancellationManager,
         wurmLogFiles,
         heuristics,
         streamReaderFactory,
         logger,
         logFileParserFactory,
         wurmApiConfig);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Extracts all lines matching scan parameters.
 /// </summary>
 /// <returns></returns>
 public LogsScanner Create(LogSearchParameters logSearchParameters, JobCancellationManager cancellationManager)
 {
     return(new LogsScanner(
                logSearchParameters,
                cancellationManager,
                wurmLogFiles,
                heuristics,
                streamReaderFactory,
                logger,
                logFileParserFactory,
                wurmApiConfig));
 }
Exemplo n.º 6
0
 public LogsScanner(
     [NotNull] LogSearchParameters logSearchParameters,
     [NotNull] JobCancellationManager cancellationManager,
     [NotNull] IWurmLogFiles wurmLogFiles,
     [NotNull] MonthlyLogFilesHeuristics monthlyHeuristics,
     [NotNull] LogFileStreamReaderFactory streamReaderFactory,
     [NotNull] IWurmApiLogger logger,
     [NotNull] LogFileParserFactory logFileParserFactory,
     [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logSearchParameters == null)
     {
         throw new ArgumentNullException(nameof(logSearchParameters));
     }
     if (cancellationManager == null)
     {
         throw new ArgumentNullException(nameof(cancellationManager));
     }
     if (wurmLogFiles == null)
     {
         throw new ArgumentNullException(nameof(wurmLogFiles));
     }
     if (monthlyHeuristics == null)
     {
         throw new ArgumentNullException(nameof(monthlyHeuristics));
     }
     if (streamReaderFactory == null)
     {
         throw new ArgumentNullException(nameof(streamReaderFactory));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (logFileParserFactory == null)
     {
         throw new ArgumentNullException(nameof(logFileParserFactory));
     }
     if (wurmApiConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmApiConfig));
     }
     this.logSearchParameters = logSearchParameters;
     this.cancellationManager = cancellationManager;
     this.wurmLogFiles        = wurmLogFiles;
     this.monthlyHeuristics   = monthlyHeuristics;
     this.streamReaderFactory = streamReaderFactory;
     this.logger = logger;
     this.logFileParserFactory = logFileParserFactory;
     this.wurmApiConfig        = wurmApiConfig;
 }
Exemplo n.º 7
0
        /// <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,
                    DateFrom = dateFrom,
                    DateTo = 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);
        }
Exemplo n.º 8
0
        /// <summary>
        /// True if any data found
        /// </summary>
        private bool SearchLogsBackwards(DateTime datetimeTo, JobCancellationManager jobCancellationManager)
        {
            var dateFrom = datetimeTo - TimeSpan.FromDays(30);

            if (datetimeTo < wurmCharacterLogFiles.OldestLogFileDate)
            {
                return false;
            }

            var results = logsSearcher.Scan(
                new LogSearchParameters()
                {
                    CharacterName = characterName,
                    DateFrom = dateFrom,
                    DateTo = datetimeTo,
                    LogType = LogType.Event
                }, jobCancellationManager.GetLinkedToken());

            UpdateEntity(dateFrom, datetimeTo);

            var found = ParseForServerInfo(results);
            if (found)
            {
                return true;
            }

            return SearchLogsBackwards(dateFrom, jobCancellationManager);
        }
Exemplo n.º 9
0
        public ServerName TryGetCurrentServer(JobCancellationManager jobCancellationManager)
        {
            ParsePendingLiveLogEvents();

            if (currentLiveLogsServer != null)
            {
                return currentLiveLogsServer;
            }
            return TryGetAtTimestamp(Time.Get.LocalNow, jobCancellationManager);
        }