Exemple #1
0
        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;
        }
Exemple #2
0
 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);
     }
 }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
        }
Exemple #5
0
 public AudioDeploymentResult Deploy(IAbsoluteProgressMonitor monitor, ITargetDirectoryProvider targetDirectoryProvider)
 {
     return(Download(monitor, targetDirectoryProvider));
 }
Exemple #6
0
 private AudioDeploymentResult DeployFile(IDeployableAudioFile downloadableFile, IAbsoluteProgressMonitor absoluteMonitor, ITargetDirectoryProvider targetDirectoryProvider)
 {
     return(downloadableFile.Deploy(absoluteMonitor, targetDirectoryProvider));
 }
Exemple #7
0
        /// <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());
        }
Exemple #8
0
 public void AfterCompleteDrag(IEnumerable <ISearchResult> selectedResults, ITargetDirectoryProvider targetDirectoryProvider)
 {
     // Deploy all required files once a drag operation has been completed
     DeployRequiredFilesForSearchResults(selectedResults, targetDirectoryProvider);
 }
Exemple #9
0
 public AudioDeploymentResult Deploy(IAbsoluteProgressMonitor monitor, ITargetDirectoryProvider targetDirectoryProvider)
 {
     ((TestAudioSource)AudioSource).ExtractEmbeddedFile(m_ResourceName, targetDirectoryProvider.GetFullPath(this));
     return(AudioDeploymentResult.SUCCESS);
 }