private static void PerformImport(System.IO.FileInfo file, IEntitySet entitySetToCreateIn) { using (System.IO.StreamReader reader = file.OpenText()) { string inputLine = reader.ReadLine(); // Get the property names from the first line of input string[] headers = inputLine.Split(',').Select(header => header.Trim()).ToArray(); int count = headers.Count(); string[] data; inputLine = reader.ReadLine(); while (inputLine != null) { data = inputLine.Split(','); // If the right number of data items were found, import the line if (data.Count() == count) { ImportSingle(entitySetToCreateIn, headers, data); } else { throw new InvalidOperationException(String.Format("Line not imported. Invalid number of elements. Data = [{0}].", inputLine)); } inputLine = reader.ReadLine(); } reader.Close(); } entitySetToCreateIn.Details.DataService.SaveChanges(); }
public EntitiesGenerator.Definitions.Definition ReadFile(System.IO.FileInfo fileInfo) { if (fileInfo.Exists) { Definition definition = new Definition(); System.IO.StreamReader streamReader = fileInfo.OpenText(); string textLine = streamReader.ReadLine(); while (textLine != null) { string text = textLine.TrimStart(); if (text.StartsWith("CREATE TABLE ", StringComparison.CurrentCultureIgnoreCase)) { string tableText; string tableName = ReadTableName(text, streamReader, out tableText); EntitiesGenerator.Definitions.DataTable table = new EntitiesGenerator.Definitions.DataTable(tableName); ProcessColumns(table, tableText); } textLine = streamReader.ReadLine(); } return definition; } else { return null; } }
public TemplateParser(System.IO.FileInfo templateFile, TemplateSettings settings) { if (templateFile == null) throw new ArgumentNullException("templateFile"); if (!templateFile.Exists) throw new System.IO.FileNotFoundException(string.Format("The template file '{0}' can not be found.", templateFile.Name)); if (settings == null) throw new ArgumentNullException("settings"); using (var fs = templateFile.OpenText()) { this.content = fs.ReadToEnd(); } this.settings = settings; }
/// <summary> /// Parse a configuration text file. /// </summary> /// <param name="f"></param> /// <returns></returns> internal static Dictionary<string, Dictionary<string, string>> ParseConfigFile(System.IO.FileInfo f) { using (var rd = f.OpenText()) { var input = rd.ReadToEnd(); var results = File.Parse(input); var r = new Dictionary<string, Dictionary<string, string>>(); foreach (var t in results) { if (!r.ContainsKey(t.Item1)) { r[t.Item1] = new Dictionary<string, string>(); } r[t.Item1][t.Item2] = t.Item3; } return r; } }