Created
June 30, 2017 14:58
-
-
Save davidwhitney/cb8c18b69e582f94c246645a7fe872f6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
namespace Pen.Loader | |
{ | |
public class QuillData | |
{ | |
public QuillData(string dbrFilePath) | |
{ | |
var lines = File.ReadAllLines(dbrFilePath); | |
var tables = new List<Table>(); | |
Table current = null; | |
foreach (var line in lines) | |
{ | |
if (line == "TABLE_START") | |
{ | |
current = new Table(); | |
} | |
if (line == "TABLE_END") | |
{ | |
tables.Add(current); | |
current = null; | |
} | |
if (current == null) | |
{ | |
continue; | |
} | |
if (line.StartsWith("TABLE '")) | |
{ | |
var value = Regex.Match(line, @"TABLE '([a-zA-Z0-9\.]+)'"); | |
current.FileName = value.Groups[1].Value; | |
} | |
if (line.StartsWith("FIELD")) | |
{ | |
var value = Regex.Match(line, @"FIELD '([a-zA-Z0-9\.]+)' ([a-zA-Z]+) ([0-9]+) (True|False)"); | |
current.Fields.Add(new Field(value.Groups[1].Value, value.Groups[2].Value, value.Groups[3].Value, value.Groups[4].Value)); | |
} | |
} | |
if (current != null) | |
{ | |
tables.Add(current); | |
} | |
} | |
} | |
public class Field | |
{ | |
public string Name { get; } | |
public string Type { get; } | |
public bool Required { get; set; } | |
public int Length { get; set; } | |
public Field(string name, string type, string length, string trueOrFalse) | |
{ | |
Name = name; | |
Type = type; | |
Length = int.Parse(length); | |
Required = bool.Parse(trueOrFalse); | |
} | |
} | |
public class Table | |
{ | |
public string FileName { get; set; } | |
public List<Field> Fields { get; set; } = new List<Field>(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment