private MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.json2.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.typescriptServices.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(DtoGenerator).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.tsservices.Serenity.CodeGeneration.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return(jsEngine); } catch { jsEngine.Dispose(); throw; } }
private MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(TypeScriptParserTests).Assembly.GetManifestResourceStream( "Serenity.Test.CodeGeneration.TypeScriptParserTests.typescriptServices.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } using (var sr = new StreamReader( typeof(DtoGenerator).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.tsservices.Serenity.CodeGeneration.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return jsEngine; } catch { jsEngine.Dispose(); throw; } }
private static MsieJsEngine SetupJsEngine() { MsieJsEngine jsEngine; try { jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraIeJsRt }); } catch { jsEngine = new MsieJsEngine(); } try { using (var sr = new StreamReader( typeof(ScriptBundleManager).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.optimization.uglifyjs.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return(jsEngine); } catch { jsEngine.Dispose(); throw; } }
public void TearDown() { if (_msieJsEngine != null) { _msieJsEngine.Dispose(); _msieJsEngine = null; } }
public virtual void TearDown() { if (_jsEngine != null) { _jsEngine.Dispose(); _jsEngine = null; } }
public override void SetUp() { _jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.Auto, UseEcmaScript5Polyfill = true, UseJson2Library = true }); }
public override void SetUp() { _jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraJsRt, UseEcmaScript5Polyfill = false, UseJson2Library = false }); }
public override void SetUp() { _jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraActiveScript, UseEcmaScript5Polyfill = false, UseJson2Library = false }); }
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); }
protected override MsieJsEngine CreateJsEngine() { var jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.Classic, UseEcmaScript5Polyfill = true, UseJson2Library = true }); return jsEngine; }
/// <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; } }
protected override MsieJsEngine CreateJsEngine() { var jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraEdgeJsRt, UseEcmaScript5Polyfill = false, UseJson2Library = false }); return(jsEngine); }
Markdownify(Options options, RenderMethods rendereMethods, MsieJsEngine engine) { this.engine = engine; var markedJsText = GetMarkedJsText(); engine.Execute(markedJsText); var js = GetContructionJs(options, rendereMethods); engine.Execute(js); }
protected override MsieJsEngine CreateJsEngine() { var jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.Classic, UseEcmaScript5Polyfill = true, UseJson2Library = true }); return(jsEngine); }
protected override MsieJsEngine CreateJsEngine() { var jsEngine = new MsieJsEngine(new JsEngineSettings { EngineMode = JsEngineMode.ChakraEdgeJsRt, UseEcmaScript5Polyfill = false, UseJson2Library = false }); return jsEngine; }
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> /// 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); } }
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(); } }
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)}"); } }
private static string MinimizeWithUglifyJS(ref MsieJsEngine jsEngine, string code) { jsEngine = jsEngine ?? SetupJsEngine(); jsEngine.SetVariableValue("CodeToCompress", code); jsEngine.Evaluate( @"(function() { var ast = UglifyJS.parse(CodeToCompress); ast.figure_out_scope(); var compressor = UglifyJS.Compressor(); ast = ast.transform(compressor); ast.figure_out_scope(); ast.compute_char_frequency(); ast.mangle_names(); CodeToCompress = ast.print_to_string(); })();"); return(jsEngine.GetVariableValue <string>("CodeToCompress")); }
bool TryInitializeJsEngine() { var testModes = new[] { JsEngineMode.Classic, JsEngineMode.ChakraActiveScript, JsEngineMode.ChakraIeJsRt }; foreach (var mode in testModes) { try { _engine = new MsieJsEngine(new JsEngineSettings { EngineMode = mode }); break; } catch (Exception e) { Trace.TraceError($"无法初始化脚本引擎 模式->{mode} 信息->{e.Message}"); } } return(_engine != null); }
public override void SetUp() { _jsEngine = new MsieJsEngine(JsEngineMode.Classic, true, true); }
public override void SetUp() { _jsEngine = new MsieJsEngine(JsEngineMode.ChakraJsRt); }
public void SetUp() { _msieJsEngine = new MsieJsEngine(true, true); }
public override void SetUp() { _jsEngine = new MsieJsEngine(JsEngineMode.Auto, false, false); }
private LoginBaseInfo GetLoginBaseInfo(AccountInfo accountInfo) { var httphelper = new HttpHelper(true, accountInfo.virtualAccount); var data = new Dictionary <string, string>(); var item = GetHttpItem(); item.URL = "https://passport.jd.com/new/login.aspx"; var rs = httphelper.GetHtml(item); //返回的Html内容 var html = rs.Html; if (!html.Contains("欢迎登录")) { Thread.Sleep(4000); rs = httphelper.GetHtml(item); html = rs.Html; } //var htmlDoc = new HtmlAgilityPack.HtmlDocument(); //htmlDoc.Load(html); //htmlDoc.SelectNodes CQ dom = html; var bold = dom["form#formlogin input[type=hidden]"]; var yzmUrl = "https://" + dom["img#JD_Verification1"][0].Attributes["src2"].Replace("//", "") + "&yys=1495705227054"; //var yzmUrl = dom["img#JD_Verification1"][0].Attributes["src"].Replace("//", ""); var hiddenInputList = bold.Select(a => new { name = a.Attributes["name"], value = a.Attributes["value"] }) .ToList(); hiddenInputList.ForEach(a => { data.Add(a.name, a.value); }); if (!hiddenInputList.Exists(a => a.name == "pubKey")) { var publicKey = dom["input[name='pubKey']"]; var publicKeyItem = publicKey .Select(a => new { name = a.Attributes["name"], value = a.Attributes["value"] }).First(); hiddenInputList.Add(publicKeyItem); } var jdLoginJs = File.ReadAllText("./jd_login.js"); var pubKey = hiddenInputList.Find(a => a.name == "pubKey").value; data["pubKey"] = pubKey; string nloginpwd; jdLoginJs += ";get('" + pubKey + "','" + accountInfo.password + "');"; using (var jsEngine = new MsieJsEngine()) { nloginpwd = jsEngine.Evaluate <string>(jdLoginJs); } data["loginname"] = accountInfo.realAccount; data["nloginpwd"] = nloginpwd; //var ss = ; var eid = "GEOVEU4EP2CNEUQ3JFZENF2YARUJWXZZSBEGHDDWMYPXDIROG73DGBOELY3GMEAGGB427RQ5T5O2G3ODOSUODUMEUQ"; var fp = "c675b7cca9e276a3bca88c407cb14dbb"; item.Postdata = "uuid=" + Encode(data["uuid"]) + "&" + "eid=" + Encode(eid) + "&" + "fp=" + fp + "&" + "_t=" + Encode(data["_t"]) + "&" + "loginType=f" + "&" + "loginname=" + accountInfo.realAccount + "&" + "nloginpwd=" + accountInfo.password + "&" + "chkRememberMe=" + "&" + "authcode="; var loginUrl = "https://passport.jd.com/uc/loginService?" + "uuid=" + Encode(data["uuid"]) + "&" + "r=" + new Random().NextDouble() + "&" + "version=2015"; return(new LoginBaseInfo { PostInfo = item.Postdata, YzmUrl = yzmUrl, LoginUrl = loginUrl }); }
public override void SetUp() { _jsEngine = new MsieJsEngine(JsEngineMode.ChakraActiveScript, false, false); }
public static void Initialize() { if (isInitialized) { return; } isInitialized = true; isEnabled = false; bundleKeyBySourceUrl = null; bundleByKey = null; MsieJsEngine jsEngine = null; try { var settings = JsonConvert.DeserializeObject <ScriptBundlingSettings>( ConfigurationManager.AppSettings["ScriptBundling"].TrimToNull() ?? "{}", JsonSettings.Tolerant); if (settings == null || settings.Enabled != true) { return; } var bundles = ScriptBundles; if (bundles == null || bundles.Count == 0) { return; } var bundleKeyBySourceUrlNew = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var bundleByKeyNew = new Dictionary <string, ConcatenatedScript>(StringComparer.OrdinalIgnoreCase); bool minimize = settings.Minimize == true; foreach (var pair in bundles) { var sourceFiles = pair.Value; if (sourceFiles == null || sourceFiles.Length == 0) { continue; } var bundleKey = pair.Key; var bundleName = "Bundle." + bundleKey; var bundleParts = new List <Func <string> >(); foreach (var sourceFile in sourceFiles) { if (sourceFile.IsNullOrEmpty()) { continue; } string sourceUrl = ExpandVersionVariable(sourceFile); sourceUrl = VirtualPathUtility.ToAbsolute(sourceUrl); if (sourceUrl.IsNullOrEmpty()) { continue; } bundleKeyBySourceUrlNew[sourceUrl] = bundleKey; bundleParts.Add(() => { if (HttpContext.Current == null) { return(String.Format(errorLines, "Tried to generate script while HttpContext is null")); } var sourcePath = HttpContext.Current.Server.MapPath(sourceUrl); if (!File.Exists(sourcePath)) { return(String.Format(errorLines, String.Format("File {0} is not found!", sourcePath))); } if (minimize) { if (settings.UseMinJS == true) { var minPath = Path.ChangeExtension(sourcePath, ".min.js"); if (File.Exists(minPath)) { sourcePath = minPath; using (StreamReader sr = new StreamReader(sourcePath)) return(sr.ReadToEnd()); } } string code; using (StreamReader sr = new StreamReader(sourcePath)) code = sr.ReadToEnd(); try { return(MinimizeWithUglifyJS(ref jsEngine, code)); } catch (Exception ex) { ex.Log(); return(code); } } using (StreamReader sr = new StreamReader(sourcePath)) return(sr.ReadToEnd()); }); } var bundle = new ConcatenatedScript(bundleParts); DynamicScriptManager.Register(bundleName, bundle); bundleByKeyNew[bundleKey] = bundle; } bundleKeyBySourceUrl = bundleKeyBySourceUrlNew; bundleByKey = bundleByKeyNew; isEnabled = true; } catch (Exception ex) { ex.Log(); } finally { if (jsEngine != null) { jsEngine.Dispose(); } } }
public override void SetUp() { _jsEngine = new MsieJsEngine(JsEngineMode.Auto, true, true); }
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}."); } } } } } } } }
private static string MinimizeWithUglifyJS(ref MsieJsEngine jsEngine, string code) { jsEngine = jsEngine ?? SetupJsEngine(); jsEngine.SetVariableValue("CodeToCompress", code); jsEngine.Evaluate( @"(function() { var ast = UglifyJS.parse(CodeToCompress); ast.figure_out_scope(); var compressor = UglifyJS.Compressor(); ast = ast.transform(compressor); ast.figure_out_scope(); ast.compute_char_frequency(); ast.mangle_names(); CodeToCompress = ast.print_to_string(); })();"); return jsEngine.GetVariableValue<string>("CodeToCompress"); }
private static MsieJsEngine SetupJsEngine() { var jsEngine = new MsieJsEngine(); try { using (var sr = new StreamReader( typeof(ScriptBundleManager).Assembly.GetManifestResourceStream( "Serenity.Web.Scripts.optimization.uglifyjs.min.js"))) { jsEngine.Evaluate(sr.ReadToEnd()); } return jsEngine; } catch { jsEngine.Dispose(); throw; } }
public MsieJsEngineAdapter(MsieJsEngine engine) { _engine = engine; }