public void BeforeStartDrag(IEnumerable <ISearchResult> selectedResults, ITargetDirectoryProvider targetDirectoryProvider, out List <string> createdStubFiles) { List <string> files = new List <string>(); // Define an action to create a stub for an IDeployableAudioFile Action <IDeployableAudioFile> createStub = (IDeployableAudioFile file) => { string filePath = targetDirectoryProvider.GetFullPath(file); // Only create stubs for files which don't exist yet if (!System.IO.File.Exists(filePath)) { System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(filePath)); FileStream s = System.IO.File.Create(filePath); s.Close(); files.Add(filePath); } }; // Go through all IDeployableAudioFiles required by the selected ISearchResults and create a stub for each one foreach (ISearchResult result in selectedResults) { if (result is IDeployableAudioFile) { createStub(result as IDeployableAudioFile); } foreach (IDeployableAudioFile file in result.RequiredFiles) { createStub(file); } } // Return a list of stub files that have been created createdStubFiles = files; }
public void AfterCancelDrag(IEnumerable <ISearchResult> selectedResults, ITargetDirectoryProvider targetDirectoryProvider, List <string> stubFilesToDelete) { // Delete all stubs when a drag operation has been cancelled foreach (string filePath in stubFilesToDelete) { System.IO.File.Delete(filePath); } }
public AudioDeploymentResult Download(IAbsoluteProgressMonitor monitor, ITargetDirectoryProvider targetDirectoryProvider) { string downloadTargetPath = targetDirectoryProvider.GetFullPath(this); // Make sure the target directory exists System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(downloadTargetPath)); // Only download if the target file doesn't exist (or is empty, that is, a stub) if (!System.IO.File.Exists(downloadTargetPath) || new System.IO.FileInfo(downloadTargetPath).Length == 0) { // Download the file (synchronously) client.DownloadFile(new Uri(SourceUrl), downloadTargetPath); // TODO: set additional ID3 information regarding source, author, license, tags etc. on the file } monitor.IncreaseProgress(DownloadSize.GetValueOrDefault(1)); return(AudioDeploymentResult.SUCCESS); }
public IModeElement GetModeElementDefinition(ITargetDirectoryProvider targetDirectoryProvider) { IElementContainer <IParallelElement> container = DataModule.ElementFactory.CreateParallelContainer("Test-Szenario"); IModeElement modeElement = DataModule.ElementFactory.CreateModeElement("Test-Szenario", container); IRandomBackgroundMusicList music = DataModule.ElementFactory.CreateRandomBackgroundMusicList("Musik"); container.AddElement(music); IBackgroundSounds sounds = DataModule.ElementFactory.CreateBackgroundSounds("Sounds"); container.AddElement(sounds); IBackgroundSoundChoice soundChoice1 = sounds.AddElement("Auswahl 1"); music.AddElement(DataModule.ElementFactory.CreateFileElement(targetDirectoryProvider.GetPathWithinLibrary(m_MusicResource), SoundFileType.Music)); soundChoice1.AddElement(DataModule.ElementFactory.CreateFileElement(targetDirectoryProvider.GetPathWithinLibrary(m_SoundResource), SoundFileType.SoundEffect)); return(modeElement); }
public AudioDeploymentResult Deploy(IAbsoluteProgressMonitor monitor, ITargetDirectoryProvider targetDirectoryProvider) { return(Download(monitor, targetDirectoryProvider)); }
private AudioDeploymentResult DeployFile(IDeployableAudioFile downloadableFile, IAbsoluteProgressMonitor absoluteMonitor, ITargetDirectoryProvider targetDirectoryProvider) { return(downloadableFile.Deploy(absoluteMonitor, targetDirectoryProvider)); }
/// <summary> /// Download the files for all given ISearchResults to the locations specified by the given ITargetDirectoryProvider. /// based on their type (sound/music) /// </summary> /// <param name="results"></param> private void DeployRequiredFilesForSearchResults(IEnumerable <ISearchResult> results, ITargetDirectoryProvider targetDirectoryProvider) { // Collect the list of files to be deployed List <IDeployableAudioFile> filesToBeDeployed = new List <IDeployableAudioFile>(); foreach (ISearchResult searchResult in results) { // Queue the ISearchResult itself for deployment if it's an IDeployableAudioFile in it's own right if (searchResult is IDeployableAudioFile) { filesToBeDeployed.Add(searchResult as IDeployableAudioFile); } // Queue additional required files for deployment foreach (IDeployableAudioFile deployableFile in searchResult.RequiredFiles) { filesToBeDeployed.Add(deployableFile); } } // Collect the total "cost" of all files to be deployed double totalDeploymentCost = 0; foreach (IDeployableAudioFile deployableFile in filesToBeDeployed) { totalDeploymentCost += deployableFile.DeploymentCost.GetValueOrDefault(1); } // Initialize a task monitor for the download process TaskProgressMonitor baseMonitor = new TaskProgressMonitor(this, StringResources.DownloadingAudio, new CancellationTokenSource()); IAbsoluteProgressMonitor absoluteMonitor = new AbsoluteProgressMonitor(baseMonitor, totalDeploymentCost, StringResources.DownloadingAudio); // Start a separate task for downloading the files Task <List <AudioDeploymentResult> > task = Task.Factory.StartNew(() => { absoluteMonitor.SetIndeterminate(); List <AudioDeploymentResult> downloadResults = new List <AudioDeploymentResult>(); // Go through all results foreach (IDeployableAudioFile deployableFile in filesToBeDeployed) { // Download each one downloadResults.Add(DeployFile(deployableFile, absoluteMonitor, targetDirectoryProvider)); absoluteMonitor.IncreaseProgress(deployableFile.DeploymentCost.GetValueOrDefault(1)); } return(downloadResults); }); // What to do when the downloads complete task.ContinueWith((t) => { baseMonitor.Close(); // TODO: Do something with the collected DownloadResults List <AudioDeploymentResult> downloadResults = task.Result; }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.NotOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); // What to do when the downloads fail task.ContinueWith((t) => { baseMonitor.Close(); if (t.Exception != null) { TaskHelpers.HandleTaskException(this, t.Exception, StringResources.SearchError); } }, System.Threading.CancellationToken.None, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted, System.Threading.Tasks.TaskScheduler.FromCurrentSynchronizationContext()); }
public void AfterCompleteDrag(IEnumerable <ISearchResult> selectedResults, ITargetDirectoryProvider targetDirectoryProvider) { // Deploy all required files once a drag operation has been completed DeployRequiredFilesForSearchResults(selectedResults, targetDirectoryProvider); }
public AudioDeploymentResult Deploy(IAbsoluteProgressMonitor monitor, ITargetDirectoryProvider targetDirectoryProvider) { ((TestAudioSource)AudioSource).ExtractEmbeddedFile(m_ResourceName, targetDirectoryProvider.GetFullPath(this)); return(AudioDeploymentResult.SUCCESS); }