// Takes in the whole config JSON file as a JObject and returns a list of Fields public FullConfig Translate(JObject config) { List <Field> fields = new List <Field>(); foreach (JObject fieldConfig in (JArray)config["dimension_attributes"]) { string typeID = (string)fieldConfig["type"]; fields.Add(this.CaseAt(typeID, fieldConfig)); } FullConfig fullConfig = new FullConfig( (int)config["threads_count"], (int)config["records_count"], (double)config["error_rate"], fields ); return(fullConfig); }
public static void Main(string[] args) { Console.WriteLine("Please enter an absolute path to config file:\n"); // Start parsing string? filePath = Console.ReadLine(); FullConfig parsed_config = ParseConfig(filePath); RecordMaker recordMaker = new RecordMaker(parsed_config.fields); // Make record Console.WriteLine("Generated Data Records: "); for (int counter = parsed_config.records_count; counter > 0; counter--) { JArray record = recordMaker.MakeRecord(); Console.WriteLine(record.ToString()); } ; // Exit Console.WriteLine("Console exiting..."); }
private static FullConfig ParseConfig(string?filePath) { Console.WriteLine($"Echoing input file path: {filePath}"); if (String.IsNullOrEmpty(filePath)) { // TODO: Throw exception Console.WriteLine("Got empty file path! Start trying default path..."); filePath = LOCAL_FILEPATH; } using (StreamReader stream = File.OpenText(filePath)) using (JsonTextReader reader = new JsonTextReader(stream)) { JObject jConfig = (JObject)JToken.ReadFrom(reader); ConfigToFieldsTranslator parser = new ConfigToFieldsTranslator(); FullConfig cfg = parser.Translate(jConfig); return(cfg); } }