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);
 }
Exemplo n.º 2
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));
        }
Exemplo n.º 3
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);
 }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            var preludeFileName = args[0];
            var preludeScript = File.ReadAllText(preludeFileName);
            var queryFileName = args[1];
            var queryScript = File.ReadAllText(queryFileName);

            Func<string, Tuple<string, string>> loadModule =
                moduleName =>
                    {
                        var moduleFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, moduleName + ".js");
                        return
                            Tuple.Create(
                                File.ReadAllText(moduleFilename),
                                moduleFilename);
                    };

            using (var prelude = new PreludeScript(preludeScript, preludeFileName, loadModule))
            using (var query = new QueryScript(prelude, queryScript, queryFileName))
            using (var events = File.OpenText(args[2]))
            using (var output = (args.Length >= 4) ? File.CreateText(args[3]) : Console.Out)
            {
                long totalMs = 0;
                int count = 0;
                query.Initialize();
                if (output != null)
                {
                    var capturedOutput = output;
                    query.Emit += s => capturedOutput.WriteLine(s.Trim());
                }
                var sw = new Stopwatch();
                while (!events.EndOfStream)
                {
                    var eventJson = events.ReadLine().Trim();
                    if (!string.IsNullOrWhiteSpace(eventJson))
                    {
                        sw.Start();
                        query.Push(eventJson, null);
                        count++;
                        sw.Stop();
                    }
                }
                totalMs = sw.ElapsedMilliseconds;
                Console.WriteLine(query.GetState());
                Console.WriteLine(query.GetStatistics());
                Console.WriteLine("Total JS push processing time: {0,5:f2} ms", totalMs);
                Console.WriteLine("Average time per 1000 pushes:  {0,5:f2} ms", 1000f*totalMs/(float) count);
                Console.WriteLine("Pure JS events per second:     {0,5:f2} events", count*1000f/totalMs);
                Console.WriteLine("Total events processed:        {0} events", count);
            }
        }
Exemplo n.º 6
0
        private static void Main(string[] args)
        {
            var preludeFileName = args[0];
            var preludeScript   = File.ReadAllText(preludeFileName);
            var queryFileName   = args[1];
            var queryScript     = File.ReadAllText(queryFileName);

            Func <string, Tuple <string, string> > loadModule =
                moduleName =>
            {
                var moduleFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, moduleName + ".js");
                return
                    (Tuple.Create(
                         File.ReadAllText(moduleFilename),
                         moduleFilename));
            };

            using (var prelude = new PreludeScript(preludeScript, preludeFileName, loadModule))
                using (var query = new QueryScript(prelude, queryScript, queryFileName))
                    using (var events = File.OpenText(args[2]))
                        using (var output = (args.Length >= 4) ? File.CreateText(args[3]) : Console.Out)
                        {
                            long totalMs = 0;
                            int  count   = 0;
                            query.Initialize();
                            if (output != null)
                            {
                                var capturedOutput = output;
                                query.Emit += s => capturedOutput.WriteLine(s.Trim());
                            }
                            var sw = new Stopwatch();
                            while (!events.EndOfStream)
                            {
                                var eventJson = events.ReadLine().Trim();
                                if (!string.IsNullOrWhiteSpace(eventJson))
                                {
                                    sw.Start();
                                    query.Push(eventJson, null);
                                    count++;
                                    sw.Stop();
                                }
                            }
                            totalMs = sw.ElapsedMilliseconds;
                            Console.WriteLine(query.GetState());
                            Console.WriteLine(query.GetStatistics());
                            Console.WriteLine("Total JS push processing time: {0,5:f2} ms", totalMs);
                            Console.WriteLine("Average time per 1000 pushes:  {0,5:f2} ms", 1000f * totalMs / (float)count);
                            Console.WriteLine("Pure JS events per second:     {0,5:f2} events", count * 1000f / totalMs);
                            Console.WriteLine("Total events processed:        {0} events", count);
                        }
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
0
        public QueryScript(PreludeScript prelude, string script, string fileName)
        {
            _commandHandlerRegisteredCallback = CommandHandlerRegisteredCallback;
            _reverseCommandHandlerDelegate = ReverseCommandHandler;

            _script = CompileScript(prelude, script, fileName);

            try
            {
                GetSources();
            }
            catch
            {
                Dispose();
                throw;
            }
        }
 public V8ProjectionStateHandler(
     string preludeName, string querySource, Func<string, Tuple<string, string>> getModuleSource,
     Action<string> logger)
 {
     var preludeSource = getModuleSource(preludeName);
     var prelude = new PreludeScript(preludeSource.Item1, preludeSource.Item2, getModuleSource, logger);
     QueryScript query;
     try
     {
         query = new QueryScript(prelude, querySource, "POST-BODY");
         query.Emit += QueryOnEmit;
     }
     catch
     {
         prelude.Dispose(); // clean up unmanaged resources if failed to create
         throw;
     }
     _prelude = prelude;
     _query = query;
 }
Exemplo n.º 10
0
        public void long_execution_of_non_v8_code_does_not_crash()
        {
            _cancelCallbackFactory = (timeout, action) => ThreadPool.QueueUserWorkItem(state =>
                {
                    Console.WriteLine("Calling a callback in " + timeout + "ms");
                    Thread.Sleep(timeout);
                    action();
                });
            Action<string> logger = Console.WriteLine;


            Func<string, Tuple<string, string>> getModuleSource = name =>
                {
                    var fullScriptFileName = Path.GetFullPath(Path.Combine(_jsPath, name + ".js"));
                    var scriptSource = File.ReadAllText(fullScriptFileName, Helper.UTF8NoBom);
                    return Tuple.Create(scriptSource, fullScriptFileName);
                };


            var preludeSource = getModuleSource("1Prelude");
            var prelude = new PreludeScript(preludeSource.Item1, preludeSource.Item2, getModuleSource, _cancelCallbackFactory, logger);
            try
            {
                //var cancelToken = 123;
                prelude.ScheduleTerminateExecution();
                Thread.Sleep(500);
                _commandHandlerRegisteredCallback = (name, handle) => { };
                _reverseCommandHandlerDelegate = (name, body) => { };
                Js1.CompileQuery(
                    prelude.GetHandle(), "log(1);", "fn", _commandHandlerRegisteredCallback,
                    _reverseCommandHandlerDelegate);

                prelude.CancelTerminateExecution();
            }
            catch
            {
                prelude.Dispose(); // clean up unmanaged resources if failed to create
                throw;
            }

        }
 public void can_compile_prelude_million_times()
 {
     _logger = s =>
         {
             if (!s.StartsWith("P:")) _logged.Add(s);
             else _logDelegate(s);
         };
     _projection = @"
         fromAll();
         on_raw(function(state, event, streamId, eventType, sequenceNumber, metadata) {
             emit('output-stream' + sequenceNumber, 'emitted-event' + sequenceNumber, {a: JSON.parse(event).a});
             return {};
         });
     ";
     for (var i = 0; i < 10000000; i++)
     {
         _logged = new List<string>();
         var preludeSource = DefaultV8ProjectionStateHandler.GetModuleSource("1Prelude");
         using (
             var prelude = new PreludeScript(
                 preludeSource.Item1, preludeSource.Item2, DefaultV8ProjectionStateHandler.GetModuleSource,
                 _logger))
         {
         }
     }
 }