Пример #1
0
 public void Remove(TaskHandle taskHandle)
 {
     lock (locker)
     {
         tasks.Remove(taskHandle);
     }
 }
Пример #2
0
 public void Add(TaskHandle taskHandle)
 {
     lock (locker)
     {
         tasks.Add(taskHandle);
     }
 }
Пример #3
0
        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();
        }
Пример #4
0
        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 WurmSubdirsMonitor([NotNull] string directoryFullPath, [NotNull] TaskManager taskManager,
            [NotNull] Action onChanged, [NotNull] ILogger logger,
            [NotNull] Action<string> validateDirectory)
        {
            if (directoryFullPath == null) throw new ArgumentNullException("directoryFullPath");
            if (taskManager == null) throw new ArgumentNullException("taskManager");
            if (onChanged == null) throw new ArgumentNullException("onChanged");
            if (validateDirectory == null) throw new ArgumentNullException("validateDirectory");
            if (logger == null) throw new ArgumentNullException("logger");
            this.DirectoryFullPath = directoryFullPath;
            this.taskManager = taskManager;
            this.onChanged = onChanged;
            this.validateDirectory = validateDirectory;
            this.logger = logger;

            directoryBlacklist = new Blacklist<string>(logger, "Character directories blacklist");

            task = new TaskHandle(Refresh, "WurmSubdirsMonitor for path: " + directoryFullPath);
            taskManager.Add(task);

            try
            {
                Refresh();
            }
            catch (Exception exception)
            {
                logger.Log(LogLevel.Error, "Error at initial Refresh of " + this.GetType().Name, this, exception);
            }

            fileSystemWatcher = new FileSystemWatcher(directoryFullPath) {NotifyFilter = NotifyFilters.DirectoryName};
            fileSystemWatcher.Created += DirectoryMonitorOnDirectoriesChanged;
            fileSystemWatcher.Renamed += DirectoryMonitorOnDirectoriesChanged;
            fileSystemWatcher.Deleted += DirectoryMonitorOnDirectoriesChanged;
            fileSystemWatcher.Changed += DirectoryMonitorOnDirectoriesChanged;
            fileSystemWatcher.EnableRaisingEvents = true;

            task.Trigger();
        }
Пример #6
0
 public void Remove(TaskHandle taskHandle)
 {
     lock (locker)
     {
         tasks.Remove(taskHandle);
     }
 }
Пример #7
0
 public void Add(TaskHandle taskHandle)
 {
     lock (locker)
     {
         tasks.Add(taskHandle);
     }
 }
Пример #8
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();
        }