Ejemplo n.º 1
0
        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));
            }
            var returnedPoints = new HashSet <Guid>();

            foreach (TemplateInfo template in allTemplates)
            {
                if (returnedPoints.Contains(template.ConfigMountPointId))
                {
                    continue;
                }

                if (!_mountPoints.TryGetValue(template.ConfigMountPointId, out MountPointInfo mountPoint))
                {
                    // TODO: This should never happen - throw an error?
                    continue;
                }

                //try to demand mount point: if the mount point is not available, the method returns false
                //if the mount point is not available, we skip it so it doesn't cause exception when scanning it
                if (!_mountPointManager.TryDemandMountPoint(mountPoint, out IMountPoint mp))
                {
                    continue;
                }
                _mountPointManager.ReleaseMountPoint(mp);

                if (forceScanAll)
                {
                    returnedPoints.Add(template.ConfigMountPointId);
                    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
                    returnedPoints.Add(template.ConfigMountPointId);
                    yield return(mountPoint);
                }
            }
        }
Ejemplo n.º 2
0
 public void ReleaseMountPoint(IMountPoint mountPoint)
 {
     _mountPointManager.ReleaseMountPoint(mountPoint);
 }