/// <summary> /// JS计算 /// </summary> /// <param name="CurrentDir">js文件地址</param> /// <param name="EvalStr">计算公式 例如 "getpwd('pwd')"</param> /// <returns>返回加密结果</returns> public string JavaScriptEval(string Code, string EvalStr) { ScriptControl script = new ScriptControl(); script.Language = "JavaScript"; script.AddCode(Code); return(script.Eval(EvalStr).ToString()); }
// JsEx.ExecuteJScript(@"encrypt(""12345678"")", File.ReadAllText("encrypt.js") public static string ExecuteJScript(string sExpression, string sCode) { ScriptControl scriptControl = new ScriptControl { UseSafeSubset = true, Language = "JScript" }; scriptControl.AddCode(sCode); string str = scriptControl.Eval(sExpression).ToString(); return(str); }
public object Excute(string sExpression) { try { return(scriptControl.Eval(sExpression)); } catch (Exception ex) { MessageBox.Show($"ExcuteScript(){ex.Message}=>\n{ex.StackTrace}"); //Logger.SysLog(ex.Message+'\n'+ex.StackTrace,"主记录"); } return(null); }
/// <summary> /// 这个临时处理方案本来不应该在这里 /// </summary> /// <param name="inputStr"></param> /// <param name="key"></param> /// <param name="codeType"></param> /// <returns></returns> private static string DesCode(string inputStr, string key, string codeType, string jsPath) { MSScriptControl.ScriptControl js = new ScriptControl(); js.AllowUI = false; js.Language = "JScript"; js.Reset(); //Server.MapPath("/static/DES.js"); string jsCode = FileHelper.ReadFile(jsPath, System.Text.Encoding.UTF8); js.AddCode(jsCode); string result = js.Eval(String.Format("{0}('{1}', '{2}')", codeType, inputStr, key)); return(result); }
/// <summary> /// 计算表达式的值 /// </summary> /// <param name="strExpression">表达式</param> /// <returns>值的字符串形式</returns> public static string Eval(string strExpression) { string strResult = string.Empty; ScriptControl vScriptControl = new ScriptControl(); try { strResult = vScriptControl.Eval(strExpression).ToString(); } catch (Exception ex) { LogHelper.WriteDebug(string.Format("RC10001 : {0}", ex.Message)); } return(strResult); }
public string Excute(string js) { string str = ""; try { str = m_sc.Eval(js).ToString(); return(str); } catch (Exception ex) { str = ex.Message; } return(str); }
/// <summary> /// 执行JS /// </summary> /// <param name="sExpression">参数体</param> /// <param name="sCode">JavaScript代码的字符串</param> /// <returns></returns> private static string ExecuteScript(string sExpression, string sCode) { var scriptControl = new ScriptControl { UseSafeSubset = true, Language = "JScript" }; scriptControl.AddCode(sCode); try { string str = scriptControl.Eval(sExpression).ToString(); return(str); } catch (Exception ex) { var str = ex.Message; } return(null); }
private static string smethod_0(string string_0, string string_1) { try { ScriptControl scriptControl = (ScriptControl)Activator.CreateInstance(Marshal.GetTypeFromCLSID(new Guid("0E59F1D5-1FBE-11D0-8FF2-00A0D10038BC"))); scriptControl.UseSafeSubset = true; scriptControl.Language = "JScript"; scriptControl.AddCode(string_1); try { return((string)((dynamic)scriptControl.Eval(string_0)).ToString()); } catch (Exception ex) { string message = ex.Message; } return(""); } catch (Exception) { return(""); } }
/// <summary> /// 运行Eval方法 /// </summary> /// <param name="expression">表达式</param> /// <param name="codeBody">函数体</param> /// <returns>返回值object</returns> public object Eval(string expression, string codeBody) { msc.AddCode(codeBody); return(msc.Eval(expression)); }
/// <summary> /// 运行Eval方法 /// </summary> /// <param name="expression">表达式</param> /// <returns>返回值object</returns> public object Eval(string expression) { return(msc.Eval(expression)); }
private bool TryToFindTheAnswer(List <string> ar, Point p) { if (ar.Count < 5) { return(false); } if (ar[3] != "=") { ar.Reverse(); } ScriptControl sc = new ScriptControl(); sc.Language = "javascript"; string result = ""; if (ar[0] == "?") { switch (ar[1]) { case "+": result = String.Format("{0}-{1}", ar[4], ar[2]); break; case "-": result = String.Format("{0}+{1}", ar[4], ar[2]); break; case "*": result = String.Format("{0}/{1}", ar[4], ar[2]); break; case "/": result = String.Format("{0}*{1}", ar[4], ar[2]); break; } } if (ar[2] == "?") { switch (ar[1]) { case "+": result = String.Format("{0}-{1}", ar[4], ar[0]); break; case "-": result = String.Format("({0}-{1})*-1", ar[4], ar[0]); break; case "*": result = String.Format("{0}/{1}", ar[4], ar[0]); break; case "/": result = String.Format("{0}/{1}", ar[0], ar[4]); break; } } if (ar[4] == "?") { result = String.Format("{0}{1}{2}", ar[0], ar[1], ar[2]); } result = Convert.ToString(sc.Eval(result)); map[p.Y][p.X] = result; return(true); }