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); }