示例#1
0
        public async Task Execute()
        {
            var loggers = new List <ILog>
            {
                new ConsoleLog()
            };

            if (!string.IsNullOrEmpty(LogTo))
            {
                loggers.Add(new FileLog(LogTo));
            }

            var engine = TemplatingEngine.Init(loggers.ToArray());

            var projectDirectory = TemplatePaths
                                   .Select(x => Path.Combine(x, $"projects\\{Template}"))
                                   .FirstOrDefault(Directory.Exists);

            if (string.IsNullOrEmpty(projectDirectory))
            {
                projectDirectory = TemplatePaths
                                   .Select(x => Path.Combine(x, "projects\\base"))
                                   .FirstOrDefault(Directory.Exists);
            }

            var substitutions = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>
            {
                { "PROJECT_NAME", Name },
                { "SOLUTION", Solution },
                { "PROJECT_GUID", ProjectGuid }
            });

            if (!string.IsNullOrEmpty(projectDirectory))
            {
                await
                engine.RunTemplate(
                    new ProjectTemplateType(Name, Solution, Location, Path.Combine(Location, $"src\\{Name}"),
                                            ProjectGuid, substitutions), projectDirectory).ConfigureAwait(false);

                await new AlterCommand
                {
                    Name          = Name,
                    Solution      = Solution,
                    Location      = Location,
                    TemplatePaths = TemplatePaths,
                    Template      = Template,
                    LogTo         = LogTo
                }.Execute().ConfigureAwait(false);
            }
        }
        public async Task Execute()
        {
            var loggers = new List <ILog>
            {
                new ConsoleLog()
            };

            if (!string.IsNullOrEmpty(LogTo))
            {
                loggers.Add(new FileLog(LogTo));
            }

            var engine = TemplatingEngine.Init(loggers.ToArray());

            var alterationDirectories = TemplatePaths
                                        .Select(x => Path.Combine(x, "alterations\\base"))
                                        .Where(Directory.Exists)
                                        .ToList();

            alterationDirectories.AddRange(TemplatePaths
                                           .Select(x => Path.Combine(x, $"alterations\\{Template}"))
                                           .Where(Directory.Exists));

            var substitutions = new ReadOnlyDictionary <string, string>(new Dictionary <string, string>
            {
                { "PROJECT_NAME", Name },
                { "SOLUTION", Solution }
            });

            foreach (var alterationDirectory in alterationDirectories)
            {
                await
                engine.RunTemplate(
                    new AlterationTemplateType(Name, Location, Path.Combine(Location, $"src\\{Name}"), substitutions),
                    alterationDirectory).ConfigureAwait(false);
            }
        }