Writer, Reader, Quote fix and formatting
This commit is contained in:
@@ -9,7 +9,7 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
public class RecordController
|
public class RecordController
|
||||||
{
|
{
|
||||||
private static int count;
|
private static int count;
|
||||||
private static string cur_fileName;
|
private static string cur_fileName;
|
||||||
|
|
||||||
public RecordController(string fileName)
|
public RecordController(string fileName)
|
||||||
@@ -30,7 +30,7 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string tag =CheckTagValue(tagValue.Key, tagValue.Value);
|
string tag = CheckTagValue(tagValue.Key, tagValue.Value);
|
||||||
xmlRecord.Append($" <{tag}>{tagValue.Value}</{tag}>\n");
|
xmlRecord.Append($" <{tag}>{tagValue.Value}</{tag}>\n");
|
||||||
}
|
}
|
||||||
catch (ArgumentException e)
|
catch (ArgumentException e)
|
||||||
@@ -44,11 +44,11 @@ namespace BoerseDataConvert
|
|||||||
}
|
}
|
||||||
private string CheckTagValue(string tag, string value)
|
private string CheckTagValue(string tag, string value)
|
||||||
{
|
{
|
||||||
string tagname="";
|
string tagname = "";
|
||||||
StreamReader reader = new StreamReader(@"..\..\..\..\tags.txt");
|
StreamReader reader = new StreamReader(@"..\..\..\..\tags.txt");
|
||||||
using (reader)
|
using (reader)
|
||||||
{
|
{
|
||||||
string[] tagLine= null ;
|
string[] tagLine = null;
|
||||||
while (!reader.EndOfStream)
|
while (!reader.EndOfStream)
|
||||||
{
|
{
|
||||||
string[] line = reader.ReadLine().Split('|').ToArray();
|
string[] line = reader.ReadLine().Split('|').ToArray();
|
||||||
@@ -76,7 +76,7 @@ namespace BoerseDataConvert
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string[] valueRange = tagLine[3].Split('#').ToArray();
|
string[] valueRange = tagLine[3].Split('#').ToArray();
|
||||||
bool countain = false;
|
bool countain = false;
|
||||||
@@ -87,10 +87,10 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return tagname;
|
return tagname;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,29 +15,47 @@ 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
|
||||||
// Console.OutputEncoding = System.Text.Encoding.UTF8;
|
|
||||||
|
// input handling
|
||||||
|
string zipFile = "", inputDir = "", outputDir = "";
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
if (args.Contains("-i") || args.Contains("--input"))
|
if (args.Contains("-i") || args.Contains("--input"))
|
||||||
{
|
{
|
||||||
string zipfile = args[Array.IndexOf(args, "-i") + 1];
|
zipFile = args[Array.IndexOf(args, "-i") + 1];
|
||||||
}
|
}
|
||||||
if (args.Contains("-d") || args.Contains("--directory"))
|
if (args.Contains("-d") || args.Contains("--directory"))
|
||||||
{
|
{
|
||||||
string inputDir = args[Array.IndexOf(args, "-d" + 1)];
|
inputDir = args[Array.IndexOf(args, "-d") + 1];
|
||||||
}
|
}
|
||||||
if (args.Contains("-o") || args.Contains("--output"))
|
if (args.Contains("-o") || args.Contains("--output"))
|
||||||
{
|
{
|
||||||
string outputDir = args[Array.IndexOf(args, "-o" + 1)];
|
outputDir = args[Array.IndexOf(args, "-o") + 1];
|
||||||
}
|
}
|
||||||
if (args.Contains("-h") || args.Contains("--help"))
|
if (args.Contains("-h") || args.Contains("--help"))
|
||||||
{
|
{
|
||||||
Help();
|
Help();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Reader reader = new Reader(@"E:\Downloads\TestData-2021_07_02", new string[1] { "subtype910.txt" });
|
zipFile = @"D:\Code\ИТ Кариера\Стаж\задача\testdata.zip";
|
||||||
// Reader reader = new Reader(@"D:\Code\ИТ Кариера\Стаж\задача\TestData-2021_07_02", new string[1] { "subtype910.txt" });
|
inputDir = @"D:\Code\ИТ Кариера\Стаж\задача\TestData";
|
||||||
RecordController a = new RecordController("subtype910.txt");
|
outputDir = @"D:\Code\ИТ Кариера\Стаж\задача\outputdir";
|
||||||
Writer writer = new Writer("subtype910.txt");
|
if (zipFile == "" || inputDir == "" || outputDir == "")
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Fields cannot be empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: clear matching files from inputDir
|
||||||
|
// TODO: check free disk space before file ops
|
||||||
|
|
||||||
|
ZipFile.ExtractToDirectory(zipFile, inputDir); // zip extract
|
||||||
|
|
||||||
|
// read files
|
||||||
|
string[] fileNames = Directory.GetFiles(inputDir).Select(x => x.Split('\\', '/').Last()).ToArray();
|
||||||
|
|
||||||
|
Reader reader = new Reader(inputDir, fileNames);
|
||||||
|
Writer writer = new Writer(outputDir, fileNames[0]);
|
||||||
|
RecordController a = new RecordController(fileNames[0]);
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -48,20 +66,21 @@ namespace BoerseDataConvert
|
|||||||
}
|
}
|
||||||
catch (IndexOutOfRangeException e)
|
catch (IndexOutOfRangeException e)
|
||||||
{
|
{
|
||||||
|
Reader.EndFile();
|
||||||
Writer.EndFile();
|
Writer.EndFile();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
static void Help()
|
||||||
|
{
|
||||||
|
Console.WriteLine("BoerseDataConvert v1.0.0");
|
||||||
|
Console.WriteLine("D. Delchev and D. Byalkov, 2021");
|
||||||
|
Console.WriteLine("---");
|
||||||
|
Console.WriteLine("-i <input zip file> or --input <input zip file>");
|
||||||
|
Console.WriteLine("-d <working directory> or --directory <working directory>");
|
||||||
|
Console.WriteLine("-o <output directory> or --output <output directory>");
|
||||||
|
Console.WriteLine("-h or --help - Prints this message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void Help()
|
|
||||||
{
|
|
||||||
Console.WriteLine("BoerseDataConvert v1.0.0");
|
|
||||||
Console.WriteLine("D. Delchev and D. Byalkov, 2021");
|
|
||||||
Console.WriteLine("---");
|
|
||||||
Console.WriteLine("-i <input zip file> or --input <input zip file>");
|
|
||||||
Console.WriteLine("-d <working directory> or --directory <working directory>");
|
|
||||||
Console.WriteLine("-o <output directory> or --output <output directory>");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ namespace BoerseDataConvert
|
|||||||
public class Reader
|
public class Reader
|
||||||
{
|
{
|
||||||
private string[] filesNames;
|
private string[] filesNames;
|
||||||
private StreamReader reader;
|
private static StreamReader reader;
|
||||||
private int fileInd;
|
private int fileInd;
|
||||||
private string adr;
|
private string adr;
|
||||||
public Reader(string adr, string[] filesNames)
|
public Reader(string adr, string[] filesNames)
|
||||||
@@ -27,14 +27,14 @@ namespace BoerseDataConvert
|
|||||||
if (s.Substring(0, 11) == "Datensaetze")
|
if (s.Substring(0, 11) == "Datensaetze")
|
||||||
{
|
{
|
||||||
fileInd++;
|
fileInd++;
|
||||||
reader.Close();
|
EndFile();
|
||||||
reader = new StreamReader($@"{adr}/{filesNames[fileInd]}", CodePagesEncodingProvider.Instance.GetEncoding(1252));
|
reader = new StreamReader($@"{adr}/{filesNames[fileInd]}", CodePagesEncodingProvider.Instance.GetEncoding(1252));
|
||||||
RecordController.NextFile(filesNames[fileInd]);
|
RecordController.NextFile(filesNames[fileInd]);
|
||||||
Writer.NextFile(filesNames[fileInd]);
|
Writer.NextFile(filesNames[fileInd]);
|
||||||
s = reader.ReadLine();
|
s = reader.ReadLine();
|
||||||
s = reader.ReadLine();
|
s = reader.ReadLine();
|
||||||
}
|
}
|
||||||
string[] sr = s.Split("|").ToArray();
|
string[] sr = s.Split("|").ToArray();
|
||||||
Dictionary<string, string> a = new Dictionary<string, string>();
|
Dictionary<string, string> a = new Dictionary<string, string>();
|
||||||
foreach (var item in sr)
|
foreach (var item in sr)
|
||||||
{
|
{
|
||||||
@@ -45,5 +45,9 @@ namespace BoerseDataConvert
|
|||||||
record.TagsValues = a;
|
record.TagsValues = a;
|
||||||
return record;
|
return record;
|
||||||
}
|
}
|
||||||
|
internal static void EndFile()
|
||||||
|
{
|
||||||
|
reader.Close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,16 @@ namespace BoerseDataConvert
|
|||||||
{
|
{
|
||||||
private static string curFilesName;
|
private static string curFilesName;
|
||||||
private static StreamWriter writer;
|
private static StreamWriter writer;
|
||||||
|
private static string address;
|
||||||
|
|
||||||
public Writer(string filesName)
|
public Writer(string _address, string filesName)
|
||||||
{
|
{
|
||||||
|
address = _address;
|
||||||
curFilesName = filesName;
|
curFilesName = filesName;
|
||||||
string[] file = curFilesName.Split('.').ToArray();
|
string[] file = curFilesName.Split('.').ToArray();
|
||||||
writer = new StreamWriter($"{file[0]}.xml");
|
writer = new StreamWriter($@"{address}/{file[0]}.xml");
|
||||||
writer.WriteLine($"<table name=”{file[0]}”>");
|
writer.WriteLine($"<table name=\"{file[0]}\">");
|
||||||
|
|
||||||
}
|
}
|
||||||
public void WriteRecord(string record)
|
public void WriteRecord(string record)
|
||||||
{
|
{
|
||||||
@@ -28,8 +31,8 @@ namespace BoerseDataConvert
|
|||||||
EndFile();
|
EndFile();
|
||||||
curFilesName = fileName;
|
curFilesName = fileName;
|
||||||
string[] file = curFilesName.Split('.').ToArray();
|
string[] file = curFilesName.Split('.').ToArray();
|
||||||
writer = new StreamWriter($"{file[0]}.xml");
|
writer = new StreamWriter($@"{address}/{file[0]}.xml");
|
||||||
writer.WriteLine($"<table name=”{file[0]}”>");
|
writer.WriteLine($"<table name=\"{file[0]}\">");
|
||||||
}
|
}
|
||||||
public static void EndFile()
|
public static void EndFile()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace BoerseDataConvert
|
|
||||||
{
|
|
||||||
class ZipHandler
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Binary file not shown.
Reference in New Issue
Block a user