/// <summary>
        /// Creates a string from an edge event.
        /// </summary>
        /// <param name="evt">The edge 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(EdgeEvent 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.EdgeType.ToString())
                    .Append(delimiter)
                    .Append(evt.StartTime.ToString())
                    .Append(delimiter)
                    .Append((EdgeType.End == evt.EdgeType) ? evt.EndTime.ToString() : string.Empty)
                    .Append(delimiter);

                SerializePayload(evt, eventType, delimiter, ref builder);
            }

            return builder.ToString();
        }
        /// <summary>
        /// Initializes a new instance of the TextFilePointOutput class.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the factory.</param>
        /// <param name="eventType">Runtime event type passed from the factory.</param>
        public TextFilePointOutput(TextFileWriterConfig configInfo, CepEventType eventType)
        {
            // If an empty string as filename was provided, dump output on the console
            this.streamWriter = configInfo.OutputFileName.Length == 0 ?
                              new StreamWriter(Console.OpenStandardOutput()) :
                              new StreamWriter(configInfo.OutputFileName);

            this.delimiter = configInfo.Delimiter;
            this.bindtimeEventType = eventType;

            this.consoleTracer = new System.Diagnostics.ConsoleTraceListener();
        }
        /// <summary>
        /// Initializes a new instance of the DedupingPointCsvOutputAdapter class that will write to a (new) file without deduplication.
        /// </summary>
        /// <param name="file">A path to the target file.</param>
        /// <param name="fields">The ordered list of field names to output.</param>
        /// <param name="cepEventType">The output type.</param>
        public DedupingPointCsvOutputAdapter(string file, IEnumerable<string> fields, CepEventType cepEventType)
            : base()
        {
            if (!this.RecordFields(fields, cepEventType))
            {
                throw new ArgumentException("The list of fields to print is not compatible with the output event type.");
            }

            this.cepEventType = cepEventType;
            this.duplicates = new HashSet<string>();
            this.writer = new StreamWriter(file, false); // Clear the output file.

            Util.Log("DedupingPointsCsvOutputAdapter init", "Created new for " + Path.GetFileName(file));
        }
        public WcfPointInputAdapter(CepEventType eventType, WcfAdapterConfig configInfo)
        {
            this.eventType = eventType;
            this.sync = new object();

            // Initialize the service host. The host is opened and closed as the adapter is started
            // and stopped.
            this.host = new ServiceHost(this);
            host.AddServiceEndpoint(typeof(IPointInputAdapter), new WSHttpBinding(), configInfo.ServiceAddress);

            // Poll the adapter to determine when it is time to stop.
            this.timer = new Timer(CheckStopping);
            this.timer.Change(StopPollingPeriod, Timeout.Infinite);
        }
