Exemple #1
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = GetTemplateInfo(args);

            NormalizeArgs(args, templateInfo);

            var templateFile = await TemplateStore.GetAsync(
                args.TemplateName,
                args.Version
                );

            var apiKey = await ApiKeyService.GetApiKeyOrNullAsync();

            if (apiKey != null)
            {
                args.ExtraProperties["api-key"] = apiKey;
            }

            var context = new ProjectBuildContext(
                templateInfo,
                templateFile,
                args
                );

            ProjectBuildPipelineBuilder.Build(context).Execute();

            if (!templateInfo.DocumentUrl.IsNullOrEmpty())
            {
                Logger.LogInformation("Check the documentation of this template: " + templateInfo.DocumentUrl);
            }

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals("tiered", StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.DatabaseProvider.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.DatabaseProvider.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.UiFramework.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.UiFramework.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = args.DatabaseProvider.ToProviderName(),
                IsTiered         = args.ExtraProperties.ContainsKey("tiered"),
                UiFramework      = args.UiFramework.ToFrameworkName(),
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = args.SolutionName.FullName,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }
Exemple #2
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = GetTemplateInfo(args);

            args.TemplateName = templateInfo.Name;

            if (args.DatabaseProvider == DatabaseProvider.NotSpecified)
            {
                if (templateInfo.DefaultDatabaseProvider != DatabaseProvider.NotSpecified)
                {
                    args.DatabaseProvider = templateInfo.DefaultDatabaseProvider;
                }
            }

            var templateFile = await TemplateStore.GetAsync(
                args.TemplateName,
                args.DatabaseProvider,
                args.SolutionName.FullName
                );

            var context = new ProjectBuildContext(
                templateInfo,
                templateFile,
                args
                );

            ProjectBuildPipelineBuilder.Build(context).Execute(context);

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }
Exemple #3
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var packageInfo = await GetPackageInfoAsync(args);

            var templateFile = await SourceCodeStore.GetAsync(
                args.TemplateName,
                SourceCodeTypes.Package,
                args.Version,
                null,
                args.ExtraProperties.ContainsKey(GetSourceCommand.Options.Preview.Long)
                );

            var apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();

            if (apiKeyResult?.ApiKey != null)
            {
                args.ExtraProperties["api-key"] = apiKeyResult.ApiKey;
            }

            if (apiKeyResult?.LicenseCode != null)
            {
                args.ExtraProperties["license-code"] = apiKeyResult.LicenseCode;
            }

            var context = new ProjectBuildContext(
                null,
                null,
                packageInfo,
                templateFile,
                args
                );

            PackageProjectBuildPipelineBuilder.Build(context).Execute();

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.TemplateSource.Short, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.TemplateSource.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = null,
                IsTiered         = null,
                UiFramework      = null,
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = null,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.TemplateName));
        }
Exemple #4
0
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = GetTemplateInfo(args);

            args.TemplateName = templateInfo.Name;

            if (args.DatabaseProvider == DatabaseProvider.NotSpecified)
            {
                if (templateInfo.DefaultDatabaseProvider != DatabaseProvider.NotSpecified)
                {
                    args.DatabaseProvider = templateInfo.DefaultDatabaseProvider;
                }
            }

            var templateFile = await TemplateStore.GetAsync(
                args.TemplateName,
                args.DatabaseProvider,
                args.SolutionName.FullName
                );

            var context = new ProjectBuildContext(
                templateInfo,
                templateFile,
                args
                );

            ProjectBuildPipelineBuilder.Build(context).Execute(context);

            if (!templateInfo.DocumentUrl.IsNullOrEmpty())
            {
                Logger.LogInformation("Check the documentation of this template: " + templateInfo.DocumentUrl);
            }

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }
Exemple #5
0
 private TemplateInfo GetTemplateInfo(ProjectBuildArgs args)
 {
     if (args.TemplateName.IsNullOrWhiteSpace())
     {
         return(TemplateInfoProvider.GetDefault());
     }
     else
     {
         return(TemplateInfoProvider.Get(args.TemplateName));
     }
 }
 private async Task <TemplateInfo> GetTemplateInfoAsync(ProjectBuildArgs args)
 {
     if (args.TemplateName.IsNullOrWhiteSpace())
     {
         return(await TemplateInfoProvider.GetDefaultAsync());
     }
     else
     {
         return(TemplateInfoProvider.Get(args.TemplateName));
     }
 }
