Create Reader,Bug Fix RecordController
This commit is contained in:
@@ -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($"</record>");
|
||||
@@ -77,6 +80,7 @@ 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)
|
||||
|
||||
@@ -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<string, string> a = new Dictionary<string, string>();
|
||||
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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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