diff --git a/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs b/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs index af711df..26a2a64 100644 --- a/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs +++ b/BoerseDataConvert/BoerseDataConvert/Controller/RecordController.cs @@ -9,15 +9,19 @@ namespace BoerseDataConvert { public class RecordController { - private int count; - private string fileName; + private static int count; + private static string cur_fileName; public RecordController(string fileName) { - this.count = 1; - this.fileName = fileName; + count = 1; + cur_fileName = fileName; + } + public static void NextFile(string fileName) + { + count = 1; + cur_fileName = fileName; } - public string ConvertToXml(Record record) { StringBuilder xmlRecord = new StringBuilder(); @@ -31,8 +35,7 @@ namespace BoerseDataConvert } catch (ArgumentException e) { - - throw new ArgumentException(e.Message); + Console.WriteLine(e.Message); } } xmlRecord.Append($""); @@ -77,13 +80,14 @@ namespace BoerseDataConvert { string[] valueRange = tagLine[3].Split('#').ToArray(); bool countain = false; + if (value == "") return tagname; for (int i = 0; i < valueRange.Length; i++) { if (valueRange[i] == value) { countain = true; break; - } + } } if(!countain) throw new ArgumentException("Value is not in value range!"); } diff --git a/BoerseDataConvert/BoerseDataConvert/Views/Program.cs b/BoerseDataConvert/BoerseDataConvert/Views/Program.cs index a97b8c2..96554d9 100644 --- a/BoerseDataConvert/BoerseDataConvert/Views/Program.cs +++ b/BoerseDataConvert/BoerseDataConvert/Views/Program.cs @@ -15,19 +15,22 @@ namespace BoerseDataConvert // -d directory or --dir directory // -o directory or --output direcory // -h - help - string s = "900#01|204#J|008#HSH Nordbank AG|205#150215|206#111138|460#HSH Nordbank|207#HSH Nordbank AG#Gerhart-Hauptmann-Platz 50#20095 Hamburg#Deutschland|208#info@hsh-nordbank.com|209#040 33330|210#https://www.hsh-nordbank.de|451#TUKDD90GPC79G1KOE162"; - string[] sr = s.Split("|").ToArray(); - Dictionary a = new Dictionary(); - foreach (var item in sr) + Console.WriteLine(); + Reader reader = new Reader(@"E:\Downloads\TestData-2021_07_02", new string[2] { "subtype910.txt","subtype916.txt" }); + RecordController a = new RecordController(""); + while (true) { - string[] d = item.Split('#').ToArray(); - a.Add(d[0], d[1]); + try + { + Record record = reader.ReadLineRecord(); + Console.WriteLine(a.ConvertToXml(record)); + } + catch (IndexOutOfRangeException e) + { + break; + } + } - Record record = new Record(); - record.TagsValues = a; - RecordController con = new RecordController("oo"); - Console.WriteLine(con.ConvertToXml(record)); - Console.WriteLine("Hello World!"); } } } diff --git a/BoerseDataConvert/BoerseDataConvert/Views/Reader.cs b/BoerseDataConvert/BoerseDataConvert/Views/Reader.cs new file mode 100644 index 0000000..7ea6f04 --- /dev/null +++ b/BoerseDataConvert/BoerseDataConvert/Views/Reader.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BoerseDataConvert +{ + public class Reader + { + private string[] filesNames; + private StreamReader reader; + private int fileInd; + private string adr; + public Reader(string adr, string[] filesNames) + { + fileInd = 0; + reader = new StreamReader($@"{adr}/{filesNames[fileInd]}"); + this.adr = adr; + this.filesNames = filesNames; + reader.ReadLine(); + } + public Record ReadLineRecord() + { + string s = reader.ReadLine(); + if (s.Substring(0, 11) == "Datensaetze") + { + fileInd++; + reader.Close(); + reader = new StreamReader($@"{adr}/{filesNames[fileInd]}"); + RecordController.NextFile(filesNames[fileInd]); + s = reader.ReadLine(); + s = reader.ReadLine(); + } + string[] sr = s.Split("|").ToArray(); + Dictionary a = new Dictionary(); + foreach (var item in sr) + { + string[] d = item.Split('#').ToArray(); + a.Add(d[0], d[1]); + } + Record record = new Record(); + record.TagsValues = a; + return record; + } + } +}