public bool ConvertArtistsXML2TAB(string basePath) { string xmlFilename = ArtistsXMLFile(basePath); //xmlFilename = @"C:\Data files\SVN\VisualStudio2017\Solutions\Discogs\Data\ARTISTS-SMALL.XML"; if (!string.IsNullOrEmpty(xmlFilename)) { XmlSnibbitReader reader = new XmlSnibbitReader(); if (reader.OpenFile(xmlFilename)) { string xmlBlock = ""; try { int blockCounter = 0; while ((xmlBlock = reader.GetXMLSnibbit("artist")) != null) { XMLArtist artist = XMLArtist.ParseXML(XmlString2XmlElement(xmlBlock)); artist.StoreInTAB(); blockCounter++; Console.Write($"\rXML Block: {blockCounter}"); } //while Console.WriteLine(); return(true); } catch (Exception e) { CDRLogger.Logger.LogError(e); Console.WriteLine(); Console.WriteLine(xmlBlock); Console.WriteLine(e.ToString()); } finally { reader.Close(); XMLArtist.Clear(); } } } return(false); }
public static XMLArtist ParseXML(XmlElement xArtist) { // ------------------------------------------------------------------------- System.Globalization.NumberFormatInfo nfi = null; System.Globalization.CultureInfo culture = null; nfi = new System.Globalization.CultureInfo("en-US", false).NumberFormat; nfi.CurrencySymbol = "€"; nfi.CurrencyDecimalDigits = 2; nfi.CurrencyDecimalSeparator = "."; nfi.NumberGroupSeparator = ""; nfi.NumberDecimalSeparator = "."; culture = new System.Globalization.CultureInfo("en-US"); // ------------------------------------------------------------------------- XMLArtist artist = new XMLArtist(); artist.ARTIST_ID = Convert.ToInt32(xArtist.GetElementsByTagName("id")[0].InnerText); artist.NAME = xArtist["name"].InnerText; if (xArtist["realname"] != null) { artist.REALNAME = xArtist["realname"].InnerText; } if (xArtist["profile"] != null) { artist.PROFILE = xArtist["profile"].InnerText; } artist.DATA_QUALITY = xArtist["data_quality"].InnerText; if (xArtist.GetElementsByTagName("images")[0] != null) { foreach (XmlNode xn in xArtist.GetElementsByTagName("images")[0].ChildNodes) { XmlElement xImage = (XmlElement)xn; Image image = new Image(); image.HEIGHT = Convert.ToInt32(xImage.Attributes["height"].Value); image.WIDTH = Convert.ToInt32(xImage.Attributes["width"].Value); image.TYPE = xImage.Attributes["type"].Value; image.URI = xImage.Attributes["uri"].Value; image.URI150 = xImage.Attributes["uri150"].Value; artist.IMAGES.Add(image); } //foreach } if (xArtist.GetElementsByTagName("urls")[0] != null) { foreach (XmlNode xn in xArtist.GetElementsByTagName("urls")[0].ChildNodes) { XmlElement xUrl = (XmlElement)xn; if (!string.IsNullOrEmpty(xUrl.InnerText)) { artist.URLS.Add(xUrl.InnerText.Trim()); } } //foreach } if (xArtist.GetElementsByTagName("namevariations")[0] != null) { foreach (XmlNode xn in xArtist.GetElementsByTagName("namevariations")[0].ChildNodes) { XmlElement xName = (XmlElement)xn; if (!string.IsNullOrEmpty(xName.InnerText)) { artist.NAMEVARIATIONS.Add(xName.InnerText.Trim()); } } //foreach } if (xArtist.GetElementsByTagName("aliases")[0] != null) { foreach (XmlNode xn in xArtist.GetElementsByTagName("aliases")[0].ChildNodes) { XmlElement xAlias = (XmlElement)xn; Alias alias = new Alias(); if (!string.IsNullOrEmpty(xAlias.InnerText)) { alias.ARTIST_ID = Convert.ToInt32(xAlias.Attributes["id"].Value); alias.NAME = xAlias.InnerText; artist.ALIASES.Add(alias); } } //foreach } if (xArtist.GetElementsByTagName("members")[0] != null) { XmlElement xMembers = (XmlElement)xArtist.GetElementsByTagName("members")[0]; foreach (XmlNode xn in xMembers.GetElementsByTagName("name")) { XmlElement xMember = (XmlElement)xn; Member member = new Member(); if (!string.IsNullOrEmpty(xMember.InnerText)) { member.ARTIST_ID = Convert.ToInt32(xMember.Attributes["id"].Value); member.NAME = xMember.InnerText; artist.MEMBERS.Add(member); } } //foreach } if (xArtist.GetElementsByTagName("groups")[0] != null) { foreach (XmlNode xn in xArtist.GetElementsByTagName("groups")[0].ChildNodes) { XmlElement xMember = (XmlElement)xn; Group group = new Group(); if (!string.IsNullOrEmpty(xMember.InnerText)) { group.ARTIST_ID = Convert.ToInt32(xMember.Attributes["id"].Value); group.NAME = xMember.InnerText; artist.GROUPS.Add(group); } } //foreach } return(artist); }
public void Run() { // when conn == null not import into database is done // When Progrsam.onlyTab = true no connection is created so // tab files remain. DateTime dtStart = DateTime.Now; string discogsLocalLastDate = Path.GetFileName(ArtistsXMLFile(Program.DataPath)); if (string.IsNullOrEmpty(discogsLocalLastDate) || discogsLocalLastDate.Length < 16) { // should never come here! ConsoleLogger.WriteLine("discogs xml files not found."); ConsoleLogger.WriteLine("Exiting..."); Environment.Exit(1); } discogsLocalLastDate = discogsLocalLastDate.Substring(8, 8); ConsoleLogger.WriteLine("Exporting ARTISTS.XML data to TAB files."); if (ConvertArtistsXML2TAB(Program.DataPath)) { if (conn != null) { ConsoleLogger.WriteLine("Importing ARTISTS TAB files into MySQL."); XMLArtist.ImportArtistsData(exportFolder); XMLArtist.CleanUpConvertedArtistsFiles(exportFolder); } ConsoleLogger.WriteLine("ARTIST Done."); ConsoleLogger.WriteLine(); } // ------------------------------------------------------------------------------------------------------- ConsoleLogger.WriteLine("Exporting LABELS.XML data to TAB files."); if (ConvertLabelsXML2TAB(Program.DataPath)) { if (conn != null) { ConsoleLogger.WriteLine("Importing LABELS TAB files into MySQL."); XMLLabel.ImportLabelsData(exportFolder); XMLLabel.CleanUpConvertedLabelsFiles(exportFolder); } ConsoleLogger.WriteLine("LABELS Done."); ConsoleLogger.WriteLine(); } // ------------------------------------------------------------------------------------------------------- ConsoleLogger.WriteLine("Exporting RELEASES.XML data to TAB files."); if (ConvertReleasesXML2TAB(Program.DataPath)) { if (conn != null) { ConsoleLogger.WriteLine("Importing RELEASES TAB files into MySQL."); XMLRelease.ImportReleasesData(exportFolder); XMLRelease.CleanUpConvertedReleasesFiles(exportFolder); } ConsoleLogger.WriteLine("RELEASES Done."); ConsoleLogger.WriteLine(); } // ------------------------------------------------------------------------------------------------------- ConsoleLogger.WriteLine("Exporting MASTERS.XML data to TAB files."); if (ConvertMastersXML2TAB(Program.DataPath)) { if (conn != null) { ConsoleLogger.WriteLine("Importing MASTERS TAB files into MySQL."); XMLMaster.ImportMastersData(exportFolder); XMLMaster.CleanUpConvertedMastersFiles(exportFolder); } ConsoleLogger.WriteLine("MASTERS Done."); ConsoleLogger.WriteLine(); } // if we created a schema then we can create the extra indexes (when onlyTab is set then // runCreateSchema = false) if (runCreateSchema && conn != null) { ConsoleLogger.WriteLine("Creating extra indexes."); ImportDBIndexes(conn); ConsoleLogger.WriteLine(); } // Store date of imported xml in database, so we can detected if we need to update the database // or not. if (discogsLocalLastDate != null && discogsLocalLastDate.Length == 8) { SETTING_IU("DBLASTDATE", discogsLocalLastDate); } TimeSpan ts = (DateTime.Now - dtStart); ConsoleLogger.WriteLine(); ConsoleLogger.WriteLine(String.Format("Elapsed index time {0:00}:{1:00}:{2:00}.{3:000}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds)); }