protected virtual void GetVirtualSolutionFolderTemplateObjects(ITemplateObject root,
                                                                       IList <VirtualSolutionFolder> virtualSolutionFolders, string parentPath)
        {
            foreach (var virtualSolutionFolder in virtualSolutionFolders)
            {
                var virtualFolderObject = new TemplateObject
                {
                    Type = TemplateObjectType.Folder,
                    DestinationFullPath = Path.Combine(parentPath, virtualSolutionFolder.Name)
                };

                foreach (var filePath in virtualSolutionFolder.Files)
                {
                    virtualFolderObject.ChildObjects.Add(new TemplateObject
                    {
                        ChildObjects        = null,
                        Type                = TemplateObjectType.File,
                        OriginalFullPath    = filePath,
                        DestinationFullPath = ReplaceTokensService.Replace(BuildDestinationPathService.Build(filePath))
                    });
                }

                if (virtualSolutionFolder.SubFolders == null || !virtualSolutionFolders.Any())
                {
                    continue;
                }
                GetVirtualSolutionFolderTemplateObjects(virtualFolderObject, virtualSolutionFolder.SubFolders,
                                                        virtualFolderObject.DestinationFullPath);
                root.ChildObjects.Add(virtualFolderObject);
            }
        }
        public IHelixProjectTemplate Run(HelixTemplateManifest manifest, string solutionRootPath)
        {
            Manifest                    = manifest;
            ReplaceTokensService        = new ReplaceTokensService(Manifest.ReplacementTokens);
            DestinationRootPath         = solutionRootPath;
            BuildDestinationPathService = new BuildDestinationPathService(Manifest.ManifestRootPath, DestinationRootPath);
            var templateObjects = new List <ITemplateObject>();

            templateObjects.AddRange(GetTemplateObjectFromDirectory(Manifest.ManifestRootPath));
            var copyTemplateObjectsService = new CopyTemplateObjectFilesService(templateObjects);
            var copiedFilePaths            = copyTemplateObjectsService.Copy();

            if (!copiedFilePaths.Any())
            {
                return new HelixProjectTemplate
                       {
                           Manifest          = Manifest,
                           TemplateObjects   = templateObjects,
                           ReplacementTokens = Manifest.ReplacementTokens
                       }
            }
            ;

            var replaceFileTokensService = new ReplaceTokensInFilesService(copiedFilePaths, Manifest.ReplacementTokens);

            replaceFileTokensService.Replace();
            MarkIfSkipped(templateObjects);
            CreateVirtualSolutionFolders(templateObjects);
            return(new HelixProjectTemplate
            {
                Manifest = Manifest,
                TemplateObjects = templateObjects,
                ReplacementTokens = Manifest.ReplacementTokens
            });
        }
        protected virtual ITemplateObject GetTemplateObjectFromFile(string filePath)
        {
            var isIgnored = IsIgnored(filePath);

            return(new TemplateObject
            {
                Type = IsProjectToAttach(filePath) ? TemplateObjectType.Project : TemplateObjectType.File,
                ChildObjects = null,
                OriginalFullPath = filePath,
                IsIgnored = isIgnored,
                DestinationFullPath = isIgnored ? "" : ReplaceTokensService.Replace(BuildDestinationPathService.Build(filePath))
            });
        }
        protected virtual IList <ITemplateObject> GetTemplateObjectFromDirectory(string directoryPath)
        {
            var templateObjects = Directory.EnumerateFiles(directoryPath).Select(GetTemplateObjectFromFile)
                                  .Where(objectFromFile => objectFromFile != null).ToList();

            templateObjects.AddRange(Directory.EnumerateDirectories(directoryPath)
                                     .Select(directory => new TemplateObject
            {
                Type                = IsSourceRoot(directory) ? TemplateObjectType.SourceRoot : TemplateObjectType.Folder,
                ChildObjects        = GetTemplateObjectFromDirectory(directory),
                OriginalFullPath    = directory,
                DestinationFullPath = ReplaceTokensService.Replace(BuildDestinationPathService.Build(directory))
            }));
            return(templateObjects);
        }
        public IHelixProjectTemplate Run(HelixTemplateManifest manifest, string solutionRootPath)
        {
            Manifest = manifest;
            WriteTraceService.WriteToTrace("Template Engine started", "\nInfo", $"Manifest: {manifest.Name}",
                                           $"root path: {solutionRootPath} ");
            ReplaceTokensService        = new ReplaceTokensService(Manifest.ReplacementTokens);
            DestinationRootPath         = solutionRootPath;
            BuildDestinationPathService = new BuildDestinationPathService(Manifest.ManifestRootPath, DestinationRootPath);
            ExpandConditions();

            var templateObjects = new List <ITemplateObject>();

            templateObjects.AddRange(GetTemplateObjectFromDirectory(Manifest.ManifestRootPath));
            var copyTemplateObjectsService = new CopyTemplateObjectFilesService(templateObjects);
            var copiedFilePaths            = copyTemplateObjectsService.Copy();

            if (!copiedFilePaths.Any())
            {
                return new HelixProjectTemplate
                       {
                           Manifest          = Manifest,
                           TemplateObjects   = templateObjects,
                           ReplacementTokens = Manifest.ReplacementTokens
                       }
            }
            ;

            var replaceFileTokensService = new ReplaceTokensInFilesService(copiedFilePaths, Manifest.ReplacementTokens);

            replaceFileTokensService.Replace();
            EvaluateSkipAttach(templateObjects);
            CreateVirtualSolutionFolders(templateObjects);

            return(new HelixProjectTemplate
            {
                Manifest = Manifest,
                TemplateObjects = templateObjects,
                ReplacementTokens = Manifest.ReplacementTokens
            });
        }