Esempio n. 1
0
        public void Load(string js)
        {
            try
            {
#if DEBUG
                engine.ExecuteFile("../../../../scripts/support.js");
#else
                engine.ExecuteFile("scripts/support.js");
#endif
                engine.ExecuteFile(js);
            }
            catch (JsEngineException e)
            {
                Log.Logs.Instance.PushError($"[Script Loader] An engine-error occurred while loading the script.\r\n" + e.Message);
            }
            catch (JsCompilationException e)
            {
                Log.Logs.Instance.PushError($"[Script Loader] An compile-error occurred while loading the script.\r\n" + e.Message);
            }
            catch (JsRuntimeException e)
            {
                Log.Logs.Instance.PushError($"[Script Loader] An runtime-error occurred while loading the script.\r\n" + e.Message);
            }
            catch (Exception e)
            {
                Log.Logs.Instance.PushError($"[Script Loader] " + e);
            }
        }
        /// <summary>
        /// Loads any user-provided scripts. Only scripts that don't need JSX transformation can
        /// run immediately here. JSX files are loaded in ReactEnvironment.
        /// </summary>
        /// <param name="engine">Engine to load scripts into</param>
        private void LoadUserScripts(IJsEngine engine)
        {
            if (_config.ReactAppBuildPath != null)
            {
                var manifest = ReactAppAssetManifest.LoadManifest(_config, _fileSystem, _cache, useCacheRead: false);
                foreach (var file in manifest.Entrypoints?.Where(x => x != null && x.EndsWith(".js")))
                {
                    if (_config.AllowJavaScriptPrecompilation &&
                        engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file))
                    {
                        // Do nothing.
                    }
                    else
                    {
                        engine.ExecuteFile(_fileSystem, file);
                    }
                }
            }

            foreach (var file in _config.ScriptsWithoutTransform)
            {
                try
                {
                    if (_config.AllowJavaScriptPrecompilation &&
                        engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file))
                    {
                        // Do nothing.
                    }
                    else
                    {
                        engine.ExecuteFile(_fileSystem, file);
                    }
                }
                catch (JsException ex)
                {
                    // We can't simply rethrow the exception here, as it's possible this is running
                    // on a background thread (ie. as a response to a file changing). If we did
                    // throw the exception here, it would terminate the entire process. Instead,
                    // save the exception, and then just rethrow it later when getting the engine.
                    _scriptLoadException = new ReactScriptLoadException(string.Format(
                                                                            "Error while loading \"{0}\": {1}",
                                                                            file,
                                                                            ex.Message
                                                                            ), ex);
                }
                catch (IOException ex)
                {
                    _scriptLoadException = new ReactScriptLoadException(ex.Message, ex);
                }
            }
        }
Esempio n. 3
0
        public void Initialize()
        {
            _jsEngine = _jsEngineFactory.CreateEngine();

            // Execute each bundle
            foreach (var reactBundleFile in ReactServerSideBundle.BundleFiles)
            {
                // Fix console is undefined errors
                _jsEngine.Evaluate("if (typeof console === 'undefined') console = { log: function() {}, error: function() {} };");

                if (reactBundleFile.ToLowerInvariant().StartsWith("http"))
                {
                    var contents = new HttpClient().GetStringAsync(reactBundleFile).Result;

                    _jsEngine.Evaluate(contents);

                    //var newCode = _jsEngine.Precompile(contents);
                    //_jsEngine.Execute(newCode);
                }
                else
                {
                    _jsEngine.ExecuteFile(_mapServerPath.MapServerPath(reactBundleFile), null);
                }
            }
        }
 /// <summary>
 /// Loads any user-provided scripts. Only scripts that don't need JSX transformation can
 /// run immediately here. JSX files are loaded in ReactEnvironment.
 /// </summary>
 /// <param name="engine">Engine to load scripts into</param>
 private void LoadUserScripts(IJsEngine engine)
 {
     foreach (var file in _config.ScriptsWithoutTransform)
     {
         try
         {
             if (_config.AllowJavaScriptPrecompilation &&
                 engine.TryExecuteFileWithPrecompilation(_cache, _fileSystem, file))
             {
                 // Do nothing.
             }
             else
             {
                 engine.ExecuteFile(_fileSystem, file);
             }
         }
         catch (JsException ex)
         {
             // We can't simply rethrow the exception here, as it's possible this is running
             // on a background thread (ie. as a response to a file changing). If we did
             // throw the exception here, it would terminate the entire process. Instead,
             // save the exception, and then just rethrow it later when getting the engine.
             _scriptLoadException = new ReactScriptLoadException(string.Format(
                                                                     "Error while loading \"{0}\": {1}",
                                                                     file,
                                                                     ex.Message
                                                                     ));
         }
         catch (IOException ex)
         {
             _scriptLoadException = new ReactScriptLoadException(ex.Message);
         }
     }
 }
Esempio n. 5
0
 public void injectJS(List <FileInfo> files)
 {
     foreach (var item in files)
     {
         jsEngine.ExecuteFile(item.FullName);
     }
 }
Esempio n. 6
0
 public void Initialize(IJsEngine engine)
 {
     try
     {
         engine.ExecuteFile(Path.Combine(_hostingEnvironment.WebRootPath, "pack", "server.generated.js"));
     }
     catch (Exception ex)
     {
         _logger.LogError("Could not initialize the React server-side environment.", ex);
     }
 }
Esempio n. 7
0
        public virtual void ExecutionOfFileIsCorrect()
        {
            // Arrange
            string       filePath     = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"../../Resources/square.js");
            const string input        = "square(6);";
            const int    targetOutput = 36;

            // Act
            _jsEngine.ExecuteFile(filePath);
            var output = _jsEngine.Evaluate <int>(input);

            // Assert
            Assert.AreEqual(targetOutput, output);
        }
Esempio n. 8
0
 public PDDApi()
 {
     jsEngine.ExecuteFile(@"../../jm.js");
     _nano_fp = (string)jsEngine.CallFunction("create_nano_fp");
     Session.WithHeader("Accept", "application/json, text/plain, */*");
     Session.WithHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36 Edg/85.0.564.68");
     Session.Cookies.Add(
         "ua",
         new Cookie("ua",
                    @"Mozilla%2F5.0%20(Windows%20NT%2010.0%3B%20
                         Win64%3B%20x64)%20AppleWebKit%2F537.36%20(KH
                         TML%2C%20like%20Gecko)%20Chrome%2F85.0.4183.1
                         21%20Safari%2F537.36%20Edg%2F85.0.564.68"));
     Session.Cookies.Add(
         "_nano_fp",
         new Cookie("_nano_fp", _nano_fp));
 }
Esempio n. 9
0
 public static void InitialiseJSRuntime(string jsPath, IJsEngine engine)
 {
     engine.ExecuteFile(jsPath);
 }
Esempio n. 10
0
 public void Initialize(IJsEngine engine)
 {
     engine.ExecuteFile(_env.MapPath("server.js"));
 }
Esempio n. 11
0
 public void ExecuteFile(string path, Encoding encoding = null)
 {
     CheckDisposed();
     _engine.ExecuteFile(path, encoding);
 }
Esempio n. 12
0
 public static void InitialiseJSRuntime(string jsPath, IJsEngine engine)
 {
     engine.ExecuteFile(jsPath);
 }