Inheritance: IDisposable
Beispiel #1
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);
            }
        }
Beispiel #2
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);
                        }
        }
 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;
 }