/// <summary> /// Initializes a new instance of the <see cref="JsxTransformer"/> class. /// </summary> /// <param name="environment">The ReactJS.NET environment</param> /// <param name="cache">The cache to use for JSX compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> /// <param name="siteConfig">Site-wide configuration</param> public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig) { _environment = environment; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _config = siteConfig; }
/// <summary> /// Creates a mock <see cref="IReactEnvironment"/> and registers it with the IoC container /// This is only required because <see cref="HtmlHelperExtensions"/> can not be /// injected :( /// </summary> private Mock <IReactEnvironment> ConfigureMockEnvironment(IReactSiteConfiguration configuration = null) { var environment = new Mock <IReactEnvironment>(); environment.Setup(x => x.Configuration).Returns(configuration ?? new ReactSiteConfiguration()); AssemblyRegistration.Container.Register(environment.Object); return(environment); }
/// <summary> /// Initializes a new instance of the <see cref="JsxTransformer"/> class. /// </summary> /// <param name="environment">The ReactJS.NET environment</param> /// <param name="cache">The cache to use for JSX compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> /// <param name="siteConfig">Site-wide configuration</param> public JsxTransformer(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig) { _environment = environment; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _config = siteConfig; }
/// <summary> /// Initializes a new instance of the <see cref="Babel"/> class. /// </summary> /// <param name="environment">The ReactJS.NET environment</param> /// <param name="cache">The cache to use for compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> /// <param name="siteConfig">Site-wide configuration</param> public Babel(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig) { _environment = environment; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _config = siteConfig; _babelConfig = siteConfig.BabelConfig.Serialize(); }
/// <summary> /// Initializes a new instance of the <see cref="ReactComponent"/> class. /// </summary> /// <param name="environment">The environment.</param> /// <param name="configuration">Site-wide configuration.</param> /// <param name="componentName">Name of the component.</param> /// <param name="containerId">The ID of the container DIV for this component</param> public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration configuration, string componentName, string containerId) { EnsureComponentNameValid(componentName); _environment = environment; _configuration = configuration; ComponentName = componentName; ContainerId = string.IsNullOrEmpty(containerId) ? GenerateId() : containerId; ContainerTag = "div"; }
/// <summary> /// Initializes a new instance of the <see cref="ReactComponent"/> class. /// </summary> /// <param name="environment">The environment.</param> /// <param name="configuration">Site-wide configuration.</param> /// <param name="componentName">Name of the component.</param> /// <param name="containerId">The ID of the container DIV for this component</param> public ReactComponent(IReactEnvironment environment, IReactSiteConfiguration configuration, string componentName, string containerId) { EnsureComponentNameValid(componentName); _environment = environment; _configuration = configuration; ComponentName = componentName; ContainerId = containerId; ContainerTag = "div"; }
/// <summary> /// Initializes a new instance of the <see cref="Babel"/> class. /// </summary> /// <param name="environment">The ReactJS.NET environment</param> /// <param name="cache">The cache to use for compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> /// <param name="siteConfig">Site-wide configuration</param> public Babel(IReactEnvironment environment, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash, IReactSiteConfiguration siteConfig) { _environment = environment; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _config = siteConfig; _babelConfig = siteConfig.BabelConfig.Serialize(_config.BabelVersion); }
/// <summary> /// Initialises a new instance of the <see cref="ReactRouterComponent"/> class. /// </summary> /// <param name="environment">The environment.</param> /// <param name="configuration">Site-wide configuration.</param> /// <param name="componentName">Name of the component.</param> /// <param name="containerId">The ID of the container DIV for this component</param> /// <param name="path">F.x. from Request.Path. Used by React Static Router to determine context and routing.</param> public ReactRouterComponent( IReactEnvironment environment, IReactSiteConfiguration configuration, string componentName, string containerId, string path ) : base(environment, configuration, componentName, containerId) { _path = path; }
/// <summary> /// recursively finds all .JSX files in the project, starting at rootPath and adds them to the configurations script collection for transformation /// </summary> /// <param name="config"></param> /// <param name="rootPath"></param> /// <returns></returns> public static IReactSiteConfiguration AddJsxScripts(this IReactSiteConfiguration config, string rootPath) { Directory.EnumerateFiles(rootPath, "*.jsx", SearchOption.AllDirectories) .ToList() .ForEach(script => { config.AddScript(script); }); return(config); }
/// <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(); } }
/// <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(); } }
/// <summary> /// Initializes a new instance of the <see cref="ReactEnvironment"/> class. /// </summary> /// <param name="engineFactory">The JavaScript engine factory</param> /// <param name="config">The site-wide configuration</param> /// <param name="cache">The cache to use for JSX compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> public ReactEnvironment( IJavaScriptEngineFactory engineFactory, IReactSiteConfiguration config, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash ) { _engineFactory = engineFactory; _config = config; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _jsxTransformer = new Lazy <IJsxTransformer>(() => new JsxTransformer(this, _cache, _fileSystem, _fileCacheHash, _config) ); }
/// <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( 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="ReactEnvironment"/> class. /// </summary> /// <param name="engineFactory">The JavaScript engine factory</param> /// <param name="config">The site-wide configuration</param> /// <param name="cache">The cache to use for JSX compilation</param> /// <param name="fileSystem">File system wrapper</param> /// <param name="fileCacheHash">Hash algorithm for file-based cache</param> public ReactEnvironment( IJavaScriptEngineFactory engineFactory, IReactSiteConfiguration config, ICache cache, IFileSystem fileSystem, IFileCacheHash fileCacheHash ) { _engineFactory = engineFactory; _config = config; _cache = cache; _fileSystem = fileSystem; _fileCacheHash = fileCacheHash; _babelTransformer = new Lazy <IBabel>(() => new Babel(this, _cache, _fileSystem, _fileCacheHash, _config) ); _engineFromPool = new Lazy <IJsEngine>(() => _engineFactory.GetEngine()); }
public static ReactAppAssetManifest LoadManifest(IReactSiteConfiguration config, IFileSystem fileSystem, ICache cache, bool useCacheRead) { string cacheKey = "REACT_APP_MANIFEST"; if (useCacheRead) { var cachedManifest = cache.Get <ReactAppAssetManifest>(cacheKey); if (cachedManifest != null) { return(cachedManifest); } } var manifestString = fileSystem.ReadAsString($"{config.ReactAppBuildPath}/asset-manifest.json"); var manifest = JsonConvert.DeserializeObject <ReactAppAssetManifest>(manifestString); cache.Set(cacheKey, manifest, TimeSpan.FromHours(1)); return(manifest); }
private JavaScriptEngineFactory CreateFactory( IReactSiteConfiguration config, ICache cache, IFileSystem fileSystem, Func <IJsEngine> innerEngineFactory ) { var engineFactory = new Mock <IJsEngineFactory>(); engineFactory.Setup(x => x.EngineName).Returns("MockEngine"); engineFactory.Setup(x => x.CreateEngine()).Returns(innerEngineFactory); var engineSwitcher = new JsEngineSwitcher( new JsEngineFactoryCollection { engineFactory.Object }, string.Empty ); return(new JavaScriptEngineFactory(engineSwitcher, config, cache, fileSystem)); }
/// <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); } } }
static ReactSiteConfiguration() { Configuration = new ReactSiteConfiguration(); }
private static void ConfigureReact(IReactSiteConfiguration config) { config.AddScript("~/js/Menu.jsx"); config.AddScript("~/js/App.jsx"); }
public AfishaJavaScriptEngineFactory(JsEngineSwitcher engineSwitcher, IReactSiteConfiguration config, IFileSystem fileSystem) : base(engineSwitcher, config, fileSystem) { }
static ReactSiteConfiguration() { Configuration = new ReactSiteConfiguration(); }