Beispiel #1
0
        public ITemplate LoadTemplate(ITemplateInfo info, string baselineName)
        {
            IGenerator generator;

            if (!Components.TryGetComponent(info.GeneratorId, out generator))
            {
                return(null);
            }

            IMountPoint mountPoint;

            if (!_mountPointManager.TryDemandMountPoint(info.ConfigMountPointId, out mountPoint))
            {
                return(null);
            }
            IFileSystemInfo config = mountPoint.FileSystemInfo(info.ConfigPlace);

            IFileSystemInfo localeConfig = null;

            if (!string.IsNullOrEmpty(info.LocaleConfigPlace) &&
                info.LocaleConfigMountPointId != null &&
                info.LocaleConfigMountPointId != Guid.Empty)
            {
                IMountPoint localeMountPoint;
                if (!_mountPointManager.TryDemandMountPoint(info.LocaleConfigMountPointId, out localeMountPoint))
                {
                    // TODO: decide if we should proceed without loc info, instead of bailing.
                    return(null);
                }

                localeConfig = localeMountPoint.FileSystemInfo(info.LocaleConfigPlace);
            }

            IFile hostTemplateConfigFile = FindBestHostTemplateConfigFile(config);

            ITemplate template;

            using (Timing.Over(_environmentSettings.Host, "Template from config"))
                if (generator.TryGetTemplateFromConfigInfo(config, out template, localeConfig, hostTemplateConfigFile, baselineName))
                {
                    return(template);
                }
                else
                {
                    //TODO: Log the failure to read the template info
                }

            return(null);
        }
Beispiel #2
0
        public static ITemplate LoadTemplate(ITemplateInfo info)
        {
            IGenerator generator;

            if (!Components.TryGetComponent(info.GeneratorId, out generator))
            {
                return(null);
            }

            IMountPoint mountPoint;

            if (!_mountPointManager.TryDemandMountPoint(info.ConfigMountPointId, out mountPoint))
            {
                return(null);
            }

            IFileSystemInfo config = mountPoint.FileSystemInfo(info.ConfigPlace);

            ITemplate template;

            using (Timing.Over("Template from config"))
                if (generator.TryGetTemplateFromConfig(config, out template))
                {
                    return(template);
                }
                else
                {
                    //TODO: Log the failure to read the template info
                }

            return(null);
        }
        public ITemplate LoadTemplate(ITemplateInfo info, string baselineName)
        {
            if (!Components.TryGetComponent(info.GeneratorId, out IGenerator component))
            {
                return(null);
            }

            if (!_mountPointManager.TryDemandMountPoint(info.ConfigMountPointId, out var mountPoint))
            {
                return(null);
            }

            var             config       = mountPoint.FileSystemInfo(info.ConfigPlace);
            IFileSystemInfo localeConfig = null;

            if (!string.IsNullOrEmpty(info.LocaleConfigPlace))
            {
                var localeConfigMountPointId = info.LocaleConfigMountPointId;
                if (info.LocaleConfigMountPointId != Guid.Empty)
                {
                    if (!_mountPointManager.TryDemandMountPoint(info.LocaleConfigMountPointId, out var mountPoint2))
                    {
                        return(null);
                    }

                    localeConfig = mountPoint2.FileSystemInfo(info.LocaleConfigPlace);
                }
            }

            var hostTemplateConfigFile = FindBestHostTemplateConfigFile(config);

            using (Timing.Over(EnvironmentSettings.Host, "Template from config"))
            {
                if (component.TryGetTemplateFromConfigInfo(config,
                                                           out var template,
                                                           localeConfig,
                                                           hostTemplateConfigFile,
                                                           baselineName))
                {
                    return(template);
                }
            }

            return(null);
        }
Beispiel #4
0
        public bool TryMount(IMountPointManager manager, MountPointInfo info, out IMountPoint mountPoint)
        {
            IMountPoint parent = null;

            if (info.ParentMountPointId != Guid.Empty)
            {
                if (!manager.TryDemandMountPoint(info.ParentMountPointId, out parent))
                {
                    mountPoint = null;
                    return(false);
                }
            }

            return(TryMount(manager.EnvironmentSettings, parent, info.MountPointId, info.Place, out mountPoint));
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #6
0
        public ITemplate LoadTemplate(ITemplateInfo info)
        {
            IGenerator generator;

            if (!Components.TryGetComponent(info.GeneratorId, out generator))
            {
                return(null);
            }

            IMountPoint mountPoint;

            if (!_mountPointManager.TryDemandMountPoint(info.ConfigMountPointId, out mountPoint))
            {
                return(null);
            }
            IFileSystemInfo config = mountPoint.FileSystemInfo(info.ConfigPlace);

            IFileSystemInfo localeConfig = null;

            if (!string.IsNullOrEmpty(info.LocaleConfigPlace) &&
                info.LocaleConfigMountPointId != null &&
                info.LocaleConfigMountPointId != Guid.Empty)
            {
                IMountPoint localeMountPoint;
                if (!_mountPointManager.TryDemandMountPoint(info.LocaleConfigMountPointId, out localeMountPoint))
                {
                    // TODO: decide if we should proceed without loc info, instead of bailing.
                    return(null);
                }

                localeConfig = localeMountPoint.FileSystemInfo(info.LocaleConfigPlace);
            }

            IFile hostTemplateConfigFile = null;

            if (!string.IsNullOrEmpty(_environmentSettings.Host.HostIdentifier))
            {
                string hostTemplateFileName = string.Join(string.Empty, _environmentSettings.Host.HostIdentifier, HostTemplateFileConfigBaseName);
                hostTemplateConfigFile = config.Parent.EnumerateFiles(hostTemplateFileName, SearchOption.TopDirectoryOnly).FirstOrDefault();
            }

            if (hostTemplateConfigFile == null && _environmentSettings.Host.FallbackHostTemplateConfigNames != null)
            {
                foreach (string fallbackName in _environmentSettings.Host.FallbackHostTemplateConfigNames)
                {
                    string hostTemplateFileName = string.Join(string.Empty, fallbackName, HostTemplateFileConfigBaseName);
                    hostTemplateConfigFile = config.Parent.EnumerateFiles(hostTemplateFileName, SearchOption.TopDirectoryOnly).FirstOrDefault();

                    if (hostTemplateConfigFile != null)
                    {
                        break;
                    }
                }
            }

            ITemplate template;

            using (Timing.Over("Template from config"))
                if (generator.TryGetTemplateFromConfigInfo(config, out template, localeConfig, hostTemplateConfigFile))
                {
                    return(template);
                }
                else
                {
                    //TODO: Log the failure to read the template info
                }

            return(null);
        }