/// <summary> /// Create event from text line. /// </summary> /// <param name="line">string in the required format for this adapter.</param> /// <returns>Newly created point event.</returns> private PointEvent 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. PointEvent pointEvent = CreateInsertEvent(); // In case we just went into the stopping state. if (pointEvent == null) { return(null); } // Set point timestamp. pointEvent.StartTime = DateTime.Parse(split[0], this.cultureInfo, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal).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); } pointEvent.SetField(cepOrdinal, value); } catch (AdapterException e) { this.consoleTracer.WriteLine(e.Message + e.StackTrace); } } return(pointEvent); }
private ResultCode EnqueueInsert(DateTimeOffset startTime, Dictionary <string, object> payload) { if (null == payload) { throw new ArgumentNullException("payload"); } PointEvent pointEvent = base.CreateInsertEvent(); if (null == pointEvent) { Ready(); return(ResultCode.Suspended); } try { foreach (KeyValuePair <string, object> keyAndValue in payload) { int ordinal = this.eventType.Fields[keyAndValue.Key].Ordinal; pointEvent.SetField(ordinal, keyAndValue.Value); } pointEvent.StartTime = startTime; if (Enqueue(ref pointEvent) == EnqueueOperationResult.Full) { Ready(); return(ResultCode.Suspended); } return(ResultCode.Success); } finally { if (null != pointEvent) { ReleaseEvent(ref pointEvent); } } }