Refactiring RecordController.CheckTagValue and Record
This commit is contained in:
@@ -11,11 +11,12 @@ namespace BoerseDataConvert
|
||||
{
|
||||
private static int count;
|
||||
private static string cur_fileName;
|
||||
|
||||
private TagsTable tagsTable;
|
||||
public RecordController(string fileName)
|
||||
{
|
||||
count = 1;
|
||||
cur_fileName = fileName;
|
||||
tagsTable = new TagsTable();
|
||||
}
|
||||
public static void NextFile(string fileName)
|
||||
{
|
||||
@@ -44,21 +45,20 @@ namespace BoerseDataConvert
|
||||
}
|
||||
private string CheckTagValue(string tag, string value)
|
||||
{
|
||||
string tagname = "";
|
||||
StreamReader reader = new StreamReader(@"..\..\..\..\tags.txt");
|
||||
using (reader)
|
||||
string[] tagLine;
|
||||
try
|
||||
{
|
||||
string[] tagLine = null;
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
string[] line = reader.ReadLine().Split('|').ToArray();
|
||||
if (line[0] == tag) tagLine = line;
|
||||
tagLine = tagsTable.GetTagValue(tag);
|
||||
}
|
||||
if (tagLine == null) throw new ArgumentException($"WARN: Invalid tag \"{tag}\", {cur_fileName} line {count + 1}");
|
||||
tagname = tagLine[1];
|
||||
if (value != "NULL" && tagLine.Length == 3)
|
||||
catch (KeyNotFoundException)
|
||||
{
|
||||
string[] valueType = tagLine[2].Split('-').ToArray();
|
||||
|
||||
throw new ArgumentException($"WARN: Invalid tag \"{tag}\", {cur_fileName} line {count + 1}");
|
||||
}
|
||||
string tagname = tagLine[0];
|
||||
if (value != "NULL" && tagLine.Length == 2)
|
||||
{
|
||||
string[] valueType = tagLine[1].Split('-').ToArray();
|
||||
if (valueType.Length == 2)
|
||||
{
|
||||
if (value.Length > int.Parse(valueType[1]))
|
||||
@@ -81,7 +81,7 @@ namespace BoerseDataConvert
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] valueRange = tagLine[3].Split('#').ToArray();
|
||||
string[] valueRange = tagLine[2].Split('#').ToArray();
|
||||
bool countain = false;
|
||||
if (value == "") return tagname;
|
||||
for (int i = 0; i < valueRange.Length; i++)
|
||||
@@ -97,8 +97,9 @@ namespace BoerseDataConvert
|
||||
throw new ArgumentException($"WARN: Value not in range \"{tag}\", \"{value}\", {cur_fileName} line {count + 1}");
|
||||
}
|
||||
}
|
||||
}
|
||||
return tagname;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,6 @@ namespace BoerseDataConvert
|
||||
{
|
||||
public class Record
|
||||
{
|
||||
public Dictionary<string, string> TagsValues;
|
||||
public List<KeyValuePair<string, string>>TagsValues;
|
||||
}
|
||||
}
|
||||
|
||||
36
BoerseDataConvert/BoerseDataConvert/Model/TagsTable.cs
Normal file
36
BoerseDataConvert/BoerseDataConvert/Model/TagsTable.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BoerseDataConvert
|
||||
{
|
||||
public class TagsTable
|
||||
{
|
||||
StreamReader reader ;
|
||||
Dictionary<string, string[]> table;
|
||||
public TagsTable()
|
||||
{
|
||||
reader = new StreamReader(@"..\..\..\..\tags.txt");
|
||||
table = new Dictionary<string, string[]>();
|
||||
LoadInfo();
|
||||
}
|
||||
private void LoadInfo()
|
||||
{
|
||||
using (reader)
|
||||
{
|
||||
while (!reader.EndOfStream)
|
||||
{
|
||||
string[] line = reader.ReadLine().Split('|').ToArray();
|
||||
table.Add(line[0], line.Skip(1).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
public string[] GetTagValue(string tag)
|
||||
{
|
||||
return table[tag];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ namespace BoerseDataConvert
|
||||
string s = a.ConvertToXml(record);
|
||||
writer.WriteRecord(s);
|
||||
}
|
||||
catch (IndexOutOfRangeException e)
|
||||
catch (IndexOutOfRangeException)
|
||||
{
|
||||
Reader.EndFile();
|
||||
Writer.EndFile();
|
||||
|
||||
@@ -35,11 +35,12 @@ namespace BoerseDataConvert
|
||||
s = reader.ReadLine();
|
||||
}
|
||||
string[] sr = s.Split("|").ToArray();
|
||||
Dictionary<string, string> a = new Dictionary<string, string>();
|
||||
List<KeyValuePair<string, string>>a = new List<KeyValuePair<string, string>>();
|
||||
foreach (var item in sr)
|
||||
{
|
||||
string[] d = item.Split('#').ToArray();
|
||||
a.Add(d[0], String.Join('#', d.Skip(1)));
|
||||
var pair = new KeyValuePair<string, string>(d[0], String.Join('#', d.Skip(1)));
|
||||
a.Add(pair);
|
||||
}
|
||||
Record record = new Record();
|
||||
record.TagsValues = a;
|
||||
|
||||
Reference in New Issue
Block a user