Exceptions and temp redir of CW for debug

This commit is contained in:
Dimitar Byalkov
2021-07-08 11:20:42 +03:00
parent 48c8cc3ac2
commit ac833ac5ad
3 changed files with 28 additions and 6 deletions

View File

@@ -54,14 +54,17 @@ namespace BoerseDataConvert
string[] line = reader.ReadLine().Split('|').ToArray(); string[] line = reader.ReadLine().Split('|').ToArray();
if (line[0] == tag) tagLine = line; if (line[0] == tag) tagLine = line;
} }
if (tagLine == null) throw new ArgumentException("Invalid tag!"); if (tagLine == null) throw new ArgumentException($"WARN: Invalid tag \"{tag}\", {cur_fileName} line {count + 1}");
tagname = tagLine[1]; tagname = tagLine[1];
if (value != "NULL" && tagLine.Length == 3) if (value != "NULL" && tagLine.Length == 3)
{ {
string[] valueType = tagLine[2].Split('-').ToArray(); string[] valueType = tagLine[2].Split('-').ToArray();
if (valueType.Length == 2) if (valueType.Length == 2)
{ {
if (value.Length > int.Parse(valueType[1])) throw new ArgumentException("Value is too long!"); if (value.Length > int.Parse(valueType[1]))
{
throw new ArgumentException($"WARN: Too long value \"{tag}\", \"{value}\", max allowed \"{valueType[1]}\", {cur_fileName} line {count + 1}");
}
} }
else else
{ {
@@ -71,7 +74,7 @@ namespace BoerseDataConvert
} }
catch (FormatException) catch (FormatException)
{ {
throw new ArgumentException("Value does not represent a number in a valid format!"); throw new ArgumentException($"WARN: Value is not in a valid format for number \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}");
} }
} }
@@ -89,7 +92,10 @@ namespace BoerseDataConvert
break; break;
} }
} }
if (!countain) throw new ArgumentException("Value is not in value range!"); if (!countain)
{
throw new ArgumentException($"WARN: Value not in range \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}");
}
} }
} }
return tagname; return tagname;

View File

@@ -16,6 +16,22 @@ namespace BoerseDataConvert
// -o directory or --output direcory // -o directory or --output direcory
// -h - help // -h - help
FileStream ostrm;
StreamWriter writer1;
TextWriter oldOut = Console.Out;
try
{
ostrm = new FileStream("./log.txt", FileMode.OpenOrCreate, FileAccess.Write);
writer1 = new StreamWriter(ostrm);
}
catch (Exception e)
{
Console.WriteLine("Cannot open Redirect.txt for writing");
Console.WriteLine(e.Message);
return;
}
Console.SetOut(writer1);
// input handling // input handling
string zipFile = "", inputDir = "", outputDir = ""; string zipFile = "", inputDir = "", outputDir = "";
Console.WriteLine(); Console.WriteLine();
@@ -37,7 +53,7 @@ namespace BoerseDataConvert
return; return;
} }
zipFile = @"D:\Code\ИТ Кариера\Стаж\задача\testdata.zip"; zipFile = @"D:\Code\ИТ Кариера\Стаж\задача\testdata.zip";
inputDir = @"D:\Code\ИТ Кариера\Стаж\задача\TestData"; inputDir = @"D:\Code\ИТ Кариера\Стаж\задача\inputdir";
outputDir = @"D:\Code\ИТ Кариера\Стаж\задача\outputdir"; outputDir = @"D:\Code\ИТ Кариера\Стаж\задача\outputdir";
if (zipFile == "" || inputDir == "" || outputDir == "") if (zipFile == "" || inputDir == "" || outputDir == "")
{ {

View File

@@ -39,7 +39,7 @@ namespace BoerseDataConvert
foreach (var item in sr) foreach (var item in sr)
{ {
string[] d = item.Split('#').ToArray(); string[] d = item.Split('#').ToArray();
a.Add(d[0], d[1]); a.Add(d[0], String.Join('#', d.Skip(1)));
} }
Record record = new Record(); Record record = new Record();
record.TagsValues = a; record.TagsValues = a;