private JsonResult GetRandomSoundFile(string component, SoundFileCategory category)
        {
            var file     = _soundFilePicker.GetRandomSoundFile(component, category);
            var relative = _filePathConverter.ToFullWebUrl(file);

            return(Json(Url.Content(relative),
                        JsonRequestBehavior.AllowGet));
        }
Beispiel #2
0
        public string GetRandomSoundFile(string component, SoundFileCategory category)
        {
            string subfolder      = FormatSubFolder(component, category);
            string fullFolderPath = FormatFullFolder(subfolder);

            lock (_lockObject)
            {
                DirectoryFileCache cache = _fileCaches.GetOrAdd(subfolder, sf => new DirectoryFileCache(fullFolderPath));
                if (cache.ContainsFiles)
                {
                    var random = new Random();
                    return(cache.Files.Skip(random.Next(0, cache.Files.Count() - 1)).FirstOrDefault());
                }
            }

            if (!component.Equals("Generic", StringComparison.CurrentCultureIgnoreCase))
            {
                return(GetRandomSoundFile("Generic", category));
            }

            return(String.Empty);
        }
Beispiel #3
0
 private string FormatSubFolder(string component, SoundFileCategory category)
 {
     return($"{component}\\{category}");
 }