Extract TrackingTextReader from CsvIndexer.
This commit is contained in:
@@ -51,38 +51,11 @@ namespace CsvView.Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TrackingTextReader : TextReader
|
|
||||||
{
|
|
||||||
private readonly TextReader _baseReader;
|
|
||||||
private int _position;
|
|
||||||
|
|
||||||
public TrackingTextReader(TextReader baseReader)
|
|
||||||
{
|
|
||||||
_baseReader = baseReader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Read()
|
|
||||||
{
|
|
||||||
_position++;
|
|
||||||
return _baseReader.Read();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int Peek()
|
|
||||||
{
|
|
||||||
return _baseReader.Peek();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int Position
|
|
||||||
{
|
|
||||||
get { return _position; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GenerateIndex(string file)
|
public void GenerateIndex(string file)
|
||||||
{
|
{
|
||||||
_insideString = false;
|
_insideString = false;
|
||||||
_index.Clear();
|
_index.Clear();
|
||||||
FileStream stream = new FileStream(file, FileMode.Open);
|
using (FileStream stream = new FileStream(file, FileMode.Open))
|
||||||
using (StreamReader streamReader = new StreamReader(stream, Encoding.Default, true, 4096))
|
using (StreamReader streamReader = new StreamReader(stream, Encoding.Default, true, 4096))
|
||||||
using (TrackingTextReader reader = new TrackingTextReader(streamReader))
|
using (TrackingTextReader reader = new TrackingTextReader(streamReader))
|
||||||
{
|
{
|
||||||
@@ -100,7 +73,6 @@ namespace CsvView.Code
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Index_SaveFile(string indexFile)
|
private void Index_SaveFile(string indexFile)
|
||||||
@@ -123,7 +95,7 @@ namespace CsvView.Code
|
|||||||
|
|
||||||
private static List<long> Index_LoadFile(string indexFile)
|
private static List<long> Index_LoadFile(string indexFile)
|
||||||
{
|
{
|
||||||
var tempIndex = new List<long>();
|
List<long> tempIndex = new List<long>();
|
||||||
|
|
||||||
Stream streamIn = File.Open(indexFile, FileMode.Open);
|
Stream streamIn = File.Open(indexFile, FileMode.Open);
|
||||||
using (BinaryReader binReader = new BinaryReader(streamIn))
|
using (BinaryReader binReader = new BinaryReader(streamIn))
|
||||||
@@ -142,7 +114,7 @@ namespace CsvView.Code
|
|||||||
public void LoadIndexOfFile(string file)
|
public void LoadIndexOfFile(string file)
|
||||||
{
|
{
|
||||||
DateTime dtFile = File.GetCreationTime(file);
|
DateTime dtFile = File.GetCreationTime(file);
|
||||||
string indexFile = file + ".idx";
|
string indexFile = $"{file}.idx";
|
||||||
if (File.Exists(indexFile) && File.GetCreationTime(indexFile) > dtFile)
|
if (File.Exists(indexFile) && File.GetCreationTime(indexFile) > dtFile)
|
||||||
{
|
{
|
||||||
_index = Index_LoadFile(indexFile);
|
_index = Index_LoadFile(indexFile);
|
||||||
|
|||||||
37
Code/TrackingTextReader.cs
Normal file
37
Code/TrackingTextReader.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace CsvView.Code
|
||||||
|
{
|
||||||
|
public class TrackingTextReader : TextReader
|
||||||
|
{
|
||||||
|
private readonly TextReader _baseReader;
|
||||||
|
private int _position;
|
||||||
|
|
||||||
|
public TrackingTextReader(TextReader baseReader)
|
||||||
|
{
|
||||||
|
_baseReader = baseReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Read()
|
||||||
|
{
|
||||||
|
_position++;
|
||||||
|
return _baseReader.Read();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Read(char[] buffer, int index, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException("Read buffered method on TrackingTextReader");
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Peek()
|
||||||
|
{
|
||||||
|
return _baseReader.Peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Position
|
||||||
|
{
|
||||||
|
get { return _position; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -66,6 +66,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Code\CsvIndexer.cs" />
|
<Compile Include="Code\CsvIndexer.cs" />
|
||||||
<Compile Include="Code\CsvParser.cs" />
|
<Compile Include="Code\CsvParser.cs" />
|
||||||
|
<Compile Include="Code\TrackingTextReader.cs" />
|
||||||
<Compile Include="UI\CTextBox.cs">
|
<Compile Include="UI\CTextBox.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ namespace CsvView.UI
|
|||||||
_loadedFile = fileName;
|
_loadedFile = fileName;
|
||||||
txtPath.Text = fileName;
|
txtPath.Text = fileName;
|
||||||
|
|
||||||
var csvIndexer = new CsvIndexer();
|
CsvIndexer csvIndexer = new CsvIndexer();
|
||||||
csvIndexer.LoadIndexOfFile(_loadedFile);
|
csvIndexer.LoadIndexOfFile(_loadedFile);
|
||||||
_index = csvIndexer.Index;
|
_index = csvIndexer.Index;
|
||||||
_totalRegs = _index.Count - 1;
|
_totalRegs = _index.Count - 1;
|
||||||
@@ -108,16 +108,16 @@ namespace CsvView.UI
|
|||||||
List<string> currentData = Index_LoadReg((int)currentReg);
|
List<string> currentData = Index_LoadReg((int)currentReg);
|
||||||
|
|
||||||
int y = 0;
|
int y = 0;
|
||||||
const int TexboxPadding = 5;
|
const int textBoxPadding = 5;
|
||||||
const int PaddingLeft = 0;
|
const int paddingLeft = 0;
|
||||||
const int PaddingRight = 0;
|
const int paddingRight = 0;
|
||||||
const int PaddingBetween = 10;
|
const int paddingBetween = 10;
|
||||||
const int LineHeight = 15;
|
const int lineHeight = 15;
|
||||||
for (int i = 0; i < currentData.Count; i++)
|
for (int i = 0; i < currentData.Count; i++)
|
||||||
{
|
{
|
||||||
TextBox txtValue = RenderValue(currentData[i], y, TexboxPadding, PaddingLeft, PaddingRight, LineHeight);
|
TextBox txtValue = RenderValue(currentData[i], y, textBoxPadding, paddingLeft, paddingRight, lineHeight);
|
||||||
pnlData.Controls.Add(txtValue);
|
pnlData.Controls.Add(txtValue);
|
||||||
y += txtValue.Height + PaddingBetween;
|
y += txtValue.Height + paddingBetween;
|
||||||
}
|
}
|
||||||
pnlData.Height = y;
|
pnlData.Height = y;
|
||||||
|
|
||||||
@@ -125,17 +125,17 @@ namespace CsvView.UI
|
|||||||
_rendering = false;
|
_rendering = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TextBox RenderValue(string value, int y, int TexboxPadding, int PaddingLeft, int PaddingRight, int LineHeight)
|
private TextBox RenderValue(string value, int y, int textBoxPadding, int paddingLeft, int paddingRight, int lineHeight)
|
||||||
{
|
{
|
||||||
string[] valueLines = value.Split('\n');
|
string[] valueLines = value.Split('\n');
|
||||||
CTextBox txtValue = new CTextBox()
|
CTextBox txtValue = new CTextBox()
|
||||||
{
|
{
|
||||||
Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right),
|
Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right),
|
||||||
Width = pnlData.Width - (PaddingLeft + PaddingRight),
|
Width = pnlData.Width - (paddingLeft + paddingRight),
|
||||||
Height = (valueLines.Length * LineHeight) + TexboxPadding,
|
Height = (valueLines.Length * lineHeight) + textBoxPadding,
|
||||||
Multiline = (valueLines.Length > 1),
|
Multiline = (valueLines.Length > 1),
|
||||||
Top = y,
|
Top = y,
|
||||||
Left = PaddingLeft,
|
Left = paddingLeft,
|
||||||
ReadOnly = true,
|
ReadOnly = true,
|
||||||
};
|
};
|
||||||
for (int j = 0; j < valueLines.Length; j++)
|
for (int j = 0; j < valueLines.Length; j++)
|
||||||
|
|||||||
Reference in New Issue
Block a user