Exemple #7
0
        private static void NormalizeArgs(ProjectBuildArgs args, TemplateInfo templateInfo)
        {
            if (args.TemplateName.IsNullOrEmpty())
            {
                args.TemplateName = templateInfo.Name;
            }

            if (args.DatabaseProvider == DatabaseProvider.NotSpecified)
            {
                if (templateInfo.DefaultDatabaseProvider != DatabaseProvider.NotSpecified)
                {
                    args.DatabaseProvider = templateInfo.DefaultDatabaseProvider;
                }
            }

            if (args.UiFramework == UiFramework.NotSpecified)
            {
                if (templateInfo.DefaultUiFramework != UiFramework.NotSpecified)
                {
                    args.UiFramework = templateInfo.DefaultUiFramework;
                }
            }
        }
        public async Task <ProjectBuildResult> BuildAsync(ProjectBuildArgs args)
        {
            var templateInfo = await GetTemplateInfoAsync(args);

            NormalizeArgs(args, templateInfo);

            var templateFile = await SourceCodeStore.GetAsync(
                args.TemplateName,
                SourceCodeTypes.Template,
                args.Version,
                args.TemplateSource,
                args.ExtraProperties.ContainsKey(NewCommand.Options.Preview.Long)
                );

            DeveloperApiKeyResult apiKeyResult = null;

#if DEBUG
            try
            {
                var apiKeyResultSection = _configuration.GetSection("apiKeyResult");
                if (apiKeyResultSection.Exists())
                {
                    apiKeyResult = apiKeyResultSection.Get <DeveloperApiKeyResult>(); //you can use user secrets
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            if (apiKeyResult == null)
            {
                apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();
            }
#else
            apiKeyResult = await ApiKeyService.GetApiKeyOrNullAsync();
#endif

            if (apiKeyResult != null)
            {
                if (apiKeyResult.ApiKey != null)
                {
                    args.ExtraProperties["api-key"] = apiKeyResult.ApiKey;
                }
                else if (templateInfo.Name == AppProTemplate.TemplateName)
                {
                    throw new UserFriendlyException(apiKeyResult.ErrorMessage);
                }
            }

            if (apiKeyResult?.LicenseCode != null)
            {
                args.ExtraProperties["license-code"] = apiKeyResult.LicenseCode;
            }

            var context = new ProjectBuildContext(
                templateInfo,
                null,
                null,
                null,
                templateFile,
                args
                );

            if (context.Template is AppTemplateBase appTemplateBase)
            {
                appTemplateBase.HasDbMigrations = SemanticVersion.Parse(templateFile.Version) < new SemanticVersion(4, 3, 99);
            }

            TemplateProjectBuildPipelineBuilder.Build(context).Execute();

            if (!templateInfo.DocumentUrl.IsNullOrEmpty())
            {
                Logger.LogInformation("Check out the documents at " + templateInfo.DocumentUrl);
            }

            // Exclude unwanted or known options.
            var options = args.ExtraProperties
                          .Where(x => !x.Key.Equals(CliConsts.Command, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Tiered.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Preview.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.DatabaseProvider.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.DatabaseProvider.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.OutputFolder.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.OutputFolder.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.UiFramework.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.UiFramework.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Mobile.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Mobile.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.Version.Long, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.Version.Short, StringComparison.InvariantCultureIgnoreCase))
                          .Where(x => !x.Key.Equals(NewCommand.Options.TemplateSource.Short, StringComparison.InvariantCultureIgnoreCase) &&
                                 !x.Key.Equals(NewCommand.Options.TemplateSource.Long, StringComparison.InvariantCultureIgnoreCase))
                          .Select(x => x.Key).ToList();

            await CliAnalyticsCollect.CollectAsync(new CliAnalyticsCollectInputDto
            {
                Tool             = Options.ToolName,
                Command          = args.ExtraProperties.ContainsKey(CliConsts.Command) ? args.ExtraProperties[CliConsts.Command] : "",
                DatabaseProvider = args.DatabaseProvider.ToProviderName(),
                IsTiered         = args.ExtraProperties.ContainsKey(NewCommand.Options.Tiered.Long),
                UiFramework      = args.UiFramework.ToFrameworkName(),
                Options          = JsonSerializer.Serialize(options),
                ProjectName      = args.SolutionName.FullName,
                TemplateName     = args.TemplateName,
                TemplateVersion  = templateFile.Version
            });

            return(new ProjectBuildResult(context.Result.ZipContent, args.SolutionName.ProjectName));
        }
 private async Task <ModuleInfo> GetModuleInfoAsync(ProjectBuildArgs args)
 {
     return(await ModuleInfoProvider.GetAsync(args.TemplateName));
 }
 private async Task <NugetPackageInfo> GetPackageInfoAsync(ProjectBuildArgs args)
 {
     return(await NugetPackageInfoProvider.GetAsync(args.TemplateName));
 }