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)); }
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); }
private string FormatSubFolder(string component, SoundFileCategory category) { return($"{component}\\{category}"); }