public bool ConvertReleasesXML2TAB(string basePath) { string xmlFilename = ReleasesXMLFile(basePath); //xmlFilename = @"C:\Data files\SVN\VisualStudio2017\Solutions\Discogs\Data\RELEASES_SMALL.XML"; //xmlFilename = @"C:\Data files\SVN\VisualStudio2017\Solutions\Discogs\Data\RELEASES_SMALL2.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("release")) != null) { XMLRelease release = XMLRelease.ParseXML(XmlString2XmlElement(xmlBlock)); release.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(); XMLRelease.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)); }