コード例 #1
0
ファイル: WurmCharacters.cs プロジェクト: imtheman/WurmApi
        public WurmCharacters([NotNull] IWurmCharacterDirectories characterDirectories,
            [NotNull] IWurmConfigs wurmConfigs, [NotNull] IWurmServers wurmServers,
            [NotNull] IWurmServerHistory wurmServerHistory, [NotNull] ILogger logger, 
            [NotNull] TaskManager taskManager)
        {
            this.characterDirectories = characterDirectories;
            this.wurmConfigs = wurmConfigs;
            this.wurmServers = wurmServers;
            this.wurmServerHistory = wurmServerHistory;
            this.logger = logger;
            this.taskManager = taskManager;
            if (characterDirectories == null) throw new ArgumentNullException("characterDirectories");
            if (wurmConfigs == null) throw new ArgumentNullException("wurmConfigs");
            if (wurmServers == null) throw new ArgumentNullException("wurmServers");
            if (wurmServerHistory == null) throw new ArgumentNullException("wurmServerHistory");
            if (logger == null) throw new ArgumentNullException("logger");
            if (taskManager == null) throw new ArgumentNullException("taskManager");

            var allChars = characterDirectories.GetAllCharacters();
            foreach (var characterName in allChars)
            {
                try
                {
                    Create(characterName);
                }
                catch (Exception exception)
                {
                    logger.Log(LogLevel.Error, "Could not initialize character for name {0}", this, exception);
                }
            }
        }
コード例 #2
0
ファイル: LogHistory.cs プロジェクト: imtheman/WurmApi
 public LogHistory(
     IWurmLogsHistory wurmLogsHistory,
     IWurmCharacterDirectories wurmCharacterDirectories,
     IWurmServerHistory wurmServerHistory,
     LogHistorySaved logHistorySaved,
     LogEntriesParser parser)
 {
     if (wurmLogsHistory == null) throw new ArgumentNullException("wurmLogsHistory");
     if (wurmCharacterDirectories == null) throw new ArgumentNullException("wurmCharacterDirectories");
     if (wurmServerHistory == null) throw new ArgumentNullException("wurmServerHistory");
     if (logHistorySaved == null) throw new ArgumentNullException("logHistorySaved");
     if (parser == null) throw new ArgumentNullException("parser");
     this.wurmLogsHistory = wurmLogsHistory;
     this.wurmCharacterDirectories = wurmCharacterDirectories;
     this.wurmServerHistory = wurmServerHistory;
     this.logHistorySaved = logHistorySaved;
     this.parser = parser;
 }
コード例 #3
0
ファイル: WurmServers.cs プロジェクト: imtheman/WurmApi
        public WurmServers(
            IWurmLogsHistory wurmLogsHistory,
            IWurmLogsMonitorInternal wurmLogsMonitor,
            IWurmServerList wurmServerList,
            IHttpWebRequests httpWebRequests,
            string dataDirectory,
            IWurmCharacterDirectories wurmCharacterDirectories,
            IWurmServerHistory wurmServerHistory,
            ILogger logger)
        {
            if (wurmLogsHistory == null) throw new ArgumentNullException("wurmLogsHistory");
            if (wurmLogsMonitor == null) throw new ArgumentNullException("wurmLogsMonitor");
            if (wurmServerList == null) throw new ArgumentNullException("wurmServerList");
            if (httpWebRequests == null) throw new ArgumentNullException("httpWebRequests");
            if (dataDirectory == null) throw new ArgumentNullException("dataDirectory");
            if (wurmCharacterDirectories == null) throw new ArgumentNullException("wurmCharacterDirectories");
            if (wurmServerHistory == null) throw new ArgumentNullException("wurmServerHistory");
            if (logger == null) throw new ArgumentNullException("logger");

            liveLogsDataQueue = new LiveLogsDataQueue(wurmLogsMonitor);
            LiveLogs liveLogs = new LiveLogs(liveLogsDataQueue, wurmServerHistory);

            persistentCollectionsLibrary =
                new PersistentCollectionsLibrary(new FlatFilesPersistenceStrategy(dataDirectory),
                    new PersObjErrorHandlingStrategy(logger));
            var persistent = persistentCollectionsLibrary.DefaultCollection.GetObject<ServersData>("WurmServers");
            LogHistorySaved logHistorySaved = new LogHistorySaved(persistent);
            LogHistory logHistory = new LogHistory(wurmLogsHistory, wurmCharacterDirectories, wurmServerHistory, logHistorySaved, new LogEntriesParser());

            WebFeeds webFeeds = new WebFeeds(httpWebRequests, wurmServerList, logger);

            runner = new QueuedJobsSyncRunner<Job, JobResult>(new JobRunner(liveLogs, logHistory, webFeeds, persistentCollectionsLibrary), logger);

            wurmServerFactory = new WurmServerFactory(runner);

            var descriptions = wurmServerList.All;
            foreach (var serverDescription in descriptions)
            {
                RegisterServer(serverDescription);
            }
        }
