static void Main(string[] args) { var soundtracksListPath = @".\soundtracks.list"; if (args.Length > 0) { soundtracksListPath = args[0]; } // Set up a logger var logFile = new FileAppender(); logFile.Threshold = Level.Error; logFile.Layout = new PatternLayout(@"%-6timestamp [%thread] %-5level %30.30logger %ndc: %message%newline"); logFile.File = Path.Combine(Path.GetTempPath(), @"parser.log"); logFile.AppendToFile = false; logFile.ImmediateFlush = true; logFile.ActivateOptions(); BasicConfigurator.Configure(logFile); Console.WriteLine("Opening file for read..."); Stream soundtracksStream = File.OpenRead(soundtracksListPath); var reader = new StreamReader(soundtracksStream); Console.WriteLine("...done"); Console.WriteLine("Counting productions in the file..."); string line = reader.ReadLine(); IList<string> rawProductions = new List<string>(); IList<string> rawSongs = new List<string>(); while (line != null) { if (line.StartsWith("#")) { rawProductions.Add(line); } if (line.StartsWith("-")) { line = line.Replace(" (uncredited)", string.Empty).TrimStart('-').Trim(); rawSongs.Add(line); } line = reader.ReadLine(); } Console.WriteLine("...done"); Console.WriteLine("Counted {0} productions and {1} songs.", rawProductions.Count, rawSongs.Count); soundtracksStream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Parsing productions in the file..."); var parser = new SoundtrackFileParser(LogManager.GetLogger(typeof(SoundtrackFileParser))); IEnumerable<SoundtrackRecord> records = parser.Parse(soundtracksStream); Console.WriteLine("...done"); var parsedSongsCount = (from r in records select r.Songs.Count).Sum(); Console.WriteLine("Parsed {0} productions of {1} total and {2} songs of {3} total.", records.Count(), rawProductions.Count, parsedSongsCount, rawSongs.Count); Console.ReadLine(); }
public void TestParseCorrectlyParsesRecordsFromAStream() { #region data = ... var data = @"CRC: 0x75F0BF28 File: soundtracks.list Date: Sat May 29 17:00:00 2010 Copyright 1991-2010 The Internet Movie Database Ltd. All rights reserved. http://www.imdb.com soundtracks.list 2010-5-27 ----------------------------------------------------------------------------- SOUNDTRACKS LIST ================ # ""$weepstake$"" (1979) - ""Without a Dream"" Music by 'Charles Fox (I)' (qv) Lyrics by 'Norman Gimbel' (qv) Performed by 'Ron Dante' (qv) # ""'Allo 'Allo!"" (1982) {A Marriage of Inconvenience (#5.6)} - ""Hear my song, Violetta"" (uncredited) Written by Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper' (qv) Performed by 'Carmen Silvera' (qv) # ""'Allo 'Allo!"" (1982) {Camp Dance (#4.2)} - ""Mad About the Boy"" (uncredited) Written by 'Noel Coward' (qv) Performed by 'Guy Siner' (qv) # ""'Allo 'Allo!"" (1982) {Christmas Puddings (#5.19)} - ""Boom"" Written by 'E. Ray Goetz' (qv) (uncredited) and 'Charles Trenet' (qv) (uncredited) Performed by 'Carmen Silvera' (qv) # ""'Allo 'Allo!"" (1982) {Communists in the Cupboard (#5.14)} - ""Love Is Where You Find It"" (uncredited) Music by 'Nacio Herb Brown' (qv) Lyrics by 'Earl K. Brent' (qv) Performed by 'Carmen Silvera' (qv) - ""Ol' Man River"" (uncredited) Music by 'Jerome Kern' (qv) Lyrics by 'Oscar Hammerstein II' (qv) Performed by 'Carmen Silvera' (qv)"; #endregion #region expectedSequence = ... IEnumerable <SoundtrackRecord> expectedSequence = new List <SoundtrackRecord> { new SoundtrackRecord { Production = new Movie { Title = "$weepstake$", Year = 1979 }, Songs = new List <Song> { new Song { Title = "Without a Dream", Composer = "Charles Fox (I)", Lyricist = "Norman Gimbel", Performer = "Ron Dante" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "A Marriage of Inconvenience", SeriesNumber = 5, EpisodeNumber = 6 }, Songs = new List <Song> { new Song { Title = "Hear my song, Violetta", Composer = "Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper'", Lyricist = "Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper'", Performer = "Carmen Silvera" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Camp Dance", SeriesNumber = 4, EpisodeNumber = 2 }, Songs = new List <Song> { new Song { Title = "Mad About the Boy", Composer = "Noel Coward", Lyricist = "Noel Coward", Performer = "Guy Siner" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Christmas Puddings", SeriesNumber = 5, EpisodeNumber = 19 }, Songs = new List <Song> { new Song { Title = "Boom", Composer = "E. Ray Goetz and Charles Trenet", Lyricist = "E. Ray Goetz and Charles Trenet", Performer = "Carmen Silvera" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Communists in the Cupboard", SeriesNumber = 5, EpisodeNumber = 14 }, Songs = new List <Song> { new Song { Title = "Love Is Where You Find It", Composer = "Nacio Herb Brown", Lyricist = "Earl K. Brent", Performer = "Carmen Silvera" }, new Song { Title = "Ol' Man River", Composer = "Jerome Kern", Lyricist = "Oscar Hammerstein II", Performer = "Carmen Silvera" } } } }; #endregion var log = new Mock <ILog>(); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { writer.Write(data); // Reset the stream's position to the beginning of the stream so the parser can read data from it. stream.Seek(0, SeekOrigin.Begin); IEnumerable <SoundtrackRecord> records = new SoundtrackFileParser(log.Object).Parse(stream); Assert.AreElementsEqual(expectedSequence, records); } }
static void Main(string[] args) { var soundtracksListPath = @".\soundtracks.list"; if (args.Length > 0) { soundtracksListPath = args[0]; } // Set up a logger var logFile = new FileAppender(); logFile.Threshold = Level.Error; logFile.Layout = new PatternLayout(@"%-6timestamp [%thread] %-5level %30.30logger %ndc: %message%newline"); logFile.File = Path.Combine(Path.GetTempPath(), @"parser.log"); logFile.AppendToFile = false; logFile.ImmediateFlush = true; logFile.ActivateOptions(); BasicConfigurator.Configure(logFile); Console.WriteLine("Opening file for read..."); Stream soundtracksStream = File.OpenRead(soundtracksListPath); var reader = new StreamReader(soundtracksStream); Console.WriteLine("...done"); Console.WriteLine("Counting productions in the file..."); string line = reader.ReadLine(); IList <string> rawProductions = new List <string>(); IList <string> rawSongs = new List <string>(); while (line != null) { if (line.StartsWith("#")) { rawProductions.Add(line); } if (line.StartsWith("-")) { line = line.Replace(" (uncredited)", string.Empty).TrimStart('-').Trim(); rawSongs.Add(line); } line = reader.ReadLine(); } Console.WriteLine("...done"); Console.WriteLine("Counted {0} productions and {1} songs.", rawProductions.Count, rawSongs.Count); soundtracksStream.Seek(0, SeekOrigin.Begin); Console.WriteLine("Parsing productions in the file..."); var parser = new SoundtrackFileParser(LogManager.GetLogger(typeof(SoundtrackFileParser))); IEnumerable <SoundtrackRecord> records = parser.Parse(soundtracksStream); Console.WriteLine("...done"); var parsedSongsCount = (from r in records select r.Songs.Count).Sum(); Console.WriteLine("Parsed {0} productions of {1} total and {2} songs of {3} total.", records.Count(), rawProductions.Count, parsedSongsCount, rawSongs.Count); Console.ReadLine(); }
public void TestParseCorrectlyParsesRecordsFromAStream() { #region data = ... var data = @"CRC: 0x75F0BF28 File: soundtracks.list Date: Sat May 29 17:00:00 2010 Copyright 1991-2010 The Internet Movie Database Ltd. All rights reserved. http://www.imdb.com soundtracks.list 2010-5-27 ----------------------------------------------------------------------------- SOUNDTRACKS LIST ================ # ""$weepstake$"" (1979) - ""Without a Dream"" Music by 'Charles Fox (I)' (qv) Lyrics by 'Norman Gimbel' (qv) Performed by 'Ron Dante' (qv) # ""'Allo 'Allo!"" (1982) {A Marriage of Inconvenience (#5.6)} - ""Hear my song, Violetta"" (uncredited) Written by Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper' (qv) Performed by 'Carmen Silvera' (qv) # ""'Allo 'Allo!"" (1982) {Camp Dance (#4.2)} - ""Mad About the Boy"" (uncredited) Written by 'Noel Coward' (qv) Performed by 'Guy Siner' (qv) # ""'Allo 'Allo!"" (1982) {Christmas Puddings (#5.19)} - ""Boom"" Written by 'E. Ray Goetz' (qv) (uncredited) and 'Charles Trenet' (qv) (uncredited) Performed by 'Carmen Silvera' (qv) # ""'Allo 'Allo!"" (1982) {Communists in the Cupboard (#5.14)} - ""Love Is Where You Find It"" (uncredited) Music by 'Nacio Herb Brown' (qv) Lyrics by 'Earl K. Brent' (qv) Performed by 'Carmen Silvera' (qv) - ""Ol' Man River"" (uncredited) Music by 'Jerome Kern' (qv) Lyrics by 'Oscar Hammerstein II' (qv) Performed by 'Carmen Silvera' (qv)"; #endregion #region expectedSequence = ... IEnumerable<SoundtrackRecord> expectedSequence = new List<SoundtrackRecord> { new SoundtrackRecord { Production = new Movie { Title = "$weepstake$", Year = 1979 }, Songs = new List<Song> { new Song { Title = "Without a Dream", Composer = "Charles Fox (I)", Lyricist = "Norman Gimbel", Performer = "Ron Dante" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "A Marriage of Inconvenience", SeriesNumber = 5, EpisodeNumber = 6 }, Songs = new List<Song> { new Song { Title = "Hear my song, Violetta", Composer = "Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper'", Lyricist = "Othmar Klose, Rudolph Lukesch and 'Harry S. Pepper'", Performer = "Carmen Silvera" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Camp Dance", SeriesNumber = 4, EpisodeNumber = 2 }, Songs = new List<Song> { new Song { Title = "Mad About the Boy", Composer = "Noel Coward", Lyricist = "Noel Coward", Performer = "Guy Siner" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Christmas Puddings", SeriesNumber = 5, EpisodeNumber = 19 }, Songs = new List<Song> { new Song { Title = "Boom", Composer = "E. Ray Goetz and Charles Trenet", Lyricist = "E. Ray Goetz and Charles Trenet", Performer = "Carmen Silvera" } } }, new SoundtrackRecord { Production = new TelevisionShow { Title = "'Allo 'Allo", Year = 1982, EpisodeTitle = "Communists in the Cupboard", SeriesNumber = 5, EpisodeNumber = 14 }, Songs = new List<Song> { new Song { Title = "Love Is Where You Find It", Composer = "Nacio Herb Brown", Lyricist = "Earl K. Brent", Performer = "Carmen Silvera" }, new Song { Title = "Ol' Man River", Composer = "Jerome Kern", Lyricist = "Oscar Hammerstein II", Performer = "Carmen Silvera" } } } }; #endregion var log = new Mock<ILog>(); using (var stream = new MemoryStream()) using (var writer = new StreamWriter(stream)) { writer.Write(data); // Reset the stream's position to the beginning of the stream so the parser can read data from it. stream.Seek(0, SeekOrigin.Begin); IEnumerable<SoundtrackRecord> records = new SoundtrackFileParser(log.Object).Parse(stream); Assert.AreElementsEqual(expectedSequence, records); } }