Skip to content

Commit 2a28d41

Browse files
committed
MaximumLineLength is no configurable, but beware it can impact the performance to change it to more then 20.000
1 parent 320744d commit 2a28d41

9 files changed

Lines changed: 1536 additions & 1544 deletions

File tree

src/LogExpert.Tests/JSONSaveTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using LogExpert.Config;
2+
23
using Newtonsoft.Json;
4+
35
using NUnit.Framework;
6+
47
using System.IO;
58

69
namespace LogExpert.Tests
@@ -17,14 +20,14 @@ public void SaveOptionsAsJSON()
1720
string settingsFile = configDir + "\\settings.json";
1821

1922
Settings settings = null;
20-
23+
2124
Assert.DoesNotThrow(CastSettings);
2225
Assert.That(settings, Is.Not.Null);
2326
Assert.That(settings.alwaysOnTop, Is.True);
2427

2528
ConfigManager.Settings.alwaysOnTop = false;
2629
ConfigManager.Save(SettingsFlags.All);
27-
30+
2831
settings = null;
2932
Assert.DoesNotThrow(CastSettings);
3033

src/LogExpert/Classes/Log/PositionAwareStreamReaderBase.cs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
using System;
1+
using LogExpert.Config;
2+
using LogExpert.Entities;
3+
4+
using System;
25
using System.IO;
36
using System.Text;
4-
using LogExpert.Entities;
57

68
namespace LogExpert.Classes.Log
79
{
810
public abstract class PositionAwareStreamReaderBase : LogStreamReaderBase
911
{
1012
#region Fields
1113

12-
private const int MAX_LINE_LEN = 20000;
13-
1414
private static readonly Encoding[] _preambleEncodings = { Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32 };
1515

1616
private readonly BufferedStream _stream;
@@ -35,7 +35,7 @@ protected PositionAwareStreamReaderBase(Stream stream, EncodingOptions encodingO
3535
_posIncPrecomputed = GetPosIncPrecomputed(usedEncoding);
3636

3737
_reader = new StreamReader(_stream, usedEncoding, true);
38-
38+
3939
Position = 0;
4040
}
4141

@@ -54,7 +54,7 @@ public sealed override long Position
5454
/*
5555
* 1: Sometime commented (+Encoding.GetPreamble().Length)
5656
* 2: Date 1.1 3207
57-
* 3: Error Message from Piet because of Unicode-Bugs.
57+
* 3: Error Message from Piet because of Unicode-Bugs.
5858
* No Idea, if this is OK.
5959
* 4: 27.07.09: Preamble-Length is now calculated in CT, because Encoding.GetPreamble().Length
6060
* always delivers a fixed length (does not mater what kind of data)
@@ -72,7 +72,7 @@ public sealed override long Position
7272

7373
public sealed override bool IsBufferComplete => true;
7474

75-
protected static int MaxLineLen => MAX_LINE_LEN;
75+
protected static int MaxLineLen => ConfigManager.Settings.preferences.MaxLineLength;
7676

7777
#endregion
7878

@@ -149,11 +149,11 @@ protected void MovePosition(int offset)
149149
private int DetectPreambleLengthAndEncoding(out Encoding detectedEncoding)
150150
{
151151
/*
152-
UTF-8: EF BB BF
153-
UTF-16-Big-Endian-Byteorder: FE FF
154-
UTF-16-Little-Endian-Byteorder: FF FE
155-
UTF-32-Big-Endian-Byteorder: 00 00 FE FF
156-
UTF-32-Little-Endian-Byteorder: FF FE 00 00
152+
UTF-8: EF BB BF
153+
UTF-16-Big-Endian-Byteorder: FE FF
154+
UTF-16-Little-Endian-Byteorder: FF FE
155+
UTF-32-Big-Endian-Byteorder: 00 00 FE FF
156+
UTF-32-Little-Endian-Byteorder: FF FE 00 00
157157
*/
158158

159159
byte[] readPreamble = new byte[4];
@@ -205,17 +205,17 @@ private int GetPosIncPrecomputed(Encoding usedEncoding)
205205
switch (usedEncoding)
206206
{
207207
case UTF8Encoding _:
208-
{
209-
return 0;
210-
}
208+
{
209+
return 0;
210+
}
211211
case UnicodeEncoding _:
212-
{
213-
return 2;
214-
}
212+
{
213+
return 2;
214+
}
215215
default:
216-
{
217-
return 1;
218-
}
216+
{
217+
return 1;
218+
}
219219
}
220220
}
221221

src/LogExpert/Config/Preferences.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ public class Preferences
103103

104104
public bool ShowErrorMessageAllowOnlyOneInstances { get; set; }
105105

106+
public int MaxLineLength { get; set; } = 20000;
107+
106108
#endregion
107109
}
108110
}

