protected override async Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context,
                                                                               CancellationToken cancellationToken)
        {
            var projectDir = context.GetVariable <string>("ProjectDirectory");

            var configFilePath = Path.Combine(projectDir, "abpvue.json");

            if (!File.Exists(configFilePath))
            {
                throw new FileNotFoundException("abpvue.json 文件没有找到。你可以使用 “abpvue init” 初始化项目 ");
            }

            var configText = await File.ReadAllTextAsync(configFilePath, cancellationToken);

            var projectInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <ProjectInfo>(configText);

            if (string.IsNullOrWhiteSpace(projectInfo.OpenApiAddr))
            {
                throw new ArgumentNullException(nameof(projectInfo.OpenApiAddr), "请提供 OpenApi 地址。");
            }

            if (!projectInfo.TemplateFileDirectory.IsNullOrWhiteSpace())
            {
                context.SetVariable("TemplateDirectory", projectInfo.TemplateFileDirectory);
            }

            context.SetVariable("ProjectInfo", projectInfo);

            return(Done());
        }
        protected override Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context, CancellationToken cancellationToken)
        {
            var projectInfo   = context.GetVariable <ProjectInfo>("ProjectInfo");
            var option        = context.GetVariable <object>("Option");
            var entityInfo    = context.GetVariable <EntityInfo>("EntityInfo");
            var interfaceInfo = context.GetVariable <TypeInfo>("InterfaceInfo");
            var classInfo     = context.GetVariable <TypeInfo>("ClassInfo");
            var variables     = context.GetVariables().Where(v => v.Key.StartsWith("Bag."));
            var bag           = new ExpandoObject();

            foreach (var variable in variables)
            {
                ((IDictionary <string, object>)bag)[variable.Key.RemovePreFix("Bag.")] = variable.Value.Value;
            }

            context.SetVariable("Model", new
            {
                ProjectInfo   = projectInfo,
                Option        = option,
                EntityInfo    = entityInfo,
                InterfaceInfo = interfaceInfo,
                ClassInfo     = classInfo,
                Bag           = bag,
            });
            return(Task.FromResult(Done()));
        }
示例#3
0
        protected override Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context, CancellationToken cancellationToken)
        {
            var startupDirectory = context.GetVariable <string>("StartupDirectory");

            Logger.LogInformation("启动目录:{dir}", startupDirectory);

            var isValidProject = CheckIsValidProject(startupDirectory);

            if (!isValidProject)
            {
                var srcPath      = @"\src\";
                var srcPathIndex = startupDirectory.LastIndexOf(srcPath, StringComparison.Ordinal);
                if (srcPathIndex == -1)
                {
                    throw new DirectoryNotFoundException($"未存在 “src” 目录,目录: {Environment.CurrentDirectory}");
                }

                startupDirectory = startupDirectory.Substring(0, srcPathIndex);

                isValidProject = CheckIsValidProject(startupDirectory);
            }

            if (!isValidProject)
            {
                throw new NotSupportedException($"未知的项目结构,目录: {startupDirectory}");
            }

            Logger.LogInformation("项目根目录:{dir}", startupDirectory);
            context.SetVariable("ProjectDirectory", startupDirectory);

            return(Task.FromResult(Done()));
        }
示例#4
0
        protected override Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context, CancellationToken cancellationToken)
        {
            var entityInfo  = context.GetVariable <EntityInfo>("EntityInfo");
            var projectInfo = context.GetVariable <ProjectInfo>("ProjectInfo");

            context.SetVariable("Model", new { EntityInfo = entityInfo, ProjectInfo = projectInfo });
            return(Task.FromResult(Done()));
        }
