private void OnReadEventLogTaskChange(IList <Microsoft.EnterpriseManagement.Runtime.TaskResult> results, bool lastUpdate) { Dbg.Log($"Entering {MethodBase.GetCurrentMethod().Name}"); try { EventListDataItem eventListResult = DeserializeDataItemFromTaskResults <EventListDataItem, EventList>(results, (xmlReader) => new EventListDataItem(xmlReader)); if (eventListResult != null && eventListResult.Data.ErrorCode == 0) { ClearEventDisplayElements(); DataTable table = PrepareEventTable(eventListResult); BindingSource bs = new BindingSource() { DataSource = table }; dgvEventsMain.DataSource = bs; tbEventText.DataBindings.Add("Text", bs, "FormattedDescription"); tbEventLogName.DataBindings.Add("Text", bs, "LogName"); tbEventSource.DataBindings.Add("Text", bs, "Source"); tbEventEventId.DataBindings.Add("Text", bs, "EventId"); tbEventLevel.DataBindings.Add("Text", bs, "Level"); tbEventUser.DataBindings.Add("Text", bs, "User"); tbEventLogged.DataBindings.Add("Text", bs, "Logged"); tbEventEventCatrgory.DataBindings.Add("Text", bs, "TaskCategory"); tbEventKeywords.DataBindings.Add("Text", bs, "Keywords"); tbEventComputer.DataBindings.Add("Text", bs, "Computer"); wbEventXML.DataBindings.Add("DocumentText", bs, "RawXML"); } else { dgvEventsMain.DataSource = null; if (eventListResult != null && eventListResult.Data.ErrorCode != 0) { MessageBox.Show($"Failed to query event log.\r\nError message: {eventListResult.Data.ErrorMessage ?? "Not provided."}", "Operation Failed", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception e) { Dbg.Log($"Exception {e.Message} in {MethodBase.GetCurrentMethod().Name}"); } }
private DataTable PrepareEventTable(EventListDataItem serviceListResult) { Dbg.Log($"Entering {MethodBase.GetCurrentMethod().Name}"); DataTable result = new DataTable(); result.Columns.Add("LogName", typeof(string)).AllowDBNull = true; result.Columns.Add("Source", typeof(string)).AllowDBNull = true; result.Columns.Add("EventId", typeof(int)).AllowDBNull = true; result.Columns.Add("Level", typeof(string)).AllowDBNull = true; result.Columns.Add("User", typeof(string)).AllowDBNull = true; result.Columns.Add("Logged", typeof(DateTime)).AllowDBNull = true; result.Columns.Add("TaskCategory", typeof(string)).AllowDBNull = true; result.Columns.Add("Keywords", typeof(string)).AllowDBNull = true; result.Columns.Add("Computer", typeof(string)).AllowDBNull = true; result.Columns.Add("FormattedDescription", typeof(string)).AllowDBNull = true; result.Columns.Add("RawXML", typeof(string)).AllowDBNull = true; foreach (Tasks.Module.Events.EventInfo eventInfo in serviceListResult.Data.Events) { result.LoadDataRow(new object[] { (object)eventInfo.LogName ?? DBNull.Value, (object)eventInfo.Source ?? DBNull.Value, eventInfo.EventId, (object)eventInfo.Level ?? DBNull.Value, (object)eventInfo.User ?? DBNull.Value, (object)eventInfo.Logged, (object)eventInfo.TaskCategory ?? DBNull.Value, (object)eventInfo.Keywords ?? DBNull.Value, (object)eventInfo.Computer ?? DBNull.Value, (object)eventInfo.FormattedDescription ?? DBNull.Value, $"<?xml version=\"1.0\"?>{eventInfo.RawXML}" }, false); } result.AcceptChanges(); Dbg.Log($"returning {result.Rows.Count} rows."); return(result); }