public string getPostData(string ExpectNo, string EncodingMsg, string ruleid, string guid) { VsaEngine Engine = VsaEngine.CreateEngine(); string txt = GlobalClass.LoadTextFile("getPostData.js", string.Format("jscript\\{0}\\", gc.ForWeb)); CSharpCodeProvider cc = new CSharpCodeProvider(); // icc = cc.CreateCompiler(); string allscript = string.Format("{0}getPostData('{1}','{2}','{3}','{4}');", txt, ExpectNo, EncodingMsg, ruleid, guid); try { object value = Eval.JScriptEvaluate(allscript, Engine); StringBuilder sb = new StringBuilder(); JavaScriptSerializer json = new JavaScriptSerializer(); json.Serialize(value, sb); return(sb.ToString()); //return DetailStringClass.ToJson(value); } catch (Exception ce) { return(null); } finally { Engine = null; } }
// Test the "parseInt" function inside an evaluation. public void TestGlobalEvalParseInt() { VsaEngine engine; IVsaCodeItem item; // Create a new engine instance. engine = VsaEngine.CreateEngine(); // Compile an empty script. item = (IVsaCodeItem)(engine.Items.CreateItem ("script1", VsaItemType.Code, VsaItemFlag.None)); item.SourceText = ""; Assert("Compile", engine.Compile()); engine.Run(); // Evaluate a "parseInt" call within the engine context. AssertEquals("EvalParseInt (1)", 123.0, (double)(Eval.JScriptEvaluate ("parseInt(\"123\", 0)", engine)), 0.0001); AssertEquals("EvalParseInt (2)", 123.0, (double)(Eval.JScriptEvaluate ("parseInt(\"123\")", engine)), 0.0001); // Close the engine. engine.Close(); }
public virtual String Evaluate(string expr) { var engine = (INeedEngine)this; var result = Eval.JScriptEvaluate(expr, engine.GetEngine()); return(Convert.ToString(result, true)); }
public bool EvaluateConditionWithCharacter(Context context) { StringBuilder builder = new StringBuilder(data); List <string> valuesToReplace = new List <string>(); int startingPosition = 0; int positionOfVariable; while ((positionOfVariable = data.IndexOf(StaticData.VariableSeparator, startingPosition)) != -1) { startingPosition = ParseUtilites.GetEndOfVariableAtPosition(data, positionOfVariable + 1); valuesToReplace.Add(data.Substring(positionOfVariable + 1, startingPosition - positionOfVariable)); } foreach (var val in valuesToReplace.Where(context.Contains)) { string replaceTo; object value = context.GetValue(val); double res; if (double.TryParse(value.ToString(), out res)) { replaceTo = res.ToString(); } else { replaceTo = '"' + value.ToString() + '"'; } builder.Replace(StaticData.VariableSeparator + val, replaceTo); } string condition = builder.ToString(); var engine = VsaEngine.CreateEngine(); var result = Eval.JScriptEvaluate(condition, engine); return(bool.Parse(result.ToString())); }
static void Main(string[] args) { object value = Eval.JScriptEvaluate("1+2-(3*5)", VsaEngine.CreateEngine()); Console.Write(value); Console.ReadLine(); }
private object EvalJScript(string src) { var engine = Engine; try { With.JScriptWith(this, Engine); return(Eval.JScriptEvaluate(src, "unsafe", engine)); } finally { engine.PopScriptObject(/* with */); } }
static javascript() { #if USEVSAHOST Engine = Evaluator.Evaluator.Engine; #else List <string> assemblies = new List <string>(DefaultAssemblyReferences); Assembly executingAssembly = Assembly.GetExecutingAssembly(); foreach (var name in executingAssembly.GetReferencedAssemblies()) { string codeBase = name.CodeBase; try { Assembly assembly = Assembly.Load(name); if (assembly.GlobalAssemblyCache) { codeBase = Path.GetFileName(assembly.Location); } else { codeBase = assembly.Location; } } catch (ChatSignal ex) { throw; } catch (Exception) { } if (codeBase == null) { codeBase = name.Name + ".dll"; } if (!assemblies.Contains(codeBase)) { assemblies.Add(codeBase); } } var GS = VsaEngine.CreateEngineAndGetGlobalScope(true, assemblies.ToArray()); Engine = GS.engine; #endif foreach (string reference in DefaultNamespaceReferences) { Import.JScriptImport(reference, Engine); } object o = Eval.JScriptEvaluate("this", Engine); writeDebugLine("JSciptThis = " + o); }
private string EvalExpression(string expression) { VsaEngine engine = VsaEngine.CreateEngine(); try { object o = Eval.JScriptEvaluate(expression, engine); return(System.Convert.ToDouble(o).ToString()); } catch { return("No se puede evaluar la expresión"); } engine.Close(); }
public string getUrl(string guid) { try { string txt = GlobalClass.LoadTextFile("getUrl.js", string.Format("jscript\\{0}\\", gc.ForWeb)); string allscript = string.Format("{0};getUrl('{1}');", txt, guid); VsaEngine Engine = VsaEngine.CreateEngine(); object value = Eval.JScriptEvaluate(allscript, Engine); return(value?.ToString()); } catch (Exception ce) { return(null); } }
private static decimal EvaluateNumericExpression(string istrExpresion) { VsaEngine engine = VsaEngine.CreateEngine(); try { object resultado = Eval.JScriptEvaluate(istrExpresion, engine); return(System.Convert.ToDecimal(resultado)); } catch { return(0); } engine.Close(); }
private double IFF(String Expression, double Value1, double Value2) { if (String.IsNullOrWhiteSpace(Expression)) { return(0.0f); } if (Expression.IndexOf("AGC01") >= 0) { String AGC01 = "(IFF(\"([1_AM18CCS0204_XQ01]-[1_AM18CCS0201_XQ01])>2\",0,-5) * IFF (\"[1_MAG01CPZ_XQ01]>31\",0,1)* IFF(\"([1_AM18BY03_XQ01]-[1_AM18CCS0201_XQ01])>10\",1,0))"; String exp = Expression.Replace("AGC01", AGC01); exp = GetIFFExpression(exp); double AGCValue = (double)P.Evaluate(exp); Expression = Expression.Replace("AGC01", AGCValue + ""); } if (Expression.IndexOf("AGC02") >= 0) { String AGC02 = "(IFF(\"([1_AM18CCS0201_XQ01]- [1_AM18CCS0205_XQ01])>2\",0,-5)*(IF(\"[1_AM18BY03_XQ01]<178\",0,1)+IF(\"[1_AMMW_XQ01]<178\",1,0))*IFF(\"([1_AM18CCS0201_XQ01]-[1_AM18BY03_XQ01])>5\",1,0))"; String exp = Expression.Replace("AGC02", AGC02); exp = GetIFFExpression(exp); double AGCValue = (double)P.Evaluate(exp); Expression = Expression.Replace("AGC02", AGCValue + ""); } if (Expression.IndexOf("AGC03") >= 0) { String AGC03 = "(IFF(\"([2_AM18CCS0204_XQ01]-[2_AM18CCS0201_XQ01])>2\",0,-5) * IFF (\"[2_MAG01CPZ_XQ01]>31\",0,1)* IFF(\"([2_AM18BY03_XQ01]-[2_AM18CCS0201_XQ01])>10\",1,0))"; String exp = Expression.Replace("AGC03", AGC03); exp = GetIFFExpression(exp); double AGCValue = (double)P.Evaluate(exp); Expression = Expression.Replace("AGC03", AGCValue + ""); } if (Expression.IndexOf("AGC04") >= 0) { String AGC04 = "(IFF(\"([2_AM18CCS0204_XQ01]-[2_AM18CCS0201_XQ01])>2\",0,-5) * IFF (\"[2_MAG01CPZ_XQ01]>31\",0,1)* IFF(\"([2_AM18BY03_XQ01]-[2_AM18CCS0201_XQ01])>10\",1,0))"; String exp = Expression.Replace("AGC04", AGC04); exp = GetIFFExpression(exp); double AGCValue = (double)P.Evaluate(exp); Expression = Expression.Replace("AGC04", AGCValue + ""); } bool result = System.Convert.ToBoolean(Eval.JScriptEvaluate(Expression, ve)); return(result ? Value1 : Value2); }
private object Execute() { string code = _htmled.Text; string sOutput; object result = null; try { VsaEngine engine1 = VsaEngine.CreateEngine(); result = Eval.JScriptEvaluate(code, true, engine1).ToString(); sOutput = "<html><body><pre>" + result.ToString() + "</pre></body></html>"; } catch (Exception ex) { sOutput = "<html><body><pre style=\"background-color: silver; color: red;\">" + ex.ToString() + "</pre></body></html>"; } _htmlvw.Html = sOutput; return(result); }
/// <summary> /// 返回值解释: /// 0-正确; /// 1-错误,标签点引用不正确; /// 2-错误,空标签点; /// 3-错误,表达式不正确; /// 4-错误, /// </summary> /// <param name="strexp"></param> /// <param name="dcexp"></param> /// <param name="result"></param> /// <param name="strinfor"></param> /// <returns></returns> public int ExpBool(string strexp, Dictionary <string, double> dcexp, out bool result, out string strresult) { result = false; strresult = ""; string strexpression = strexp; foreach (KeyValuePair <string, double> kvp in dcexp) { strexpression = strexpression.Replace(kvp.Key, kvp.Value.ToString("0.00000")); } try { //result = Evaluator.Evaluator.EvaluateToBool(strexpression); result = System.Convert.ToBoolean(Eval.JScriptEvaluate(strexpression, ve)); //result = true; return(0); } catch (Exception e) { LogUtil.LogMessage("错误信息:" + e.Message + "堆栈信息:" + e.StackTrace); LogUtil.LogMessage("原始表达式:" + strexp + "解析后表达式:" + strexpression); strresult = e.Message; return(1); } }
public override void Sync(Action <ElemeLuckyMoney> onReceived, Action onExpired) { StringBuilder synckey = new StringBuilder(); foreach (dynamic o in SyncKey["List"]) { synckey.Append(o["Key"] + "_" + o["Val"] + "|"); } if (synckey.Length > 0) { synckey.Remove(synckey.Length - 1, 1); } string synccheck = "https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck?r=" + Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString() + "&skey=" + HttpUtility.UrlEncode(Skey) + "&sid=" + HttpUtility.UrlEncode(Sid) + "&uin=" + Uin + "&deviceid=" + DeviceID + "&synckey=" + HttpUtility.UrlEncode(synckey.ToString()); Http.Get(synccheck) .OnSuccess((result) => { Match match = Regex.Match(result, "retcode:\"(\\d+)\""); if (match.Success && match.Groups.Count > 1 && match.Groups[1].Value == "0") { match = Regex.Match(result, "selector:\"(\\d+)\""); if (match.Success && match.Groups.Count > 1 && match.Groups[1].Value != "0") { Http.Post("https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsync?sid=" + Sid + "&skey=" + Skey + "&lang=zh_CN&pass_ticket=" + PassTicket) .Body("json", jsSerializer.Serialize( new { BaseRequest = new { Uin = Uin, Sid = Sid, Skey = Skey, DeviceID = DeviceID }, SyncKey = SyncKey, rr = Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString() })) .OnSuccess((header, result_1) => { if (!header.AllKeys.Contains("Set-Cookie")) { onExpired(); return; } dynamic obj = jsSerializer.Deserialize <dynamic>(result_1); SyncKey = obj["SyncKey"]; dynamic[] msgList = obj["AddMsgList"]; foreach (dynamic msg in msgList) { if (!string.IsNullOrEmpty(msg["Url"]) && ((string)msg["Url"]).StartsWith("https://h5.ele.me/hongbao")) { ElemeLuckyMoney eleme = new ElemeLuckyMoney(); eleme.Url = msg["Url"]; Match match1 = Regex.Match(msg["Url"], "sn=([^&]+)&"); if (match1.Success && match1.Groups.Count > 1) { eleme.Sn = match1.Groups[1].Value; } match1 = Regex.Match(msg["Url"], "lucky_number=(\\d+)&"); if (match1.Success && match1.Groups.Count > 1) { eleme.LuckyNum = int.Parse(match1.Groups[1].Value); } onReceived(eleme); } else if (!string.IsNullOrEmpty(msg["Content"])) { MatchCollection matchCollection = Regex.Matches(msg["Content"], "https://h5\\.ele\\.me/hongbao/#hardware_id=&is_lucky_group=True&lucky_number=(\\d+)&track_id=&platform=\\d+&sn=([^&]+)&theme_id=\\d+&device_id="); foreach (Match m in matchCollection) { if (m.Success && m.Groups.Count > 2) { ElemeLuckyMoney eleme = new ElemeLuckyMoney(); eleme.Url = m.Groups[0].Value; eleme.LuckyNum = int.Parse(m.Groups[1].Value); eleme.Sn = m.Groups[2].Value; onReceived(eleme); } } } } }).Go(); } Sync(onReceived, onExpired); } else { onExpired(); } }).Go(); }
public static string JScriptEval(string expr) { return(Eval.JScriptEvaluate(expr, _engine).ToString()); }
private void checkLogin(int tip, Action <bool> onCompleted) { string r = Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString(); Http.Get("https://login.wx2.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&uuid=" + uuid + "&tip=" + tip + "&r=" + r) .OnSuccess((result) => { Match match = Regex.Match(result, "code=(\\d+);"); if (match.Success && match.Groups.Count > 1 && match.Groups[1].Value.Equals("200")) { match = Regex.Match(result, "redirect_uri=\"([^\"]+)\""); if (match.Success && match.Groups.Count > 1) { string redirectUri = match.Groups[1].Value; Http.Get(redirectUri + "&fun=new&version=v2") .OnSuccess((result_1) => { Random random = new Random(); DeviceID = "e" + ("" + random.Next(0, 9999999) + random.Next(0, 99999999)).PadLeft(15, '0'); Match resultMatch = Regex.Match(result_1, "<wxuin>([^<]+)</wxuin>"); if (resultMatch.Success && resultMatch.Groups.Count > 1) { Uin = resultMatch.Groups[1].Value; } resultMatch = Regex.Match(result_1, "<wxsid>([^<]+)</wxsid>"); if (resultMatch.Success && resultMatch.Groups.Count > 1) { Sid = resultMatch.Groups[1].Value; } resultMatch = Regex.Match(result_1, "<skey>([^<]+)</skey>"); if (resultMatch.Success && resultMatch.Groups.Count > 1) { Skey = resultMatch.Groups[1].Value; } resultMatch = Regex.Match(result_1, "<pass_ticket>([^<]+)</pass_ticket>"); if (resultMatch.Success && resultMatch.Groups.Count > 1) { PassTicket = resultMatch.Groups[1].Value; Dictionary <string, string> dic = new Dictionary <string, string>(); Http.Post("https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=" + Eval.JScriptEvaluate("~new Date();", vsaEngine).ToString() + "&lang=zh_CN&pass_ticket=" + PassTicket) .Body("json", jsSerializer.Serialize( new { BaseRequest = new { Uin = Uin, Sid = Sid, Skey = Skey, DeviceID = DeviceID } } )).OnSuccess((result_2) => { dynamic ret = jsSerializer.Deserialize <dynamic>(result_2); SyncKey = ret["SyncKey"]; UserName = ret["User"]["NickName"]; onCompleted(true); }).Go(); } }).Go(); } } else if (match.Success && match.Groups.Count > 1 && (match.Groups[1].Value.Equals("201") || match.Groups[1].Value.Equals("408"))) { Thread.Sleep(1000); checkLogin(0, onCompleted); } else { onCompleted(false); } }).Go(); }
public ActionResult AddDebt(string summ, int group_id, string count, string comment) { var t = JsonConvert.DeserializeObject <result>(count); var div = t.array.Count(); Decimal Sum = 0; try { Sum = System.Convert.ToDecimal(Eval.JScriptEvaluate(summ, VsaEngine.CreateEngine())); } catch (Exception) { return(RedirectToAction("Index", "Error", new { error = "Введено неверное выражение" })); } if (Sum > 0) { Decimal debt = Sum / div; foreach (var id in t.array) { var user = db.users.Where((x) => x.id == id.id).First(); VDolgah.debt first = null; if ((first = user.debts1.Where((x) => x.column == (Session["user"] as VDolgah.user).id).FirstOrDefault()) != null) { first.value += debt; addLog(debt, group_id, comment, user.id); } else if ((first = user.debts.Where((x) => x.row == (Session["user"] as VDolgah.user).id).FirstOrDefault()) != null) { first.value -= debt; if (first.value == 0) { db.debts.Remove(first); } if (first.value < 0) { debt tmp = new VDolgah.debt(); tmp.row = first.column; tmp.column = first.row; tmp.value = -first.value; db.debts.Add(tmp); addLog(debt, group_id, comment, tmp.row); db.debts.Remove(first); } else { addLog(debt, group_id, comment, user.id); } } else if (id.id != (Session["user"] as VDolgah.user).id) { var d = new debt(); d.row = id.id; d.column = (Session["user"] as VDolgah.user).id; d.value = debt; db.debts.Add(d); addLog(debt, group_id, comment, user.id); } } db.SaveChanges(); return(RedirectToAction("Index", new { group_id = group_id })); } else { return(RedirectToAction("Index", "Error", new { error = "Введен долг, который равен 0 или отрицательный" })); } }
public static string RunJavascript(string scriptText) { VsaEngine engine = VsaEngine.CreateEngine(); return(Eval.JScriptEvaluate(scriptText, engine).ToString()); }
private decimal TinhBieuThucDonGian(string bieuthuc) { VsaEngine vsaEngine = VsaEngine.CreateEngine(); return(decimal.Parse(Eval.JScriptEvaluate(bieuthuc, vsaEngine).ToString())); }
public object EvalJScript(string src) { return(Eval.JScriptEvaluate(src, eng)); }