internal void Trigger(InternalEvent internalEvent) { EventManager em; if (events.TryGetValue(internalEvent, out em)) { em.Pending = 1; } }
public EventManager([NotNull] InternalEvent internalEvent, TimeSpan betweenDelay, [NotNull] Func<Message> messageFactory) { if (internalEvent == null) throw new ArgumentNullException(nameof(internalEvent)); if (messageFactory == null) throw new ArgumentNullException(nameof(messageFactory)); InternalEvent = internalEvent; BetweenDelay = betweenDelay; MessageFactory = messageFactory; }
internal WurmCharacterLogFiles([NotNull] CharacterName characterName, [NotNull] string fullDirPathToCharacterLogsDir, [NotNull] ILogger logger, [NotNull] LogFileInfoFactory logFileInfoFactory, [NotNull] IInternalEventInvoker internalEventInvoker, [NotNull] TaskManager taskManager) { if (characterName == null) throw new ArgumentNullException("characterName"); if (fullDirPathToCharacterLogsDir == null) throw new ArgumentNullException("fullDirPathToCharacterLogsDir"); if (logger == null) throw new ArgumentNullException("logger"); if (logFileInfoFactory == null) throw new ArgumentNullException("logFileInfoFactory"); if (internalEventInvoker == null) throw new ArgumentNullException("internalEventInvoker"); if (taskManager == null) throw new ArgumentNullException("taskManager"); this.logger = logger; this.logFileInfoFactory = logFileInfoFactory; this.taskManager = taskManager; CharacterName = characterName; FullDirPathToCharacterLogsDir = fullDirPathToCharacterLogsDir; onFilesAddedOrRemoved = internalEventInvoker.Create(() => new CharacterLogFilesAddedOrRemoved(CharacterName)); try { Refresh(); } catch (Exception exception) { logger.Log(LogLevel.Error, "Error at initial WurmCharacterLogFiles refresh: " + CharacterName, this, exception); } directoryWatcher = new FileSystemWatcher(fullDirPathToCharacterLogsDir) { Filter = "*.txt", NotifyFilter = NotifyFilters.FileName }; directoryWatcher.Created += DirectoryWatcherOnChanged; directoryWatcher.Deleted += DirectoryWatcherOnChanged; directoryWatcher.Renamed += DirectoryWatcherOnChanged; directoryWatcher.Changed += DirectoryWatcherOnChanged; directoryWatcher.EnableRaisingEvents = true; taskHandle = new TaskHandle(Refresh, "WurmCharacterLogFiles refresh: " + CharacterName); taskManager.Add(taskHandle); taskHandle.Trigger(); }
internal void Detach(InternalEvent internalEvent) { EventManager em; events.TryRemove(internalEvent, out em); }