示例#5
0
        protected override ActivityExecutionResult OnExecute(WorkflowExecutionContext context)
        {
            var entityInfo = context.GetVariable <EntityInfo>("EntityInfo");
            var option     = context.GetVariable <object>("Option") as CrudCommandOption;

            try
            {
                string[] actionNames = { string.Empty, string.Empty, string.Empty };

                if (option != null && option.SeparateDto)
                {
                    actionNames[1] = "Create";
                    actionNames[2] = "Update";
                }
                else
                {
                    actionNames[1] = "CreateUpdate";
                    actionNames[2] = actionNames[1];
                }

                string[] typeNames = new string[actionNames.Length];

                var useEntityPrefix = option != null && option.EntityPrefixDto;
                var dtoSubfix       = option?.DtoSuffix ?? "Dto";

                for (int i = 0; i < typeNames.Length; i++)
                {
                    typeNames[i] = useEntityPrefix
                        ? $"{entityInfo.Name}{actionNames[i]}{dtoSubfix}"
                        : $"{actionNames[i]}{entityInfo.Name}{dtoSubfix}";
                }

                DtoInfo dtoInfo = new DtoInfo(typeNames[0], typeNames[1], typeNames[2]);

                context.SetLastResult(dtoInfo);
                context.SetVariable("DtoInfo", dtoInfo);
                LogOutput(() => dtoInfo);

                return(Done());
            }
            catch (Exception e)
            {
                Logger.LogError(e, "Building DTO info failed.");
                if (e is ParseException pe)
                {
                    foreach (var error in pe.Errors)
                    {
                        Logger.LogError(error);
                    }
                }
                throw;
            }
        }
示例#6
0
        protected override async Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context,
                                                                               CancellationToken cancellationToken)
        {
            var openApiDocument = context.GetVariable <OpenApiDocument>("OpenApiDocument");
            var options         = context.GetVariable <GenerateCommandOptionBasic>("Option");

            var moduleApiPathItems =
                (from item in openApiDocument.Paths
                 let haveTag = item.Value.Operations.Any(x => x.Value.Tags
                                                         .Any(y => y.Name.Equals(options.Module, StringComparison.OrdinalIgnoreCase)))
                               where haveTag
                               select item).ToList();

            //var moduleApiPathItems =
            //    (from item in openApiDocument.Paths
            //        let match = item.Key.StartsWith(options.ModulePrefix)
            //        where match
            //        select item).ToList();

            var emptyModule = "empty".Equals(options.ModulePrefix, StringComparison.OrdinalIgnoreCase);

            context.SetVariable("EmptyModule", emptyModule);

            if (moduleApiPathItems.Count == 0 && !emptyModule)
            {
                Logger.LogWarning("找不到模块:{module} 的任何接口。", options.Module);
                return(base.Fault(""));
            }

            var projectInfo = context.GetVariable <ProjectInfo>("ProjectInfo");
            var modelInfo   = new ModuleInfo(moduleApiPathItems)
            {
                Option      = options,
                ProjectInfo = projectInfo
            };

            context.SetVariable("ModuleInfo", modelInfo);
            return(Done());
        }
        protected override ActivityExecutionResult OnExecute(WorkflowExecutionContext context)
        {
            var modelInfo          = context.GetVariable <ModuleInfo>("ModuleInfo");
            ModuleApiOperation api = modelInfo.ModuleApis.FirstOrDefault(api =>
                                                                         api.Url.Equals(modelInfo.Option.ModulePrefix, StringComparison.OrdinalIgnoreCase) &&
                                                                         api.Method.Equals("get", StringComparison.OrdinalIgnoreCase));

            if (api == null)
            {
                Logger.LogError("找不到 GET LIST API");
                return(Fault("找不到 GET LIST API"));
            }

            Logger.LogInformation("GET LIST API:{api}", modelInfo.Option.ModulePrefix);

            context.SetVariable("GetListModuleApi", api);

            return(Done());
        }
        protected override async Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context,
                                                                               CancellationToken cancellationToken)
        {
            using var httpClient = new HttpClient();

            var projectInfo = context.GetVariable <ProjectInfo>("ProjectInfo");

            Logger.LogInformation("正在获取 OpenApi 文档,url:{url}。", projectInfo.OpenApiAddr);
            var responseStream = await httpClient.GetStreamAsync(projectInfo.OpenApiAddr);

            var openApiDocument = new OpenApiStreamReader().Read(responseStream, out OpenApiDiagnostic diagnostic);

            //if (diagnostic.Errors.Count > 0)
            //{
            //    throw new InvalidOperationException();
            //}

            Logger.LogInformation("读取 OpenApi 文档成功。");
            context.SetVariable("OpenApiDocument", openApiDocument);
            return(Done());
        }
