Skip to content

Commit

Permalink
#35 Filter by correlation id
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Rapp committed Jan 12, 2017
1 parent 6717c95 commit e4931e8
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 80 deletions.
2 changes: 2 additions & 0 deletions Cinteros.XTB.PluginTraceViewer/PTVFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ public class PTVFilter
public string Plugin { get; set; }
public string Message { get; set; }
public string Entity { get; set; }
public string CorrelationId { get; set; }
public bool Exceptions { get; set; }
public bool ExceptionSummary { get; set; } = true;
public bool Correlation { get; set; } = true;
public int Mode { get; set; }
public int MinDuration { get; set; }
public int MaxDuration { get; set; }
Expand Down
62 changes: 59 additions & 3 deletions Cinteros.XTB.PluginTraceViewer/PluginTraceViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ private void FetchUpdated(string fetchxml)

private void RefreshTraces(QueryExpression query)
{
if (query == null)
{
return;
}
var excSummary = chkExceptionSummary.Checked;
if (Service != null)
{
Expand Down Expand Up @@ -560,6 +564,16 @@ private QueryExpression GetQuery()
}
}
}
if (chkCorrelation.Checked)
{
Guid id;
if (!Guid.TryParse(textCorrelationId.Text, out id))
{
MessageBox.Show("Correlation id is not a valid Guid.", "Correlation", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
QEplugintracelog.Criteria.AddCondition("correlationid", ConditionOperator.Equal, id);
}
if (chkExceptions.Checked)
{
QEplugintracelog.Criteria.AddCondition("exceptiondetails", ConditionOperator.NotNull);
Expand Down Expand Up @@ -838,8 +852,10 @@ private PTVFilter GetFilter()
Plugin = chkPlugin.Checked ? comboPlugin.Text : string.Empty,
Message = chkMessage.Checked ? comboMessage.Text : string.Empty,
Entity = chkEntity.Checked ? comboEntity.Text : string.Empty,
CorrelationId = chkCorrelation.Checked ? textCorrelationId.Text : string.Empty,
Exceptions = chkExceptions.Checked,
ExceptionSummary = chkExceptionSummary.Checked,
Correlation = chkShowCorrelation.Checked,
Mode = rbModeSync.Checked ? 1 : rbModeAsync.Checked ? 2 : 0,
MinDuration = chkDurationMin.Checked ? (int)numDurationMin.Value : -1,
MaxDuration = chkDurationMax.Checked ? (int)numDurationMax.Value : -1,
Expand Down Expand Up @@ -909,8 +925,11 @@ private void ApplyFilter(PTVFilter filter)
comboMessage.SelectedIndex = comboMessage.Items.IndexOf(filter.Message);
chkEntity.Checked = !string.IsNullOrEmpty(filter.Entity);
comboEntity.Text = filter.Entity;
chkCorrelation.Checked = !string.IsNullOrEmpty(filter.CorrelationId);
textCorrelationId.Text = filter.CorrelationId;
chkExceptions.Checked = filter.Exceptions;
chkExceptionSummary.Checked = filter.ExceptionSummary;
chkShowCorrelation.Checked = filter.Correlation;
switch (filter.Mode)
{
case 1:
Expand Down Expand Up @@ -1194,6 +1213,10 @@ private void SaveSettings()
private void buttonOpenFXB_Click(object sender, EventArgs e)
{
var fetchxml = GetQueryFetchXML();
if (string.IsNullOrEmpty(fetchxml))
{
return;
}
var messageBusEventArgs = new MessageBusEventArgs("FetchXML Builder")
{
TargetArgument = fetchxml
Expand All @@ -1204,6 +1227,10 @@ private void buttonOpenFXB_Click(object sender, EventArgs e)
private string GetQueryFetchXML()
{
QueryExpression query = GetQuery();
if (query == null)
{
return string.Empty;
}
var resp = Service.Execute(new QueryExpressionToFetchXmlRequest() { Query = query }) as QueryExpressionToFetchXmlResponse;
return resp.FetchXml;
}
Expand All @@ -1223,6 +1250,10 @@ private void SaveQuery()
if (sfd.ShowDialog() == DialogResult.OK && !string.IsNullOrEmpty(sfd.FileName))
{
var fetchxml = GetQueryFetchXML();
if (string.IsNullOrEmpty(fetchxml))
{
return;
}
var fetchdoc = new XmlDocument();
fetchdoc.LoadXml(fetchxml);
fetchdoc.Save(sfd.FileName);
Expand Down Expand Up @@ -1258,10 +1289,9 @@ private void comboLogSetting_SelectedIndexChanged(object sender, EventArgs e)
private void tsmiCorrelationSelectThis_Click(object sender, EventArgs e)
{
var count = 0;
var entities = crmGridView.SelectedCellRecords?.Entities;
if (entities?.Count == 1 && entities[0]["correlationid"].ToString() != "")
var corrId = GetSelectedCorrelationId();
if (!corrId.Equals(Guid.Empty))
{
var corrId = entities[0]["correlationid"];
foreach (DataGridViewRow row in crmGridView.Rows)
{
var idstr = row.Cells["correlationid"]?.Value?.ToString();
Expand All @@ -1279,5 +1309,31 @@ private void tsmiCorrelationSelectThis_Click(object sender, EventArgs e)
}
SendMessageToStatusBar(this, new StatusBarMessageEventArgs($"Selected {count} log records"));
}

private void chkCorrelation_CheckedChanged(object sender, EventArgs e)
{
textCorrelationId.Enabled = chkCorrelation.Checked;
}

private void tsmiCorrelationFilterByThis_Click(object sender, EventArgs e)
{
var corrId = GetSelectedCorrelationId();
if (!corrId.Equals(Guid.Empty))
{
chkCorrelation.Checked = true;
textCorrelationId.Text = corrId.ToString();
RefreshTraces(GetQuery());
}
}

private Guid GetSelectedCorrelationId()
{
var entities = crmGridView.SelectedCellRecords?.Entities;
if (entities?.Count == 1 && entities[0]["correlationid"].ToString() != "")
{
return (Guid)entities[0]["correlationid"];
}
return Guid.Empty;
}
}
}
Loading

0 comments on commit e4931e8

Please sign in to comment.