Exemple #5
0
        /// <summary>
        /// Creates a dictionary that maps each payload field to a positional ordinal.
        /// This is used to specify the order of CSV fields in the input file,
        /// as well as to force a certain order when producing CSV output.
        /// </summary>
        /// <param name="fields">The ordered list of payload field names.</param>
        /// <param name="eventType">The event type.</param>
        /// <returns>A mapping between the string ordinal and the payload field ordinal.</returns>
        public static Dictionary<int, int> MapPayloadToFieldsByOrdinal(IList<string> fields, CepEventType eventType)
        {
            if (null != fields && fields.Count != eventType.Fields.Count)
            {
                throw new ArgumentException(
                    string.Format(
                    CultureInfo.CurrentCulture,
                    "List of fields has {0} elements, but should have {1} elements",
                    fields.Count,
                    eventType.Fields.Count));
            }

            CepEventTypeField cepEventField;

            Dictionary<int, int> mapPayloadToCepEventField = new Dictionary<int, int>();

            for (int ordinal = 0; ordinal < eventType.Fields.Count; ordinal++)
            {
                if (null == fields)
                {
                    // Use default mapping: the built-in order of the payload fields
                    // (lexicographic)
                    mapPayloadToCepEventField.Add(ordinal, ordinal);
                }
                else
                {
                    // find the ordinal of each of the payload fields specified in the list
                    if (!eventType.Fields.TryGetValue(fields[ordinal], out cepEventField))
                    {
                        throw new ArgumentException(
                            string.Format(
                            CultureInfo.CurrentCulture,
                            "Event type {0} doesn't have an input field named '{1}'",
                            eventType.ShortName,
                            fields[ordinal]));
                    }

                    mapPayloadToCepEventField.Add(ordinal, cepEventField.Ordinal);
                }
            }

            return mapPayloadToCepEventField;
        }
        public WcfPointOutputAdapter(CepEventType eventType, WcfAdapterConfig configInfo)
        {
            this.eventType = eventType;
            this.sync = new object();

            //// Initialize the service host. The host is opened and closed as the adapter is started
            //// and stopped.
            //this.host = new ServiceHost(this);
            //host.AddServiceEndpoint(typeof(IPointOutputAdapter), new WSHttpBinding(), address);
            #region
            //start up channelfactory
            WSHttpBinding myBinding = new WSHttpBinding();
            EndpointAddress addr = new EndpointAddress(configInfo.ServiceAddress);
            factory = new ChannelFactory<IPointEventReceiver>(myBinding, addr);
            #endregion

            // Poll the adapter to determine when it is time to stop.
            //this.timer = new Timer(CheckStopping);
            //this.timer.Change(StopPollingPeriod, Timeout.Infinite);
        }
        /// <summary>
        /// Creates a string from an event payload.
        /// </summary>
        /// <param name="evt">Event of which to serialize the payload.</param>
        /// <param name="eventType">CEP event type.</param>
        /// <param name="delimiter">Delimiter between event fields.</param>
        /// <param name="builder">StringBuilder to append the payload string to.</param>
        private static void SerializePayload(UntypedEvent evt, CepEventType eventType, char delimiter, ref StringBuilder builder)
        {
            for (int ordinal = 0; ordinal < eventType.FieldsByOrdinal.Count; ordinal++)
            {
                object value = evt.GetField(ordinal) ?? "NULL";

                if (value.GetType().FullName == "System.Byte[]")
                {
                    System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
                    builder
                        .AppendFormat(CultureInfo.InvariantCulture, "{0}", enc.GetString((byte[])value))
                        .Append(delimiter);
                }
                else
                {
                    builder
                        .AppendFormat(CultureInfo.InvariantCulture, "{0}", value)
                        .Append(delimiter);
                }
            }
        }
Exemple #8
0
 /// <summary>
 /// Initializes a new instance of the Tracer class.
 /// </summary>
 /// <param name="config">Adapter configuration passed from the query binding.</param>
 /// <param name="type">Event type passed from the query binding.</param>
 public Tracer(TracerConfig config, CepEventType type)
 {
     this.trace = TracerRouter.GetHandler(config.TracerKind, config.TraceName);
     this.config = config;
     this.type = type;
 }
        /// <summary>
        /// Create a DedupingPointCsvOutputAdapter with a fresh output file.
        /// </summary>
        /// <param name="configInfo">The configuration.</param>
        /// <param name="eventShape">The event shape: must be Point.</param>
        /// <param name="cepEventType">The output type.</param>
        /// <returns>The new adapter.</returns>
        public OutputAdapterBase Create(DedupingPointCsvOutputAdapterConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            if (eventShape != EventShape.Point)
            {
                throw new ArgumentException("Got event shape = " + eventShape + "; only Point is supported.");
            }

            return(new DedupingPointCsvOutputAdapter(configInfo.File, configInfo.Fields, cepEventType));
        }
 public CsvInputInterval(CsvInputConfig configInfo, CepEventType eventType)
 {
     this.inputAdapter = new CsvInputAdapter <CsvInputInterval, IntervalEvent>(configInfo, eventType, this);
 }
