public MonthlyHeuristicsExtractor(
     LogFileInfo logFileInfo,
     LogFileStreamReaderFactory logFileStreamReaderFactory,
     IWurmApiLogger logger, [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logFileInfo == null)
     {
         throw new ArgumentNullException(nameof(logFileInfo));
     }
     if (logFileStreamReaderFactory == null)
     {
         throw new ArgumentNullException(nameof(logFileStreamReaderFactory));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (wurmApiConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmApiConfig));
     }
     this.logFileInfo = logFileInfo;
     this.logFileStreamReaderFactory = logFileStreamReaderFactory;
     this.logger        = logger;
     this.wurmApiConfig = wurmApiConfig;
 }
Example #2
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;
 }
 public SingleFileMonitorFactory(
     LogFileStreamReaderFactory streamReaderFactory,
     LogFileParser logFileParser)
 {
     if (streamReaderFactory == null)
     {
         throw new ArgumentNullException(nameof(streamReaderFactory));
     }
     if (logFileParser == null)
     {
         throw new ArgumentNullException(nameof(logFileParser));
     }
     this.streamReaderFactory = streamReaderFactory;
     this.logFileParser       = logFileParser;
 }
        public WurmLogsHistory([NotNull] IWurmLogFiles wurmLogFiles, [NotNull] IWurmApiLogger logger,
                               [NotNull] string heuristicsDataDirectory, [NotNull] LogFileStreamReaderFactory logFileStreamReaderFactory,
                               [NotNull] IWurmApiConfig wurmApiConfig)
        {
            if (wurmLogFiles == null)
            {
                throw new ArgumentNullException(nameof(wurmLogFiles));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (heuristicsDataDirectory == null)
            {
                throw new ArgumentNullException(nameof(heuristicsDataDirectory));
            }
            if (logFileStreamReaderFactory == null)
            {
                throw new ArgumentNullException(nameof(logFileStreamReaderFactory));
            }
            if (wurmApiConfig == null)
            {
                throw new ArgumentNullException(nameof(wurmApiConfig));
            }

            IPersistenceStrategy persistenceStrategy = new FlatFilesPersistenceStrategy(heuristicsDataDirectory);

            var persistentLibrary =
                new PersistentCollectionsLibrary(persistenceStrategy,
                                                 new PersObjErrorHandlingStrategy(logger));
            var heuristicsCollection = persistentLibrary.GetCollection("heuristics");

            var logsScannerFactory = new LogsScannerFactory(
                new LogFileParserFactory(logger),
                logFileStreamReaderFactory,
                new MonthlyLogFilesHeuristics(
                    heuristicsCollection,
                    wurmLogFiles,
                    new MonthlyHeuristicsExtractorFactory(logFileStreamReaderFactory, logger, wurmApiConfig)),
                wurmLogFiles,
                logger,
                wurmApiConfig);

            runner =
                new QueuedJobsSyncRunner <LogSearchParameters, ScanResult>(
                    new ScanJobExecutor(logsScannerFactory, persistentLibrary, logger),
                    logger);
        }
Example #5
0
        public void Setup()
        {
            wurmApiConfig = new WurmApiConfig {
                Platform = Platform.Linux
            };

            system = new LogFileStreamReaderFactory(wurmApiConfig);

            ubuntuDir = TempDirectoriesFactory.CreateByUnzippingFile(Path.Combine(TestPaksZippedDirFullPath,
                                                                                  "ubuntu-wurm-dir.7z"));

            sampleLogFilePath = Path.Combine(ubuntuDir.AbsolutePath,
                                             "players",
                                             "aldur",
                                             "logs",
                                             "_Event.2015-08.txt");
        }
Example #6
0
 public LogsScannerFactory(
     LogFileParserFactory logFileParserFactory,
     LogFileStreamReaderFactory streamReaderFactory,
     MonthlyLogFilesHeuristics heuristics,
     IWurmLogFiles wurmLogFiles,
     IWurmApiLogger logger, [NotNull] IWurmApiConfig wurmApiConfig)
 {
     if (logFileParserFactory == null)
     {
         throw new ArgumentNullException(nameof(logFileParserFactory));
     }
     if (streamReaderFactory == null)
     {
         throw new ArgumentNullException(nameof(streamReaderFactory));
     }
     if (heuristics == null)
     {
         throw new ArgumentNullException(nameof(heuristics));
     }
     if (wurmLogFiles == null)
     {
         throw new ArgumentNullException(nameof(wurmLogFiles));
     }
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     if (wurmApiConfig == null)
     {
         throw new ArgumentNullException(nameof(wurmApiConfig));
     }
     this.logFileParserFactory = logFileParserFactory;
     this.streamReaderFactory  = streamReaderFactory;
     this.heuristics           = heuristics;
     this.wurmLogFiles         = wurmLogFiles;
     this.logger        = logger;
     this.wurmApiConfig = wurmApiConfig;
 }
        public SingleFileMonitor(
            LogFileInfo logFileInfo,
            LogFileStreamReaderFactory streamReaderFactory,
            LogFileParser logFileParser)
        {
            if (logFileInfo == null)
            {
                throw new ArgumentNullException(nameof(logFileInfo));
            }
            if (streamReaderFactory == null)
            {
                throw new ArgumentNullException(nameof(streamReaderFactory));
            }
            if (logFileParser == null)
            {
                throw new ArgumentNullException(nameof(logFileParser));
            }
            this.logFileInfo         = logFileInfo;
            this.streamReaderFactory = streamReaderFactory;
            this.logFileParser       = logFileParser;

            fileInfo     = new FileInfo(logFileInfo.FullPath);
            lastFileSize = fileInfo.Length;
        }
        public WurmLogsMonitor([NotNull] IWurmLogFiles wurmLogFiles, [NotNull] IWurmApiLogger logger,
                               [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] IInternalEventAggregator internalEventAggregator,
                               [NotNull] IWurmCharacterDirectories wurmCharacterDirectories,
                               [NotNull] InternalEventInvoker internalEventInvoker, [NotNull] TaskManager taskManager,
                               [NotNull] LogFileStreamReaderFactory logFileStreamReaderFactory)
        {
            if (wurmLogFiles == null)
            {
                throw new ArgumentNullException(nameof(wurmLogFiles));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (publicEventInvoker == null)
            {
                throw new ArgumentNullException(nameof(publicEventInvoker));
            }
            if (internalEventAggregator == null)
            {
                throw new ArgumentNullException(nameof(internalEventAggregator));
            }
            if (wurmCharacterDirectories == null)
            {
                throw new ArgumentNullException(nameof(wurmCharacterDirectories));
            }
            if (internalEventInvoker == null)
            {
                throw new ArgumentNullException(nameof(internalEventInvoker));
            }
            if (taskManager == null)
            {
                throw new ArgumentNullException(nameof(taskManager));
            }
            if (logFileStreamReaderFactory == null)
            {
                throw new ArgumentNullException(nameof(logFileStreamReaderFactory));
            }
            this.wurmLogFiles               = wurmLogFiles;
            this.logger                     = logger;
            this.publicEventInvoker         = publicEventInvoker;
            this.internalEventAggregator    = internalEventAggregator;
            this.wurmCharacterDirectories   = wurmCharacterDirectories;
            this.internalEventInvoker       = internalEventInvoker;
            this.taskManager                = taskManager;
            this.logFileStreamReaderFactory = logFileStreamReaderFactory;

            try
            {
                Rebuild();
            }
            catch (Exception exception)
            {
                logger.Log(LogLevel.Error, "Error at WurmLogsMonitor initial rebuild", this, exception);
            }

            internalEventAggregator.Subscribe(this);

            taskHandle = new TaskHandle(Rebuild, "WurmLogsMonitor rebuild");
            taskManager.Add(taskHandle);

            updater = new Task(() =>
            {
                while (true)
                {
                    if (stop)
                    {
                        return;
                    }
                    Thread.Sleep(500);
                    if (stop)
                    {
                        return;
                    }

                    try
                    {
                        foreach (var logsMonitorEngineManager in characterNameToEngineManagers.Values)
                        {
                            logsMonitorEngineManager.Update(allEventSubscriptionsTsafe);
                        }
                    }
                    catch (Exception exception)
                    {
                        logger.Log(LogLevel.Error, "WurmLogsMonitor 'updater' task crashed", this, exception);
                    }
                }
            }, TaskCreationOptions.LongRunning);
            updater.Start();

            taskHandle.Trigger();
        }
Example #9
0
        void ConstructSystems(string wurmApiDataDirectoryFullPath, IWurmClientInstallDirectory installDirectory,
                              IHttpWebRequests httpWebRequests, IWurmApiLogger logger, IWurmApiEventMarshaller publicEventMarshaller,
                              IWurmApiEventMarshaller internalEventMarshaller, WurmApiConfig wurmApiConfig)
        {
            IWurmApiConfig internalWurmApiConfig = wurmApiConfig.CreateCopy();

            LogFileStreamReaderFactory logFileStreamReaderFactory = Wire(new LogFileStreamReaderFactory(internalWurmApiConfig));

            Wire(installDirectory);
            Wire(httpWebRequests);

            if (logger == null)
            {
                logger = new WurmApiLoggerStub();
            }

            PublicEventInvoker publicEventInvoker = Wire(new PublicEventInvoker(publicEventMarshaller, logger));

            TaskManager taskManager = Wire(new TaskManager(logger));

            InternalEventAggregator internalEventAggregator = Wire(new InternalEventAggregator());

            InternalEventInvoker internalEventInvoker =
                Wire(new InternalEventInvoker(internalEventAggregator, logger, internalEventMarshaller));

            WurmPaths        paths        = Wire(new WurmPaths(installDirectory, wurmApiConfig));
            WurmServerGroups serverGroups = Wire(new WurmServerGroups(internalWurmApiConfig.ServerInfoMap));

            WurmServerList serverList = Wire(new WurmServerList(internalWurmApiConfig.ServerInfoMap));

            WurmLogDefinitions logDefinitions = Wire(new WurmLogDefinitions());

            WurmConfigDirectories configDirectories =
                Wire(new WurmConfigDirectories(paths, internalEventAggregator, taskManager, logger));
            WurmCharacterDirectories characterDirectories =
                Wire(new WurmCharacterDirectories(paths, internalEventAggregator, taskManager, logger));
            WurmLogFiles logFiles =
                Wire(new WurmLogFiles(characterDirectories,
                                      logger,
                                      logDefinitions,
                                      internalEventAggregator,
                                      internalEventInvoker,
                                      taskManager,
                                      paths));

            WurmLogsMonitor logsMonitor =
                Wire(new WurmLogsMonitor(logFiles,
                                         logger,
                                         publicEventInvoker,
                                         internalEventAggregator,
                                         characterDirectories,
                                         internalEventInvoker,
                                         taskManager,
                                         logFileStreamReaderFactory));
            var heuristicsDataDirectory = Path.Combine(wurmApiDataDirectoryFullPath, "WurmLogsHistory");

            if (internalWurmApiConfig.ClearAllCaches)
            {
                ClearDir(heuristicsDataDirectory, logger);
            }

            WurmLogsHistory logsHistory =
                Wire(new WurmLogsHistory(logFiles,
                                         logger,
                                         heuristicsDataDirectory,
                                         logFileStreamReaderFactory,
                                         wurmApiConfig));

            WurmConfigs wurmConfigs =
                Wire(new WurmConfigs(configDirectories,
                                     logger,
                                     publicEventInvoker,
                                     internalEventAggregator,
                                     taskManager));
            WurmAutoruns autoruns = Wire(new WurmAutoruns(wurmConfigs, characterDirectories, logger));

            var wurmServerHistoryDataDirectory = Path.Combine(wurmApiDataDirectoryFullPath, "WurmServerHistory");

            if (internalWurmApiConfig.ClearAllCaches)
            {
                ClearDir(wurmServerHistoryDataDirectory, logger);
            }
            WurmServerHistory wurmServerHistory =
                Wire(new WurmServerHistory(wurmServerHistoryDataDirectory,
                                           logsHistory,
                                           serverList,
                                           logger,
                                           logsMonitor,
                                           logFiles,
                                           internalEventAggregator,
                                           serverGroups,
                                           wurmApiConfig));

            var wurmServersDataDirectory = Path.Combine(wurmApiDataDirectoryFullPath, "WurmServers");

            if (internalWurmApiConfig.ClearAllCaches)
            {
                ClearDir(wurmServersDataDirectory, logger);
            }
            WurmServers wurmServers =
                Wire(new WurmServers(logsHistory,
                                     logsMonitor,
                                     serverList,
                                     httpWebRequests,
                                     wurmServersDataDirectory,
                                     characterDirectories,
                                     wurmServerHistory,
                                     logger,
                                     serverGroups,
                                     wurmApiConfig));

            WurmCharacters characters =
                Wire(new WurmCharacters(characterDirectories,
                                        wurmConfigs,
                                        wurmServers,
                                        wurmServerHistory,
                                        logger,
                                        taskManager,
                                        logsMonitor,
                                        publicEventInvoker,
                                        internalEventAggregator,
                                        paths,
                                        logsHistory,
                                        serverGroups));

            HttpWebRequests          = httpWebRequests;
            Autoruns                 = autoruns;
            Characters               = characters;
            Configs                  = wurmConfigs;
            LogDefinitions           = logDefinitions;
            LogsHistory              = logsHistory;
            LogsMonitor              = logsMonitor;
            Servers                  = wurmServers;
            WurmLogFiles             = logFiles;
            WurmServerHistory        = wurmServerHistory;
            WurmCharacterDirectories = characterDirectories;
            WurmConfigDirectories    = configDirectories;
            InternalEventAggregator  = internalEventAggregator;
            Paths        = paths;
            ServerGroups = serverGroups;
            Logger       = logger;
            ServersList  = serverList;
        }