Skip to content

Commit 4b9a831

Browse files
committed
(x) Fix requested changes
1 parent 0a3b831 commit 4b9a831

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010

1111
# Please keep the list sorted.
1212

13-
Maksim Khomutov <mkhomutov@gmail.com>
1413
Igr Alexánder Fernández Saúco <alexander.fernandez.sauco@gmail.com>
14+
Maksim Khomutov <mkhomutov@gmail.com>
15+

src/LogViewer/Commands/FilterCopyResultToClipboardCommandContainer.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,26 @@
77

88
namespace LogViewer
99
{
10-
using System.IO;
10+
using System.Linq;
11+
using System.Text;
12+
1113
using Catel;
1214
using Catel.MVVM;
15+
16+
using LogViewer.Services;
17+
1318
using Orchestra.Services;
14-
using Services;
1519

1620
public class FilterCopyResultToClipboardCommandContainer : CommandContainerBase
1721
{
22+
#region Fields
1823
private readonly IClipboardService _clipboardService;
24+
1925
private readonly ILogTableService _logTableService;
26+
#endregion
2027

21-
public FilterCopyResultToClipboardCommandContainer(ICommandManager commandManager, IClipboardService clipboardService,
22-
ILogTableService logTableService)
28+
#region Constructors
29+
public FilterCopyResultToClipboardCommandContainer(ICommandManager commandManager, IClipboardService clipboardService, ILogTableService logTableService)
2330
: base(Commands.Filter.CopyResultToClipboard, commandManager)
2431
{
2532
Argument.IsNotNull(() => clipboardService);
@@ -28,16 +35,19 @@ public FilterCopyResultToClipboardCommandContainer(ICommandManager commandManage
2835
_clipboardService = clipboardService;
2936
_logTableService = logTableService;
3037
}
38+
#endregion
3139

40+
#region Methods
3241
protected override void Execute(object parameter)
3342
{
34-
StringWriter writer = new StringWriter();
43+
var stringBuilder = new StringBuilder();
3544
foreach (var record in _logTableService.LogTable.Records)
3645
{
37-
writer.WriteLine(record.ToString());
46+
stringBuilder.AppendLine(record.ToString());
3847
}
3948

40-
_clipboardService.CopyToClipboard(writer.GetStringBuilder().ToString());
49+
_clipboardService.CopyToClipboard(stringBuilder.ToString());
4150
}
51+
#endregion
4252
}
4353
}

src/LogViewer/Commands/FilterExportResultCommandContainer.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
namespace LogViewer
99
{
1010
using System.IO;
11+
using System.Linq;
12+
using System.Threading.Tasks;
13+
1114
using Catel;
1215
using Catel.MVVM;
1316
using Catel.Services;
@@ -35,21 +38,12 @@ public FilterExportResultCommandContainer(ICommandManager commandManager,
3538
_logTableService = logTableService;
3639
}
3740

38-
protected override void Execute(object parameter)
41+
protected override async Task ExecuteAsync(object parameter)
3942
{
4043
_saveFileService.FileName = "LogViewerFilterExport_" + FastDateTime.Now.ToString("yy-MM-dd_HHmmss_ms") + ".log";
41-
var determineFileAsync = _saveFileService.DetermineFileAsync();
42-
determineFileAsync.Wait();
43-
44-
if (determineFileAsync.Result)
44+
if (await _saveFileService.DetermineFileAsync())
4545
{
46-
using (var writer = new StreamWriter(_fileService.Open(_saveFileService.FileName, FileMode.Create, FileAccess.Write)))
47-
{
48-
foreach (var record in _logTableService.LogTable.Records)
49-
{
50-
writer.WriteLine(record.ToString());
51-
}
52-
}
46+
_fileService.WriteAllLines(_saveFileService.FileName, _logTableService.LogTable.Records.Select(record => record.ToString()));
5347
}
5448
}
5549
}

src/LogViewer/Models/LogRecord.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,27 @@
88
namespace LogViewer.Models
99
{
1010
using System;
11+
using System.Collections.Generic;
1112

1213
using Catel.Data;
1314
using Catel.Logging;
1415

1516
public class LogRecord : ModelBase
1617
{
18+
#region Fields
19+
private static readonly Dictionary<LogEvent, string> LogEventCache = new Dictionary<LogEvent, string>();
20+
#endregion
21+
22+
#region Constructors
23+
static LogRecord()
24+
{
25+
foreach (LogEvent value in Enum.GetValues(typeof(LogEvent)))
26+
{
27+
LogEventCache.Add(value, value.ToString().ToUpper());
28+
}
29+
}
30+
#endregion
31+
1732
#region Properties
1833
public FileNode FileNode { get; set; }
1934

@@ -35,9 +50,11 @@ public class LogRecord : ModelBase
3550
public bool IsSelected { get; set; }
3651
#endregion
3752

53+
#region Methods
3854
public override string ToString()
3955
{
40-
return $"{DateTime:HH:mm:ss:ms} => [{LogEvent.ToString().ToUpper()}] [{TargetTypeName}] [{ThreadId}] {Message}";
56+
return $"{DateTime:HH:mm:ss:ms} => [{LogEventCache[LogEvent]}] [{TargetTypeName}] [{ThreadId}] {Message}";
4157
}
58+
#endregion
4259
}
4360
}

0 commit comments

Comments
 (0)