Exemple #11
0
        /// <summary>
        /// Creates a dictionary that maps each payload field to a positional ordinal.
        /// This is used to specify the order of CSV fields in the input file,
        /// as well as to force a certain order when producing CSV output.
        /// </summary>
        /// <param name="fields">The ordered list of payload field names.</param>
        /// <param name="eventType">The event type.</param>
        /// <returns>A mapping between the string ordinal and the payload field ordinal.</returns>
        public static Dictionary <int, int> MapPayloadToFieldsByOrdinal(IList <string> fields, CepEventType eventType)
        {
            if (null != fields && fields.Count != eventType.Fields.Count)
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.CurrentCulture,
                              "List of fields has {0} elements, but should have {1} elements",
                              fields.Count,
                              eventType.Fields.Count));
            }

            CepEventTypeField cepEventField;

            Dictionary <int, int> mapPayloadToCepEventField = new Dictionary <int, int>();

            for (int ordinal = 0; ordinal < eventType.Fields.Count; ordinal++)
            {
                if (null == fields)
                {
                    // Use default mapping: the built-in order of the payload fields
                    // (lexicographic)
                    mapPayloadToCepEventField.Add(ordinal, ordinal);
                }
                else
                {
                    // find the ordinal of each of the payload fields specified in the list
                    if (!eventType.Fields.TryGetValue(fields[ordinal], out cepEventField))
                    {
                        throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      "Event type {0} doesn't have an input field named '{1}'",
                                      eventType.ShortName,
                                      fields[ordinal]));
                    }

                    mapPayloadToCepEventField.Add(ordinal, cepEventField.Ordinal);
                }
            }

            return(mapPayloadToCepEventField);
        }
        /// <summary>
        /// Initializes a new instance of the DedupingPointCsvOutputAdapter class that will append to a file and do deduplication of events based
        /// on the marked provided.
        /// </summary>
        /// <param name="file">A path to the target file.</param>
        /// <param name="fields">The ordered list of field names to output.</param>
        /// <param name="cepEventType">The output event type.</param>
        /// <param name="replayHighWaterMark">The high-water mark to deduplicate from.</param>
        /// <param name="eventOffset">The event offset from the high-water mark to deduplicate from.</param>
        public DedupingPointCsvOutputAdapter(string file, IEnumerable<string> fields, CepEventType cepEventType, DateTimeOffset replayHighWaterMark, int eventOffset)
            : base()
        {
            if (!this.RecordFields(fields, cepEventType))
            {
                throw new ArgumentException("The list of fields to print is not compatible with the output event type.");
            }

            this.cepEventType = cepEventType;
            this.duplicates = new HashSet<string>();
            this.PopulateDuplicates(file, replayHighWaterMark, eventOffset);
            this.writer = new StreamWriter(file, true); // Open output for append.

            Util.Log("DedupingPointsCsvOutputAdapter init", "Created for restart for " + Path.GetFileName(file));
        }
Exemple #13
0
        /// <summary>
        /// Returns an instance of a text file writer output adapter.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <param name="cepEventType">Event type produced by the bound query template.</param>
        /// <returns>An instance of a text file writer output adapter.</returns>
        public OutputAdapterBase Create(TextFileWriterConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            OutputAdapterBase adapter = default(OutputAdapterBase);

            switch (eventShape)
            {
            case EventShape.Point:
                adapter = new TextFilePointOutput(configInfo, cepEventType);
                break;

            case EventShape.Interval:
                adapter = new TextFileIntervalOutput(configInfo, cepEventType);
                break;

            case EventShape.Edge:
                adapter = new TextFileEdgeOutput(configInfo, cepEventType);
                break;

            default:
                throw new ArgumentException(string.Format(
                                                CultureInfo.InvariantCulture,
                                                "TextFileWriterFactory cannot instantiate adapter with event shape {0}",
                                                eventShape.ToString()));
            }

            return(adapter);
        }