示例#9
0
        protected override ActivityExecutionResult OnExecute(WorkflowExecutionContext context)
        {
            var modelInfo = context.GetVariable <ModuleInfo>("ModuleInfo");
            ModuleApiOperation postApi = modelInfo.ModuleApis.FirstOrDefault(api =>
                                                                             api.Url.Equals(modelInfo.Option.ModulePrefix, StringComparison.OrdinalIgnoreCase) &&
                                                                             api.Method.Equals("post", StringComparison.OrdinalIgnoreCase));

            if (postApi == null)
            {
                Logger.LogError("找不到 POST API");
                return(Fault("找不到 POST API"));
            }

            var apiSchema = postApi.Operation.RequestBody.Content.First().Value.Schema;

            Logger.LogInformation("POST API:{api}, Model:{model}", modelInfo.Option.ModulePrefix,
                                  apiSchema.Reference.Id);

            context.SetVariable("PostModuleApi", postApi);

            return(Done());
        }
示例#10
0
        protected override async Task <ActivityExecutionResult> OnExecuteAsync(WorkflowExecutionContext context, CancellationToken cancellationToken)
        {
            var baseDirectory = await context.EvaluateAsync(BaseDirectory, cancellationToken);

            LogInput(() => baseDirectory);
            var excludeDirectories = await context.EvaluateAsync(ExcludeDirectories, cancellationToken);

            LogInput(() => excludeDirectories, string.Join("; ", excludeDirectories));

            TemplateType templateType;

            if (FileExistsInDirectory(baseDirectory, "*.DbMigrator.csproj", excludeDirectories))
            {
                templateType = TemplateType.Application;
            }
            else if (FileExistsInDirectory(baseDirectory, "*.Host.Shared.csproj", excludeDirectories))
            {
                templateType = TemplateType.Module;
            }
            else
            {
                throw new NotSupportedException($"Unknown ABP project structure. Directory: {baseDirectory}");
            }


            // Assume the domain project must be existed for an ABP project
            var domainCsprojFile = SearchFileInDirectory(baseDirectory, "*.Domain.csproj", excludeDirectories);

            if (domainCsprojFile == null)
            {
                throw new NotSupportedException($"Cannot find the domain project file. Make sure it is a valid ABP project. Directory: {baseDirectory}");
            }

            var fileName = Path.GetFileName(domainCsprojFile);
            var fullName = fileName.RemovePostFix(".Domain.csproj");

            UiFramework uiFramework;

            if (FileExistsInDirectory(baseDirectory, "*.cshtml", excludeDirectories))
            {
                uiFramework = UiFramework.RazorPages;
            }
            else if (FileExistsInDirectory(baseDirectory, "app.module.ts", excludeDirectories))
            {
                uiFramework = UiFramework.Angular;
            }
            else
            {
                uiFramework = UiFramework.None;
            }

            string aspNetCoreDir = Path.Combine(baseDirectory, "aspnet-core");

            if (Directory.Exists(aspNetCoreDir))
            {
                context.SetVariable(VariableNames.AspNetCoreDir, aspNetCoreDir);
            }
            else
            {
                context.SetVariable(VariableNames.AspNetCoreDir, baseDirectory);
            }
            EnsureSlnFileExists(context, fullName);

            var tiered = false;

            if (templateType == TemplateType.Application)
            {
                tiered = FileExistsInDirectory(baseDirectory, "*.IdentityServer.csproj", excludeDirectories);
            }

            var projectInfo = new ProjectInfo(baseDirectory, fullName, templateType, uiFramework, tiered);

            context.SetLastResult(projectInfo);
            context.SetVariable("ProjectInfo", projectInfo);
            LogOutput(() => projectInfo);

            return(Done());
        }