public string[] ParseAndExec(string[] args) { string filepath = null; string artistTitle = null; string albumTitle = null; string songTitle = null; string compilationTitle = null; string genreTitle = null; string subGenreTitle = null; foreach (string arg in args) { if (HelpRegex.IsMatch(arg)) { return(new[] { GetHelp() }); } if (filepath == null && FilepathRegex.IsMatch(arg)) { filepath = FilepathRegex.Match(arg).Groups[1].Value; _musicCatalog = MusicCatalog.CreateFromXml(filepath); if (_musicCatalog == null) { return(new[] { "File reading error: \"" + filepath + "\"" }); } } if (artistTitle == null && ArtistRegex.IsMatch(arg)) { artistTitle = ArtistRegex.Match(arg).Groups[1].Value; } if (albumTitle == null && AlbumRegex.IsMatch(arg)) { albumTitle = AlbumRegex.Match(arg).Groups[1].Value; } if (songTitle == null && SongRegex.IsMatch(arg)) { songTitle = SongRegex.Match(arg).Groups[1].Value; } if (compilationTitle == null && CompilationRegex.IsMatch(arg)) { compilationTitle = CompilationRegex.Match(arg).Groups[1].Value; } if (genreTitle == null && GenreRegex.IsMatch(arg)) { genreTitle = GenreRegex.Match(arg).Groups[1].Value; } if (subGenreTitle == null && SubGenreRegex.IsMatch(arg)) { subGenreTitle = SubGenreRegex.Match(arg).Groups[1].Value; } } if (filepath == null) { return(new[] { "--filepath= parameter required" }); } string[] result = _musicCatalog.GetData( artistTitle, albumTitle, songTitle, genreTitle, subGenreTitle, compilationTitle); if (result.Length == 0) { return(new[] { "No data found" }); } return(result); }
private MusicCatalogXmlParser(XDocument dataDoc) { _dataDoc = dataDoc; _musicCatalog = new MusicCatalog(); ParseStart(); }