Exemple #14
0
        public OutputAdapterBase Create(SqlOutputConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            OutputAdapterBase adapter = default(OutputAdapterBase);

            switch (eventShape)
            {
            case EventShape.Point:
                adapter = new SqlOutputPoint(configInfo, cepEventType);
                break;

            case EventShape.Interval:
                adapter = new SqlOutputInterval(configInfo, cepEventType);
                break;

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Unknown event shape {0}", eventShape.ToString()));
            }

            return(adapter);
        }
        /// <summary>
        /// Initializes a new instance of the TextFileEdgeInput class.
        /// </summary>
        /// <param name="configInfo">Configuration structure provided by the Factory. If
        /// the InputFieldOrders member is null, the default mapping will be applied.</param>
        /// <param name="eventType">Represents the actual event type that will be passed into this
        /// constructor from the query binding via the adapter factory class.</param>
        public TextFileEdgeInput(TextFileReaderConfig configInfo, CepEventType eventType)
        {
            this.streamReader = new StreamReader(configInfo.InputFileName);
            this.cultureInfo = new CultureInfo(configInfo.CultureName);
            this.delimiter = configInfo.Delimiter;

            this.bindtimeEventType = eventType;

            // check whether all fields are contained in the config's field-to-column mapping
            if (configInfo.InputFieldOrders != null && configInfo.InputFieldOrders.Count != eventType.Fields.Count)
            {
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "The configuration element InputFieldOrders should have {0} elements, but it has {1} elements",
                        eventType.Fields.Count,
                        configInfo.InputFieldOrders.Count));
            }

            // Create mapping from input field ordinal to engine field ordinal
            this.inputOrdinalToCepOrdinal = new Dictionary<int, int>();

            for (int i = 0; i < eventType.Fields.Count; i++)
            {
                if (configInfo.InputFieldOrders != null)
                {
                    CepEventTypeField engineField;

                    if (!eventType.Fields.TryGetValue(configInfo.InputFieldOrders[i], out engineField))
                    {
                        throw new ArgumentException(
                            string.Format(
                                CultureInfo.InvariantCulture,
                                "Event type {0} doesn't have an input field named '{1}'",
                                eventType.ShortName,
                                configInfo.InputFieldOrders[i]));
                    }

                    this.inputOrdinalToCepOrdinal.Add(i, engineField.Ordinal);
                }
                else
                {
                    // Use default mapping: lexicographic ordering.
                    this.inputOrdinalToCepOrdinal.Add(i, i);
                }
            }

            this.consoleTracer = new System.Diagnostics.ConsoleTraceListener();
        }
        /// <summary>
        /// Returns an instance of a text file reader input adapter.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <param name="cepEventType">Event type expected by the bound query template.</param>
        /// <returns>An instance of a text file reader input adapter.</returns>
        public InputAdapterBase Create(TextFileReaderConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            InputAdapterBase adapter = default(InputAdapterBase);

            if (eventShape == EventShape.Point)
            {
                adapter = new TextFilePointInput(configInfo, cepEventType);
            }
            else if (eventShape == EventShape.Interval)
            {
                adapter = new TextFileIntervalInput(configInfo, cepEventType);
            }
            else if (eventShape == EventShape.Edge)
            {
                adapter = new TextFileEdgeInput(configInfo, cepEventType);
            }
            else
            {
                throw new ArgumentException(
                          string.Format(
                              CultureInfo.InvariantCulture,
                              "TextFileReaderFactory cannot instantiate adapter with event shape {0}",
                              eventShape.ToString()));
            }

            return(adapter);
        }
 public CsvOutputEdge(CsvOutputConfig configInfo, CepEventType eventType)
 {
     this.outputAdapter = new CsvOutputAdapter <CsvOutputEdge, EdgeEvent>(configInfo, eventType);
 }
 public CsvInputPoint(CsvInputConfig configInfo, CepEventType eventType)
 {
     this.inputAdapter = new CsvInputAdapter <CsvInputPoint, PointEvent>(configInfo, eventType, this);
 }
        /// <summary>
        /// Returns an instance of a tracer output adapter.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <param name="cepEventType">Event type produced by the bound query template.</param>
        /// <returns>An instance of a tracer output adapter.</returns>
        public OutputAdapterBase Create(TracerConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            OutputAdapterBase adapter = default(OutputAdapterBase);

            switch (eventShape)
            {
            case EventShape.Point:
                adapter = new TracerPointOutputAdapter(configInfo, cepEventType);
                break;

            case EventShape.Interval:
                adapter = new TracerIntervalOutputAdapter(configInfo, cepEventType);
                break;

            case EventShape.Edge:
                adapter = new TracerEdgeOutputAdapter(configInfo, cepEventType);
                break;
            }

            return(adapter);
        }
        /// <summary>
        /// Verify that all of the fields we've been asked to output actually exist in the output type and
        /// record the fields we are to print in our fields list.
        /// </summary>
        /// <param name="fields">The list of fields to output.</param>
        /// <param name="cepEventType">The type of our output.</param>
        /// <returns>True if the list of fields is compatible with the type; false otherwise.</returns>
        private bool RecordFields(IEnumerable<string> fields, CepEventType cepEventType)
        {
            if (fields == null)
            {
                // Null is fine: it just means we should output them all.
                fields = cepEventType.Fields.Keys;
            }
            else if (!fields.All(s => cepEventType.Fields.ContainsKey(s)))
            {
                // Oops... something didn't match.
                return false;
            }

            // build the list of ordinals
            this.fieldOrdinals = fields.Select(s => cepEventType.Fields[s].Ordinal).ToArray();
            return true;
        }
        /// <summary>
        /// Specifies the CTI behavior of this adapter. This method will be called whenever
        /// a new adapter instance is needed, with the respective configuration and event type.
        /// </summary>
        /// <param name="configInfo">Configuration passed from the query binding.</param>
        /// <param name="eventShape">Event shape requested from the query binding.</param>
        /// <param name="cepEventType">Event type expected by the bound query template.</param>
        /// <returns>An instance of AdapterAdvanceTimeSettings.</returns>
        public AdapterAdvanceTimeSettings DeclareAdvanceTimeProperties(TextFileReaderConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            // use the user-provided CTI frequency and -1 as the CTI delay. This will set the CTI timestamp
            // one tick _after_ the respective event timestamp, hence committing each event right away.
            var atgs = new AdvanceTimeGenerationSettings(configInfo.CtiFrequency, TimeSpan.FromTicks(-1), true);

            return(new AdapterAdvanceTimeSettings(atgs, AdvanceTimePolicy.Drop));
        }
