Writer, Reader, Quote fix and formatting
This commit is contained in:
@@ -15,29 +15,47 @@ namespace BoerseDataConvert
|
||||
// -d directory or --dir directory
|
||||
// -o directory or --output direcory
|
||||
// -h - help
|
||||
// Console.OutputEncoding = System.Text.Encoding.UTF8;
|
||||
|
||||
// input handling
|
||||
string zipFile = "", inputDir = "", outputDir = "";
|
||||
Console.WriteLine();
|
||||
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"))
|
||||
{
|
||||
string inputDir = args[Array.IndexOf(args, "-d" + 1)];
|
||||
inputDir = args[Array.IndexOf(args, "-d") + 1];
|
||||
}
|
||||
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"))
|
||||
{
|
||||
Help();
|
||||
return;
|
||||
}
|
||||
Reader reader = new Reader(@"E:\Downloads\TestData-2021_07_02", new string[1] { "subtype910.txt" });
|
||||
// Reader reader = new Reader(@"D:\Code\ИТ Кариера\Стаж\задача\TestData-2021_07_02", new string[1] { "subtype910.txt" });
|
||||
RecordController a = new RecordController("subtype910.txt");
|
||||
Writer writer = new Writer("subtype910.txt");
|
||||
zipFile = @"D:\Code\ИТ Кариера\Стаж\задача\testdata.zip";
|
||||
inputDir = @"D:\Code\ИТ Кариера\Стаж\задача\TestData";
|
||||
outputDir = @"D:\Code\ИТ Кариера\Стаж\задача\outputdir";
|
||||
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)
|
||||
{
|
||||
try
|
||||
@@ -48,11 +66,10 @@ namespace BoerseDataConvert
|
||||
}
|
||||
catch (IndexOutOfRangeException e)
|
||||
{
|
||||
Reader.EndFile();
|
||||
Writer.EndFile();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
static void Help()
|
||||
{
|
||||
@@ -62,6 +79,8 @@ namespace BoerseDataConvert
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace BoerseDataConvert
|
||||
public class Reader
|
||||
{
|
||||
private string[] filesNames;
|
||||
private StreamReader reader;
|
||||
private static StreamReader reader;
|
||||
private int fileInd;
|
||||
private string adr;
|
||||
public Reader(string adr, string[] filesNames)
|
||||
@@ -27,7 +27,7 @@ namespace BoerseDataConvert
|
||||
if (s.Substring(0, 11) == "Datensaetze")
|
||||
{
|
||||
fileInd++;
|
||||
reader.Close();
|
||||
EndFile();
|
||||
reader = new StreamReader($@"{adr}/{filesNames[fileInd]}", CodePagesEncodingProvider.Instance.GetEncoding(1252));
|
||||
RecordController.NextFile(filesNames[fileInd]);
|
||||
Writer.NextFile(filesNames[fileInd]);
|
||||
@@ -45,5 +45,9 @@ namespace BoerseDataConvert
|
||||
record.TagsValues = a;
|
||||
return record;
|
||||
}
|
||||
internal static void EndFile()
|
||||
{
|
||||
reader.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,13 +11,16 @@ namespace BoerseDataConvert
|
||||
{
|
||||
private static string curFilesName;
|
||||
private static StreamWriter writer;
|
||||
private static string address;
|
||||
|
||||
public Writer(string filesName)
|
||||
public Writer(string _address, string filesName)
|
||||
{
|
||||
address = _address;
|
||||
curFilesName = filesName;
|
||||
string[] file = curFilesName.Split('.').ToArray();
|
||||
writer = new StreamWriter($"{file[0]}.xml");
|
||||
writer.WriteLine($"<table name=”{file[0]}”>");
|
||||
writer = new StreamWriter($@"{address}/{file[0]}.xml");
|
||||
writer.WriteLine($"<table name=\"{file[0]}\">");
|
||||
|
||||
}
|
||||
public void WriteRecord(string record)
|
||||
{
|
||||
@@ -28,8 +31,8 @@ namespace BoerseDataConvert
|
||||
EndFile();
|
||||
curFilesName = fileName;
|
||||
string[] file = curFilesName.Split('.').ToArray();
|
||||
writer = new StreamWriter($"{file[0]}.xml");
|
||||
writer.WriteLine($"<table name=”{file[0]}”>");
|
||||
writer = new StreamWriter($@"{address}/{file[0]}.xml");
|
||||
writer.WriteLine($"<table name=\"{file[0]}\">");
|
||||
}
|
||||
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