private async Task <string> GetHelpFileContentsAsync(HelpInfoDefinition model) { string urlBase = $"{VersionManager.GetAddOnPackageUrl(model.Package.AreaName)}Help"; string urlCustomBase = VersionManager.GetCustomUrlFromUrl(urlBase); string file = $"{model.Name}.html"; string lang = MultiString.ActiveLanguage; // try custom language specific HelpFileInfo helpCustomLang = await TryHelpFileAsync($"{urlCustomBase}/{lang}/{file}", model.UseCache); if (helpCustomLang.Exists) { return(helpCustomLang.Contents); } // try custom HelpFileInfo helpCustom = await TryHelpFileAsync($"{urlCustomBase}/{file}", model.UseCache); if (helpCustom.Exists) { return(helpCustom.Contents); } // try fallback language specific HelpFileInfo helpLang = await TryHelpFileAsync($"{urlBase}/{lang}/{file}", model.UseCache); if (helpLang.Exists) { return(helpLang.Contents); } // try fallback HelpFileInfo help = await TryHelpFileAsync($"{urlBase}/{file}", model.UseCache); if (help.Exists) { return(help.Contents); } return(null); }
private async Task <HelpFileInfo> TryHelpFileAsync(string url, bool useCache) { string file = Utility.UrlToPhysical(url); using (ICacheDataProvider cacheDP = YetaWF.Core.IO.Caching.GetStaticSmallObjectCacheProvider()) { // Check cache first GetObjectInfo <HelpFileInfo> cache = await cacheDP.GetAsync <HelpFileInfo>(file); if (cache.Success) { return(cache.Data); } // read file if (!await FileSystem.FileSystemProvider.FileExistsAsync(file)) { HelpFileInfo noInfo = new HelpFileInfo { Contents = null, Exists = false, }; await cacheDP.AddAsync <HelpFileInfo>(file, noInfo);// failure also saved in cache return(noInfo); } string contents = await FileSystem.FileSystemProvider.ReadAllTextAsync(file); HelpFileInfo info = new HelpFileInfo { Contents = contents, Exists = true, }; // save in cache if (contents.Length < MAXSIZE && useCache) { await cacheDP.AddAsync <HelpFileInfo>(file, info); } return(info); } }