public bool ConvertMastersXML2TAB(string basePath) { string xmlFilename = MastersXMLFile(basePath); //xmlFilename = @"C:\Data files\SVN\VisualStudio2017\Solutions\Discogs\Data\MASTERS_SMALL.XML"; if (!string.IsNullOrEmpty(xmlFilename)) { XmlSnibbitReader reader = new XmlSnibbitReader(); if (reader.OpenFile(xmlFilename)) { XMLRelease.CleanUpConvertedReleasesFiles(exportFolder); string xmlBlock = ""; try { int blockCounter = 0; while ((xmlBlock = reader.GetXMLSnibbit("master")) != null) { XMLMaster master = XMLMaster.ParseXML(XmlString2XmlElement(xmlBlock)); master.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(); XMLMaster.Clear(); } } } return(false); }
public static XMLMaster ParseXML(XmlElement xMaster) { // ------------------------------------------------------------------------- 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"); // ------------------------------------------------------------------------- XMLMaster master = new XMLMaster(); master.MASTER_ID = Convert.ToInt32(xMaster.Attributes["id"].Value); master.TITLE = xMaster["title"].InnerText; if (xMaster["year"] != null) { DateTime.TryParse($"{xMaster["year"].InnerText}-01-01", out master.RELEASED); } if (xMaster["notes"] != null) { master.NOTES = xMaster["notes"].InnerText; } if (xMaster["main_release"] != null) { master.MAIN_RELEASE_ID = Convert.ToInt32(xMaster["main_release"].InnerText); } if (xMaster["data_quality"] != null) { master.DATA_QUALITY = xMaster["data_quality"].InnerText; } if (xMaster.GetElementsByTagName("images")[0] != null) { foreach (XmlNode xn in xMaster.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; master.IMAGES.Add(image); } //foreach } master.ARTISTS = Artist.ParseArtists(xMaster); if (xMaster.GetElementsByTagName("genres")[0] != null) { foreach (XmlNode xn in xMaster.GetElementsByTagName("genres")[0].ChildNodes) { XmlElement xGenre = (XmlElement)xn; master.GENRES.Add(xGenre.InnerText); } //foreach } if (xMaster.GetElementsByTagName("styles")[0] != null) { foreach (XmlNode xn in xMaster.GetElementsByTagName("styles")[0].ChildNodes) { XmlElement xStyle = (XmlElement)xn; master.STYLES.Add(xStyle.InnerText); } //foreach } if (xMaster.GetElementsByTagName("videos")[0] != null) { foreach (XmlNode xn in xMaster.GetElementsByTagName("videos")[0].ChildNodes) { XmlElement xVideo = (XmlElement)xn; Video video = new Video(); video.EMBED = (xVideo.Attributes["embed"].Value == "true"); video.DURATION_IN_SEC = Convert.ToInt32(xVideo.Attributes["duration"].Value); video.SRC = xVideo.Attributes["src"].Value; video.TITLE = xVideo["title"].InnerText; video.DESCRIPTION = xVideo["description"].InnerText; master.VIDEOS.Add(video); } //foreach } return(master); }
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)); }