private CompiledScript CompileScript(string script, string fileName) { IntPtr prelude = Js1.CompilePrelude(script, fileName, _loadModuleDelegate, _logDelegate); CompiledScript.CheckResult(prelude, disposeScriptOnException: true); return(new CompiledScript(prelude, fileName)); }
private string ExecuteHandler( IntPtr commandHandlerHandle, string json, string[] other, out string newSharedState) { _reverseCommandHandlerException = null; _prelude.ScheduleTerminateExecution(); IntPtr resultJsonPtr; IntPtr result2JsonPtr; IntPtr memoryHandle; bool success = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr, out result2JsonPtr, out memoryHandle); var terminated = _prelude.CancelTerminateExecution(); if (!success) { CompiledScript.CheckResult(_script.GetHandle(), terminated, disposeScriptOnException: false); } string resultJson = Marshal.PtrToStringUni(resultJsonPtr); string result2Json = Marshal.PtrToStringUni(result2JsonPtr); Js1.FreeResult(memoryHandle); if (_reverseCommandHandlerException != null) { throw new ApplicationException( "An exception occurred while executing a reverse command handler. " + _reverseCommandHandlerException.Message, _reverseCommandHandlerException); } newSharedState = result2Json; return(resultJson); }
private CompiledScript CompileScript(PreludeScript prelude, string script, string fileName) { IntPtr query = Js1.CompileQuery( prelude.GetHandle(), script, fileName, _commandHandlerRegisteredCallback, _reverseCommandHandlerDelegate); CompiledScript.CheckResult(query, disposeScriptOnException: true); return(new CompiledScript(query, fileName)); }
private CompiledScript CompileScript(PreludeScript prelude, string script, string fileName) { prelude.ScheduleTerminateExecution(); IntPtr query = Js1.CompileQuery( prelude.GetHandle(), script, fileName, _commandHandlerRegisteredCallback, _reverseCommandHandlerDelegate); var terminated = prelude.CancelTerminateExecution(); CompiledScript.CheckResult(query, terminated, disposeScriptOnException: true); return(new CompiledScript(query, fileName)); }
// a reference must be kept to make a delegate callable from unmanaged world public PreludeScript( string script, string fileName, Func <string, Tuple <string, string> > getModuleSourceAndFileName, Action <string> logger = null) { _logDelegate = LogHandler; _loadModuleDelegate = GetModule; _getModuleSourceAndFileName = getModuleSourceAndFileName; _logger = logger; _script = CompileScript(script, fileName); }
// a reference must be kept to make a delegate callable from unmanaged world public PreludeScript( string script, string fileName, Func<string, Tuple<string, string>> getModuleSourceAndFileName, Action<string> logger = null) { _logDelegate = LogHandler; _loadModuleDelegate = GetModule; _getModuleSourceAndFileName = getModuleSourceAndFileName; _logger = logger; _script = CompileScript(script, fileName); }
private CompiledScript CompileScript(string script, string fileName) { ScheduleTerminateExecution(); IntPtr prelude = Js1.CompilePrelude( script, fileName, _loadModuleDelegate, _enterCancellableRegion, _exitCancellableRegion, _logDelegate); CancelTerminateExecution(); CompiledScript.CheckResult(prelude, false, disposeScriptOnException: true); return(new CompiledScript(prelude, fileName)); }
public PreludeScript( string script, string fileName, Func<string, Tuple<string, string>> getModuleSourceAndFileName, Action<int, Action> cancelCallbackFactory, Action<string, object[]> logger = null) { _logDelegate = LogHandler; _loadModuleDelegate = GetModule; _getModuleSourceAndFileName = getModuleSourceAndFileName; _logger = logger; _enterCancellableRegion = EnterCancellableRegion; _exitCancellableRegion = ExitCancellableRegion; _cancelCallbackFactory = cancelCallbackFactory; _script = CompileScript(script, fileName); }
public PreludeScript( string script, string fileName, Func <string, Tuple <string, string> > getModuleSourceAndFileName, Action <int, Action> cancelCallbackFactory, Action <string, object[]> logger = null) { _logDelegate = LogHandler; _loadModuleDelegate = GetModule; _getModuleSourceAndFileName = getModuleSourceAndFileName; _logger = logger; _enterCancellableRegion = EnterCancellableRegion; _exitCancellableRegion = ExitCancellableRegion; _cancelCallbackFactory = cancelCallbackFactory; _script = CompileScript(script, fileName); }
public QueryScript(PreludeScript prelude, string script, string fileName) { _prelude = prelude; _commandHandlerRegisteredCallback = CommandHandlerRegisteredCallback; _reverseCommandHandlerDelegate = ReverseCommandHandler; _script = CompileScript(prelude, script, fileName); try { GetSources(); } catch { Dispose(); throw; } }
private string ExecuteHandler(IntPtr commandHandlerHandle, string json, string[] other = null) { IntPtr resultJsonPtr; IntPtr resultHandle = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr); if (resultHandle == IntPtr.Zero) { CompiledScript.CheckResult(_script.GetHandle(), disposeScriptOnException: false); } string resultJson = Marshal.PtrToStringUni(resultJsonPtr); Js1.FreeResult(resultHandle); return(resultJson); }
public QueryScript(PreludeScript prelude, string script, string fileName) { _commandHandlerRegisteredCallback = CommandHandlerRegisteredCallback; _reverseCommandHandlerDelegate = ReverseCommandHandler; _script = CompileScript(prelude, script, fileName); try { GetSources(); } catch { Dispose(); throw; } }
private IntPtr GetModule(string moduleName) { try { var moduleSourceAndFileName = GetModuleSourceAndFileName(moduleName); var compiledModuleHandle = Js1.CompileModule( GetHandle(), moduleSourceAndFileName.Item1, moduleSourceAndFileName.Item2); CompiledScript.CheckResult(compiledModuleHandle, disposeScriptOnException: true); var compiledModule = new CompiledScript(compiledModuleHandle, moduleSourceAndFileName.Item2); _modules.Add(compiledModule); return(compiledModuleHandle); } catch (Exception) { //TODO: this is not a good way to report missing module and other exceptions back to caller return(IntPtr.Zero); } }
private CompiledScript CompileScript(string script, string fileName) { try { var attempts = 3; var prelude = default(IntPtr); do { attempts--; try { ScheduleTerminateExecution(); prelude = Js1.CompilePrelude( script, fileName, _loadModuleDelegate, _enterCancellableRegion, _exitCancellableRegion, _logDelegate); CancelTerminateExecution(); CompiledScript.CheckResult(prelude, false, disposeScriptOnException: true); } catch (Js1Exception ex) { if (attempts > 0 && (ex.ErrorCode == -1 || ex.ErrorCode == -2)) { // timeouts Thread.Sleep(2000); } else { throw; } } } while (prelude == default(IntPtr)); return(new CompiledScript(prelude)); } catch (DllNotFoundException ex) { Log.Info("{0}\n{1}\n{2}", ex.ToString(), ex.Message, ex.StackTrace); throw new ApplicationException( "The projection subsystem failed to load a libjs1.so/js1.dll/... or one of its dependencies. The original error message is: " + ex.Message, ex); } }
private IntPtr GetModule(IntPtr prelude, string moduleName) { try { var moduleSourceAndFileName = GetModuleSourceAndFileName(moduleName); // NOTE: no need to schedule termination; modules are loaded only in context if (_cancelTokenOrStatus == NonScheduled) { throw new InvalidOperationException("Requires scheduled terminate execution"); } var compiledModuleHandle = Js1.CompileModule( prelude, moduleSourceAndFileName.Item1, moduleSourceAndFileName.Item2); CompiledScript.CheckResult(compiledModuleHandle, terminated: false, disposeScriptOnException: true); var compiledModule = new CompiledScript(compiledModuleHandle); _modules.Add(compiledModule); return(compiledModuleHandle); } catch (Exception ex) { Log.Error(ex, "Cannot load module '{module}'", moduleName); //TODO: this is not a good way to report missing module and other exceptions back to caller return(IntPtr.Zero); } }
private string ExecuteHandler(IntPtr commandHandlerHandle, string json, string[] other = null) { _reverseCommandHandlerException = null; IntPtr resultJsonPtr; IntPtr resultHandle = Js1.ExecuteCommandHandler( _script.GetHandle(), commandHandlerHandle, json, other, other != null ? other.Length : 0, out resultJsonPtr); if (resultHandle == IntPtr.Zero) { CompiledScript.CheckResult(_script.GetHandle(), disposeScriptOnException: false); } //TODO: do we need to free resulktJsonPtr in case of exception thrown a line above string resultJson = Marshal.PtrToStringUni(resultJsonPtr); Js1.FreeResult(resultHandle); if (_reverseCommandHandlerException != null) { throw new ApplicationException( "An exception occurred while executing a reverse command handler. " + _reverseCommandHandlerException.Message, _reverseCommandHandlerException); } return(resultJson); }
private IntPtr GetModule(string moduleName) { try { var moduleSourceAndFileName = GetModuleSourceAndFileName(moduleName); var compiledModuleHandle = Js1.CompileModule( GetHandle(), moduleSourceAndFileName.Item1, moduleSourceAndFileName.Item2); CompiledScript.CheckResult(compiledModuleHandle, disposeScriptOnException: true); var compiledModule = new CompiledScript(compiledModuleHandle, moduleSourceAndFileName.Item2); _modules.Add(compiledModule); return compiledModuleHandle; } catch (Exception) { //TODO: this is not a good way to report missing module and other exceptions back to caller return IntPtr.Zero; } }
private IntPtr GetModule(string moduleName) { try { var moduleSourceAndFileName = GetModuleSourceAndFileName(moduleName); // NOTE: no need to schedule termination; modules are loaded only in context if (_cancelTokenOrStatus == NonScheduled) throw new InvalidOperationException("Requires scheduled terminate execution"); var compiledModuleHandle = Js1.CompileModule( GetHandle(), moduleSourceAndFileName.Item1, moduleSourceAndFileName.Item2); CompiledScript.CheckResult(compiledModuleHandle, terminated: false, disposeScriptOnException: true); var compiledModule = new CompiledScript(compiledModuleHandle); _modules.Add(compiledModule); return compiledModuleHandle; } catch (Exception ex) { _systemLogger.ErrorException(ex, "Cannot load module '{0}'", moduleName); //TODO: this is not a good way to report missing module and other exceptions back to caller return IntPtr.Zero; } }