private static string CreateLineFromEvent(UntypedEvent evt, CepEventType eventType, string[] delimiter, Dictionary <int, int> order, CultureInfo culture) { StringBuilder builder = new StringBuilder(); PointEvent pointEvent = evt as PointEvent; IntervalEvent intervalEvent = evt as IntervalEvent; EdgeEvent edgeEvent = evt as EdgeEvent; if (EventKind.Cti == evt.EventKind) { builder .Append("CTI") .Append(delimiter[0]); if (null != pointEvent) { builder.Append(pointEvent.StartTime.ToString()); } else if (null != intervalEvent) { builder.Append(intervalEvent.StartTime.ToString()); } else { builder.Append(edgeEvent.StartTime.ToString()); } } else { builder .Append("INSERT") .Append(delimiter[0]); if (null != pointEvent) { builder.Append(pointEvent.StartTime.ToString()); } else if (null != intervalEvent) { builder .Append(intervalEvent.StartTime.ToString()) .Append(delimiter[0]) .Append(intervalEvent.EndTime.ToString()) .Append(delimiter[0]); } else { builder .Append(edgeEvent.EdgeType.ToString()) .Append(delimiter[0]) .Append(edgeEvent.StartTime.ToString()) .Append(delimiter[0]) .Append((EdgeType.End == edgeEvent.EdgeType) ? edgeEvent.EndTime.ToString() : string.Empty) .Append(delimiter[0]); } SerializePayload(evt, eventType, delimiter, order, culture, ref builder); } return(builder.ToString()); }
// Start is called before the first frame update void Start() { audioSource = GetComponent <AudioSource>(); secPerBeat = 60 / songBpm; dspSongTime = (float)AudioSettings.dspTime; audioSource.Play(); if (newLoopEvent == null) { newLoopEvent = new UnityEvent(); } if (Interval == null) { Interval = new IntervalEvent(); } if (Beat == null) { Beat = new UnityEvent(); } }
/// <summary> /// Reads the contents of the TollInput.txt data file to an IEnumerable source. /// </summary> /// <returns>Toll data.</returns> public static IEnumerable <IntervalEvent <TollReading> > CreateTollDataSource() { foreach (string line in File.ReadLines(@"Data\TollInput.txt")) { string[] fields = line.Split(','); yield return(IntervalEvent.CreateInsert( DateTime.Parse(fields[0], CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal), DateTime.Parse(fields[1], CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal), new TollReading { TollId = fields[2], LicensePlate = fields[3], State = fields[4], Make = fields[5], Model = fields[6], VehicleType = int.Parse(fields[7], CultureInfo.InvariantCulture), VehicleWeight = string.IsNullOrWhiteSpace(fields[8]) ? default(float) : float.Parse(fields[8], CultureInfo.InvariantCulture), Toll = float.Parse(fields[9], CultureInfo.InvariantCulture), Tag = fields[10], })); } }
private double weightcharge = 0.5; // defined as a constant within the UDO; this could be passed as a config if required public override IEnumerable <IntervalEvent <VehicleWeightInfo> > GenerateOutput( IEnumerable <IntervalEvent <TollReading> > events, WindowDescriptor windowDescriptor) { List <IntervalEvent <VehicleWeightInfo> > output = new List <IntervalEvent <VehicleWeightInfo> >(); // Identify any commercial vehicles in this window for the given window duration foreach (var e in events.Where(e => e.StartTime.Hour >= 0 && e.Payload.VehicleType == 2)) { // create an output interval event IntervalEvent <VehicleWeightInfo> vehicleWeightEvent = CreateIntervalEvent(); // populate the output interval event vehicleWeightEvent.StartTime = e.StartTime; vehicleWeightEvent.EndTime = e.EndTime; vehicleWeightEvent.Payload = new VehicleWeightInfo { LicensePlate = e.Payload.LicensePlate, Weight = e.Payload.VehicleWeight, // here is the interesting part; note how the output is dependent on // the start and end timestamps of the input event. The weight charge // is a function of the rush hour definition, the weigh charge factor // and the vehicle tonnage itself WeightCharge = ((e.StartTime.Hour >= 7 && e.StartTime.Hour <= 14) ? 2 : 1) * this.weightcharge * e.Payload.VehicleWeight }; // output the event via the IEnumerable interface output.Add(vehicleWeightEvent); } return(output); }
/// <summary> /// Main driver to dequeue events and output them to the CSV file /// </summary> private void ConsumeEvents() { IntervalEvent currentEvent = default(IntervalEvent); try { while (true) { if (AdapterState.Stopping == AdapterState) { this.streamWriter.Flush(); this.streamWriter.Close(); Stopped(); return; } if (DequeueOperationResult.Empty == Dequeue(out currentEvent)) { Ready(); return; } this.streamWriter.WriteLine(TextFileWriterCommon.CreateLineFromEvent(currentEvent, this.bindtimeEventType, this.delimiter)); // Every received event needs to be released. ReleaseEvent(ref currentEvent); } } catch (AdapterException e) { this.consoleTracer.WriteLine("ConsumeEvents - " + e.Message + e.StackTrace); } }
private void ApplyTransition(List <IntervalEvent <TRegister> > result, DateTimeOffset endTime, Run previousRun, EventSet <TInput> inputEvents, LinkedList <Run> currentRuns) { int fromState = previousRun.State; List <int> toStates = _descriptor.GetToStates(fromState); foreach (int toState in toStates) { TRegister targetRegister; if (_descriptor.TryApplyTransition(inputEvents, fromState, toState, previousRun.Register, out targetRegister)) { Run newRun = new Run(toState, targetRegister); if (_descriptor.IsFinalState(toState)) { // If we have reached a final state, include the register value in result. IntervalEvent <TRegister> outputEvent = CreateIntervalEvent(); outputEvent.Payload = newRun.Register; outputEvent.StartTime = inputEvents.StartTime; outputEvent.EndTime = endTime; result.Add(outputEvent); } currentRuns.AddLast(newRun); } } }
/// <summary> /// Creates a string from an interval event. /// </summary> /// <param name="evt">The interval event to serialize.</param> /// <param name="eventType">CEP event type.</param> /// <param name="delimiter">Delimiter between event fields.</param> /// <returns>Serialized event.</returns> public static string CreateLineFromEvent(IntervalEvent evt, CepEventType eventType, char delimiter) { StringBuilder builder = new StringBuilder(); if (EventKind.Cti == evt.EventKind) { builder .Append("CTI") .Append(delimiter) .Append(evt.StartTime.ToString()); } else { builder .Append("INSERT") .Append(delimiter) .Append(evt.StartTime.ToString()) .Append(delimiter) .Append(evt.EndTime.ToString()) .Append(delimiter); SerializePayload(evt, eventType, delimiter, ref builder); } return(builder.ToString()); }
private void PrepareToStop(IntervalEvent <T> currEvent, DequeueOperationResult result) { if (result == DequeueOperationResult.Success) { ReleaseEvent(ref currEvent); } }
public void Add(IntervalEvent <TInput> evt) { this.eventList.Add(evt.Payload); if (evt.EndTime < this.endTime) { this.endTime = evt.EndTime; } }
public IntervalEvent <TPayloadType> GetIntervalEvent() { if (this.EventKind == EventKind.Insert) { return(IntervalEvent <TPayloadType> .CreateInsert(this.Start, this.End, Payload)); } return(IntervalEvent <TPayloadType> .CreateCti(Start)); }
protected override void PopulateEvent(out IntervalEvent <T> typedEvent) { typedEvent = IntervalEvent.CreateInsert(DateTime.Now, DateTime.Now + TimeSpan.FromMilliseconds( Math.Max( EventInterval - (this.Rnd.Next(EventIntervalDiff * 2) - EventIntervalDiff), 1)), new T()); }
/// <summary> /// Starts repeatedly calling a javascript function. /// </summary> public int Add(object sender, FunctionInstance fn, int delayMs) { var ie = new IntervalEvent(); ie.Sender = sender; ie.Callback = fn; ie.DelayMsec = delayMs; IntervalEvents.Add(ie); return(ie.ID); }
/// <summary> /// When the timer fires, check for the state of the adapter; if running /// raise a new simulated event /// </summary> /// <param name="state"></param> private void RaiseEvent(object state) { // Ensure that the adapter is in the running state. If we're // shutting down, kill the timer and signal Stopped() if (AdapterState.Stopping == AdapterState) { myTimer.Dispose(); Stopped(); } if (AdapterState.Running != AdapterState) { return; } // Allocate a point event to hold the data for the incoming message. // If the event could not be allocated, exit the function lock (lockObj) { // The next event will be raised at now + event period ms, plus a // random offset int nextEventInterval = config.EventPeriod + rand.Next(config.EventPeriodRandomOffset); myTimer.Change(nextEventInterval, nextEventInterval); IntervalEvent <TPayload> currEvent = CreateInsertEvent(); if (currEvent == null) { return; } currEvent.StartTime = DateTime.Now; currEvent.EndTime = currEvent.StartTime.AddMilliseconds(nextEventInterval); // Create a payload object, and fill with values if we have a // an initializer defined currEvent.Payload = (TPayload)Activator.CreateInstance(typeof(TPayload)); if (init != null) { init.FillValues(currEvent.Payload); } if (trace.ShouldLog(TraceEventType.Verbose)) { trace.LogMsg(TraceEventType.Verbose, "INSERT - {0}", currEvent.FormatEventForDisplay(false)); } // If the event cannot be enqueued, release the memory and signal that // the adapter is ready to process more events (via. Ready()) if (EnqueueOperationResult.Full == Enqueue(ref currEvent)) { ReleaseEvent(ref currEvent); Ready(); } } }
//use for sink creation if sink consists of IntervalEvents static void ConsoleWriteInterval <TPayload>(IntervalEvent <TPayload> e) { if (e.EventKind == EventKind.Insert) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "INSERT <{0} - {1}> {2}", e.StartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss.fff"), e.EndTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss.fff"), e.Payload.ToString())); } else { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "CTI <{0}>", e.StartTime.ToLocalTime().ToString("MM/dd/yyyy HH:mm:ss.fff"))); } }
static void ConsoleWriteInterval <TPayload>(IntervalEvent <TPayload> e) { if (e.EventKind == EventKind.Insert) { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "INSERT <{0} - {1}> {2}", e.StartTime.DateTime, e.EndTime.DateTime, e.Payload.ToString())); } else { Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "CTI <{0}>", e.StartTime.DateTime)); } }
/// <summary> /// Main worker thread function responsible for dequeueing events and /// posting them to the output stream. /// </summary> private void ConsumeEvents() { IntervalEvent currentEvent = default(IntervalEvent); try { while (true) { if (AdapterState.Stopping == AdapterState) { Stopped(); return; } // Dequeue the event. If the dequeue fails, then the adapter state is suspended // or stopping. Assume the former and call Ready() to indicate // readiness to be resumed, and exit the thread. if (DequeueOperationResult.Empty == Dequeue(out currentEvent)) { Ready(); return; } string writeMsg = String.Empty; if (currentEvent.EventKind == EventKind.Insert) { writeMsg = currentEvent.FormatEventForDisplay(eventType, !config.SingleLine); } else if (currentEvent.EventKind == EventKind.Cti) { writeMsg = String.Format("CTI - {0}", currentEvent.StartTime.ToString("hh:mm:ss.fff")); } if (config.Target == TraceTarget.Console) { Console.WriteLine(writeMsg); } else if (config.Target == TraceTarget.Debug) { Debug.Write(writeMsg); } // Every received event needs to be released. ReleaseEvent(ref currentEvent); } } catch (Exception e) { trace.LogException(e, "Error in console adapter dequeue"); } }
/// <summary> /// Create event from line. /// </summary> /// <param name="line">string in the required format for this adapter.</param> /// <returns>Newly created interval event.</returns> private IntervalEvent CreateEventFromLine(string line) { string[] split = line.Split(new char[] { this.delimiter }, StringSplitOptions.None); if (this.bindtimeEventType.Fields.Count != (split.Length - NumNonPayloadFields)) { throw new InvalidOperationException("Number of payload columns in input file: " + (split.Length - NumNonPayloadFields) + " does not match number of fields in EventType: " + this.bindtimeEventType.Fields.Count); } // Request event memory allocation from engine. IntervalEvent intervalEvent = CreateInsertEvent(); // In case we just went into the stopping state. if (intervalEvent == null) { return(null); } // Set start and end times. intervalEvent.StartTime = DateTime.Parse(split[0], this.cultureInfo, DateTimeStyles.AssumeUniversal).ToUniversalTime(); intervalEvent.EndTime = DateTime.Parse(split[1], this.cultureInfo, DateTimeStyles.AssumeUniversal).ToUniversalTime(); // Populate the payload fields. for (int ordinal = 0; ordinal < this.bindtimeEventType.FieldsByOrdinal.Count; ordinal++) { try { int cepOrdinal = this.inputOrdinalToCepOrdinal[ordinal]; CepEventTypeField evtField = this.bindtimeEventType.FieldsByOrdinal[cepOrdinal]; object value; if (evtField.Type.ClrType.FullName == "System.Byte[]") { System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding(); value = encoding.GetBytes(split[ordinal + NumNonPayloadFields]); } else { Type t = Nullable.GetUnderlyingType(evtField.Type.ClrType) ?? evtField.Type.ClrType; value = Convert.ChangeType(split[ordinal + NumNonPayloadFields], t, this.cultureInfo); } intervalEvent.SetField(cepOrdinal, value); } catch (AdapterException e) { this.consoleTracer.WriteLine(e.Message + e.StackTrace); } } return(intervalEvent); }
/// <summary> /// Creates and output event from a source event. /// </summary> /// <param name="sourceEvent">The source event.</param> /// <returns></returns> public static StreamOutputEvent <TPayload> Create(IntervalEvent <TPayload> sourceEvent) { var outputEvent = new StreamOutputEvent <TPayload>() { StartTime = sourceEvent.StartTime, EventKind = sourceEvent.EventKind, EventShape = EventShape.Interval }; if (sourceEvent.EventKind == EventKind.Insert) { outputEvent.EndTime = sourceEvent.EndTime; outputEvent.Payload = sourceEvent.Payload; } return(outputEvent); }
private void ConsumeEvents() { IntervalEvent currentEvent = default(IntervalEvent); try { while (true) { if (AdapterState.Stopping == AdapterState) { Stopped(); return; } // Dequeue the event. If the dequeue fails, then the adapter state is suspended // or stopping. Assume the former and call Ready() to indicate // readiness to be resumed, and exit the thread. if (DequeueOperationResult.Empty == Dequeue(out currentEvent)) { Ready(); return; } if (currentEvent.EventKind == EventKind.Insert) { string prefix = String.Format( CultureInfo.InvariantCulture, "Interval from {0} to {1}:", currentEvent.StartTime, currentEvent.EndTime); this.tracer.TraceInsert(currentEvent, prefix); } else if (currentEvent.EventKind == EventKind.Cti) { this.tracer.TraceCti(currentEvent.StartTime); } // Every received event needs to be released. ReleaseEvent(ref currentEvent); } } catch (Exception e) { Debug.WriteLine(e.ToString()); } }
protected override void OnNext(IntervalEvent <TPayload> currentEvent, StreamWriter writer) { if (EventKind.Cti == currentEvent.EventKind) { writer.Write("CTI"); writer.Write(Delimiter); writer.Write(GetTimeByCulture(currentEvent.StartTime.ToString())); } else { writer.Write("INSERT"); writer.Write(Delimiter); writer.Write(GetTimeByCulture(currentEvent.StartTime.ToString())); writer.Write(Delimiter); writer.Write(GetTimeByCulture(currentEvent.EndTime.ToString())); writer.Write(Delimiter); SerializePayload(writer, currentEvent); } writer.Flush(); }
/// <summary> /// Makes a non-blocking call to the function passed to /// setInterval(). Will never call the same function again /// until the first non-blocking call finishes. /// </summary> /// <remarks> /// Slow functions will never prevent other functions from /// triggering, and as a consequence, true javascript threading /// can be implemented by simply using setInterval with a call /// that never returns. /// </remarks> private void Call(IntervalEvent ie) { // ignore if already running if (ie == null || ie.Running) { return; } // use a non-blocking call to run the function try { ie.Running = true; Task.Factory.StartNew(() => { ie.Callback.Call(null); }); } finally { ie.Running = false; } }
protected override void OnNextEvent(IntervalEvent <T> currentEvent) { if (currentEvent.EventKind == EventKind.Insert) { StringBuilder builder = new StringBuilder() .Append("Interval from ") .Append(currentEvent.StartTime.DateTime.ToShortTimeString()) .Append(" to ") .Append(currentEvent.EndTime); AppendPayload(ref builder, currentEvent.Payload);; Console.WriteLine(builder.ToString()); } else if (currentEvent.EventKind == EventKind.Cti) { if (DisplayCti) { Console.WriteLine( String.Format(CultureInfo.InvariantCulture, "CTI at {1}", currentEvent.StartTime)); } } }
/// <summary> /// This method enqueues one event. It is used as the callback for the /// actual data source. /// </summary> /// <param name="data">Data item to be enqueued as event.</param> /// <param name="timestamp">Timestamp of the data</param> private void ProduceEvent(GeneratedEvent data, DateTimeOffset timestamp) { // Check for the stopping state and stop if necessary. if (AdapterState.Stopping == AdapterState) { this.dataSource.Stop(); Stopped(); return; } // Since this method is called from a thread that is independend of // Start() and Resume(), we need to make sure that the adapter is // actually running. if (AdapterState.Running != AdapterState) { // Throw away the current event. return; } IntervalEvent <GeneratedEvent> currEvent = CreateInsertEvent(); if (null == currEvent) { // Throw away the current event. return; } currEvent.StartTime = timestamp; currEvent.EndTime = currEvent.StartTime + TimeSpan.FromMilliseconds(this.intervalLengthInMs); currEvent.Payload = data; if (EnqueueOperationResult.Full == Enqueue(ref currEvent)) { ReleaseEvent(ref currEvent); Ready(); return; } }
public void IsPeriodicShouldThrowException() { var history = new IntervalEvent<ItemStructureTest>(); var startTime = history.GetIntervalStartTime(); }
/// <summary> /// Defines a stream of TollReadings used throughout examples. A simulated data array /// is wrapped into the Enumerable source which is then converted to a stream. /// </summary> /// <param name="app">StreamInsight application object.</param> /// <returns>Returns stream of simulated TollReadings used in examples.</returns> static IQStreamable <TollReading> GetTollReadings(this Application app) { return(app.DefineEnumerable(() => // Simulated readings data defined as an array. // IntervalEvent objects are constructed directly to avoid copying. new[] { IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 01, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 03, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "JNB 7001", State = "NY", Make = "Honda", Model = "CRV", VehicleType = 1, VehicleWeight = 0, Toll = 7.0f, Tag = "" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 02, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 03, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "YXZ 1001", State = "NY", Make = "Toyota", Model = "Camry", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "123456789" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 02, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 04, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "ABC 1004", State = "CT", Make = "Ford", Model = "Taurus", VehicleType = 1, VehicleWeight = 0, Toll = 5.0f, Tag = "456789123" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 03, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 07, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "XYZ 1003", State = "CT", Make = "Toyota", Model = "Corolla", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 03, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 08, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "BNJ 1007", State = "NY", Make = "Honda", Model = "CRV", VehicleType = 1, VehicleWeight = 0, Toll = 5.0f, Tag = "789123456" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 05, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 07, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "CDE 1007", State = "NJ", Make = "Toyota", Model = "4x4", VehicleType = 1, VehicleWeight = 0, Toll = 6.0f, Tag = "321987654" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 06, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 09, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "BAC 1005", State = "NY", Make = "Toyota", Model = "Camry", VehicleType = 1, VehicleWeight = 0, Toll = 5.5f, Tag = "567891234" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 07, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "ZYX 1002", State = "NY", Make = "Honda", Model = "Accord", VehicleType = 1, VehicleWeight = 0, Toll = 6.0f, Tag = "234567891" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 07, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "ZXY 1001", State = "PA", Make = "Toyota", Model = "Camry", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "987654321" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 08, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "CBA 1008", State = "PA", Make = "Ford", Model = "Mustang", VehicleType = 1, VehicleWeight = 0, Toll = 4.5f, Tag = "891234567" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 09, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 11, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "DCB 1004", State = "NY", Make = "Volvo", Model = "S80", VehicleType = 1, VehicleWeight = 0, Toll = 5.5f, Tag = "654321987" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 09, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 16, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "CDB 1003", State = "PA", Make = "Volvo", Model = "C30", VehicleType = 1, VehicleWeight = 0, Toll = 5.0f, Tag = "765432198" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 09, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "YZX 1009", State = "NY", Make = "Volvo", Model = "V70", VehicleType = 1, VehicleWeight = 0, Toll = 4.5f, Tag = "912345678" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 12, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "BCD 1002", State = "NY", Make = "Toyota", Model = "Rav4", VehicleType = 1, VehicleWeight = 0, Toll = 5.5f, Tag = "876543219" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 10, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 14, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "CBD 1005", State = "NY", Make = "Toyota", Model = "Camry", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "543219876" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 11, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 13, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "NJB 1006", State = "CT", Make = "Ford", Model = "Focus", VehicleType = 1, VehicleWeight = 0, Toll = 4.5f, Tag = "678912345" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 12, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 15, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "PAC 1209", State = "NJ", Make = "Chevy", Model = "Malibu", VehicleType = 1, VehicleWeight = 0, Toll = 6.0f, Tag = "219876543" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 15, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 22, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "BAC 1005", State = "PA", Make = "Peterbilt", Model = "389", VehicleType = 2, VehicleWeight = 2.675f, Toll = 15.5f, Tag = "567891234" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 15, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 18, 0, DateTimeKind.Utc), new TollReading { TollId = "3", LicensePlate = "EDC 3109", State = "NJ", Make = "Ford", Model = "Focus", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "198765432" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 18, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 20, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "DEC 1008", State = "NY", Make = "Toyota", Model = "Corolla", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 20, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 22, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "DBC 1006", State = "NY", Make = "Honda", Model = "Civic", VehicleType = 1, VehicleWeight = 0, Toll = 5.0f, Tag = "432198765" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 20, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 23, 0, DateTimeKind.Utc), new TollReading { TollId = "2", LicensePlate = "APC 2019", State = "NJ", Make = "Honda", Model = "Civic", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "345678912" }), IntervalEvent.CreateInsert(new DateTime(2009, 06, 25, 12, 22, 0, DateTimeKind.Utc), new DateTime(2009, 06, 25, 12, 25, 0, DateTimeKind.Utc), new TollReading { TollId = "1", LicensePlate = "EDC 1019", State = "NJ", Make = "Honda", Model = "Accord", VehicleType = 1, VehicleWeight = 0, Toll = 4.0f, Tag = "" }), }) // Predefined AdvanceTimeSettings.IncreasingStartTime is used to insert CTIs after each event, which occurs later than the previous one. .ToIntervalStreamable(e => e, AdvanceTimeSettings.IncreasingStartTime)); }
/// <summary> /// Creates a string from an interval event. /// </summary> /// <param name="evt">The interval event to serialize.</param> /// <param name="eventType">CEP event type.</param> /// <param name="delimiter">Delimiter between event fields.</param> /// <returns>Serialized event.</returns> public static string CreateLineFromEvent(IntervalEvent evt, CepEventType eventType, char delimiter) { StringBuilder builder = new StringBuilder(); if (EventKind.Cti == evt.EventKind) { builder .Append("CTI") .Append(delimiter) .Append(evt.StartTime.ToString()); } else { builder .Append("INSERT") .Append(delimiter) .Append(evt.StartTime.ToString()) .Append(delimiter) .Append(evt.EndTime.ToString()) .Append(delimiter); SerializePayload(evt, eventType, delimiter, ref builder); } return builder.ToString(); }
/// <summary> /// Main driver to read events from the CSV file and enqueue them. /// </summary> private void ProduceEvents() { IntervalEvent currentEvent = default(IntervalEvent); try { // Keep reading lines from the file. while (true) { if (AdapterState.Stopping == AdapterState) { Stopped(); return; } // Did we enqueue the previous line successfully? if (this.currentLine == null) { this.currentLine = this.streamReader.ReadLine(); if (this.currentLine == null) { // Stop adapter (and hence the query) at the end of the file. Stopped(); return; } } try { // Create and fill event structure with data from text file line. currentEvent = this.CreateEventFromLine(this.currentLine); // In case we just went into the stopping state. if (currentEvent == null) { continue; } } catch (Exception e) { // The line couldn't be transformed into an event. // Just ignore it, and release the event's memory. if (currentEvent != null) { ReleaseEvent(ref currentEvent); } this.consoleTracer.WriteLine(this.currentLine + " could not be read into a CEP event: " + e.Message); // Make sure we read a new line next time. this.currentLine = null; continue; } if (EnqueueOperationResult.Full == Enqueue(ref currentEvent)) { // If the enqueue was not successful, we keep the event. // It is good practice to release the event right away and // not hold on to it. if (currentEvent != null) { ReleaseEvent(ref currentEvent); } // We are suspended now. Tell the engine we are ready to be resumed. Ready(); // Leave thread to wait for call into Resume(). return; } // Enqueue was successful, so we can read a new line again. this.currentLine = null; } } catch (AdapterException e) { this.consoleTracer.WriteLine("ProduceEvents - " + e.Message + e.StackTrace); } }
public void OnNext(IntervalEvent <TPayloadType> value) { EventReceived(StreamOutputEvent <TPayloadType> .Create((IntervalEvent <TPayloadType>)value)); }
/// <summary> /// Turns a CSV line into an event. /// </summary> public TEvent CreateEventFromLine(string line) { CultureInfo culture = new CultureInfo(this.config.CultureName); // split the incoming line into component fields string[] split = line.Split(this.config.Delimiter, StringSplitOptions.None); if (this.bindTimeEventType.Fields.Count != (split.Length - this.config.NonPayloadFieldCount)) { throw new ArgumentException(string.Format( CultureInfo.CurrentCulture, "Payload field count in input file {0} does not match field count in EventType {1}", split.Length - this.config.NonPayloadFieldCount, this.bindTimeEventType.Fields.Count)); } // create a new event TEvent evt = this.inputAdapter.CreateInsertEvent(); if (null == evt) { return(evt); } // populate the payload fields // Assume your EventType definition consists of fields {b, a, c} // and the input file provides values of these fields in this // order. StreamInsight understands CepEventType in alphabetical // order of the fields - that is, {a, b, c}. If you set values by // position, there could be mismatched types or assignments of // values to fields. So we map the fields in each line with the // correct field in CepEventType using an ordinal mapper - and use // SetField() to assign the correct input values to the payload fields. object value = null; for (int pos = 0; pos < (this.bindTimeEventType.FieldsByOrdinal.Count + this.config.NonPayloadFieldCount); pos++) { // if the position counter maps to a StartTime or EndTime field position in the file, skip. if ((this.config.StartTimePos - 1) == pos || (this.config.EndTimePos - 1) == pos) { continue; } // get the corresponding ordinal for the CepEvent based on the specified payload field ordering int cepOrdinal = this.mapOrdinalsFromInputToCepEvent[pos - this.config.NonPayloadFieldCount]; // identify the CepEvent field by ordinal CepEventTypeField evtField = this.bindTimeEventType.FieldsByOrdinal[cepOrdinal]; // set the value for the field, handling NULLs (byte array and GUID not covered) if (split[pos].Length == 0) { value = this.GetDefaultValue(evtField.Type.ClrType, culture); } else { Type t = Nullable.GetUnderlyingType(evtField.Type.ClrType) ?? evtField.Type.ClrType; value = Convert.ChangeType(split[pos], t, culture); } evt.SetField(cepOrdinal, value); } // set the timestamps PointEvent pointEvent = evt as PointEvent; IntervalEvent intervalEvent = evt as IntervalEvent; if (intervalEvent != null) { intervalEvent.StartTime = DateTime.Parse(split[this.config.StartTimePos - 1], culture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); intervalEvent.EndTime = DateTime.Parse(split[this.config.EndTimePos - 1], culture, DateTimeStyles.AssumeUniversal).ToUniversalTime(); } else if (pointEvent != null) { pointEvent.StartTime = DateTime.ParseExact(split[this.config.StartTimePos - 1], "ddd MMM d HH:mm:ss 'GMT' yyyy", culture).ToUniversalTime(); } return(evt); }
public void IsPeriodicShouldThrowException() { var history = new IntervalEvent <ItemStructureTest>(); var startTime = history.GetIntervalStartTime(); }