Esempio n. 1
0
        private ImmutableList <ITemplate> LoadTemplates(IFileSystem fileSystem, ITemplateLoader templateLoader,
                                                        ILogger <RepositoryLoader> logger)
        {
            var templates     = ImmutableList.CreateBuilder <ITemplate>();
            var templatePaths = fileSystem.Directory.
                                EnumerateDirectories(this.RootPath.Join("templates").ToString()).
                                Select(path => PurePath.Create(path));

            foreach (var templatePath in templatePaths)
            {
                try
                {
                    var templateFolderName = templatePath.Basename;
                    ValidateTemplateFolderName(templateFolderName);

                    var p        = PurePath.Create("/opt/stamp/repos/TestRepo/templates/TestTemplate@1");
                    var template = templateLoader.LoadFromTemplateDirectory(templatePath);
                    ValidateTemplateAgainstTemplateFolderName(template, templateFolderName);
                    templates.Add(template);
                }
                catch (Exception ex)
                {
                    logger.LogWarning(ex, $"Failed to load template from {templatePath}.");
                    throw;
                }
            }

            return(templates.ToImmutable());
        }