private void BeginFileWatcher() { _timer = new Timer(OnTimer, null, Timeout.Infinite, Timeout.Infinite); _fileSystemWatcher = new FileSystemWatcher(_fileSystem.MapPath("~/")) { IncludeSubdirectories = true, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName }; _fileSystemWatcher.Changed += OnFileChanged; _fileSystemWatcher.Created += OnFileChanged; _fileSystemWatcher.Deleted += OnFileChanged; _fileSystemWatcher.Renamed += OnFileChanged; _fileSystemWatcher.EnableRaisingEvents = true; void OnFileChanged(object source, FileSystemEventArgs e) { if (_watchedFiles.Contains(e.FullPath)) { _timer.Change(500, Timeout.Infinite); } } void OnTimer(object state) { lock (_watchedFiles) { var oldPool = _pool; _pool = CreatePool(); _scriptLoadException = null; oldPool.Dispose(); } } }
/// <summary> /// Creates a new JavaScript engine pool. /// </summary> private ZeroJsPool CreatePool() { var poolConfig = new ZeroJsPoolConfig { EngineFactory = EngineFactory, StartEngines = _config.StartEngines, MaxEngines = _config.MaxEngines, MaxUsagesPerEngine = _config.MaxUsagesPerEngine, }; var pool = new ZeroJsPool(poolConfig); return(pool); }
/// <summary> /// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class. /// </summary> public JavaScriptEngineFactory( ReactConfiguration config, ICache cache, IFileSystem fileSystem ) { _config = config; _cache = cache; _fileSystem = fileSystem; _pool = CreatePool(); _watchedFiles = _config.ScriptFilesWithoutTransform.Select(_fileSystem.MapPath).ToHashSet(); BeginFileWatcher(); }
public void Dispose() { if (disposed.Set()) { _fileSystemWatcher.Dispose(); _fileSystemWatcher = null; _timer.Dispose(); _timer = null; if (_pool != null) { _pool.Dispose(); _pool = null; } } }