public TranscodingController(IMessageService messageService, IShellService shellService, IMusicFileContext musicFileContext, ISelectionService selectionService, TranscodingService transcodingService, Lazy <ITranscoder> transcoder, Lazy <TranscodingListViewModel> transcodingListViewModel) { this.messageService = messageService; this.shellService = shellService; this.musicFileContext = musicFileContext; this.selectionService = selectionService; this.transcodingService = transcodingService; this.transcoder = transcoder; this.transcodingListViewModel = transcodingListViewModel; cancellationTokenSources = new Dictionary <TranscodeItem, CancellationTokenSource>(); convertToMp3AllCommand = new DelegateCommand(ConvertToMp3All, CanConvertToMp3All); convertToMp3SelectedCommand = new DelegateCommand(ConvertToMp3Selected, CanConvertToMp3Selected); cancelAllCommand = new DelegateCommand(CancelAll, CanCancelAll); cancelSelectedCommand = new DelegateCommand(CancelSelected, CanCancelSelected); throttler = new SemaphoreSlim(Environment.ProcessorCount); // Do not dispose the throttler; it is used after Shutdown to cancel the open tasks transcodingManager = new TranscodingManager(); throttledMusicFilesCollectionChangedAction = new ThrottledAction(ThrottledMusicFilesCollectionChanged, ThrottledActionMode.InvokeOnlyIfIdleForDelayTime, TimeSpan.FromMilliseconds(10)); }
public void AddRemoveTranscodeItemsTest() { var musicFile1 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile1.wma"); var musicFile2 = new MockMusicFile(new MusicMetadata(TimeSpan.FromSeconds(33), 320), "TestFile2.wma"); var item1 = new TranscodeItem(musicFile1, "TestFile1.mp3"); var item2 = new TranscodeItem(musicFile1, "TestFile2.mp3"); var manager = new TranscodingManager(); Assert.IsFalse(manager.TranscodeItems.Any()); manager.AddTranscodeItem(item1); manager.AddTranscodeItem(item2); Assert.IsTrue(new[] { item1, item2 }.SequenceEqual(manager.TranscodeItems)); manager.RemoveTranscodeItem(item1); Assert.AreEqual(item2, manager.TranscodeItems.Single()); }