public static int GetEventMode(PublishedEvent e) { foreach (PublishedEventField xe_field in e.Fields) { if (xe_field.Name == "mode") { return(Int16.Parse(xe_field.Value.ToString())); } } return(-1); }
private long?TryGetInt64(PublishedEvent evt, FieldType t, string name) { object tmp = TryGetValue(evt, t, name); if (tmp != null && tmp.GetType() != typeof(DBNull)) { return(Convert.ToInt64(tmp)); } else { return(null); } }
public void ShouldCallSubscriberWhenPublisherFiresEvent() { PublishedEvent pe = new PublishedEvent(); EventSource1 publisher = new EventSource1(); pe.AddPublisher(publisher, "Event1"); bool subscriberCalled = false; EventHandler subscriber = delegate { subscriberCalled = true; }; pe.AddSubscriber(subscriber); publisher.FireEvent1(); Assert.IsTrue(subscriberCalled); }
public void AddPublicEvent(PublishedEvent publishedEvent) { EventQueueConfiguration config = EventQueueConfiguration.GetConfig(); if (!config.PublishedEvents.ContainsKey(publishedEvent.EventName)) { config.PublishedEvents.Add(publishedEvent.EventName, publishedEvent); RegisterAsIntegrationEvent(publishedEvent.EventName); config.Save(); } else { throw new ArgumentException($"{publishedEvent.EventName} already exists."); } }
public void Insert(PublishedEvent x_event) { bool ok = true; if (inserted == batchSize) { CommitTran(); BeginTran(); inserted = 0; } SQLiteCommand cmd = Tables.PrepareInsertCmd(sqliteConn, x_event); try { if (cmd != null) { cmd.ExecuteNonQuery(); } else { ok = false; errorCount++; Logger.LogMessage("[ERROR]cmd is null!"); } } catch (Exception e) { ok = false; errorCount++; Logger.LogException(e, Thread.CurrentThread); } if (cmd != null) { cmd.Dispose(); } if (ok) { count++; inserted++; } // Logger.LogMessage(this.TableName + ":" + count+" processed."); }
private static string[] GetSubscribers(string eventName) { //Get the subscribers to this event string[] subscribers = null; PublishedEvent publishedEvent = null; if (EventQueueConfiguration.GetConfig().PublishedEvents.TryGetValue(eventName, out publishedEvent)) { subscribers = publishedEvent.Subscribers.Split(";".ToCharArray()); } else { subscribers = new string[] {}; } return(subscribers); }
public void ProcessEvent() { PublishedEvent e = null; // Logger.LogMessage("ProcessEvent:" + eventsQueue.Count); while (eventsQueue.Count > 0) { lock (_lock) { e = eventsQueue.Dequeue(); } if (e != null) { Insert(e); } } }
public static SQLiteCommand PrepareInsertCmd(SQLiteConnection conn, PublishedEvent e) { SQLiteCommand cmd = new SQLiteCommand(conn); lock (cmdObj) { if (!insertSQLMap.ContainsKey(e.Name)) { string insert = Tables.GetInsertSQL(e); insertSQLMap.Add(e.Name, insert); } } cmd.CommandText = insertSQLMap[e.Name]; try { cmd.Parameters.Add(new SQLiteParameter("@EventTimeStamp", e.Timestamp.Ticks)); cmd.Parameters.Add(new SQLiteParameter("@TimeDelta", null)); foreach (PublishedEventField xe_field in e.Fields) { string colName = xe_field.Name; if (xe_field.Type == typeof(System.Guid)) { cmd.Parameters.Add(new SQLiteParameter("@" + colName, xe_field.Value.ToString())); } else { cmd.Parameters.Add(new SQLiteParameter("@" + colName, xe_field.Value)); } } } catch (Exception ex) { cmd = null; Logger.LogException(ex, Thread.CurrentThread); } return(cmd); }
public void ShouldNotCallSubscriberAfterRemoval() { PublishedEvent pe = new PublishedEvent(); EventSource1 publisher = new EventSource1(); pe.AddPublisher(publisher, "Event1"); int numberOfSubscriberCalls = 0; EventHandler subscriber = delegate { ++numberOfSubscriberCalls; }; pe.AddSubscriber(subscriber); publisher.FireEvent1(); pe.RemoveSubscriber(subscriber); publisher.FireEvent1(); Assert.AreEqual(1, numberOfSubscriberCalls); }
public SQLAuditLog(PublishedEvent currentEvent) { if (currentEvent.Fields["event_time"].Value == null) { throw new InvalidOperationException("Event log has no time field. Can not send it to OMS"); } ActionId = Convert.ToInt32(currentEvent.Fields["action_id"].Value); if (ActionIdDictionary.ContainsKey(ActionId)) { ActionName = ActionIdDictionary[ActionId]; } ClassType = Convert.ToInt16(currentEvent.Fields["class_type"].Value); if (ClassTypeDictionary.ContainsKey(ClassType)) { ClassTypeDescription = ClassTypeDictionary[ClassType].ClassTypeDescription; SecurableClassType = ClassTypeDictionary[ClassType].SecurableClassType; } var time = (DateTimeOffset)currentEvent.Fields["event_time"].Value; EventTime = time.ToString("s"); SequenceNumber = Convert.ToInt32(currentEvent.Fields["sequence_number"].Value); Succeeded = Convert.ToBoolean(currentEvent.Fields["succeeded"].Value); SessionId = Convert.ToInt16(currentEvent.Fields["session_id"].Value); ServerPrincipalId = Convert.ToInt32(currentEvent.Fields["server_principal_id"].Value); DatabasePrincipalId = Convert.ToInt32(currentEvent.Fields["database_principal_id"].Value); ObjectId = Convert.ToInt32(currentEvent.Fields["object_id"].Value); ClientIp = Convert.ToString(currentEvent.Fields["client_ip"].Value); ServerPrincipalName = Convert.ToString(currentEvent.Fields["server_principal_name"].Value); DatabasePrincipalName = Convert.ToString(currentEvent.Fields["database_principal_name"].Value); ServerInstanceName = Convert.ToString(currentEvent.Fields["server_instance_name"].Value); DatabaseName = Convert.ToString(currentEvent.Fields["database_name"].Value); SchemaName = Convert.ToString(currentEvent.Fields["schema_name"].Value); ObjectName = Convert.ToString(currentEvent.Fields["object_name"].Value); Statement = Convert.ToString(currentEvent.Fields["statement"].Value); ApplicationName = Convert.ToString(currentEvent.Fields["application_name"].Value); DurationInMilliSeconds = Convert.ToInt64(currentEvent.Fields["duration_milliseconds"].Value); ResponseRows = Convert.ToInt64(currentEvent.Fields["response_rows"].Value); AffectedRows = Convert.ToInt64(currentEvent.Fields["affected_rows"].Value); ConnectionId = Convert.ToString(currentEvent.Fields["connection_id"].Value); DataSensitivityInformation = Convert.ToString(currentEvent.Fields["data_sensitivity_information"].Value); }
public void ShouldMulticastEventsToMultipleSubscribers() { PublishedEvent pe = new PublishedEvent(); EventSource1 publisher = new EventSource1(); pe.AddPublisher(publisher, "Event1"); bool subscriber1Called = false; EventHandler subscriber1 = delegate { subscriber1Called = true; }; bool subscriber2Called = false; EventHandler subscriber2 = delegate { subscriber2Called = true; }; pe.AddSubscriber(subscriber1); pe.AddSubscriber(subscriber2); publisher.FireEvent1(); Assert.IsTrue(subscriber1Called); Assert.IsTrue(subscriber2Called); }
public void Handle(PublishedEvent <NewNoteAdded> evnt) { using (var context = new ReadModelContainer()) { var date = evnt.Payload.CreationDate.Date; var totalsForDate = context.TotalsPerDayItemSet.SingleOrDefault(i => i.Date == date); if (totalsForDate == null) { totalsForDate = new TotalsPerDayItem { Id = 1, Date = date }; context.TotalsPerDayItemSet.AddObject(totalsForDate); } totalsForDate.NewCount++; context.SaveChanges(); } }
private JObject ConvertXEventToJSON(PublishedEvent evt) { var json = new JObject(); json.Add("UUID", evt.UUID); json.Add("Timestamp", evt.Timestamp); json.Add("Name", evt.Name); var fields = new JObject(); foreach (PublishedEventField field in evt.Fields) { fields.Add(field.Name, JToken.FromObject(field.Value)); } json.Add("Fields", fields); return(json); }
public void Handle(PublishedEvent <NoteTextChanged> evnt) { using (var context = new ReadModelContainer()) { var date = evnt.EventTimeStamp.Date; var totalsForDate = context.TotalsPerDayItemSet.SingleOrDefault(i => i.Date == date); if (totalsForDate == null) { totalsForDate = new TotalsPerDayItem { Date = date }; context.TotalsPerDayItemSet.AddObject(totalsForDate); } totalsForDate.EditCount++; context.SaveChanges(); } }
public void Handle(PublishedEvent <NewNoteAdded> evnt) { using (var context = new ReadModelContainer()) { var existing = context.NoteItemSet.SingleOrDefault(x => x.Id == evnt.Payload.NoteId); if (existing != null) { return; } var newItem = new NoteItem { Id = evnt.Payload.NoteId, Text = evnt.Payload.Text, CreationDate = evnt.Payload.CreationDate }; context.NoteItemSet.AddObject(newItem); context.SaveChanges(); } }
/// <summary> /// Call this method when an event occurs to respond to it. /// </summary> public void Respond(PublishedEvent xEvent) { if (playSound) { sysSound.Play(); } if (sendEmail) { #region SQL command parameters. cmd.Parameters.Clear(); SqlParameter subject = new SqlParameter("@subject", System.Data.SqlDbType.NVarChar, 255); subject.Value = csb.DataSource + " - " + xEvent.Name + " Event"; SqlParameter body = new SqlParameter("@body", System.Data.SqlDbType.NVarChar, -1); StringBuilder sb = new StringBuilder("Extended Event: " + xEvent.Name + Environment.NewLine); foreach (PublishedEventField fld in xEvent.Fields) { sb.AppendLine("\t" + fld.Name + " = " + fld.Value.ToString()); } foreach (PublishedAction act in xEvent.Actions) { sb.AppendLine("\t" + act.Name + " = " + act.Value.ToString()); } //https://stackoverflow.com/questions/2292850/c-sharp-what-does-0-equate-to sb.Replace("\0", ""); body.Value = sb.ToString(); #endregion cmd.Parameters.Add(recipient); cmd.Parameters.Add(subject); cmd.Parameters.Add(body); cmd.ExecuteNonQuery(); } }
private object TryGetValue(PublishedEvent evt, FieldType t, string name) { object result = null; if (t == FieldType.Action) { PublishedAction act; if (evt.Actions.TryGetValue(name, out act)) { result = act.Value; } } else { PublishedEventField fld; if (evt.Fields.TryGetValue(name, out fld)) { result = fld.Value; } } return(result); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { // Display detail information dataGridView2.Rows.Clear(); PublishedEvent evt = (PublishedEvent)dataGridView1.Rows[e.RowIndex].Tag; foreach (PublishedEventField fld in evt.Fields) { int idx = dataGridView2.Rows.Add(); DataGridViewRow newRow = dataGridView2.Rows[idx]; newRow.Cells[0].Value = fld.Name; newRow.Cells[1].Value = fld.Value; } foreach (PublishedAction act in evt.Actions) { int idx = dataGridView2.Rows.Add(); DataGridViewRow newRow = dataGridView2.Rows[idx]; newRow.Cells[0].Value = act.Name; newRow.Cells[1].Value = act.Value; } }
public static void ReplaySingleEvent(PublishedEvent evt) { string commandText = "", dbName = ""; SqlCommand sqlCommand; if (evt != null) { dbName = evt.Actions["database_name"].Value.ToString(); if (evt.Name == "rpc_completed") { commandText = evt.Fields["statement"].Value.ToString(); } else if (evt.Name == "sql_batch_completed") { commandText = evt.Fields["batch_text"].Value.ToString(); } Console.WriteLine(Ellipsis(commandText)); if ((dbName != "") && (commandText != "")) { if (DatabaseList.FindIndex(x => x.Equals(dbName, StringComparison.OrdinalIgnoreCase)) != -1) { using (SqlConnection sqlConnection = new SqlConnection(ReplayServerConnectionString)) { sqlCommand = new SqlCommand(); sqlCommand.CommandText = commandText; sqlCommand.Connection = sqlConnection; sqlConnection.Open(); sqlConnection.ChangeDatabase(dbName); sqlCommand.ExecuteNonQuery(); } } } } }
private string TryGetString(PublishedEvent evt, FieldType t, string name) { object tmp = TryGetValue(evt, t, name); if (tmp != null && tmp.GetType() != typeof(DBNull)) { if (tmp is string) { return((string)tmp); } else if (tmp is byte[]) { return(Encoding.Unicode.GetString((byte[])tmp)); } else { throw new ArgumentException("Argument is of the wrong type"); } } else { return(null); } }
public override void Process(PublishedEvent evt) { if (xeadapter == null) { xeadapter = new XEventDataTableAdapter(eventsTable); xeadapter.Filter = this.Filter; xeadapter.OutputColumns = new List <OutputColumn>(); } xeadapter.ReadEvent(evt); if (DelaySeconds == 0 && ReplayIntervalSeconds == 0) { // run replay synchronously Replay(); } else { // start replay asynchronously if (ReplayTask == null) { ReplayTask = Task.Factory.StartNew(() => ReplayTaskMain()); } } }
public override void ReadEvents() { EventCount = 0; SqlTransformer transformer = new SqlTransformer(); using (QueryableXEventData eventstream = new QueryableXEventData( ConnectionString, SessionName, EventStreamSourceOptions.EventStream, EventStreamCacheOptions.DoNotCache)) { var eventsEnumerator = eventstream.GetEnumerator(); while (!stopped && eventsEnumerator.MoveNext()) { PublishedEvent evt = eventsEnumerator.Current; ExecutionWorkloadEvent evnt = new ExecutionWorkloadEvent(); string commandText = String.Empty; if (evt.Name == "rpc_completed") { commandText = (string)TryGetValue(evt, FieldType.Field, "statement"); evnt.Type = WorkloadEvent.EventType.RPCCompleted; } else if (evt.Name == "sql_batch_completed") { commandText = (string)TryGetValue(evt, FieldType.Field, "batch_text"); evnt.Type = WorkloadEvent.EventType.BatchCompleted; } else if (evt.Name == "attention") { object value = TryGetValue(evt, FieldType.Action, "sql_text"); try { if (value is string) { commandText = (string)value; } else if (value is byte[]) { commandText = Encoding.Unicode.GetString((byte[])value); } else { throw new ArgumentException("Argument is of the wrong type"); } } catch (Exception e) { logger.Error(e, $"Unable to extract sql_text from attention event. Value is of type ${value.GetType().FullName}"); } evnt.Type = WorkloadEvent.EventType.Timeout; } else if (evt.Name == "user_event") { int num = (int)TryGetValue(evt, FieldType.Field, "event_id"); if (num == 83) { commandText = (string)TryGetValue(evt, FieldType.Field, "user_data"); evnt.Type = WorkloadEvent.EventType.Error; } } else { evnt.Type = WorkloadEvent.EventType.Unknown; continue; } try { evnt.ApplicationName = (string)TryGetValue(evt, FieldType.Action, "client_app_name"); evnt.DatabaseName = (string)TryGetValue(evt, FieldType.Action, "database_name"); evnt.HostName = (string)TryGetValue(evt, FieldType.Action, "client_hostname"); evnt.LoginName = (string)TryGetValue(evt, FieldType.Action, "server_principal_name"); object oSession = TryGetValue(evt, FieldType.Action, "session_id"); if (oSession != null) { evnt.SPID = Convert.ToInt32(oSession); } if (commandText != null) { evnt.Text = commandText; } evnt.StartTime = evt.Timestamp.LocalDateTime; if (evnt.Type == WorkloadEvent.EventType.Error) { // do nothing } else if (evnt.Type == WorkloadEvent.EventType.Timeout) { evnt.Duration = Convert.ToInt64(evt.Fields["duration"].Value); evnt.CPU = Convert.ToInt64(evnt.Duration); } else { evnt.Reads = Convert.ToInt64(evt.Fields["logical_reads"].Value); evnt.Writes = Convert.ToInt64(evt.Fields["writes"].Value); evnt.CPU = Convert.ToInt64(evt.Fields["cpu_time"].Value); evnt.Duration = Convert.ToInt64(evt.Fields["duration"].Value); } } catch (Exception e) { logger.Error(e, "Error converting XE data from the stream."); throw; } if (evnt.Type <= WorkloadEvent.EventType.BatchCompleted) { if (transformer.Skip(evnt.Text)) { continue; } evnt.Text = transformer.Transform(evnt.Text); } Events.Enqueue(evnt); EventCount++; } } }
private DataTable ReadEvent(PublishedEvent evt) { DataTable dt = new DataTable("events"); // // Add computed columns // if (dt.Columns.Contains("collection_time")) { dt.Columns["collection_time"].ColumnName = "__collection_time"; } DataColumn cl_dt = new DataColumn("collection_time", typeof(DateTime)); cl_dt.DefaultValue = DateTime.Now; cl_dt.ExtendedProperties.Add("auto_column", true); dt.Columns.Add(cl_dt); // // Add Name column // dt.Columns.Add("Name", typeof(String)); dt.Columns["Name"].ExtendedProperties.Add("auto_column", true); // // Read event data // foreach (PublishedEventField fld in evt.Fields) { DataColumn dc = null; if (fld.Type.IsSerializable) { dc = dt.Columns.Add(fld.Name, fld.Type); } else { dc = dt.Columns.Add(fld.Name, typeof(String)); } dc.ExtendedProperties.Add("subtype", "field"); } foreach (PublishedAction act in evt.Actions) { DataColumn dc = dt.Columns.Add(act.Name, act.Type); dc.ExtendedProperties.Add("subtype", "action"); } DataRow row = dt.NewRow(); row.SetField("Name", evt.Name); foreach (PublishedEventField fld in evt.Fields) { if (fld.Type.IsSerializable) { row.SetField(fld.Name, fld.Value); } else { row.SetField(fld.Name, fld.Value.ToString()); } } foreach (PublishedAction act in evt.Actions) { row.SetField(act.Name, act.Value); } dt.Rows.Add(row); return(dt); }
public void Handle(PublishedEvent evt) { Model.Method.Invoke(Target, new[] { evt.Object }); }
public override void Process(PublishedEvent evt) { if (xeadapter == null) { xeadapter = new XEventDataTableAdapter(EventsTable); xeadapter.Filter = this.Filter; xeadapter.OutputColumns = new List <OutputColumn>(); } xeadapter.ReadEvent(evt); lock (EventsTable) { foreach (DataRow dr in EventsTable.Rows) { string formattedBody = Body; string formattedSubject = Subject; Dictionary <string, object> eventTokens = new Dictionary <string, object>(); foreach (DataColumn dc in EventsTable.Columns) { eventTokens.Add(dc.ColumnName, dr[dc]); } // also add the Response tokens foreach (string t in Tokens.Keys) { if (!eventTokens.ContainsKey(t)) { eventTokens.Add(t, Tokens[t]); } } formattedBody = SmartFormatHelper.Format(Body, eventTokens); formattedSubject = SmartFormatHelper.Format(Subject, eventTokens); using (MailMessage msg = new MailMessage() { From = new MailAddress(Sender), Subject = formattedSubject, Body = formattedBody }) { foreach (var addrTo in To.Split(';')) { msg.To.Add(new MailAddress(addrTo)); } using (MemoryStream attachStream = new MemoryStream()) { if (!String.IsNullOrEmpty(Attachment) && dr.Table.Columns.Contains(Attachment)) { StreamWriter wr = new StreamWriter(attachStream); wr.Write(dr[Attachment].ToString()); wr.Flush(); attachStream.Position = 0; System.Net.Mime.ContentType ct = new System.Net.Mime.ContentType(System.Net.Mime.MediaTypeNames.Text.Plain); Attachment at = new Attachment(attachStream, ct); at.ContentDisposition.FileName = AttachmentFileName; msg.Attachments.Add(at); } msg.IsBodyHtml = HTMLFormat; using (SmtpClient client = new SmtpClient(SMTPServer)) { if (!String.IsNullOrEmpty(UserName)) { client.Credentials = new System.Net.NetworkCredential(UserName, Password); } // could be inefficient: sends synchronously client.Send(msg); } } } } EventsTable.Clear(); } }
public void ProcessEvent(object sender) { PublishedEvent pe = (PublishedEvent)sender; Console.WriteLine(string.Format("Timestamp: {0}\nEvent Name:{1}\nNumber of Fields:{2}\n\n", pe.Timestamp.ToString("G"), pe.Name, pe.Fields.Count)); }
public void ReadEvent(PublishedEvent evt) { Prepare(); // // Read event data // lock (eventsTable) { foreach (PublishedEventField fld in evt.Fields) { if (!eventsTable.Columns.Contains(fld.Name) && (OutputColumns.Count == 0 || OutputColumns.Contains(fld.Name))) { Type t; DataColumn dc; bool disallowed = false; if (DataTableTSQLAdapter.AllowedDataTypes.Contains(fld.Type.ToString())) { t = fld.Type; } else { t = Type.GetType("System.String"); } dc = eventsTable.Columns.Add(fld.Name, t); dc.ExtendedProperties.Add("subtype", "field"); dc.ExtendedProperties.Add("disallowedtype", disallowed); dc.ExtendedProperties.Add("calculated", false); } } foreach (PublishedAction act in evt.Actions) { if (!eventsTable.Columns.Contains(act.Name) && (OutputColumns.Count == 0 || OutputColumns.Contains(act.Name))) { Type t; DataColumn dc; bool disallowed = false; if (DataTableTSQLAdapter.AllowedDataTypes.Contains(act.Type.ToString())) { t = act.Type; } else { t = Type.GetType("System.String"); } dc = eventsTable.Columns.Add(act.Name, t); dc.ExtendedProperties.Add("subtype", "action"); dc.ExtendedProperties.Add("disallowedtype", disallowed); dc.ExtendedProperties.Add("calculated", false); } } // add calculated columns for (int i = 0; i < OutputColumns.Count; i++) { string outCol = OutputColumns[i]; if (!eventsTable.Columns.Contains(outCol)) { if (Regex.IsMatch(outCol, @"\s+AS\s+", RegexOptions.IgnoreCase)) { var tokens = Regex.Split(outCol, @"\s+AS\s+", RegexOptions.IgnoreCase); string colName = tokens[0]; string colDefinition = tokens[1]; DataColumn dc; dc = eventsTable.Columns.Add(); dc.ColumnName = colName; dc.Expression = colDefinition; dc.ExtendedProperties.Add("subtype", "calculated"); dc.ExtendedProperties.Add("disallowedtype", false); dc.ExtendedProperties.Add("calculated", true); //change OutputColumns OutputColumns[i] = colName; } } } } DataTable tmpTab = eventsTable.Clone(); DataRow row = tmpTab.NewRow(); if (row.Table.Columns.Contains("Name")) { row.SetField("Name", evt.Name); } if (row.Table.Columns.Contains("collection_time")) { row.SetField("collection_time", evt.Timestamp.LocalDateTime); } foreach (PublishedEventField fld in evt.Fields) { if (row.Table.Columns.Contains(fld.Name)) { if ((bool)row.Table.Columns[fld.Name].ExtendedProperties["disallowedtype"]) { row.SetField(fld.Name, fld.Value.ToString()); } else { row.SetField(fld.Name, fld.Value); } } } foreach (PublishedAction act in evt.Actions) { if (row.Table.Columns.Contains(act.Name)) { if ((bool)row.Table.Columns[act.Name].ExtendedProperties["disallowedtype"]) { row.SetField(act.Name, act.Value.ToString()); } else { row.SetField(act.Name, act.Value); } } } if (!String.IsNullOrEmpty(Filter)) { DataView dv = new DataView(tmpTab); dv.RowFilter = Filter; tmpTab.Rows.Add(row); lock (eventsTable) { foreach (DataRow dr in dv.ToTable().Rows) { eventsTable.ImportRow(dr); } } } else { tmpTab.Rows.Add(row); lock (eventsTable) { foreach (DataRow dr in tmpTab.Rows) { eventsTable.ImportRow(dr); } } } }
public void Raise() { PublishedEvent.Raise(); }
public void ReadEvents() { EventCount = 0; SqlTransformer transformer = new SqlTransformer(); using (QueryableXEventData eventstream = new QueryableXEventData(Path)) { var eventsEnumerator = eventstream.GetEnumerator(); while (!stopped && eventsEnumerator.MoveNext()) { PublishedEvent evt = eventsEnumerator.Current; ExecutionWorkloadEvent evnt = new ExecutionWorkloadEvent(); string commandText = String.Empty; if (evt.Name == "rpc_completed") { commandText = (string)TryGetValue(evt, FieldType.Field, "statement"); evnt.Type = WorkloadEvent.EventType.RPCCompleted; } else if (evt.Name == "sql_batch_completed") { commandText = (string)TryGetValue(evt, FieldType.Field, "batch_text"); evnt.Type = WorkloadEvent.EventType.BatchCompleted; } else if (evt.Name == "attention") { commandText = (string)TryGetValue(evt, FieldType.Action, "sql_text"); evnt.Type = WorkloadEvent.EventType.Timeout; } else { evnt.Type = WorkloadEvent.EventType.Unknown; continue; } try { evnt.ApplicationName = (string)TryGetValue(evt, FieldType.Action, "client_app_name"); evnt.DatabaseName = (string)TryGetValue(evt, FieldType.Action, "database_name"); evnt.HostName = (string)TryGetValue(evt, FieldType.Action, "client_hostname"); evnt.LoginName = (string)TryGetValue(evt, FieldType.Action, "server_principal_name"); object oSession = TryGetValue(evt, FieldType.Action, "session_id"); if (oSession != null) { evnt.SPID = Convert.ToInt32(oSession); } if (commandText != null) { evnt.Text = commandText; } evnt.StartTime = evt.Timestamp.LocalDateTime; if (evnt.Type == WorkloadEvent.EventType.Timeout) { evnt.Duration = Convert.ToInt64(evt.Fields["duration"].Value); evnt.CPU = Convert.ToInt64(evnt.Duration); } else { evnt.Reads = Convert.ToInt64(evt.Fields["logical_reads"].Value); evnt.Writes = Convert.ToInt64(evt.Fields["writes"].Value); evnt.CPU = Convert.ToInt64(evt.Fields["cpu_time"].Value); evnt.Duration = Convert.ToInt64(evt.Fields["duration"].Value); } } catch (Exception e) { logger.Error(e, "Error converting XE data from the stream."); throw; } if (transformer.Skip(evnt.Text)) { continue; } evnt.Text = transformer.Transform(evnt.Text); Events.Enqueue(evnt); EventCount++; } finished = true; } }
public bool Handles(PublishedEvent evt) { return(Model.Event.Type == evt.Object.GetType()); }