public LogsMonitorEngineManager( [NotNull] CharacterName characterName, [NotNull] CharacterLogsMonitorEngineFactory characterLogsMonitorEngineFactory, [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] IWurmApiLogger logger, [NotNull] IInternalEventInvoker internalEventInvoker) { if (characterName == null) { throw new ArgumentNullException(nameof(characterName)); } if (characterLogsMonitorEngineFactory == null) { throw new ArgumentNullException(nameof(characterLogsMonitorEngineFactory)); } if (publicEventInvoker == null) { throw new ArgumentNullException(nameof(publicEventInvoker)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (internalEventInvoker == null) { throw new ArgumentNullException(nameof(internalEventInvoker)); } this.characterName = characterName; this.publicEventInvoker = publicEventInvoker; this.logger = logger; this.internalEventInvoker = internalEventInvoker; engine = characterLogsMonitorEngineFactory.Create(characterName); }
internal WurmConfigs( [NotNull] IWurmConfigDirectories wurmConfigDirectories, [NotNull] IWurmApiLogger logger, [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] IInternalEventAggregator eventAggregator, [NotNull] TaskManager taskManager) { if (wurmConfigDirectories == null) { throw new ArgumentNullException(nameof(wurmConfigDirectories)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (publicEventInvoker == null) { throw new ArgumentNullException(nameof(publicEventInvoker)); } if (eventAggregator == null) { throw new ArgumentNullException(nameof(eventAggregator)); } if (taskManager == null) { throw new ArgumentNullException(nameof(taskManager)); } this.wurmConfigDirectories = wurmConfigDirectories; this.logger = logger; this.publicEventInvoker = publicEventInvoker; this.eventAggregator = eventAggregator; this.taskManager = taskManager; onAvailableConfigsChanged = publicEventInvoker.Create( () => AvailableConfigsChanged.SafeInvoke(this, EventArgs.Empty), WurmApiTuningParams.PublicEventMarshallerDelay); onAnyConfigChanged = publicEventInvoker.Create( () => AnyConfigChanged.SafeInvoke(this, EventArgs.Empty), WurmApiTuningParams.PublicEventMarshallerDelay); try { Refresh(); } catch (Exception exception) { logger.Log(LogLevel.Error, "Error at initial configs update", this, exception); } taskHandle = new TaskHandle(Refresh, "WurmConfigs update"); taskManager.Add(taskHandle); eventAggregator.Subscribe(this); taskHandle.Trigger(); }
internal WurmConfig(string gameSettingsFullPath, [NotNull] IPublicEventInvoker publicEventMarshaller, [NotNull] TaskManager taskManager, IWurmApiLogger logger) { if (gameSettingsFullPath == null) { throw new ArgumentNullException(nameof(gameSettingsFullPath)); } if (taskManager == null) { throw new ArgumentNullException(nameof(taskManager)); } gameSettingsFileInfo = new FileInfo(gameSettingsFullPath); if (gameSettingsFileInfo.Directory == null) { throw new WurmApiException("gameSettingsFileInfo.Directory is null, provided file raw path: " + gameSettingsFullPath); } Name = gameSettingsFileInfo.Directory.Name; this.taskManager = taskManager; onConfigChanged = publicEventMarshaller.Create(() => ConfigChanged.SafeInvoke(this, EventArgs.Empty), WurmApiTuningParams.PublicEventMarshallerDelay); configReader = new ConfigReader(this); try { Refresh(); } catch (Exception exception) { logger.Log(LogLevel.Error, "Error at initial config update: " + Name, this, exception); } configFileWatcher = new FileSystemWatcher(gameSettingsFileInfo.Directory.FullName) { Filter = gameSettingsFileInfo.Name, NotifyFilter = NotifyFilters.Size | NotifyFilters.LastWrite }; configFileWatcher.Changed += ConfigFileWatcherOnChanged; configFileWatcher.Created += ConfigFileWatcherOnChanged; configFileWatcher.Deleted += ConfigFileWatcherOnChanged; configFileWatcher.Renamed += ConfigFileWatcherOnChanged; configFileWatcher.EnableRaisingEvents = true; taskHandle = new TaskHandle(Refresh, "WurmConfig update: " + Name); taskManager.Add(taskHandle); taskHandle.Trigger(); }
public WurmCharacterSkills([NotNull] IWurmCharacter character, [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] IWurmLogsMonitorInternal logsMonitor, [NotNull] IWurmLogsHistory logsHistory, [NotNull] IWurmApiLogger logger, IWurmPaths wurmPaths, [NotNull] IInternalEventAggregator internalEventAggregator) { if (character == null) { throw new ArgumentNullException(nameof(character)); } if (publicEventInvoker == null) { throw new ArgumentNullException(nameof(publicEventInvoker)); } if (logsMonitor == null) { throw new ArgumentNullException(nameof(logsMonitor)); } if (logsHistory == null) { throw new ArgumentNullException(nameof(logsHistory)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } if (internalEventAggregator == null) { throw new ArgumentNullException(nameof(internalEventAggregator)); } this.character = character; this.publicEventInvoker = publicEventInvoker; this.logsMonitor = logsMonitor; this.logsHistory = logsHistory; this.logger = logger; skillsMap = new SkillsMap(); skillDumps = new SkillDumpsManager(character, wurmPaths, logger); UpdateCurrentServer(); onSkillsChanged = publicEventInvoker.Create( InvokeOnSkillsChanged, WurmApiTuningParams.PublicEventMarshallerDelay); internalEventAggregator.Subscribe(this); logsMonitor.SubscribeInternal(character.Name, LogType.Skills, EventHandler); }
public LogsMonitorEngineManager( [NotNull] CharacterName characterName, [NotNull] CharacterLogsMonitorEngineFactory characterLogsMonitorEngineFactory, [NotNull] IPublicEventInvoker publicEventInvoker, [NotNull] ILogger logger, [NotNull] IInternalEventInvoker internalEventInvoker) { if (characterName == null) throw new ArgumentNullException("characterName"); if (characterLogsMonitorEngineFactory == null) throw new ArgumentNullException("characterLogsMonitorEngineFactory"); if (publicEventInvoker == null) throw new ArgumentNullException("publicEventInvoker"); if (logger == null) throw new ArgumentNullException("logger"); if (internalEventInvoker == null) throw new ArgumentNullException("internalEventInvoker"); this.characterName = characterName; this.characterLogsMonitorEngineFactory = characterLogsMonitorEngineFactory; this.publicEventInvoker = publicEventInvoker; this.logger = logger; this.internalEventInvoker = internalEventInvoker; engine = characterLogsMonitorEngineFactory.Create(characterName); }
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(); }
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); }
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); } } }