Exemple #22
0
 public Tracer(TracerConfig config, CepEventType type)
 {
     this._trace  = TracerRouter.GetHandler(config.TracerKind, config.TraceName);
     this._config = config;
     this._type   = type;
 }
 /// <summary>
 /// Initializes a new instance of the TracerPointOutputAdapter class, based on
 /// the payload type (CepEventType) and the configuration information.
 /// </summary>
 /// <param name="config">Configuration passed from the factory.</param>
 /// <param name="type">Runtime event type passed from the factory.</param>
 public TracerPointOutputAdapter(TracerConfig config, CepEventType type)
 {
     this.tracer = new Tracer(config, type);
 }
        public OutputAdapterBase Create(WcfAdapterConfig configInfo, EventShape eventShape, CepEventType cepEventType)
        {
            OutputAdapterBase outputAdapter;

            switch (eventShape)
            {
            case EventShape.Point:
            {
                outputAdapter = new WcfPointOutputAdapter(cepEventType, configInfo);
            }
            break;

            default:
                throw new NotImplementedException();
            }

            return(outputAdapter);
        }
 public TotalCountOutput(string StopSignalName, CepEventType EventType)
 {
     _bindtimeEventType = EventType;
     _adapterStopSignal = EventWaitHandle.OpenExisting(StopSignalName);
 }
Exemple #26
0
 public CsvOutputPoint(CsvOutputConfig configInfo, CepEventType eventType)
 {
     this.outputAdapter = new CsvOutputAdapter <CsvOutputPoint, PointEvent>(configInfo, eventType);
 }
 /// <summary>
 /// Initializes a new instance of the TracerPointOutputAdapter class, based on
 /// the payload type (CepEventType) and the configuration information.
 /// </summary>
 /// <param name="config">Configuration passed from the factory.</param>
 /// <param name="type">Runtime event type passed from the factory.</param>
 public TracerPointOutputAdapter(TracerConfig config, CepEventType type)
 {
     this.tracer = new Tracer(config, type);
 }
 public CsvOutputInterval(CsvOutputConfig configInfo, CepEventType eventType)
 {
     this.outputAdapter = new CsvOutputAdapter <CsvOutputInterval, IntervalEvent>(configInfo, eventType);
 }