コード例 #4
0
ファイル: WurmCharacter.cs プロジェクト: imtheman/WurmApi
        public WurmCharacter([NotNull] CharacterName name, [NotNull] string playerDirectoryFullPath,
            [NotNull] IWurmConfigs wurmConfigs, [NotNull] IWurmServers wurmServers,
            [NotNull] IWurmServerHistory wurmServerHistory,
            [NotNull] ILogger logger, 
            [NotNull] TaskManager taskManager)
        {
            if (name == null) throw new ArgumentNullException("name");
            if (playerDirectoryFullPath == null) throw new ArgumentNullException("playerDirectoryFullPath");
            if (wurmConfigs == null) throw new ArgumentNullException("wurmConfigs");
            if (wurmServers == null) throw new ArgumentNullException("wurmServers");
            if (wurmServerHistory == null) throw new ArgumentNullException("wurmServerHistory");
            if (logger == null) throw new ArgumentNullException("logger");
            if (taskManager == null) throw new ArgumentNullException("taskManager");

            this.wurmConfigs = wurmConfigs;
            this.wurmServers = wurmServers;
            this.wurmServerHistory = wurmServerHistory;
            this.logger = logger;
            this.taskManager = taskManager;

            Name = name;
            configDefiningFileFullPath = Path.Combine(playerDirectoryFullPath, ConfigDefinerFileName);

            RefreshCurrentConfig();

            configUpdateTask = new TaskHandle(RefreshCurrentConfig, "Current config update for player " + Name);
            taskManager.Add(configUpdateTask);

            configFileWatcher = new FileSystemWatcher(playerDirectoryFullPath)
            {
                Filter = ConfigDefinerFileName
            };
            configFileWatcher.Changed += ConfigFileWatcherOnChanged;
            configFileWatcher.Created += ConfigFileWatcherOnChanged;
            configFileWatcher.Deleted += ConfigFileWatcherOnChanged;
            configFileWatcher.Renamed += ConfigFileWatcherOnChanged;
            configFileWatcher.EnableRaisingEvents = true;
            
            configUpdateTask.Trigger();
        }
