public bool ConvertLabelsXML2TAB(string basePath) { string xmlFilename = LabelsXMLFile(basePath); //xmlFilename = @"C:\Data files\SVN\VisualStudio2017\Solutions\Discogs\Data\LABELS_SMALL.XML"; if (!string.IsNullOrEmpty(xmlFilename)) { XmlSnibbitReader reader = new XmlSnibbitReader(); if (reader.OpenFile(xmlFilename)) { string xmlBlock = ""; try { int blockCounter = 0; while ((xmlBlock = reader.GetXMLSnibbit("label")) != null) { XMLLabel label = XMLLabel.ParseXML(XmlString2XmlElement(xmlBlock)); label.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(); XMLLabel.Clear(); } } } return(false); }
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)); }
public static XMLLabel ParseXML(XmlElement xLabel) { // ------------------------------------------------------------------------- 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"); // ------------------------------------------------------------------------- XMLLabel label = new XMLLabel(); label.LABEL_ID = Convert.ToInt32(xLabel.GetElementsByTagName("id")[0].InnerText); label.NAME = xLabel["name"].InnerText; if (xLabel["contactinfo"] != null) { label.CONTACTINFO = xLabel["contactinfo"].InnerText; } if (xLabel["profile"] != null) { label.PROFILE = xLabel["profile"].InnerText; } if (xLabel["data_quality"] != null) { label.DATA_QUALITY = xLabel["data_quality"].InnerText; } if (xLabel["parentLabel"] != null) { label.PARENTLABEL = new SubLabel(); label.PARENTLABEL.LABEL_ID = Convert.ToInt32(xLabel["parentLabel"].Attributes["id"].Value); label.PARENTLABEL.NAME = xLabel["parentLabel"].InnerText; } if (xLabel.GetElementsByTagName("images")[0] != null) { foreach (XmlNode xn in xLabel.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; label.IMAGES.Add(image); } //foreach } if (xLabel.GetElementsByTagName("urls")[0] != null) { foreach (XmlNode xn in xLabel.GetElementsByTagName("urls")[0].ChildNodes) { XmlElement xUrl = (XmlElement)xn; if (!string.IsNullOrEmpty(xUrl.InnerText)) { label.URLS.Add(xUrl.InnerText.Trim()); } } //foreach } if (xLabel.GetElementsByTagName("sublabels")[0] != null) { foreach (XmlNode xn in xLabel.GetElementsByTagName("sublabels")[0].ChildNodes) { XmlElement xSublabel = (XmlElement)xn; SubLabel subLabel = new SubLabel(); if (!string.IsNullOrEmpty(xSublabel.InnerText)) { subLabel.LABEL_ID = Convert.ToInt32(xSublabel.Attributes["id"].Value); subLabel.NAME = xSublabel.InnerText; label.SUBLABELS.Add(subLabel); } } //foreach } return(label); }