private IEnumerable <MountPointInfo> FindMountPointsToScan(bool forceRebuild) { // If the user settings version is out of date, or // we've been asked to rebuild everything then // we need to scan everything bool forceScanAll = !IsVersionCurrent || forceRebuild; // load up the culture neutral cache // and get the mount points for templates from the culture neutral cache HashSet <TemplateInfo> allTemplates = new HashSet <TemplateInfo>(_userTemplateCache.GetTemplatesForLocale(null, _userSettings.Version)); // loop through the localized caches and get all the locale mount points foreach (string locale in _userTemplateCache.AllLocalesWithCacheFiles) { allTemplates.UnionWith(_userTemplateCache.GetTemplatesForLocale(locale, _userSettings.Version)); } foreach (TemplateInfo template in allTemplates) { if (!_mountPoints.TryGetValue(template.ConfigMountPointId, out MountPointInfo mountPoint)) { // TODO: This should never happen - throw an error? continue; } if (forceScanAll) { yield return(mountPoint); continue; } // For MountPoints using FileSystemMountPointFactories // we scan the file system to see if the template // is more recent than our cached version if (mountPoint.MountPointFactoryId != FileSystemMountPointFactory.FactoryId) { continue; } string pathToTemplateFile = Path.Combine(mountPoint.Place, template.ConfigPlace.TrimStart('/')); DateTime?timestampOnDisk = null; if (_environmentSettings.Host.FileSystem is IFileLastWriteTimeSource timeSource) { timestampOnDisk = timeSource.GetLastWriteTimeUtc(pathToTemplateFile); } if (!template.ConfigTimestampUtc.HasValue || (timestampOnDisk.HasValue && template.ConfigTimestampUtc.Value < timestampOnDisk)) { // Template on disk is more recent yield return(mountPoint); } } }
public void RebuildCacheFromSettingsIfNotCurrent(bool forceRebuild) { EnsureLoaded(); if (IsVersionCurrent && !forceRebuild) { return; } // load up the culture neutral cache // and get the mount points for templates from the culture neutral cache IReadOnlyList <TemplateInfo> cultureNeutralTemplates = _userTemplateCache.GetTemplatesForLocale(null, _userSettings.Version); HashSet <Guid> templateMountPointIds = new HashSet <Guid>(cultureNeutralTemplates.Select(x => x.ConfigMountPointId)); _userTemplateCache.TemplateInfo.Clear(); HashSet <Guid> scannedMountPoints = new HashSet <Guid>(); // Scan the unique mount points for the templates. foreach (MountPointInfo mountPoint in MountPoints) { if (templateMountPointIds.Contains(mountPoint.MountPointId) && scannedMountPoints.Add(mountPoint.MountPointId)) { _userTemplateCache.Scan(mountPoint.Place); } } // loop through the localized caches and get all the locale mount points HashSet <Guid> localeMountPointIds = new HashSet <Guid>(); foreach (string locale in _userTemplateCache.AllLocalesWithCacheFiles) { IReadOnlyList <TemplateInfo> templatesForLocale = _userTemplateCache.GetTemplatesForLocale(locale, _userSettings.Version); localeMountPointIds.UnionWith(templatesForLocale.Select(x => x.LocaleConfigMountPointId)); } // Scan the unique local mount points foreach (MountPointInfo mountPoint in MountPoints) { if (localeMountPointIds.Contains(mountPoint.MountPointId) && scannedMountPoints.Add(mountPoint.MountPointId)) { _userTemplateCache.Scan(mountPoint.Place); } } Save(); ReloadTemplates(); }