コード例 #1
0
ファイル: PreludeScript.cs プロジェクト: Sarmaad/EventStore-1
        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));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        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));
        }
コード例 #5
0
        // 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);
        }
コード例 #6
0
ファイル: PreludeScript.cs プロジェクト: robashton/EventStore
 // 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);
 }
コード例 #7
0
ファイル: PreludeScript.cs プロジェクト: tubo70/EventStore
        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));
        }
コード例 #8
0
ファイル: PreludeScript.cs プロジェクト: danieldeb/EventStore
 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);
 }
コード例 #9
0
 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);
 }
コード例 #10
0
        public QueryScript(PreludeScript prelude, string script, string fileName)
        {
            _prelude = prelude;
            _commandHandlerRegisteredCallback = CommandHandlerRegisteredCallback;
            _reverseCommandHandlerDelegate    = ReverseCommandHandler;

            _script = CompileScript(prelude, script, fileName);

            try {
                GetSources();
            } catch {
                Dispose();
                throw;
            }
        }
コード例 #11
0
ファイル: QueryScript.cs プロジェクト: vishal-h/EventStore-1
        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);
        }
コード例 #12
0
ファイル: QueryScript.cs プロジェクト: trbngr/EventStore
        public QueryScript(PreludeScript prelude, string script, string fileName)
        {
            _commandHandlerRegisteredCallback = CommandHandlerRegisteredCallback;
            _reverseCommandHandlerDelegate = ReverseCommandHandler;

            _script = CompileScript(prelude, script, fileName);

            try
            {
                GetSources();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
コード例 #13
0
 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);
     }
 }
コード例 #14
0
 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);
     }
 }
コード例 #15
0
ファイル: PreludeScript.cs プロジェクト: zerox981/EventStore
 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);
     }
 }
コード例 #16
0
        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);
        }
コード例 #17
0
ファイル: PreludeScript.cs プロジェクト: robashton/EventStore
 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;
     }
 }
コード例 #18
0
ファイル: PreludeScript.cs プロジェクト: danieldeb/EventStore
 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;
     }
 }