public virtual void ExecutionOfResourceByTypeIsCorrect() { // Arrange const string resourceName = "MsieJavaScriptEngine.Tests.Resources.cube.js"; const string input = "cube(5);"; const int targetOutput = 125; // Act _jsEngine.ExecuteResource(resourceName, GetType()); var output = _jsEngine.Evaluate <int>(input); // Assert Assert.AreEqual(targetOutput, output); }
/// <summary> /// Initializes compiler /// </summary> private void Initialize() { if (!_initialized) { _jsEngine = new MsieJsEngine(true); _jsEngine.ExecuteResource(COFFEESCRIPT_LIBRARY_RESOURCE_NAME, GetType()); _jsEngine.Execute(string.Format(@"var {0} = function(code) {{ return CoffeeScript.compile(code, {{ bare: false }});}}", COMPILATION_FUNCTION_NAME)); _initialized = true; } }
/// <summary> /// Initializes compiler /// </summary> private void Initialize() { if(!_initialized) { _jsEngine = new MsieJsEngine(true); _jsEngine.ExecuteResource(HOGAN_LIBRARY_RESOURCE_NAME, GetType()); _jsEngine.Execute(string.Format("var {0} = function (template) {{return Hogan.compile(template, {{ asString: 1 }});}};", COMPILATION_FUNCTION_NAME)); _initialized = true; } }
/// <summary> /// Initializes compiler /// </summary> private void Initialize() { if (!_initialized) { _jsEngine = new MsieJsEngine(true); _jsEngine.ExecuteResource(HOGAN_LIBRARY_RESOURCE_NAME, GetType()); _jsEngine.Execute(string.Format("var {0} = function (template) {{return Hogan.compile(template, {{ asString: 1 }});}};", COMPILATION_FUNCTION_NAME)); _initialized = true; } }
/// <summary> /// Initializes compiler /// </summary> private void Initialize() { if (!_initialized) { _jsEngine = new MsieJsEngine(true); _jsEngine.ExecuteResource(COFFEESCRIPT_LIBRARY_RESOURCE_NAME, GetType()); _jsEngine.Execute(string.Format(@"var {0} = function(code) {{ return CoffeeScript.compile(code, {{ bare: false }});}}", COMPILATION_FUNCTION_NAME)); _initialized = true; } }
public static string UnmaskFrom(string maskedUrl, string userId) { try { using (var jsEngine = new MsieJsEngine()) { jsEngine.ExecuteResource("VkAudioSync.Vk.audioUnmask.js", Assembly.GetExecutingAssembly()); return(jsEngine.Evaluate <string>($"unmaskUrl(\"{maskedUrl}\", {userId});")); } } catch (JsEngineLoadException e) { throw new Exception($"JS Compile error: {JsErrorHelpers.Format(e)}"); } catch (JsRuntimeException e) { throw new Exception($"JS Runtime error: {JsErrorHelpers.Format(e)}"); } }