コード例 #5
0
 public LogHistory(
     IWurmLogsHistory wurmLogsHistory,
     IWurmCharacterDirectories wurmCharacterDirectories,
     IWurmServerHistory wurmServerHistory,
     LogHistorySaved logHistorySaved,
     LogEntriesParser parser,
     [NotNull] IWurmApiLogger wurmApiLogger)
 {
     if (wurmLogsHistory == null)
     {
         throw new ArgumentNullException(nameof(wurmLogsHistory));
     }
     if (wurmCharacterDirectories == null)
     {
         throw new ArgumentNullException(nameof(wurmCharacterDirectories));
     }
     if (wurmServerHistory == null)
     {
         throw new ArgumentNullException(nameof(wurmServerHistory));
     }
     if (logHistorySaved == null)
     {
         throw new ArgumentNullException(nameof(logHistorySaved));
     }
     if (parser == null)
     {
         throw new ArgumentNullException(nameof(parser));
     }
     if (wurmApiLogger == null)
     {
         throw new ArgumentNullException(nameof(wurmApiLogger));
     }
     this.wurmLogsHistory          = wurmLogsHistory;
     this.wurmCharacterDirectories = wurmCharacterDirectories;
     this.wurmServerHistory        = wurmServerHistory;
     this.logHistorySaved          = logHistorySaved;
     this.parser        = parser;
     this.wurmApiLogger = wurmApiLogger;
 }
コード例 #6
0
ファイル: LiveLogs.cs プロジェクト: tiba666/WurmAssistant3
 public LiveLogs(LiveLogsDataQueue liveLogsDataQueue, IWurmServerHistory wurmServerHistory)
 {
     this.liveLogsDataQueue = liveLogsDataQueue;
     this.wurmServerHistory = wurmServerHistory;
 }
コード例 #7
0
        public WurmCharacter([NotNull] CharacterName name, [NotNull] string playerDirectoryFullPath,
                             [NotNull] IWurmConfigs wurmConfigs, [NotNull] IWurmServers wurmServers,
                             [NotNull] IWurmServerHistory wurmServerHistory,
                             [NotNull] IWurmApiLogger logger,
                             [NotNull] TaskManager taskManager, [NotNull] IWurmLogsMonitorInternal logsMonitor,
                             [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] InternalEventAggregator internalEventAggregator,
                             [NotNull] IWurmLogsHistory logsHistory, [NotNull] IWurmPaths wurmPaths,
                             [NotNull] IWurmServerGroups wurmServerGroups)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (playerDirectoryFullPath == null)
            {
                throw new ArgumentNullException(nameof(playerDirectoryFullPath));
            }
            if (wurmConfigs == null)
            {
                throw new ArgumentNullException(nameof(wurmConfigs));
            }
            if (wurmServers == null)
            {
                throw new ArgumentNullException(nameof(wurmServers));
            }
            if (wurmServerHistory == null)
            {
                throw new ArgumentNullException(nameof(wurmServerHistory));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (taskManager == null)
            {
                throw new ArgumentNullException(nameof(taskManager));
            }
            if (logsMonitor == null)
            {
                throw new ArgumentNullException(nameof(logsMonitor));
            }
            if (publicEventInvoker == null)
            {
                throw new ArgumentNullException(nameof(publicEventInvoker));
            }
            if (internalEventAggregator == null)
            {
                throw new ArgumentNullException(nameof(internalEventAggregator));
            }
            if (logsHistory == null)
            {
                throw new ArgumentNullException(nameof(logsHistory));
            }
            if (wurmPaths == null)
            {
                throw new ArgumentNullException(nameof(wurmPaths));
            }
            if (wurmServerGroups == null)
            {
                throw new ArgumentNullException(nameof(wurmServerGroups));
            }

            this.wurmConfigs             = wurmConfigs;
            this.wurmServers             = wurmServers;
            this.wurmServerHistory       = wurmServerHistory;
            this.logger                  = logger;
            this.taskManager             = taskManager;
            this.logsMonitor             = logsMonitor;
            this.publicEventInvoker      = publicEventInvoker;
            this.internalEventAggregator = internalEventAggregator;
            this.logsHistory             = logsHistory;
            this.wurmServerGroups        = wurmServerGroups;

            internalEventAggregator.Subscribe(this);

            Name = name;
            configDefiningFileFullPath = Path.Combine(playerDirectoryFullPath, ConfigDefinerFileName);

            RefreshCurrentConfig();

            configUpdateTask = new TaskHandle(RefreshCurrentConfig, "Current config update for player " + Name);
            taskManager.Add(configUpdateTask);

            configFileWatcher = new FileSystemWatcher(playerDirectoryFullPath)
            {
                Filter = ConfigDefinerFileName
            };
            configFileWatcher.Changed            += ConfigFileWatcherOnChanged;
            configFileWatcher.Created            += ConfigFileWatcherOnChanged;
            configFileWatcher.Deleted            += ConfigFileWatcherOnChanged;
            configFileWatcher.Renamed            += ConfigFileWatcherOnChanged;
            configFileWatcher.EnableRaisingEvents = true;

            configUpdateTask.Trigger();

            try
            {
                wurmServerHistory.BeginTracking(Name);
            }
            catch (Exception exception)
            {
                logger.Log(LogLevel.Error,
                           string.Format("Failed to initiate tracking of server history for character {0}", name),
                           this,
                           exception);
            }

            skills = new WurmCharacterSkills(this,
                                             publicEventInvoker,
                                             logsMonitor,
                                             logsHistory,
                                             logger,
                                             wurmPaths,
                                             internalEventAggregator);
            Logs = new WurmCharacterLogs(this, wurmServerGroups, logsHistory, wurmServers, logger);
        }
