Create Reader,Bug Fix RecordController
This commit is contained in:
@@ -9,15 +9,19 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
public class RecordController
|
public class RecordController
|
||||||
{
|
{
|
||||||
private int count;
|
private static int count;
|
||||||
private string fileName;
|
private static string cur_fileName;
|
||||||
|
|
||||||
public RecordController(string fileName)
|
public RecordController(string fileName)
|
||||||
{
|
{
|
||||||
this.count = 1;
|
count = 1;
|
||||||
this.fileName = fileName;
|
cur_fileName = fileName;
|
||||||
|
}
|
||||||
|
public static void NextFile(string fileName)
|
||||||
|
{
|
||||||
|
count = 1;
|
||||||
|
cur_fileName = fileName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ConvertToXml(Record record)
|
public string ConvertToXml(Record record)
|
||||||
{
|
{
|
||||||
StringBuilder xmlRecord = new StringBuilder();
|
StringBuilder xmlRecord = new StringBuilder();
|
||||||
@@ -31,8 +35,7 @@ namespace BoerseDataConvert
|
|||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine(e.Message);
|
||||||
throw new ArgumentException(e.Message);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlRecord.Append($"</record>");
|
xmlRecord.Append($"</record>");
|
||||||
@@ -77,13 +80,14 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
string[] valueRange = tagLine[3].Split('#').ToArray();
|
string[] valueRange = tagLine[3].Split('#').ToArray();
|
||||||
bool countain = false;
|
bool countain = false;
|
||||||
|
if (value == "") return tagname;
|
||||||
for (int i = 0; i < valueRange.Length; i++)
|
for (int i = 0; i < valueRange.Length; i++)
|
||||||
{
|
{
|
||||||
if (valueRange[i] == value)
|
if (valueRange[i] == value)
|
||||||
{
|
{
|
||||||
countain = true;
|
countain = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!countain) throw new ArgumentException("Value is not in value range!");
|
if(!countain) throw new ArgumentException("Value is not in value range!");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,19 +15,22 @@ namespace BoerseDataConvert
|
|||||||
// -d directory or --dir directory
|
// -d directory or --dir directory
|
||||||
// -o directory or --output direcory
|
// -o directory or --output direcory
|
||||||
// -h - help
|
// -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";
|
Console.WriteLine();
|
||||||
string[] sr = s.Split("|").ToArray();
|
Reader reader = new Reader(@"E:\Downloads\TestData-2021_07_02", new string[2] { "subtype910.txt","subtype916.txt" });
|
||||||
Dictionary<string, string> a = new Dictionary<string, string>();
|
RecordController a = new RecordController("");
|
||||||
foreach (var item in sr)
|
while (true)
|
||||||
{
|
{
|
||||||
string[] d = item.Split('#').ToArray();
|
try
|
||||||
a.Add(d[0], d[1]);
|
{
|
||||||
|
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!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
BoerseDataConvert/BoerseDataConvert/Views/Reader.cs
Normal file
48
BoerseDataConvert/BoerseDataConvert/Views/Reader.cs
Normal file
@@ -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<string, string> a = new Dictionary<string, string>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user