Skip to content

Commit

Permalink
Message viewer doesn't understand Linux-style new lines #1770
Browse files Browse the repository at this point in the history
  • Loading branch information
LiorBanai committed Aug 18, 2023
1 parent e36b956 commit c3b96e7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Analogy.CommonControls/UserControls/LogMessagesUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2428,19 +2428,19 @@ private void LoadTextBoxes(AnalogyLogMessage m)
{
bbtnRawMessageViewer.Tag = m;
recMessageDetails.Tag = m;
recMessageDetails.Text = m.Text;
recMessageDetails.Text = Utils.ProcessLinuxMessage(m.Text);
meMessageDetails.Tag = m;
meMessageDetails.Text = m.Text;
meMessageDetails.Text = Utils.ProcessLinuxMessage(m.Text); ;
recMessageDetails.HtmlText = Markdown.ToHtml(m.Text, pipeline);
}));
}
else
{
bbtnRawMessageViewer.Tag = m;
recMessageDetails.Tag = m;
recMessageDetails.Text = m.Text;
recMessageDetails.Text = Utils.ProcessLinuxMessage(m.Text); ;
meMessageDetails.Tag = m;
meMessageDetails.Text = m.Text;
meMessageDetails.Text = Utils.ProcessLinuxMessage(m.Text); ;
recMessageDetails.HtmlText = Markdown.ToHtml(m.Text, pipeline);
}

Expand Down
2 changes: 1 addition & 1 deletion Analogy.CommonControls/UserControls/MessageDetailsUC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task LoadMessage()
Message.AdditionalProperties.Select(kv => $"{kv.Key}:{kv.Value}"));
}

memoText.Text = Message.Text;
memoText.Text =Utils.ProcessLinuxMessage(Message.Text);
txtbMachineName.Text = Message.MachineName;
txtID.Text = Message.Id.ToString();
txtbDataSource.Text = DataSource;
Expand Down
29 changes: 26 additions & 3 deletions Analogy.CommonControls/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Controls;
using Newtonsoft.Json;
using System.Text;

namespace Analogy.CommonControls
{
Expand Down Expand Up @@ -67,7 +68,7 @@ public static DataRow CreateRow(DataTable table, IAnalogyLogMessage message, str
{
var dtr = table.NewRow();
dtr.BeginEdit();
dtr["Date"] = GetOffsetTime(message.Date,timeOffsetType,customOffset);
dtr["Date"] = GetOffsetTime(message.Date, timeOffsetType, customOffset);
dtr["Text"] = message.Text ?? "";
dtr["Source"] = message.Source ?? "";
dtr["Level"] = message.Level;
Expand Down Expand Up @@ -101,7 +102,7 @@ public static bool IsCompressedArchive(string filename)
filename.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase);
}

public static DateTime GetOffsetTime(DateTime time, TimeOffsetType timeOffsetType,TimeSpan customOffset)
public static DateTime GetOffsetTime(DateTime time, TimeOffsetType timeOffsetType, TimeSpan customOffset)
{
return timeOffsetType switch
{
Expand Down Expand Up @@ -216,7 +217,7 @@ static long GetLastInputTime()
}
public static TimeSpan IdleTime() => TimeSpan.FromSeconds(GetLastInputTime());

public static string GetOpenFilter(string openFilter,bool addCompressedArchives)
public static string GetOpenFilter(string openFilter, bool addCompressedArchives)
{
if (!addCompressedArchives)
{
Expand Down Expand Up @@ -260,5 +261,27 @@ public static SuperToolTip GetSuperTip(string title, string content)
toolTip.Setup(args);
return toolTip;
}

public static string ProcessLinuxMessage(string? msg)
{
if (msg == null)
{
return string.Empty;
}
StringBuilder sb = new();
foreach (var line in msg.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries))
{
if (!line.Contains("\n"))
{
sb.AppendLine(line);
continue;
}
foreach (var innerLines in line.Split(new[] { "\n" }, StringSplitOptions.RemoveEmptyEntries))
{
sb.AppendFormat("{0}{1}", innerLines.Replace("\n",""), Environment.NewLine);
}
}
return sb.ToString();
}
}
}

0 comments on commit c3b96e7

Please sign in to comment.