src/LogExpert/Controls/LogWindow/LogWindow.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ internal void ChangeMultifileMask()
579579
internal void ToggleColumnFinder(bool show, bool setFocus)
580580
{
581581
_guiStateArgs.ColumnFinderVisible = show;
582+
582583
if (show)
583584
{
584585
columnComboBox.AutoCompleteMode = AutoCompleteMode.Suggest;

src/LogExpert/Controls/LogWindow/LogWindowsPublic.cs

Lines changed: 72 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,10 @@ public void LoadFile(string fileName, EncodingOptions encodingOptions)
8181

8282
try
8383
{
84-
_logFileReader = new LogfileReader(fileName, EncodingOptions, IsMultiFile, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions);
85-
_logFileReader.UseNewReader = !Preferences.useLegacyReader;
84+
_logFileReader = new LogfileReader(fileName, EncodingOptions, IsMultiFile, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions)
85+
{
86+
UseNewReader = !Preferences.useLegacyReader
87+
};
8688
}
8789
catch (LogFileException lfe)
8890
{
@@ -154,8 +156,10 @@ public void LoadFilesAsMulti(string[] fileNames, EncodingOptions encodingOptions
154156
EncodingOptions = encodingOptions;
155157
_columnCache = new ColumnCache();
156158

157-
_logFileReader = new LogfileReader(fileNames, EncodingOptions, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions);
158-
_logFileReader.UseNewReader = !Preferences.useLegacyReader;
159+
_logFileReader = new LogfileReader(fileNames, EncodingOptions, Preferences.bufferCount, Preferences.linesPerBuffer, _multiFileOptions)
160+
{
161+
UseNewReader = !Preferences.useLegacyReader
162+
};
159163
RegisterLogFileReaderEvents();
160164
_logFileReader.StartMonitoring();
161165
FileName = fileNames[^1];
@@ -207,23 +211,25 @@ public string SavePersistenceData(bool force)
207211

208212
public PersistenceData GetPersistenceData()
209213
{
210-
PersistenceData persistenceData = new();
211-
persistenceData.bookmarkList = _bookmarkProvider.BookmarkList;
212-
persistenceData.rowHeightList = _rowHeightList;
213-
persistenceData.multiFile = IsMultiFile;
214-
persistenceData.multiFilePattern = _multiFileOptions.FormatPattern;
215-
persistenceData.multiFileMaxDays = _multiFileOptions.MaxDayTry;
216-
persistenceData.currentLine = dataGridView.CurrentCellAddress.Y;
217-
persistenceData.firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex;
218-
persistenceData.filterVisible = !splitContainerLogWindow.Panel2Collapsed;
219-
persistenceData.filterAdvanced = !advancedFilterSplitContainer.Panel1Collapsed;
220-
persistenceData.filterPosition = splitContainerLogWindow.SplitterDistance;
221-
persistenceData.followTail = _guiStateArgs.FollowTail;
222-
persistenceData.fileName = FileName;
223-
persistenceData.tabName = Text;
224-
persistenceData.sessionFileName = SessionFileName;
225-
persistenceData.columnizerName = CurrentColumnizer.GetName();
226-
persistenceData.lineCount = _logFileReader.LineCount;
214+
PersistenceData persistenceData = new()
215+
{
216+
bookmarkList = _bookmarkProvider.BookmarkList,
217+
rowHeightList = _rowHeightList,
218+
multiFile = IsMultiFile,
219+
multiFilePattern = _multiFileOptions.FormatPattern,
220+
multiFileMaxDays = _multiFileOptions.MaxDayTry,
221+
currentLine = dataGridView.CurrentCellAddress.Y,
222+
firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex,
223+
filterVisible = !splitContainerLogWindow.Panel2Collapsed,
224+
filterAdvanced = !advancedFilterSplitContainer.Panel1Collapsed,
225+
filterPosition = splitContainerLogWindow.SplitterDistance,
226+
followTail = _guiStateArgs.FollowTail,
227+
fileName = FileName,
228+
tabName = Text,
229+
sessionFileName = SessionFileName,
230+
columnizerName = CurrentColumnizer.GetName(),
231+
lineCount = _logFileReader.LineCount
232+
};
227233
_filterParams.isFilterTail = filterTailCheckBox.Checked; // this option doesnt need a press on 'search'
228234

229235
if (Preferences.saveFilters)
@@ -233,9 +239,11 @@ public PersistenceData GetPersistenceData()
233239

234240
foreach (FilterPipe filterPipe in _filterPipeList)
235241
{
236-
FilterTabData data = new();
237-
data.persistenceData = filterPipe.OwnLogWindow.GetPersistenceData();
238-
data.filterParams = filterPipe.FilterParams;
242+
FilterTabData data = new()
243+
{
244+
persistenceData = filterPipe.OwnLogWindow.GetPersistenceData(),
245+
filterParams = filterPipe.FilterParams
246+
};
239247
persistenceData.filterTabDataList.Add(data);
240248
}
241249
}
@@ -467,9 +475,11 @@ public void CellPainting(DataGridView gridView, int rowIndex, DataGridViewCellPa
467475

468476
if (bookmark.Text.Length > 0)
469477
{
470-
StringFormat format = new();
471-
format.LineAlignment = StringAlignment.Center;
472-
format.Alignment = StringAlignment.Center;
478+
StringFormat format = new()
479+
{
480+
LineAlignment = StringAlignment.Center,
481+
Alignment = StringAlignment.Center
482+
};
473483
Brush brush2 = new SolidBrush(Color.FromArgb(255, 190, 100, 0));
474484
Font font = new("Courier New", Preferences.fontSize, FontStyle.Bold);
475485
e.Graphics.DrawString("i", font, brush2, new RectangleF(r.Left, r.Top, r.Width, r.Height),
@@ -916,7 +926,7 @@ public void SetBookmarkFromTrigger(int lineNum, string comment)
916926
{
917927
return;
918928
}
919-
ParamParser paramParser = new ParamParser(comment);
929+
ParamParser paramParser = new(comment);
920930
try
921931
{
922932
comment = paramParser.ReplaceParams(line, lineNum, FileName);
@@ -1160,26 +1170,31 @@ public void CopyMarkedLinesToTab()
11601170
{
11611171
if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
11621172
{
1163-
List<int> lineNumList = new List<int>();
1173+
List<int> lineNumList = [];
1174+
11641175
foreach (DataGridViewRow row in dataGridView.SelectedRows)
11651176
{
11661177
if (row.Index != -1)
11671178
{
11681179
lineNumList.Add(row.Index);
11691180
}
11701181
}
1182+
11711183
lineNumList.Sort();
11721184
// create dummy FilterPipe for connecting line numbers to original window
11731185
// setting IsStopped to true prevents further filter processing
1174-
FilterPipe pipe = new FilterPipe(new FilterParams(), this);
1175-
pipe.IsStopped = true;
1186+
FilterPipe pipe = new(new FilterParams(), this)
1187+
{
1188+
IsStopped = true
1189+
};
1190+
11761191
WritePipeToTab(pipe, lineNumList, Text + "->C", null);
11771192
}
11781193
else
11791194
{
11801195
string fileName = Path.GetTempFileName();
1181-
FileStream fStream = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.Read);
1182-
StreamWriter writer = new StreamWriter(fStream, Encoding.Unicode);
1196+
FileStream fStream = new(fileName, FileMode.Append, FileAccess.Write, FileShare.Read);
1197+
StreamWriter writer = new(fStream, Encoding.Unicode);
11831198

11841199
DataObject data = dataGridView.GetClipboardContent();
11851200
string text = data.GetText(TextDataFormat.Text);
@@ -1199,6 +1214,7 @@ public void ChangeEncoding(Encoding encoding)
11991214
{
12001215
_logFileReader.ChangeEncoding(encoding);
12011216
EncodingOptions.Encoding = encoding;
1217+
12021218
if (_guiStateArgs.CurrentEncoding.IsSingleByte != encoding.IsSingleByte ||
12031219
_guiStateArgs.CurrentEncoding.GetPreamble().Length != encoding.GetPreamble().Length)
12041220
{
@@ -1216,9 +1232,11 @@ public void Reload()
12161232
{
12171233
SavePersistenceData(false);
12181234

1219-
_reloadMemento = new ReloadMemento();
1220-
_reloadMemento.currentLine = dataGridView.CurrentCellAddress.Y;
1221-
_reloadMemento.firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex;
1235+
_reloadMemento = new ReloadMemento
1236+
{
1237+
currentLine = dataGridView.CurrentCellAddress.Y,
1238+
firstDisplayedLine = dataGridView.FirstDisplayedScrollingRowIndex
1239+
};
12221240
_forcedColumnizerForLoading = CurrentColumnizer;
12231241

12241242
if (_fileNames == null || !IsMultiFile)
@@ -1587,7 +1605,7 @@ public void PatternStatisticSelectRange(PatternArgs patternArgs)
15871605
{
15881606
if (dataGridView.SelectionMode == DataGridViewSelectionMode.FullRowSelect)
15891607
{
1590-
List<int> lineNumList = new List<int>();
1608+
List<int> lineNumList = new();
15911609
foreach (DataGridViewRow row in dataGridView.SelectedRows)
15921610
{
15931611
if (row.Index != -1)
@@ -1615,19 +1633,21 @@ public void PatternStatisticSelectRange(PatternArgs patternArgs)
16151633

16161634
public void PatternStatistic(PatternArgs patternArgs)
16171635
{
1618-
PatternStatisticFx fx = new PatternStatisticFx(TestStatistic);
1636+
PatternStatisticFx fx = new(TestStatistic);
16191637
fx.BeginInvoke(patternArgs, null, null);
16201638
}
16211639

16221640
public void ExportBookmarkList()
16231641
{
1624-
SaveFileDialog dlg = new SaveFileDialog();
1625-
dlg.Title = "Choose a file to save bookmarks into";
1626-
dlg.AddExtension = true;
1627-
dlg.DefaultExt = "csv";
1628-
dlg.Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk";
1629-
dlg.FilterIndex = 1;
1630-
dlg.FileName = Path.GetFileNameWithoutExtension(FileName);
1642+
SaveFileDialog dlg = new()
1643+
{
1644+
Title = "Choose a file to save bookmarks into",
1645+
AddExtension = true,
1646+
DefaultExt = "csv",
1647+
Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk",
1648+
FilterIndex = 1,
1649+
FileName = Path.GetFileNameWithoutExtension(FileName)
1650+
};
16311651
if (dlg.ShowDialog() == DialogResult.OK)
16321652
{
16331653
try
@@ -1645,10 +1665,12 @@ public void ExportBookmarkList()
16451665

16461666
public void ImportBookmarkList()
16471667
{
1648-
OpenFileDialog dlg = new OpenFileDialog();
1649-
dlg.Title = "Choose a file to load bookmarks from";
1650-
dlg.AddExtension = true;
1651-
dlg.DefaultExt = "csv";
1668+
OpenFileDialog dlg = new()
1669+
{
1670+
Title = "Choose a file to load bookmarks from",
1671+
AddExtension = true,
1672+
DefaultExt = "csv"
1673+
};
16521674
dlg.DefaultExt = "csv";
16531675
dlg.Filter = "CSV file (*.csv)|*.csv|Bookmark file (*.bmk)|*.bmk";
16541676
dlg.FilterIndex = 1;
@@ -1658,7 +1680,7 @@ public void ImportBookmarkList()
16581680
try
16591681
{
16601682
// add to the existing bookmarks
1661-
SortedList<int, Bookmark> newBookmarks = new SortedList<int, Bookmark>();
1683+
SortedList<int, Bookmark> newBookmarks = new();
16621684
BookmarkExporter.ImportBookmarkList(FileName, dlg.FileName, newBookmarks);
16631685

16641686
// Add (or replace) to existing bookmark list

0 commit comments

Comments
 (0)