/// <summary>imports the icon YAML file into a new SQL table, as it was removed from the data export database file.</summary> /// <param name="file">file name to import</param> /// <param name="databaseServer">The database Server.</param> /// <param name="databaseName">The database Name.</param> /// <param name="databaseUser">The database User.</param> /// <param name="databasePassword">The database Password.</param> private static void ProcessIconData(string file, string databaseServer, string databaseName, string databaseUser, string databasePassword) { var icons = new List <EveIcon>(); // first read the file to make sure its valid yaml using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var textReader = new StreamReader(fs)) { var yaml = new YamlStream(); yaml.Load(textReader); var root = yaml.Documents[0].RootNode as YamlMappingNode; foreach (KeyValuePair <YamlNode, YamlNode> item in root.Children) { // convert each of the records in the yaml into objects var icon = new EveIcon(); int temp; if (int.TryParse(item.Key.ToString(), out temp)) { icon.IconId = temp; // parse the children nodes YamlMappingNode data; if ((data = item.Value as YamlMappingNode) != null) { foreach (KeyValuePair <YamlNode, YamlNode> node in data.Children) { switch (node.Key.ToString()) { case "description": icon.Description = node.Value.ToString(); break; case "iconFile": icon.IconFile = node.Value.ToString(); break; } } icons.Add(icon); } } } } // icons have been parsed into objects... create the final SQL table and submit the objects. using (var dbcon = new SqlConnection(string.Format(ConnectionStringFormat, databaseServer, databaseName, databaseUser, databasePassword))) { try { dbcon.Open(); // initialize the table var cmd = new SqlCommand(CreateIconTableCommand, dbcon); cmd.ExecuteNonQuery(); foreach (EveIcon icon in icons) { cmd = new SqlCommand(string.Format(InsertIconFormat, icon.IconId, icon.IconFile, string.IsNullOrWhiteSpace(icon.Description) ? null : icon.Description.Replace("\'", "\'\'")), dbcon); cmd.ExecuteNonQuery(); } } finally { dbcon.Close(); } } }
/// <summary>imports the icon YAML file into a new SQL table, as it was removed from the data export database file.</summary> /// <param name="file">file name to import</param> /// <param name="databaseServer">The database Server.</param> /// <param name="databaseName">The database Name.</param> /// <param name="databaseUser">The database User.</param> /// <param name="databasePassword">The database Password.</param> private static void ProcessIconData(string file, string databaseServer, string databaseName, string databaseUser, string databasePassword) { var icons = new List<EveIcon>(); // first read the file to make sure its valid yaml using (var fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) using (var textReader = new StreamReader(fs)) { var yaml = new YamlStream(); yaml.Load(textReader); var root = yaml.Documents[0].RootNode as YamlMappingNode; foreach (KeyValuePair<YamlNode, YamlNode> item in root.Children) { // convert each of the records in the yaml into objects var icon = new EveIcon(); int temp; if (int.TryParse(item.Key.ToString(), out temp)) { icon.IconId = temp; // parse the children nodes YamlMappingNode data; if ((data = item.Value as YamlMappingNode) != null) { foreach (KeyValuePair<YamlNode, YamlNode> node in data.Children) { switch (node.Key.ToString()) { case "description": icon.Description = node.Value.ToString(); break; case "iconFile": icon.IconFile = node.Value.ToString(); break; } } icons.Add(icon); } } } } // icons have been parsed into objects... create the final SQL table and submit the objects. using (var dbcon = new SqlConnection(string.Format(ConnectionStringFormat, databaseServer, databaseName, databaseUser, databasePassword))) { try { dbcon.Open(); // initialize the table var cmd = new SqlCommand(CreateIconTableCommand, dbcon); cmd.ExecuteNonQuery(); foreach (EveIcon icon in icons) { cmd = new SqlCommand(string.Format(InsertIconFormat, icon.IconId, icon.IconFile, string.IsNullOrWhiteSpace(icon.Description) ? null : icon.Description.Replace("\'", "\'\'")), dbcon); cmd.ExecuteNonQuery(); } } finally { dbcon.Close(); } } }