public Markdownify(Options options, RenderMethods rendereMethods, MsieJsEngine engine) { this.engine = engine; var markedJsText = GetMarkedJsText(); engine.Execute(markedJsText); var js = GetContructionJs(options, rendereMethods); engine.Execute(js); }
Markdownify(Options options, RenderMethods rendereMethods, MsieJsEngine engine) { this.engine = engine; var markedJsText = GetMarkedJsText(); engine.Execute(markedJsText); var js = GetContructionJs(options, rendereMethods); engine.Execute(js); }
private string ExecuteJs(string exeFilePath, string corlibPath, string entryPoint, out int exitCode, List <string> errors) { string jsOutput = null; exitCode = -1; using (var jsEngine = new MsieJsEngine(engineMode: JsEngineMode.Auto, useEcmaScript5Polyfill: false, useJson2Library: false)) { object exitCodeObj = null; try { jsEngine.Execute(@"var braille_testlib_output = """";"); jsEngine.Execute(@"function braille_test_log(message) { braille_testlib_output += asm0.ToJavaScriptString(message) + ""\r\n""; }"); if (corlibPath != null) { jsEngine.ExecuteFile(corlibPath); } jsEngine.ExecuteFile(exeFilePath + ".js"); exitCodeObj = jsEngine.Evaluate(entryPoint + ".entryPoint()"); } catch (JsEngineLoadException e) { errors.Add("During loading of JavaScript engine an error occurred.\n" + JsErrorHelpers.Format(e)); } catch (JsRuntimeException e) { errors.Add("During execution of JavaScript code an error occurred.\n" + JsErrorHelpers.Format(e)); } if (exitCodeObj == null || exitCodeObj == MsieJavaScriptEngine.Undefined.Value) { exitCode = 0; } else { exitCode = (int)(double)exitCodeObj; } try { jsOutput = (string)jsEngine.Evaluate("braille_testlib_output"); } catch { errors.Add("Exception while evaluating script output"); } } return(jsOutput); }
/// <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; } }
static void Main(string[] args) { var basePath = AppDomain.CurrentDomain.BaseDirectory; using (var jsEngine = new MsieJsEngine()) { //jsEngine.ExecuteFile(string.Format(@"{0}/Scripts/myscript.js", basePath)); jsEngine.Execute("function add(left, right){ return (left + right) & 0xFFFFFF; }"); string[] arr = new string[] { "1", "2" }; var res = Convert.ToInt32(jsEngine.CallFunction("add", arr)); Console.WriteLine(res); Console.ReadKey(); } }
/// <summary> /// Eval JavaScript code. /// </summary> /// <param name="code">JavaScript code.</param> /// <param name="variableName">Variable name.</param> /// <returns>JavaScript code return result.</returns> public static object EvaluateJavaScriptCode(string code, string variableName) { try { using var engine = new MsieJsEngine(); engine.Execute(code); return(engine.GetVariableValue(variableName)); } catch (Exception exception) { return(exception.Message); } }
public void ExecutionOfCodeAndCallingOfFunctionIsCorrect() { // Arrange const string jsLibraryCode = @"function add(num1, num2) { return (num1 + num2); }" ; _msieJsEngine.Execute(jsLibraryCode); // Act var result = _msieJsEngine.CallFunction <int>("add", 2, 3); // Assert Assert.AreEqual(5, result); }
public virtual void ExecutionOfCodeIsCorrect() { // Arrange const string functionCode = @"function add(num1, num2) { return (num1 + num2); }" ; const string input = "add(7, 9);"; const int targetOutput = 16; // Act _jsEngine.Execute(functionCode); var output = _jsEngine.Evaluate <int>(input); // Assert Assert.AreEqual(targetOutput, output); }
public virtual void ArrayEveryMethodIsSupported() { // Arrange const string initCode = "var engines = ['Chakra', 'V8', 'SpiderMonkey', 'Jurassic'];"; const string input1 = "engines.every(function (value, index, array) { return value.length > 1; });"; const bool targetOutput1 = true; const string input2 = "engines.every(function (value, index, array) { return value.length < 10; });"; const bool targetOutput2 = false; // Act _jsEngine.Execute(initCode); var output1 = _jsEngine.Evaluate <bool>(input1); var output2 = _jsEngine.Evaluate <bool>(input2); // Assert Assert.AreEqual(targetOutput1, output1); Assert.AreEqual(targetOutput2, output2); }
static void Main() { api.Authorize(new ApiAuthParams() { // Your Token. AccessToken = "" }); while (true) { // Your LongPoll. var lpsr = api.Groups.GetLongPollServer(123123); var blphr = api.Groups.GetBotsLongPollHistory( new BotsLongPollHistoryParams() { Wait = 25, Server = lpsr.Server, Ts = lpsr.Ts, Key = lpsr.Key }); if (blphr?.Updates == null) { continue; } else { foreach (var events in blphr.Updates) { if (events.Type == GroupUpdateType.MessageNew) { string userMessage = events.Message.Body.ToLower(); long? userId = events.Message.UserId; long? chatId = events.Message.ChatId; if (chatId == null) { if (userMessage.Contains("[JS code]".ToLower())) { string newText = userMessage.Replace("[JS code]".ToLower(), ""); newText = newText.Replace("?", " "); try { var engine = new MsieJsEngine(); var result = engine.Evaluate(newText); engine.Execute(newText); SendMessage($"Output: {result}.", userId); Console.WriteLine($"[Log, user({userId})]: UserMessageText - {newText}, VariableResult - {result}."); } catch (Exception e) { SendMessage($"Ошибка. Название исключения: {e.Message}.", userId); Console.WriteLine($"[Error Log, user({userId})]: Error - {e.Message}, UserMessageText - {newText}."); } } } else { if (userMessage.Contains("[JS code]".ToLower())) { string newText = userMessage.Replace("[JS code]".ToLower(), ""); newText = newText.Replace("?", " "); try { var engine = new MsieJsEngine(); var result = engine.Evaluate(newText); engine.Execute(newText); SendChatMessage($"Output: {result}.", chatId); Console.WriteLine($"[Log, user({userId})]: UserMessageText - {newText}, VariableResult - {result}."); } catch (Exception e) { SendChatMessage($"Ошибка. Название исключения: {e.Message}.", userId); Console.WriteLine($"[Error Log, user({userId})]: Error - {e.Message}, UserMessageText - {newText}."); } } } } } } } }
public void Execute(string code) { _engine.Execute(code); }