public void ApplyChanges(MusicFile musicFile) { if (ApplyChangesAction != null) { ApplyChangesAction(musicFile); } }
public Task SaveChangesAsync(MusicFile musicFile) { if (SaveChangesAsyncAction != null) { return SaveChangesAsyncAction(musicFile); } return Task.FromResult((object)null); }
public void ImplicitLoadMetadataWithNull() { var musicFile = new MusicFile(fileName => Task.FromResult((MusicMetadata)null), ""); Assert.IsNull(musicFile.Metadata); Assert.IsFalse(musicFile.IsMetadataLoaded); Assert.IsInstanceOfType(musicFile.LoadError, typeof(InvalidOperationException)); }
public void ImplicitLoadMetadataWithException() { var musicFile = new MusicFile(fileName => { throw new InvalidOperationException("Test Exception"); }, ""); Assert.IsNull(musicFile.Metadata); Assert.IsFalse(musicFile.IsMetadataLoaded); Assert.IsInstanceOfType(musicFile.LoadError, typeof(InvalidOperationException)); }
public MusicFileDataModel(MusicFile musicFile) { MusicFile = musicFile; if (musicFile.IsMetadataLoaded) { MetadataLoaded(); } else { PropertyChangedEventManager.AddHandler(musicFile, MusicFilePropertyChanged, ""); } }
private void SetMusicFileData(MusicFile musicFile) { musicFile.Metadata.Artists = new[] { "Artist1", "Artist2" }; musicFile.Metadata.Title = "Title"; musicFile.Metadata.Rating = 75; musicFile.Metadata.Album = "Album"; musicFile.Metadata.TrackNumber = 3; musicFile.Metadata.Year = 2000; musicFile.Metadata.Genre = new[] { "Genre1", "Genre2" }; musicFile.Metadata.AlbumArtist = "AlbumArtist"; musicFile.Metadata.Publisher = "Publisher"; musicFile.Metadata.Subtitle = "Subtitle"; musicFile.Metadata.Composers = new[] { "Composer1", "Composer2" }; musicFile.Metadata.Conductors = new[] { "Conductor1", "Conductor2" }; }
public async Task ImplicitLoadMetadata() { var metadata = new MusicMetadata(TimeSpan.Zero, 0); var musicFile = new MusicFile(async fileNme => { await Task.Yield(); return metadata; }, "testfile.mp3"); Assert.AreEqual("testfile.mp3", musicFile.FileName); Assert.IsFalse(musicFile.SharedMusicFiles.Any()); Assert.IsFalse(musicFile.IsMetadataLoaded); Assert.IsNull(musicFile.Metadata); await Task.Delay(5); Assert.AreEqual(metadata, musicFile.Metadata); Assert.AreEqual(metadata, musicFile.GetMetadataAsync().Result); Assert.IsTrue(musicFile.IsMetadataLoaded); }
public TranscodeItem(MusicFile source, string destinationFileName) { Source = source; DestinationFileName = destinationFileName; UpdateStatus(); }
private async Task SaveChangesAsync(MusicFile musicFile) { if (musicFile == null) { return; } IReadOnlyCollection<MusicFile> allFilesToSave; if (musicFile.SharedMusicFiles.Any()) { allFilesToSave = musicFile.SharedMusicFiles; } else { allFilesToSave = new[] { musicFile }; } // Filter out the music file that is currently playing var playingMusicFile = PlaylistManager.CurrentItem != null ? PlaylistManager.CurrentItem.MusicFile : null; var filesToSave = allFilesToSave.Except(new[] { playingMusicFile }).ToArray(); foreach (var x in allFilesToSave.Intersect(new[] { playingMusicFile })) { musicFilesToSaveAfterPlaying.Add(x); } if (!filesToSave.Any()) { return; } var tasks = filesToSave.Select(x => musicFileContext.SaveChangesAsync(x)).ToArray(); try { await Task.WhenAll(tasks); } catch (Exception ex) { Logger.Error("SaveChangesAsync: {0}", ex); if (filesToSave.Count() == 1) { shellService.ShowError(ex, Resources.CouldNotSaveFile, filesToSave.First().FileName); } else { shellService.ShowError(ex, Resources.CouldNotSaveFiles); } } finally { RemoveMusicFilesToSaveAfterPlaying(filesToSave); } }
public PlaylistItem(MusicFile musicFile) { MusicFile = musicFile; }
private async void TranscodeAsync(MusicFile musicFile) { var destinationFileName = GetDestinationFileName(musicFile.FileName); var transcodeItem = new TranscodeItem(musicFile, destinationFileName); transcodingManager.AddTranscodeItem(transcodeItem); Logger.Verbose("Start Transcode: {0} > {1}", musicFile.FileName, destinationFileName); var cts = new CancellationTokenSource(); cancellationTokenSources.Add(transcodeItem, cts); UpdateCancelCommands(); var metadata = await musicFile.GetMetadataAsync(); uint bitrate = GetConvertBitrate(metadata.Bitrate); try { await TranscodeAsyncCore(transcodeItem, bitrate, cts.Token); } catch (OperationCanceledException) { transcodingManager.RemoveTranscodeItem(transcodeItem); } catch (Exception ex) { Logger.Error("TranscodeAsync exception: {0}", ex); transcodeItem.Error = ex; } finally { cancellationTokenSources.Remove(transcodeItem); if (allTranscodingsCanceledCompletion != null && !cancellationTokenSources.Any()) { allTranscodingsCanceledCompletion.SetResult(null); } UpdateCancelCommands(); Logger.Verbose("End Transcode: {0} > {1}", musicFile.FileName, destinationFileName); } }
public void TotalDurationWithMetadataLoading() { var manager = new PlaylistManager(); Assert.AreEqual(TimeSpan.Zero, manager.TotalDuration); var firstFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(10), 0), ""); manager.AddAndReplaceItems(new[] { new PlaylistItem(firstFile) }); var secondMetadata = new MusicMetadata(TimeSpan.FromSeconds(20), 0); var secondFile = new MusicFile(async x => { await Task.Delay(10); return secondMetadata; }, ""); manager.AddItems(new[] { new PlaylistItem(secondFile) }); Assert.IsTrue(manager.IsTotalDurationEstimated); Assert.AreEqual(TimeSpan.FromSeconds(20), manager.TotalDuration); AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => secondFile.GetMetadataAsync().GetResult()); Assert.IsFalse(manager.IsTotalDurationEstimated); Assert.AreEqual(TimeSpan.FromSeconds(30), manager.TotalDuration); var thirdFile = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(30), 0), ""); AssertHelper.PropertyChangedEvent(manager, x => x.TotalDuration, () => manager.AddItems(new[] { new PlaylistItem(thirdFile) })); Assert.AreEqual(TimeSpan.FromSeconds(60), manager.TotalDuration); }