public FileService(string contentRoot, string[] sectionsToExcludeFromLists, ContentCultureService contentCultureService, ILogger logger) { if (string.IsNullOrWhiteSpace(contentRoot)) { throw new Exception("FileService expects a contentRoot when initialized."); } if (!Directory.Exists(contentRoot)) { throw new Exception($"Path for contentRoot does not exist: {contentRoot}"); } this.contentRoot = contentRoot; this.contentRootDirectoryInfo = new DirectoryInfo(this.contentRoot); this.contentCultureService = contentCultureService; this.logger = logger; this.sectionsToExcludeFromLists = sectionsToExcludeFromLists; }
public ContentController(ILogger<ContentController> logger, IConfiguration config, IMemoryCache memoryCache, IWebHostEnvironment env, IStringLocalizerFactory factory) { this.logger = logger; this.config = config; this.env = env; if (factory != null) { this.localizer = factory.Create(typeof(SharedResource)); } this.stopwatch = new Stopwatch(); this.stopwatch.Start(); this.contentRoot = this.config.GetAppSettingsContentRootPath(); this.contentCultureService = new ContentCultureService(); var fileService = new FileService(this.contentRoot, this.config.GetAppSettingsSectionsToExcludeFromLists(), this.contentCultureService, logger); this.rootCultures = fileService.GetRootCultures(); this.allFiles = fileService.GetAllFileFullNames(); if (!memoryCache.TryGetValue(AllFilesCacheKey, out List<IRecordCollectorFile> allFileModelsFromCache)) { lock (AllFilesLock) { if (!memoryCache.TryGetValue(AllFilesCacheKey, out allFileModelsFromCache)) { allFileModelsFromCache = fileService.GetAllFileModels(); var cacheEntryOptions = new MemoryCacheEntryOptions() .SetAbsoluteExpiration(TimeSpan.FromDays(1000)) .SetPriority(CacheItemPriority.High); memoryCache.Set(AllFilesCacheKey, allFileModelsFromCache, cacheEntryOptions); } } } this.allFileModels = allFileModelsFromCache; this.pagesForNavigation = new List<SinglePage>(); }
public CustomRequestCultureProvider(IConfiguration config) { this.contentCultureService = new ContentCultureService(); this.fileService = new FileService(config.GetAppSettingsContentRootPath(), config.GetAppSettingsSectionsToExcludeFromLists(), this.contentCultureService, NullLogger.Instance); }