public List <config_file> load(string folder_path, bool build) { List <config_file> config_files = new List <config_file>(); string[] files = Directory.GetFiles(folder_path + "/simple", "*.yaml", SearchOption.AllDirectories); foreach (string file in files) { config_file cf = thing(file, folder_path, build); if (cf != null) { config_files.Add(cf); } } files = Directory.GetFiles(folder_path + "/complex", "*.yaml", SearchOption.AllDirectories); foreach (string file in files) { config_file cf = thing(file, folder_path, build); if (cf != null) { config_files.Add(cf); } } System.GC.Collect(); return(config_files); }
public table_base(config_file table_config) { this.uid = table_config.uid; stats.name = table_config.name; stats.file_path = table_config.path; stats.properties = table_config.properties; stats.property_ordinals = table_config.property_ordinals; }
public config_summary(config_file config) { this.name = config.name; this.entity = config.entity; this.display = config.display; this.group = config.group; this.ordinal = config.ordinal; this.uid = config.uid; this.active = config.active; }
public bool add(config_file table_config) { if (null != this[table_config.uid]) { if (globals.debug) { Console.WriteLine(String.Format("table already exists: {0}", table_config.name)); } return(false); //already exists. } if (globals.debug) { Console.WriteLine(string.Format("Adding Table {0}", table_config.name)); } tables.Add(new table_base(table_config)); return(true); }
public config_file thing(string file, string folder_path, bool build) { if (globals.debug) { Console.WriteLine(String.Format("Loading: {0}", file)); } config_file cf = config_file.load_yaml(file); if (cf == null) { if (globals.debug) { Console.WriteLine(String.Format("bad configuration file -> {0}", file)); } return(null); } if (globals.models.ContainsKey(cf.uid)) { if (globals.debug) { Console.WriteLine(String.Format("Skipping model load -> {0}", cf.uid)); } return(globals.models[cf.uid]); } if (globals.debug) { Console.WriteLine(String.Format("model load -> {0}, active: {1}", cf.uid, cf.active)); } string ns = "model"; string dir = folder_path + "/compiled"; string source_dir = folder_path + "/source"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } string dll_path = String.Format("{0}/{1}.dll", dir, cf.uid); // Path.GetFileNameWithoutExtension(file) string source_path = String.Format("{0}/{1}.cs", source_dir, cf.uid); // Path.GetFileNameWithoutExtension(file)); template template = new template(dll_path, dir, source_path, ns, cf.name, cf.properties, build); cf.update_ordinals(); globals.models[cf.uid] = cf; globals.add_model_properties(cf.uid, template.class_type); cf.class_type = template.class_type; return(cf); }
}//end load_yaml public static bool save_yaml(config_file config, string file) { try{ if (config == null) { Console.WriteLine($"Cant save, config is null."); return(false); } Console.WriteLine($"Saving: {file}"); using (TextWriter text_writer = new StreamWriter(file)) { var serializer = new Serializer(); serializer.Serialize(text_writer, config); return(true); } } catch (Exception ex) { Console.WriteLine($"Error saving: {ex.Message}"); } return(false); } //end load_yaml
public void build_config(string filename, string dest_file, delimiters delimiters) { config_file cf = new config_file(); cf.delimiters = delimiters; cf.comments_visible = false; cf.empty_lines_visible = false; cf.data_starts_on_line = 0; cf.display = filename; cf.active = true; cf.errors_visible = false; cf.group = ""; cf.multi_search = true; cf.name = Path.GetFileName(filename); cf.path = filename; int max_fields = 0; string[] lines = File.ReadAllLines(filename); if (lines.Length == 0) { Console.WriteLine("Empty file"); return; } List <property> properties = new List <property>(); int control = 0; //loop all lines and get the maximum column/field count. if (!is_comment(lines[0], delimiters)) { Console.WriteLine("No comment on first line. "); return; } foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) //skip whitespace { continue; } if (is_comment(line, delimiters)) //skip comments { continue; } foreach (char c in line) { if (c == 0) { control++; } } string[] temp_fields = line.Split(new char[] { delimiters.field }); //TODO comment delim if (temp_fields.Length > max_fields) { max_fields = temp_fields.Length; } } if (control > 5) { Console.WriteLine("More than 5 control characters. Skipping. "); return; } if (max_fields == 0) { Console.WriteLine("No properties. Not saving."); return; } //create properties in config for (int i = 0; i < max_fields; i++) { property property = new property(); property.name = "field" + i.ToString(); property.display = String.Empty; property.type = "string"; property.@default = String.Empty; property.is_array = false; property.has_default = false; property.ordinal = i; property.visible = true; property.fixed_width = true; property.width = 100; property.max_width = 0; property.min_width = 0; property.overflow = false; property.search = true; property.multi_search = true; property.sort = true; property.sort_ordinal = 0; property.sort_default = false; property.sort_default_asc = false; property.data_ordinal = i; property.export = true; //property.options { get; set; } properties.Add(property); } cf.properties = properties.ToArray(); //determine property type foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) //skip whitespace { continue; } if (is_comment(line, delimiters)) //skip comments { continue; } string[] temp_fields = line.Split(new char[] { delimiters.field }); //TODO comment int index = 0; foreach (string temp_field in temp_fields) { if (temp_field.IndexOf(delimiters.array.ToString()) >= 0) { properties[index].is_array = true; } index++; } } cf.update_ordinals(); config_file.save_yaml(cf, dest_file); }