コード例 #8
0
ファイル: WurmServers.cs プロジェクト: tiba666/WurmAssistant3
        public WurmServers(
            [NotNull] IWurmLogsHistory wurmLogsHistory,
            [NotNull] IWurmLogsMonitorInternal wurmLogsMonitor,
            [NotNull] IWurmServerList wurmServerList,
            [NotNull] IHttpWebRequests httpWebRequests,
            [NotNull] string dataDirectory,
            [NotNull] IWurmCharacterDirectories wurmCharacterDirectories,
            [NotNull] IWurmServerHistory wurmServerHistory,
            [NotNull] IWurmApiLogger logger,
            [NotNull] IWurmServerGroups wurmServerGroups,
            [NotNull] IWurmApiConfig wurmApiConfig)
        {
            if (wurmLogsHistory == null)
            {
                throw new ArgumentNullException(nameof(wurmLogsHistory));
            }
            if (wurmLogsMonitor == null)
            {
                throw new ArgumentNullException(nameof(wurmLogsMonitor));
            }
            if (wurmServerList == null)
            {
                throw new ArgumentNullException(nameof(wurmServerList));
            }
            if (httpWebRequests == null)
            {
                throw new ArgumentNullException(nameof(httpWebRequests));
            }
            if (dataDirectory == null)
            {
                throw new ArgumentNullException(nameof(dataDirectory));
            }
            if (wurmCharacterDirectories == null)
            {
                throw new ArgumentNullException(nameof(wurmCharacterDirectories));
            }
            if (wurmServerHistory == null)
            {
                throw new ArgumentNullException(nameof(wurmServerHistory));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (wurmServerGroups == null)
            {
                throw new ArgumentNullException(nameof(wurmServerGroups));
            }
            if (wurmApiConfig == null)
            {
                throw new ArgumentNullException(nameof(wurmApiConfig));
            }

            this.wurmServerGroups = wurmServerGroups;
            this.wurmApiConfig    = wurmApiConfig;

            liveLogsDataQueue = new LiveLogsDataQueue(wurmLogsMonitor);
            LiveLogs liveLogs = new LiveLogs(liveLogsDataQueue, wurmServerHistory);

            IPersistenceStrategy persistenceStrategy = new FlatFilesPersistenceStrategy(dataDirectory);

            persistentCollectionsLibrary =
                new PersistentCollectionsLibrary(persistenceStrategy,
                                                 new PersObjErrorHandlingStrategy(logger));
            var             persistent      = persistentCollectionsLibrary.DefaultCollection.GetObject <ServersData>("WurmServers");
            LogHistorySaved logHistorySaved = new LogHistorySaved(persistent);
            LogHistory      logHistory      = new LogHistory(wurmLogsHistory,
                                                             wurmCharacterDirectories,
                                                             wurmServerHistory,
                                                             logHistorySaved,
                                                             new LogEntriesParser(),
                                                             logger);

            WebFeeds webFeeds = new WebFeeds(httpWebRequests, wurmServerList, logger);

            runner = new QueuedJobsSyncRunner <Job, JobResult>(new JobRunner(liveLogs, logHistory, webFeeds, persistentCollectionsLibrary), logger);

            wurmServerFactory = new WurmServerFactory(runner);

            var descriptions = wurmServerList.All;

            foreach (var serverDescription in descriptions)
            {
                RegisterServer(serverDescription);
            }
        }
コード例 #9
0
ファイル: LiveLogs.cs プロジェクト: imtheman/WurmApi
 public LiveLogs(LiveLogsDataQueue liveLogsDataQueue, IWurmServerHistory wurmServerHistory)
 {
     this.liveLogsDataQueue = liveLogsDataQueue;
     this.wurmServerHistory = wurmServerHistory;
 }
コード例 #10
0
        public WurmCharacters([NotNull] IWurmCharacterDirectories characterDirectories,
                              [NotNull] IWurmConfigs wurmConfigs, [NotNull] IWurmServers wurmServers,
                              [NotNull] IWurmServerHistory wurmServerHistory, [NotNull] IWurmApiLogger logger,
                              [NotNull] TaskManager taskManager, [NotNull] IWurmLogsMonitorInternal wurmLogsMonitor,
                              [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] InternalEventAggregator internalEventAggregator,
                              [NotNull] IWurmPaths wurmPaths, [NotNull] IWurmLogsHistory wurmLogsHistory,
                              [NotNull] IWurmServerGroups serverGroups)
        {
            this.characterDirectories = characterDirectories;
            this.wurmConfigs          = wurmConfigs;
            this.wurmServers          = wurmServers;
            this.wurmServerHistory    = wurmServerHistory;
            this.logger                  = logger;
            this.taskManager             = taskManager;
            this.wurmLogsMonitor         = wurmLogsMonitor;
            this.publicEventInvoker      = publicEventInvoker;
            this.internalEventAggregator = internalEventAggregator;
            this.wurmPaths               = wurmPaths;
            this.wurmLogsHistory         = wurmLogsHistory;
            this.serverGroups            = serverGroups;
            if (characterDirectories == null)
            {
                throw new ArgumentNullException(nameof(characterDirectories));
            }
            if (wurmConfigs == null)
            {
                throw new ArgumentNullException(nameof(wurmConfigs));
            }
            if (wurmServers == null)
            {
                throw new ArgumentNullException(nameof(wurmServers));
            }
            if (wurmServerHistory == null)
            {
                throw new ArgumentNullException(nameof(wurmServerHistory));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (taskManager == null)
            {
                throw new ArgumentNullException(nameof(taskManager));
            }
            if (wurmLogsMonitor == null)
            {
                throw new ArgumentNullException(nameof(wurmLogsMonitor));
            }
            if (publicEventInvoker == null)
            {
                throw new ArgumentNullException(nameof(publicEventInvoker));
            }
            if (internalEventAggregator == null)
            {
                throw new ArgumentNullException(nameof(internalEventAggregator));
            }
            if (wurmPaths == null)
            {
                throw new ArgumentNullException(nameof(wurmPaths));
            }
            if (wurmLogsHistory == null)
            {
                throw new ArgumentNullException(nameof(wurmLogsHistory));
            }
            if (serverGroups == null)
            {
                throw new ArgumentNullException(nameof(serverGroups));
            }

            var allChars = characterDirectories.GetAllCharacters();

            foreach (var characterName in allChars)
            {
                try
                {
                    Create(characterName);
                }
                catch (Exception exception)
                {
                    logger.Log(LogLevel.Error,
                               string.Format("Could not initialize character for name {0}", characterName),
                               this,
                               exception);
                }
            }
        }