Adding comments and fastCheck option
This commit is contained in:
@@ -20,6 +20,12 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
get { return count - 1; }
|
get { return count - 1; }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// It create XML writer,xml file, writes the first line in it
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="adr">output directoty</param>
|
||||||
|
/// <param name="fileName">currnt file name</param>
|
||||||
|
/// <param name="tags">Locataion of tags,txt</param>
|
||||||
public RecordController(string adr, string fileName, string tags)
|
public RecordController(string adr, string fileName, string tags)
|
||||||
{
|
{
|
||||||
count = 1;
|
count = 1;
|
||||||
@@ -36,6 +42,11 @@ namespace BoerseDataConvert
|
|||||||
writer.WriteAttributeString("name", null, cur_fileName);
|
writer.WriteAttributeString("name", null, cur_fileName);
|
||||||
warning = new WarningStat(fileName);
|
warning = new WarningStat(fileName);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// It writes the last line, closes the flie, and XMLwriter
|
||||||
|
/// and It creates new XML writer,new xml file, writes the first line in it
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="fileName">name of the next file</param>
|
||||||
public static void NextFile(string fileName)
|
public static void NextFile(string fileName)
|
||||||
{
|
{
|
||||||
writer.WriteEndElement();
|
writer.WriteEndElement();
|
||||||
@@ -54,13 +65,27 @@ namespace BoerseDataConvert
|
|||||||
writer.WriteStartElement("table");
|
writer.WriteStartElement("table");
|
||||||
writer.WriteAttributeString("name", null, cur_fileName);
|
writer.WriteAttributeString("name", null, cur_fileName);
|
||||||
}
|
}
|
||||||
public void WriteXmlRecord(Record record)
|
/// <summary>
|
||||||
|
/// It write the information in the record into the XML file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="record">Record that stores information about one record from the files</param>
|
||||||
|
/// <param name="fastCheck">if true it makes a fastChech</param>
|
||||||
|
public void WriteXmlRecord(Record record,bool fastCheck)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement("record");
|
writer.WriteStartElement("record");
|
||||||
writer.WriteAttributeString("id", null, count.ToString());
|
writer.WriteAttributeString("id", null, count.ToString());
|
||||||
foreach (var tagValue in record)
|
foreach (var tagValue in record)
|
||||||
{
|
{
|
||||||
string tag = CheckTagValue(tagValue.Key, tagValue.Value);
|
string tag = "";
|
||||||
|
if (fastCheck)
|
||||||
|
{
|
||||||
|
tag = FastChechTag(tagValue.Key);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tag = FullCheckTagValue(tagValue.Key, tagValue.Value);
|
||||||
|
}
|
||||||
|
|
||||||
if (tag != null)
|
if (tag != null)
|
||||||
{
|
{
|
||||||
writer.WriteStartElement(tag);
|
writer.WriteStartElement(tag);
|
||||||
@@ -78,7 +103,30 @@ namespace BoerseDataConvert
|
|||||||
writer.Close();
|
writer.Close();
|
||||||
warning.PrintWarnigs();
|
warning.PrintWarnigs();
|
||||||
}
|
}
|
||||||
private string CheckTagValue(int tag, string value)
|
/// <summary>
|
||||||
|
/// It checks only if the tag is valid
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">tag in the numeric form</param>
|
||||||
|
/// <returns>return name of the tag</returns>
|
||||||
|
private string FastChechTag(int tag)
|
||||||
|
{
|
||||||
|
if (tagsTable.CheckInvalidTag(tag))
|
||||||
|
{
|
||||||
|
warning.Add(tag);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return tagsTable.GetTagName(tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// It make a full check on the value
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">tag in the numeric form</param>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
/// <returns>return name of the tag</returns>
|
||||||
|
private string FullCheckTagValue(int tag, string value)
|
||||||
{
|
{
|
||||||
if (tagsTable.CheckInvalidTag(tag))
|
if (tagsTable.CheckInvalidTag(tag))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -7,19 +7,30 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace BoerseDataConvert
|
namespace BoerseDataConvert
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Class Recorrd stores information about the tags and the values of every record
|
||||||
|
/// </summary>
|
||||||
public class Record : IEnumerable
|
public class Record : IEnumerable
|
||||||
{
|
{
|
||||||
|
//The tags and the values are stored in list from KeyValuePair where the tags are the keys
|
||||||
private List<KeyValuePair<int, string>> TagsValues;
|
private List<KeyValuePair<int, string>> TagsValues;
|
||||||
|
|
||||||
public Record()
|
public Record()
|
||||||
{
|
{
|
||||||
TagsValues = new List<KeyValuePair<int, string>>();
|
TagsValues = new List<KeyValuePair<int, string>>();
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// This method adds a new TagValuePair in the TagsValues
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag"></param>
|
||||||
|
/// <param name="value"></param>
|
||||||
public void Add(int tag, string value)
|
public void Add(int tag, string value)
|
||||||
{
|
{
|
||||||
TagsValues.Add(new KeyValuePair<int, string>(tag, value));
|
TagsValues.Add(new KeyValuePair<int, string>(tag, value));
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// The iterator for class Record
|
||||||
|
/// </summary>
|
||||||
public IEnumerator<KeyValuePair<int, string>> GetEnumerator()
|
public IEnumerator<KeyValuePair<int, string>> GetEnumerator()
|
||||||
{
|
{
|
||||||
foreach (var item in TagsValues)
|
foreach (var item in TagsValues)
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace BoerseDataConvert
|
namespace BoerseDataConvert
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class stores the name,the type and the value ranges for one tag
|
||||||
|
/// </summary>
|
||||||
public class Tag
|
public class Tag
|
||||||
{
|
{
|
||||||
private string name;
|
private string name;
|
||||||
@@ -31,22 +34,37 @@ namespace BoerseDataConvert
|
|||||||
}
|
}
|
||||||
else haveValueRanges = false;
|
else haveValueRanges = false;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the name of the tag
|
||||||
|
/// </summary>
|
||||||
public string Name
|
public string Name
|
||||||
{
|
{
|
||||||
get { return name; }
|
get { return name; }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the type of the tag is string
|
||||||
|
/// </summary>
|
||||||
public bool IsString
|
public bool IsString
|
||||||
{
|
{
|
||||||
get { return isString; }
|
get { return isString; }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the tag has a value ranges
|
||||||
|
/// </summary>
|
||||||
public bool HaveValueRanges
|
public bool HaveValueRanges
|
||||||
{
|
{
|
||||||
get { return haveValueRanges; }
|
get { return haveValueRanges; }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns max length of the string value
|
||||||
|
/// </summary>
|
||||||
public int StringLength
|
public int StringLength
|
||||||
{
|
{
|
||||||
get { return stringLength; }
|
get { return stringLength; }
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Returns true if the value is in the value ranges
|
||||||
|
/// </summary>
|
||||||
public bool ValidValue(string value)
|
public bool ValidValue(string value)
|
||||||
{
|
{
|
||||||
foreach (string validValue in valueRanges)
|
foreach (string validValue in valueRanges)
|
||||||
|
|||||||
@@ -6,6 +6,9 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace BoerseDataConvert
|
namespace BoerseDataConvert
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This class strores information about a invalid tags in a file
|
||||||
|
/// </summary>
|
||||||
public class WarningStat
|
public class WarningStat
|
||||||
{
|
{
|
||||||
private Dictionary<int, int> tableWarnings;
|
private Dictionary<int, int> tableWarnings;
|
||||||
@@ -15,7 +18,11 @@ namespace BoerseDataConvert
|
|||||||
curFile = fileName;
|
curFile = fileName;
|
||||||
tableWarnings = new Dictionary<int, int>();
|
tableWarnings = new Dictionary<int, int>();
|
||||||
}
|
}
|
||||||
public void Add(int tag)
|
/// <summary>
|
||||||
|
/// It increases count of encounters if the invalid tag or it sets it to 1 if the tag is new
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="tag">Invalid tag in numerical form</param>
|
||||||
|
public void Add(int tag)
|
||||||
{
|
{
|
||||||
if (tableWarnings.ContainsKey(tag))
|
if (tableWarnings.ContainsKey(tag))
|
||||||
{
|
{
|
||||||
@@ -26,6 +33,9 @@ namespace BoerseDataConvert
|
|||||||
tableWarnings.Add(tag, 1);
|
tableWarnings.Add(tag, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// It prints the count of encounters of every invalid tag in the file
|
||||||
|
/// </summary>
|
||||||
public void PrintWarnigs()
|
public void PrintWarnigs()
|
||||||
{
|
{
|
||||||
if (tableWarnings.Count == 0)
|
if (tableWarnings.Count == 0)
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ namespace BoerseDataConvert
|
|||||||
static string outputDirectory;
|
static string outputDirectory;
|
||||||
static string tagsFile;
|
static string tagsFile;
|
||||||
static bool helpMessage;
|
static bool helpMessage;
|
||||||
|
static bool fastCheck;
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@@ -48,6 +49,7 @@ namespace BoerseDataConvert
|
|||||||
"The working directory is cleared recursively if it isn't empty!",
|
"The working directory is cleared recursively if it isn't empty!",
|
||||||
{ "o|output=", "specify output directory", x => outputDirectory = x },
|
{ "o|output=", "specify output directory", x => outputDirectory = x },
|
||||||
{ "t|tags=", "specify tag file", x => tagsFile = x },
|
{ "t|tags=", "specify tag file", x => tagsFile = x },
|
||||||
|
{ "f|fast|fastcheck=", "specify tag file", x => fastCheck = true },
|
||||||
{ "<>", v => throw new ArgumentException("ERROR: Invalid arguments") }, // default
|
{ "<>", v => throw new ArgumentException("ERROR: Invalid arguments") }, // default
|
||||||
"",
|
"",
|
||||||
"Created by D. Delchev and D. Byalkov, 2021"
|
"Created by D. Delchev and D. Byalkov, 2021"
|
||||||
@@ -87,7 +89,7 @@ namespace BoerseDataConvert
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Record record = reader.ReadLineRecord();
|
Record record = reader.ReadLineRecord();
|
||||||
a.WriteXmlRecord(record);
|
a.WriteXmlRecord(record,fastCheck);
|
||||||
}
|
}
|
||||||
catch (IndexOutOfRangeException)
|
catch (IndexOutOfRangeException)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,11 @@ namespace BoerseDataConvert
|
|||||||
private static StreamReader reader;
|
private static StreamReader reader;
|
||||||
private static int fileInd;
|
private static int fileInd;
|
||||||
private string adr;
|
private string adr;
|
||||||
|
/// <summary>
|
||||||
|
/// it create a reader for first file, start the StopWatch and Checks the first line from the current file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="adr">input directoty</param>
|
||||||
|
/// <param name="_filesNames">array with the names of the every TXT file</param>
|
||||||
public Reader(string adr, string[] _filesNames)
|
public Reader(string adr, string[] _filesNames)
|
||||||
{
|
{
|
||||||
fileInd = 0;
|
fileInd = 0;
|
||||||
@@ -26,6 +31,11 @@ namespace BoerseDataConvert
|
|||||||
stopwatch.Start();
|
stopwatch.Start();
|
||||||
CheckFirstLine(date);
|
CheckFirstLine(date);
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// It reads a line from the current file and return a Record with this information
|
||||||
|
/// and it goes to next file if it the current file ends
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Record with information from 1 line from current file</returns>
|
||||||
public Record ReadLineRecord()
|
public Record ReadLineRecord()
|
||||||
{
|
{
|
||||||
string s = reader.ReadLine();
|
string s = reader.ReadLine();
|
||||||
@@ -42,6 +52,12 @@ namespace BoerseDataConvert
|
|||||||
}
|
}
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// it checks the last line from the current file, closes the reader, create a new reader for he file
|
||||||
|
/// also it check first line from the next file and synchronizes a current file in RecordController with its current file
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s"></param>
|
||||||
|
/// <returns></returns>
|
||||||
private string NextFile(string s)
|
private string NextFile(string s)
|
||||||
{
|
{
|
||||||
CheckFinalLine(s);
|
CheckFinalLine(s);
|
||||||
@@ -55,6 +71,10 @@ namespace BoerseDataConvert
|
|||||||
s = reader.ReadLine();
|
s = reader.ReadLine();
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// it checks if string date is in the correct format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="date">first line from a file</param>
|
||||||
private void CheckFirstLine(string date)
|
private void CheckFirstLine(string date)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -68,6 +88,10 @@ namespace BoerseDataConvert
|
|||||||
Console.WriteLine($"WARN: Invalid date in file {filesNames[fileInd]}");
|
Console.WriteLine($"WARN: Invalid date in file {filesNames[fileInd]}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if string s is in the correct format
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="s">last line from a file</param>
|
||||||
private void CheckFinalLine(string s)
|
private void CheckFinalLine(string s)
|
||||||
{
|
{
|
||||||
if ("Datensaetze: " != s.Substring(0, 13))
|
if ("Datensaetze: " != s.Substring(0, 13))
|
||||||
@@ -93,6 +117,9 @@ namespace BoerseDataConvert
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Closes the reader, stops the stopwatch,print the its time, resets it and start it again
|
||||||
|
/// </summary>
|
||||||
internal static void EndFile()
|
internal static void EndFile()
|
||||||
{
|
{
|
||||||
reader.Close();
|
reader.Close();
|
||||||
|
|||||||
Reference in New Issue
Block a user