Пример #1
0
        internal void Trigger(PublicEvent publicEvent)
        {
            EventManager em;

            if (events.TryGetValue(publicEvent, out em))
            {
                em.Pending = 1;
            }
        }
Пример #2
0
 public EventManager([NotNull] PublicEvent publicEvent, TimeSpan betweenDelay, [NotNull] Action action)
 {
     if (publicEvent == null)
     {
         throw new ArgumentNullException(nameof(publicEvent));
     }
     if (action == null)
     {
         throw new ArgumentNullException(nameof(action));
     }
     PublicEvent  = publicEvent;
     BetweenDelay = betweenDelay;
     Action       = action;
 }
Пример #3
0
        internal WurmConfig(string gameSettingsFullPath, [NotNull] IPublicEventInvoker publicEventMarshaller,
            [NotNull] TaskManager taskManager, ILogger logger)
        {
            if (gameSettingsFullPath == null) throw new ArgumentNullException("gameSettingsFullPath");
            if (taskManager == null) throw new ArgumentNullException("taskManager");
            this.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),
                WurmApiTuningParams.PublicEventMarshallerDelay);

            this.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();
        }
Пример #4
0
        internal void Detach(PublicEvent publicEvent)
        {
            EventManager em;

            events.TryRemove(publicEvent, out em);
        }