Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JsEngineFactory"/> class.
 /// </summary>
 public JsEngineFactory(IJsPool pool, IJsEngineBuilder jsEngineBuilder, IJsEngineInitializer jsEngineInitializer)
 {
     _pool                = pool;
     _jsEngineBuilder     = jsEngineBuilder;
     _jsEngineInitializer = jsEngineInitializer;
     // Reset the recycle exception on recycle. If there *are* errors loading the scripts
     // during recycle, the errors will be caught in the initializer.
     _pool.Recycled += (sender, args) => _scriptLoadException = null;
 }
        /// <summary>
        /// Called when any of the watched files have changed. Recycles the JavaScript engine pool
        /// so the files are all reloaded.
        /// </summary>
        /// <param name="state">Unused</param>
        protected virtual void OnResetPoolTimer(object state)
        {
            // Create the new pool before disposing the old pool so that _pool is never null.
            var oldPool = _pool;

            _pool = CreatePool();
            if (oldPool != null)
            {
                oldPool.Dispose();
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
		/// </summary>
		public JavaScriptEngineFactory(
			IEnumerable<Registration> availableFactories, 
			IReactSiteConfiguration config,
			IFileSystem fileSystem
		)
		{
			_config = config;
			_fileSystem = fileSystem;
			_factory = GetFactory(availableFactories, config.AllowMsieEngine);
			if (_config.ReuseJavaScriptEngines)
			{
				_pool = CreatePool();
			}
		}
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
 /// </summary>
 public JavaScriptEngineFactory(
     IEnumerable <Registration> availableFactories,
     IReactSiteConfiguration config,
     IFileSystem fileSystem
     )
 {
     _config     = config;
     _fileSystem = fileSystem;
     _factory    = GetFactory(availableFactories, config.AllowMsieEngine);
     if (_config.ReuseJavaScriptEngines)
     {
         _pool = CreatePool();
     }
 }
Esempio n. 5
0
 /// <summary>
 /// Clean up all engines
 /// </summary>
 public virtual void Dispose()
 {
     _disposed = true;
     foreach (var engine in _engines)
     {
         if (engine.Value != null)
         {
             engine.Value.Dispose();
         }
     }
     if (_pool != null)
     {
         _pool.Dispose();
         _pool = null;
     }
 }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
        /// </summary>
        public JavaScriptEngineFactory(
            IJsEngineSwitcher jsEngineSwitcher,
            IReactSiteConfiguration config,
            IFileSystem fileSystem
            )
        {
            _jsEngineSwitcher = jsEngineSwitcher;
            _config           = config;
            _fileSystem       = fileSystem;
#pragma warning disable 618
            _factory = GetFactory(_jsEngineSwitcher, config.AllowMsieEngine);
#pragma warning restore 618
            if (_config.ReuseJavaScriptEngines)
            {
                _pool = CreatePool();
            }
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
		/// </summary>
		public JavaScriptEngineFactory(
			JsEngineSwitcher jsEngineSwitcher,
			IReactSiteConfiguration config,
			IFileSystem fileSystem
		)
		{
			_jsEngineSwitcher = jsEngineSwitcher;
			_config = config;
			_fileSystem = fileSystem;
#pragma warning disable 618
			_factory = GetFactory(_jsEngineSwitcher, config.AllowMsieEngine);
#pragma warning restore 618
			if (_config.ReuseJavaScriptEngines)
			{
				_pool = CreatePool();
			}
		}
 /// <summary>
 /// Initializes a new instance of the <see cref="JavaScriptEngineFactory"/> class.
 /// </summary>
 public JavaScriptEngineFactory(
     IEnumerable <Registration> availableFactories,
     IReactSiteConfiguration config,
     IFileSystem fileSystem
     )
 {
     _config     = config;
     _fileSystem = fileSystem;
     _factory    = GetFactory(availableFactories);
     if (_config.ReuseJavaScriptEngines)
     {
         _pool           = CreatePool();
         _resetPoolTimer = new Timer(OnResetPoolTimer);
         _watchedFiles   = new HashSet <string>(_config.Scripts.Select(
                                                    fileName => _fileSystem.MapPath(fileName).ToLowerInvariant()
                                                    ));
         try
         {
             // Attempt to initialise a FileSystemWatcher so we can recycle the JavaScript
             // engine pool when files are changed.
             _watcher = new FileSystemWatcher
             {
                 Path = _fileSystem.MapPath("~"),
                 IncludeSubdirectories = true,
                 EnableRaisingEvents   = true,
             };
             _watcher.Changed += OnFileChanged;
             _watcher.Created += OnFileChanged;
             _watcher.Deleted += OnFileChanged;
             _watcher.Renamed += OnFileChanged;
         }
         catch (Exception ex)
         {
             // Can't use FileSystemWatcher (eg. not running in Full Trust)
             Trace.WriteLine("Unable to initialise FileSystemWatcher: " + ex.Message);
         }
     }
 }
		/// <summary>
		/// Clean up all engines
		/// </summary>
		public virtual void Dispose()
		{
			_disposed = true;
			foreach (var engine in _engines)
			{
				if (engine.Value != null)
				{
					engine.Value.Dispose();
				}
			}
			if (_pool != null)
			{
				_pool.Dispose();
				_pool = null;
			}
		}
Esempio n. 10
0
 public HomeController(IJsPool jsPool)
 {
     _jsPool = jsPool;
 }