public MainAlgo(MainAlgoConfig algoConfig) { conf = algoConfig; diSourceFolder = new DirectoryInfo(conf.sourchDirPath); diTargetFolder = new DirectoryInfo(conf.targetDirPath); using (ScriptEngine engine = new ScriptEngine(ScriptEngine.JavaScriptLanguage)) { helpScript = engine.Parse(conf.jsCodeHelper); } }
private object Parse(string text, bool expression) { const string varName = "x___"; object result; _engine.SetScriptState(ScriptState.Connected); ScriptText flags = ScriptText.None; if (expression) { flags |= ScriptText.IsExpression; } try { // immediate expression computation seems to work only for 64-bit // so hack something for 32-bit... System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo; if (_parse32 != null) { if (expression) { // should work for jscript & vbscript at least... text = varName + "=" + text; } _parse32.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo); } else { _parse64.ParseScriptText(text, null, IntPtr.Zero, null, 0, 0, flags, out result, out exceptionInfo); } } catch { if (Site.LastException != null) { throw Site.LastException; } throw; } IntPtr dispatch; if (expression) { // continue our 32-bit hack... if (_parse32 != null) { _engine.GetScriptDispatch(null, out dispatch); object dp = Marshal.GetObjectForIUnknown(dispatch); try { return(dp.GetType().InvokeMember(varName, System.Reflection.BindingFlags.GetProperty, null, dp, null)); } catch { if (Site.LastException != null) { throw Site.LastException; } throw; } } return(result); } _engine.GetScriptDispatch(null, out dispatch); ParsedScript parsed = new ParsedScript(this, dispatch); return(parsed); }