public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category, ResolvedEvent @event, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { CheckDisposed(); _eventPosition = eventPosition; _emittedEvents = null; Tuple <string, string> newStates = null; var data = GetEventData(@event); if (@event == null || data == null) { newStates = _query.Push( "", new string[] { }); } else { newStates = _query.Push( data, new[] { @event.IsJson ? "1" : "", @event.EventStreamId, @event.EventType, category ?? "", @event.EventSequenceNumber.ToString(CultureInfo.InvariantCulture), @event.Metadata ?? "", @event.PositionMetadata ?? "", partition, @event.EventId.ToString() }); } newState = newStates.Item1; newSharedState = newStates.Item2; /* try * { * if (!string.IsNullOrEmpty(newState)) * { * var jo = newState.ParseJson<JObject>(); * } * * } * catch (InvalidCastException) * { * Console.Error.WriteLine(newState); * } * catch (JsonException) * { * Console.Error.WriteLine(newState); * }*/ emittedEvents = _emittedEvents == null ? null : _emittedEvents.ToArray(); return(true); }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category, ResolvedEvent data, out string newState, out EmittedEventEnvelope[] emittedEvents) { CheckDisposed(); if (data == null) { throw new ArgumentNullException("data"); } _eventPosition = eventPosition; _emittedEvents = null; newState = _query.Push( data.Data.Trim(), // trimming data passed to a JS new[] { data.IsJson ? "1" : "", data.EventStreamId, data.EventType, category ?? "", data.EventSequenceNumber.ToString(CultureInfo.InvariantCulture), data.Metadata, partition }); try { if (!string.IsNullOrEmpty(newState)) { var jo = newState.ParseJson <JObject>(); } } catch (JsonException jex) { Console.Error.WriteLine(newState); } emittedEvents = _emittedEvents == null ? null : _emittedEvents.ToArray(); return(true); }
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 bool ProcessEvent(string partition, CheckpointTag eventPosition, string category, ResolvedEvent @event, out string newState, out string newSharedState, out EmittedEventEnvelope[] emittedEvents) { CheckDisposed(); _eventPosition = eventPosition; _emittedEvents = null; Tuple <string, string> newStates = null; var data = GetEventData(@event); if (@event == null || data == null || string.IsNullOrEmpty(@event.EventType)) { newStates = _query.Push( "", new string[] { }); } else { newStates = _query.Push( data, new[] { @event.IsJson ? "1" : "", @event.EventStreamId, @event.EventType, category ?? "", @event.EventSequenceNumber.ToString(CultureInfo.InvariantCulture), @event.Metadata ?? "", @event.PositionMetadata ?? "", partition, @event.EventId.ToString() }); } newState = newStates.Item1; newSharedState = newStates.Item2; emittedEvents = _emittedEvents == null ? null : _emittedEvents.ToArray(); return(true); }
public bool ProcessEvent( EventPosition position, string streamId, string eventType, string category, Guid eventid, int sequenceNumber, string metadata, string data, out string newState, out EmittedEvent[] emittedEvents) { if (eventType == null) { throw new ArgumentNullException("eventType"); } if (streamId == null) { throw new ArgumentNullException("streamId"); } _emittedEvents = null; _query.Push( data.Trim(), // trimming data passed to a JS new string[] { streamId, eventType, category ?? "", sequenceNumber.ToString(CultureInfo.InvariantCulture), metadata ?? "" }); newState = _query.GetState(); emittedEvents = _emittedEvents == null ? null : _emittedEvents.ToArray(); return(true); }
public bool ProcessEvent( string partition, CheckpointTag eventPosition, string category, ResolvedEvent data, out string newState, out EmittedEvent[] emittedEvents) { CheckDisposed(); if (data == null) { throw new ArgumentNullException("data"); } _eventPosition = eventPosition; _emittedEvents = null; newState = _query.Push( data.Data.Trim(), // trimming data passed to a JS new[] { data.IsJson ? "1" : "", data.EventStreamId, data.EventType, category ?? "", data.EventSequenceNumber.ToString(CultureInfo.InvariantCulture), data.Metadata, partition }); emittedEvents = _emittedEvents == null ? null : _emittedEvents.ToArray(); return(true); }