diff --git a/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs b/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs index 7ad3e45..e07ef8d 100644 --- a/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs +++ b/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs @@ -34,6 +34,8 @@ namespace BoerseDataConvert writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); + WarningStat.PrintWarnigs(); + WarningStat.Refresh(fileName); cur_fileName = fileName.Split('.').First(); count = 1; Console.WriteLine(cur_fileName + " start"); @@ -50,17 +52,11 @@ namespace BoerseDataConvert writer.WriteAttributeString("id", null, count.ToString()); foreach (var tagValue in record) { - try - { string tag = CheckTagValue(tagValue.Key, tagValue.Value); writer.WriteStartElement(tag); writer.WriteValue(tagValue.Value); writer.WriteEndElement(); - } - catch (ArgumentException e) - { - Console.WriteLine(e.Message); - } + } writer.WriteEndElement(); count++; @@ -70,10 +66,11 @@ namespace BoerseDataConvert writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); + WarningStat.PrintWarnigs(); } private string CheckTagValue(int tag, string value) { - if(tagsTable.CheckInvalidTag(tag)) throw new ArgumentException($"WARN: Invalid tag \"{tag}\", {cur_fileName} line {count + 1}"); + if (tagsTable.CheckInvalidTag(tag)) WarningStat.Add(tag); string tagname = tagsTable.GetTagName(tag); if (value == "") return tagname; if (value != "NULL" && !tagsTable.HaveValueRanges(tag)) //Checks if the tag have not a value ranges @@ -82,7 +79,7 @@ namespace BoerseDataConvert { if (tagsTable.CheckStringLengthToBig(tag, value.Length)) { - throw new ArgumentException($"WARN: Too long value \"{tag}\", \"{value}\", max allowed \"{tagsTable.GetTagName(tag)}\", {cur_fileName} line {count + 1}"); + Console.WriteLine($"WARN: Too long value \"{tag}\", \"{value}\", max allowed \"{tagsTable.GetTagName(tag)}\", {cur_fileName} line {count + 1}"); } } else//Checks if value type is decimal @@ -94,7 +91,7 @@ namespace BoerseDataConvert } catch (FormatException) { - throw new ArgumentException($"WARN: Value is not in a valid format for number \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}"); + Console.WriteLine($"WARN: Value is not in a valid format for number \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}"); } } } @@ -102,7 +99,7 @@ namespace BoerseDataConvert { if (!tagsTable.CheckValidValue(tag, value)) { - throw new ArgumentException($"WARN: Value not in range \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}"); + Console.WriteLine($"WARN: Value not in range \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}"); } } return tagname; diff --git a/BoerseDataConvert/BoerseDataConvert/Model/WarningStat.cs b/BoerseDataConvert/BoerseDataConvert/Model/WarningStat.cs index 2d09894..75617d4 100644 --- a/BoerseDataConvert/BoerseDataConvert/Model/WarningStat.cs +++ b/BoerseDataConvert/BoerseDataConvert/Model/WarningStat.cs @@ -4,32 +4,16 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace BoerseDataConvert.Model +namespace BoerseDataConvert { - public static class WarningStat + public static class WarningStat { - private class Warning - { - string type; - int count; - - public Warning(string type) - { - this.type = type; - count = 1; - } - public void Add() - { - count++; - } - } - - private static Dictionary tableWarnings = tableWarnings = new Dictionary(); + private static Dictionary tableWarnings = tableWarnings = new Dictionary(); private static string curFile; public static void Refresh(string fileName) { curFile = fileName; - tableWarnings = new Dictionary(); + tableWarnings = new Dictionary(); } /* type "inv" - Ivalid tag @@ -37,17 +21,34 @@ namespace BoerseDataConvert.Model type "notnum" - is not in a valid format for number type "range" - Value not in range */ - public static void Add(int tag,string type)// + public static void Add(int tag)// { if (tableWarnings.ContainsKey(tag)) { - tableWarnings[tag].Add(); + tableWarnings[tag]++; } - else + else { - Warning warning = new Warning(type); - tableWarnings.Add(tag, warning); + tableWarnings.Add(tag, 1); + } + } + public static void PrintWarnigs() + { + if (tableWarnings.Count == 0) + { + Console.WriteLine($"There is no warnings in file {curFile}"); + } + else + { + Console.WriteLine($"Warnings in file {curFile}"); + foreach (var warning in tableWarnings) + { + int tag = warning.Key; + int count = warning.Value; + Console.WriteLine($"Invalid tag \"{tag}\": {count} times."); + } } } } } +