private async Task ReadTagsAsync(XmlReader reader, Category cat) { await reader.ReadAsync(); while (reader.LocalName.Equals(Constants.Db.Tag)) { Logger.Debug("Reading tag"); UInt32 id; if (!UInt32.TryParse(reader.GetAttribute(Constants.Db.Id), out id)) { Logger.Debug("Could not read tag id"); await reader.ReadAsync(); continue; } var name = reader.GetAttribute(Constants.Db.Name); var t = new Tag(name, cat, id); SongDb.AddTag(t); if (!reader.IsEmptyElement) { await reader.ReadAsync(); } await reader.ReadAsync(); } }
public App() { Configuration = Settings.Default; InitializeComponent(); SongDb = new SongDb(this); Task.Run(() => SongDb.ReadDbAsync(Configuration.DbLocation)); }
public void CheckSong(SongDb db, Song song, int ms, int tagCount, uint playCount, bool guess, int bpm) { CheckValue(song.Milliseconds, ms, "Milliseconds"); CheckValue(db.SongTagDictionary[song].Count(), tagCount, "TagCount"); CheckValue(song.PlayCount, playCount, "PlayCount"); CheckValue(song.Bpm.Guess, guess, "BPM guess"); CheckValue(song.Bpm.Value, bpm, "BPM Value"); }
public Song FindSong(SongDb songDb, string title) { var song = songDb.Songs.FirstOrDefault( s => s.SongTitle.Equals(title, StringComparison.InvariantCultureIgnoreCase)); Assert.IsNotNull(song, string.Format("Couldn't find song {0}", title)); return(song); }
public void MissingFileTest() { const string filename = "../../../Musagetes/Collaterals/Testing/doesntExist.xml"; var songDb = new SongDb(null); var reader = new SongDbReader(filename, songDb); reader.ReadDb().Wait(); Assert.IsFalse(reader.ReadSuccessful, "Reading was successful, though it shouldn't have been"); }
public void ConstructorTest() { const string filename = "Filename"; var songDb = new SongDb(null); var reader = new SongDbReader(filename, songDb); Assert.AreEqual(reader.Filename, filename, "Filename doesn't match"); Assert.AreEqual(reader.SongDb, songDb, "SongDb doesn't match"); }
public void HasTag(SongDb db, Song s, string tagName, Category c) { var tags = db.SongTagDictionary[s]; var tag = tags.FirstOrDefault(t => t.TagName.Equals(tagName, StringComparison.InvariantCultureIgnoreCase)); Assert.IsNotNull(tag, string.Format("song {0} is missing tag {1}", s.SongTitle, tagName)); Assert.IsTrue(tag.Category == c, string.Format("Tag {0} is not a {1} tag", tag.TagName, c.CategoryName)); }
private async Task ReadCategoryTagsAsync(XmlReader reader) { await reader.ReadAsync(); while (reader.LocalName.Equals(Constants.Db.Category)) { var cat = new Category(reader.GetAttribute(Constants.Db.Name)); Logger.Debug("Reading category {0}", cat.CategoryName); if (reader.IsEmptyElement) { Logger.Debug("Category element is empty"); await ReadTagsAsync(reader, cat); continue; } var displayStr = reader.GetAttribute(Constants.Db.Display); bool display; if (!bool.TryParse(displayStr, out display)) { Logger.Error("Unable to read display for {0}", cat.CategoryName); await reader.ReadAsync(); continue; } var orderStr = reader.GetAttribute(Constants.Db.Order); int order; if (!int.TryParse(orderStr, out order)) { Logger.Error("Unable to read order for {0}", cat.CategoryName); await reader.ReadAsync(); continue; } _columns.Add(order, new GridColumn(GridColumn.ColumnTypeEnum.Category, isVisible: display, cateogry: cat)); await ReadTagsAsync(reader, cat); SongDb.AddCategory(cat); reader.ReadEndElement(); } }
public void EmptyDbTest() { const string filename = "../../../Musagetes/Collaterals/Testing/EmptyDb.xml"; var songDb = new SongDb(null); var reader = new SongDbReader(filename, songDb); reader.ReadDb().Wait(); Assert.IsTrue(reader.ReadSuccessful, "Reading threw an exception"); Assert.IsTrue(songDb.Categories.Count == 0, "Categories count was not zero"); Assert.IsTrue(songDb.Songs.Count == 0, "Songs count was not zero"); Assert.IsTrue(songDb.TagIds.Count == 0, "Tag ids is not zero"); Assert.IsTrue(songDb.Columns.Count != 0, "Columns was zero"); }
public void ReadWriteTest() { const string filename = "../../../Musagetes/Collaterals/Testing/ReadWriteTest.xml"; var songDbWrite = new SongDb(null); songDbWrite.AddSong( new Song("title", "location", 1234, new Bpm(4321, false), songDbWrite, 321)); songDbWrite.AddSong( new Song("title2", "location2", 7890, new Bpm(987, true), songDbWrite, 654)); var writer = new SongDbWriter(filename, songDbWrite); writer.WriteDb().Wait(); Assert.IsTrue(writer.WriteSuccessful); var songDbRead = new SongDb(null); var reader = new SongDbReader(filename, songDbRead); reader.ReadDb().Wait(); Assert.IsTrue(reader.ReadSuccessful); Assert.AreEqual(songDbRead.Songs.Count, songDbWrite.Songs.Count, "Reader/Writer song counts don't match"); foreach (var song in songDbWrite.Songs) { var localSong = song; var match = songDbRead.Songs.First(s => s.SongTitle.Equals(localSong.SongTitle)); var matchTags = songDbRead.SongTagDictionary[match]; var tags = songDbRead.SongTagDictionary[localSong]; foreach (var tag in tags) { Assert.IsTrue(matchTags.Count(t => t.TagName.Equals(tag.TagName)) == 1, "Read/Write dictionary have different tags"); } Assert.AreEqual(localSong.Location, match.Location, "Locations don't match"); Assert.AreEqual(localSong.Milliseconds, match.Milliseconds, "Milliseconds don't match"); Assert.AreEqual(localSong.PlayCount, match.PlayCount, "Playcounts don't match"); Assert.AreEqual(localSong.Bpm.Guess, match.Bpm.Guess, "BPM Guesses don't match"); Assert.AreEqual(localSong.Bpm.Value, match.Bpm.Value, "BPM Values don't match"); } }
public void BasicReadTest() { const string filename = "../../../Musagetes/Collaterals/Testing/BasicDb.xml"; var songDb = new SongDb(null); var reader = new SongDbReader(filename, songDb); reader.ReadDb().Wait(); Assert.IsTrue(reader.ReadSuccessful, "Reading threw an exception"); Assert.IsTrue(songDb.Categories.Count == 4, string.Format("Categories count was {0} instead of 4", songDb.Categories.Count)); Assert.IsTrue(songDb.Songs.Count == 3, string.Format("Songs count was {0}, not 3", songDb.Songs.Count)); Assert.IsTrue(songDb.TagIds.Count == 4, string.Format("Tag ids was {0}, not 4", songDb.TagIds.Count)); Assert.IsTrue(songDb.Columns.Count == 9, string.Format("Columns was {0}, not 7", songDb.Columns.Count)); var song = FindSong(songDb, "Mud on the Tires"); CheckSong(songDb, song, 140000, 2, 0, false, 140); HasTag(songDb, song, "Brad Paisley", songDb.ArtistCategory); HasTag(songDb, song, "Country", songDb.GenreCategory); song = FindSong(songDb, "Throttleneck"); CheckSong(songDb, song, 1000, 2, 0, true, 1); HasTag(songDb, song, "Brad Paisley", songDb.ArtistCategory); HasTag(songDb, song, "Country", songDb.GenreCategory); song = FindSong(songDb, "When We All Get To Heaven"); CheckSong(songDb, song, 1000, 3, 5, true, 1); HasTag(songDb, song, "Brad Paisley", songDb.ArtistCategory); HasTag(songDb, song, "Kenny Chesney", songDb.ArtistCategory); HasTag(songDb, song, "Rock", songDb.GenreCategory); }
public override void Execute(object parameter) { var viewModel = (SongViewModel)parameter; var song = new SongDb(); var sw = new SongWindow(); sw.DataContext = song; sw.ShowDialog(); if (sw.DialogResult.HasValue && sw.DialogResult.Value) { using (var db = new SongDbContext()) { db.Songs.Add(song); db.SaveChanges(); } viewModel.Songs.Add(SongViewModel.SongConverter(song)); viewModel.SelectedSong = SongViewModel.SongConverter(song); } }
private async Task ReadSongTagsAsync(XmlReader reader, Song song) { await reader.ReadAsync(); while (reader.LocalName.Equals(Constants.Db.Tag)) { UInt32 id; if (!UInt32.TryParse(await reader.TryGetContentAsync(), out id)) { Logger.Error("Song {0} has empty or unreadable tag id", song.SongTitle); continue; } if (SongDb.TagIds.ContainsKey(id)) { SongDb.TagSong(song, SongDb.TagIds[id]);//song.TagSong(SongDb.TagIds[id]); } else { Logger.Error("Song {0} trying to add missing tag id {1}", song.SongTitle, id); } } }
public SongToTagsConverter(SongDb songDb, Category category = null) { Db = songDb; Category = category; }
public SongToTagsMultiConverter(SongDb songDb) { _sttConverter = new SongToTagsConverter(songDb); }
public SongController(SongDb _Db) { Db = _Db; }
public SongDbWriter(string filename, SongDb songDb) { Filename = filename; SongDb = songDb; }
public SongController() { _context = new SongDb(); }
public SongDbReader(string filename, SongDb songDb) { Filename = filename; SongDb = songDb; ReadSuccessful = true; }
private async Task ReadSongsAsync(XmlReader reader) { await reader.ReadAsync(); while (reader.LocalName.Equals(Constants.Db.Song)) { Logger.Debug("Reading a song"); UInt32 id; if (!UInt32.TryParse(reader.GetAttribute(Constants.Db.Id), out id)) { Logger.Debug("Could not read song id"); await reader.ReadAsync(); continue; } if (reader.IsEmptyElement) { Logger.Debug("Song element is empty"); await reader.ReadAsync(); continue; } await reader.ReadAsync(); if (reader.IsEndElement(Constants.Db.Song)) { Logger.Debug("Song element is followed by end element"); reader.ReadEndElement(); continue; } reader.ConfirmElement(Constants.Db.SongTitle); var title = await reader.TryGetContentAsync(); reader.ConfirmElement(Constants.Db.Location); var location = await reader.TryGetContentAsync(); reader.ConfirmElement(Constants.Db.Milliseconds); int milliseconds; if (!int.TryParse(await reader.TryGetContentAsync(), out milliseconds)) { Logger.Error("Song {0} has a missing or unreadable millisecond value", title); } reader.ConfirmElement(Constants.Db.PlayCount); uint playCount; if (!uint.TryParse(await reader.TryGetContentAsync(), out playCount)) { Logger.Error("Song {0} has a missing or unreadable playcount", title); } reader.ConfirmElement(Constants.Db.Bpm); var guess = Convert.ToBoolean(reader.GetAttribute(Constants.Db.Guess)); int bpmValue; if (!int.TryParse(await reader.TryGetContentAsync(), out bpmValue)) { Logger.Error("Song {0} has a missing or unreadable BPM value", title); } var song = new Song(title, location, milliseconds, new Bpm(bpmValue, guess), playCount, id); SongDb.AddSong(song); reader.ConfirmElement(Constants.Db.Tags); if (reader.IsEmptyElement) { await reader.ReadAsync(); } else { await ReadSongTagsAsync(reader, song); reader.ReadEndElement(); } reader.ReadEndElement(); } }
public async Task ReadDbAsync(string filename, SongDb songDb) { var reader = new SongDbReader(filename, songDb); await reader.ReadDb(); }
public async Task WriteDbAsync(string filename, SongDb songDb) { var writer = new SongDbWriter(filename, songDb); await writer.WriteDb(); }
protected override void OnExit(ExitEventArgs e) { Task.WaitAll(Task.Run(() => SongDb.SaveDbAsync(Configuration.DbLocation))); WriteConfiguration(); base.OnExit(e); }
public CategoryTagEditorVm(SongDb songDb) { _songDb = songDb; Categories = _songDb.Categories; }