diff --git a/OSharp.CodeGenerator.sln b/OSharp.CodeGenerator.sln index ef756fbd6f9e952dec5e4df3eb9e55958dd35831..0fa0464d39a35250d4d0e74d971502e21f35dbf9 100644 --- a/OSharp.CodeGenerator.sln +++ b/OSharp.CodeGenerator.sln @@ -12,7 +12,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{87C5555B-87C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSharp.CodeGenerator", "src\OSharp.CodeGenerator\OSharp.CodeGenerator.csproj", "{5AF55A1E-7A19-4886-B4B0-D840694AA997}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSharp.CodeGeneration", "src\OSharp.CodeGeneration\OSharp.CodeGeneration.csproj", "{B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OSharp.CodeGeneration", "src\OSharp.CodeGeneration\OSharp.CodeGeneration.csproj", "{B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSharp.CodeConsoles", "src\OSharp.CodeConsoles\OSharp.CodeConsoles.csproj", "{13784656-5A4F-4083-919C-F64471F8CFBF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -28,6 +30,10 @@ Global {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}.Debug|Any CPU.Build.0 = Debug|Any CPU {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}.Release|Any CPU.ActiveCfg = Release|Any CPU {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}.Release|Any CPU.Build.0 = Release|Any CPU + {13784656-5A4F-4083-919C-F64471F8CFBF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13784656-5A4F-4083-919C-F64471F8CFBF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13784656-5A4F-4083-919C-F64471F8CFBF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13784656-5A4F-4083-919C-F64471F8CFBF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -35,6 +41,7 @@ Global GlobalSection(NestedProjects) = preSolution {5AF55A1E-7A19-4886-B4B0-D840694AA997} = {87C5555B-87C3-46FE-9BF0-ACA575890EC6} {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA} = {87C5555B-87C3-46FE-9BF0-ACA575890EC6} + {13784656-5A4F-4083-919C-F64471F8CFBF} = {87C5555B-87C3-46FE-9BF0-ACA575890EC6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AFCE6A5E-D5ED-4BAA-8CCF-45A229EF3405} diff --git a/OSharp.CodeGenerator.sln.DotSettings b/OSharp.CodeGenerator.sln.DotSettings index 768439d4b82c6a37462673b6cf4fea4adacccbbb..0462b99076c69103ac71373fe397eb722d90e212 100644 --- a/OSharp.CodeGenerator.sln.DotSettings +++ b/OSharp.CodeGenerator.sln.DotSettings @@ -155,10 +155,16 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> C:\Users\Administrator\AppData\Local\JetBrains\Transient\ReSharperPlatformVs15\v08_9a28c652\SolutionCaches + Never + False + Never False False LIVE_MONITOR NOTIFY + True + True + True True True True @@ -4155,6 +4161,7 @@ finally True True True + True True True True diff --git a/src/OSharp.CodeConsoles/OSharp.CodeConsoles.csproj b/src/OSharp.CodeConsoles/OSharp.CodeConsoles.csproj new file mode 100644 index 0000000000000000000000000000000000000000..5071d8d7ccb63db573a935889681454df6215068 --- /dev/null +++ b/src/OSharp.CodeConsoles/OSharp.CodeConsoles.csproj @@ -0,0 +1,12 @@ + + + + Exe + net5.0 + + + + + + + diff --git a/src/OSharp.CodeConsoles/Program.cs b/src/OSharp.CodeConsoles/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..6a9251cef60825c94bd83652f39a5833e7613565 --- /dev/null +++ b/src/OSharp.CodeConsoles/Program.cs @@ -0,0 +1,147 @@ +using System; +using System.Diagnostics; + +using MiniRazor; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGeneration.Templates; + + +namespace OSharp.CodeConsoles +{ + class Program + { + static void Main(string[] args) + { + bool exit = false; + while (true) + { + try + { + Console.WriteLine(@"请输入命令:0; 退出程序,功能命令:1 - n"); + string input = Console.ReadLine(); + if (input == null) + { + continue; + } + + Stopwatch watch = Stopwatch.StartNew(); + switch (input.ToLower()) + { + case "0": + exit = true; + break; + case "1": + Method01(); + break; + case "2": + Method02(); + break; + case "3": + Method03(); + break; + case "4": + Method04(); + break; + case "5": + Method05(); + break; + case "6": + Method06(); + break; + case "7": + Method07(); + break; + case "8": + Method08(); + break; + case "9": + Method09(); + break; + case "10": + Method10(); + break; + case "11": + Method11(); + break; + } + + watch.Stop(); + Console.WriteLine($"执行完成,耗时:{watch.Elapsed}\n"); + if (exit) + { + break; + } + } + catch (Exception e) + { + Console.WriteLine(e); + } + } + } + + private static async void Method01() + { + var model = new CodeModule { Name = "Infos" }; + await TestTemplate.RenderAsync(Console.Out, model); + ITemplate tmp = new TestTemplate(); + tmp.Model = model; + tmp.Output = Console.Out; + await tmp.ExecuteAsync(); + } + + private static async void Method02() + { + // Compile the template into an in-memory assembly + TemplateDescriptor template = Razor.Compile("

Hello, @Model.Name!

"); + + // Render the template to string + var output = await template.RenderAsync(new CodeModule { Name = "World" }); + } + + private static void Method03() + { + throw new NotImplementedException(); + } + + private static void Method04() + { + throw new NotImplementedException(); + } + + private static void Method05() + { + throw new NotImplementedException(); + } + + private static void Method06() + { + throw new NotImplementedException(); + } + + private static void Method07() + { + throw new NotImplementedException(); + } + + private static void Method08() + { + throw new NotImplementedException(); + } + + private static void Method09() + { + throw new NotImplementedException(); + } + + private static void Method10() + { + throw new NotImplementedException(); + } + + private static void Method11() + { + throw new NotImplementedException(); + } + } +} diff --git a/src/OSharp.CodeGeneration/Generates/CodeFile.cs b/src/OSharp.CodeGeneration/Generates/CodeFile.cs new file mode 100644 index 0000000000000000000000000000000000000000..b7f11ec34ed37434064e0a66b4a67c47e71599e9 --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/CodeFile.cs @@ -0,0 +1,41 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using OSharp.Extensions; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 表示代码文件信息 + /// + public class CodeFile + { + private string _sourceCode; + + /// + /// 获取或设置 代码配置 + /// + public GenCodeConfig CodeConfig { get; set; } + + /// + /// 获取或设置 源代码字符串 + /// + public string SourceCode + { + get => _sourceCode; + set => _sourceCode = value.ToHtmlDecode(); + } + + /// + /// 获取或设置 代码输出文件 + /// + public string FileName { get; set; } + } +} diff --git a/src/OSharp.CodeGeneration/Generates/GenCodeConfig.cs b/src/OSharp.CodeGeneration/Generates/GenCodeConfig.cs new file mode 100644 index 0000000000000000000000000000000000000000..415f8885ae43c3739a015e2d6873c149ab6d8d30 --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/GenCodeConfig.cs @@ -0,0 +1,102 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using System; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Extensions; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 代码配置 + /// + public class GenCodeConfig + { + /// + /// 获取或设置 配置名称 + /// + public string Name { get; set; } + + /// + /// 获取或设置 元数据类型 + /// + public MetadataType MetadataType { get; set; } + + /// + /// 获取或设置 模板文件,默认内置,也可以由用户自定义加载 + /// + public string TemplateFile { get; set; } + + /// + /// 获取或设置 模板类型,内置模板使用 + /// + public Type TemplateType { get; set; } + + /// + /// 获取或设置 排序 + /// + public int Order { get; set; } + + /// + /// 获取或设置 代码输出文件名格式 + /// + public string OutputFileFormat { get; set; } + + /// + /// 获取或设置 是否只生成一次 + /// + public bool IsOnce { get; set; } + + /// + /// 获取或设置 系统类型 + /// + public bool IsSystem { get; set; } + + /// + /// 获取或设置 是否启用 + /// + public bool IsEnabled { get; set; } = true; + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeProject project) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", project.NamespacePrefix) + .Replace("{Project.Name:Lower}", project.Name.UpperToLowerAndSplit()) + .Replace("{Project.Name}", project.Name); + return fileName; + } + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeModule module) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", module.Project.NamespacePrefix) + .Replace("{Module.Name:Lower}", module.Name.UpperToLowerAndSplit()) + .Replace("{Module.Name}", module.Name); + return fileName; + } + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeEntity entity) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", entity.Module.Project.NamespacePrefix) + .Replace("{Module.Name:Lower}", entity.Module.Name.UpperToLowerAndSplit()) + .Replace("{Entity.Name:Lower}", entity.Name.UpperToLowerAndSplit()) + .Replace("{Module.Name}", entity.Module.Name).Replace("{Entity.Name}", entity.Name); + return fileName; + } + } +} diff --git a/src/OSharp.CodeGeneration/Generates/GenerateManager.cs b/src/OSharp.CodeGeneration/Generates/GenerateManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..13b8b331f7f54d69003f4f153945e57ac4cb3cab --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/GenerateManager.cs @@ -0,0 +1,40 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using System; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 代码生成管理器 + /// + public class GenerateManager : IGenerateManager + { + private readonly IServiceProvider _provider; + + public GenerateManager(IServiceProvider provider) + { + _provider = provider; + } + + /// + /// 开始生成代码 + /// + /// + public Task Start() + { + throw new NotImplementedException(); + } + + } +} diff --git a/src/OSharp.CodeGeneration/Generates/GeneratePack.cs b/src/OSharp.CodeGeneration/Generates/GeneratePack.cs new file mode 100644 index 0000000000000000000000000000000000000000..29455e4bcb5a62d825b78363686b72b4407ef256 --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/GeneratePack.cs @@ -0,0 +1,33 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.Core.Packs; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 代码生成模块 + /// + public class GeneratePack : OsharpPack + { + /// 将模块服务添加到依赖注入服务容器中 + /// 依赖注入服务容器 + /// + public override IServiceCollection AddServices(IServiceCollection services) + { + services.AddScoped(); + services.AddSingleton(); + + return base.AddServices(services); + } + } +} diff --git a/src/OSharp.CodeGeneration/Generates/ICodeGenerator.cs b/src/OSharp.CodeGeneration/Generates/ICodeGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..ad2f1b3ef8a5c4a3b082088592849f9b91712215 --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/ICodeGenerator.cs @@ -0,0 +1,51 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 定义代码生成器 + /// + public interface ICodeGenerator + { + /// + /// 生成项目所有代码 + /// + /// 要处理的代码配置集合 + /// 代码项目信息 + /// 输出的代码文件信息集合 + Task GenerateCodes(GenCodeConfig[] codeConfigs, CodeProject project); + + /// + /// 生成项目元数据相关代码 + /// 代码配置 + /// 项目元数据 + /// + Task GenerateCode(GenCodeConfig codeConfig, CodeProject project); + + /// + /// 生成模块元数据相关代码 + /// 代码配置 + /// 模块元数据 + /// + Task GenerateCode(GenCodeConfig codeConfig, CodeModule module); + + /// + /// 生成实体元数据相关代码 + /// 代码配置 + /// 实体元数据 + /// + Task GenerateCode(GenCodeConfig codeConfig, CodeEntity entity); + } +} diff --git a/src/OSharp.CodeGeneration/Generates/IGenerateManager.cs b/src/OSharp.CodeGeneration/Generates/IGenerateManager.cs new file mode 100644 index 0000000000000000000000000000000000000000..6061c7de46541b70c2fbca91bfeae15cf746a685 --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/IGenerateManager.cs @@ -0,0 +1,26 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using System.Threading.Tasks; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// 定义代码生成管理器 + /// + public interface IGenerateManager + { + /// + /// 开始生成代码 + /// + /// + Task Start(); + } +} diff --git a/src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs b/src/OSharp.CodeGeneration/Generates/MetadataType.cs similarity index 43% rename from src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs rename to src/OSharp.CodeGeneration/Generates/MetadataType.cs index 0c64a256dd7ce3155d73a534ed6ae9c9155e31e9..f27122b378e66f6d758926b6c9e25ad80e9d4606 100644 --- a/src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs +++ b/src/OSharp.CodeGeneration/Generates/MetadataType.cs @@ -1,25 +1,23 @@ // ----------------------------------------------------------------------- -// -// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. // // http://www.osharp.org // 郭明锋 -// 2020-05-05 12:38 +// 2021-04-08 21:39 // ----------------------------------------------------------------------- -using OSharp.Wpf.Stylet; - - -namespace OSharp.CodeGenerator.Views +namespace OSharp.CodeGeneration.Generates { /// - /// ProjectView.xaml 的交互逻辑 + /// 表示生成代码需要的元数据类型,有实体和模块 /// - public partial class ProjectView + public enum MetadataType { - public ProjectView() - { - InitializeComponent(); - } + Entity, + + Module, + + Project } } diff --git a/src/OSharp.CodeGeneration/Generates/RazorCodeGenerator.cs b/src/OSharp.CodeGeneration/Generates/RazorCodeGenerator.cs new file mode 100644 index 0000000000000000000000000000000000000000..b87e169498cf244e3a7a13b877502288f60d234a --- /dev/null +++ b/src/OSharp.CodeGeneration/Generates/RazorCodeGenerator.cs @@ -0,0 +1,141 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 21:39 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using MiniRazor; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Exceptions; + + +namespace OSharp.CodeGeneration.Generates +{ + /// + /// Razor代码生成器 + /// + public class RazorCodeGenerator : ICodeGenerator + { + /// + /// 生成项目所有代码 + /// + /// 要处理的代码配置集合 + /// 代码项目信息 + /// 输出的代码文件信息集合 + public async Task GenerateCodes(GenCodeConfig[] codeConfigs, CodeProject project) + { + List codeFiles = new List(); + CodeModule[] modules = project.Modules.ToArray(); + CodeEntity[] entities = modules.SelectMany(m => m.Entities).ToArray(); + + foreach (GenCodeConfig codeConfig in codeConfigs.Where(m => m.MetadataType == MetadataType.Entity)) + { + foreach (CodeEntity entity in entities) + { + codeFiles.Add(await GenerateCode(codeConfig, entity)); + } + } + + foreach (GenCodeConfig codeConfig in codeConfigs.Where(m => m.MetadataType == MetadataType.Module)) + { + foreach (CodeModule module in modules) + { + codeFiles.Add(await GenerateCode(codeConfig, module)); + } + } + + foreach (GenCodeConfig codeConfig in codeConfigs.Where(m => m.MetadataType == MetadataType.Project)) + { + codeFiles.Add(await GenerateCode(codeConfig, project)); + } + + return codeFiles.OrderBy(m => m.FileName).ToArray(); + } + + /// + /// 生成项目元数据相关代码 + /// 代码配置 + /// 项目元数据 + /// + public Task GenerateCode(GenCodeConfig codeConfig, CodeProject project) + { + string fileName = codeConfig.GetCodeFileName(project); + return GenerateCodeCore(codeConfig, project, fileName); + } + + /// + /// 生成模块元数据相关代码 + /// 代码配置 + /// 模块元数据 + /// + public Task GenerateCode(GenCodeConfig codeConfig, CodeModule module) + { + string fileName = codeConfig.GetCodeFileName(module); + return GenerateCodeCore(codeConfig, module, fileName); + } + + /// + /// 生成实体元数据相关代码 + /// 代码配置 + /// 实体元数据 + /// + public Task GenerateCode(GenCodeConfig codeConfig, CodeEntity entity) + { + string fileName = codeConfig.GetCodeFileName(entity); + return GenerateCodeCore(codeConfig, entity, fileName); + } + + /// + /// 生成代码 + /// + /// 代码配置 + /// 代码数据模型 + /// 代码输出文件 + /// + protected virtual async Task GenerateCodeCore(GenCodeConfig codeConfig, object model, string fileName) + { + StringBuilder sb = new StringBuilder(); + await using TextWriter writer = new StringWriter(sb); + if (codeConfig.TemplateType == null) + { + if (codeConfig.TemplateFile == null || !File.Exists(codeConfig.TemplateFile)) + { + throw new OsharpException($"代码配置“{codeConfig.Name}”的模板文件“{codeConfig.TemplateFile}”不存在"); + } + + string templateSource = await File.ReadAllTextAsync(codeConfig.TemplateFile); + TemplateDescriptor descriptor = Razor.Compile(templateSource); + await descriptor.RenderAsync(writer, model); + } + else + { + ITemplate template = (ITemplate)(Activator.CreateInstance(codeConfig.TemplateType) + ?? throw new OsharpException($"代码配置“{codeConfig.Name}”的模板类型实例化失败")); + template.Model = model; + template.Output = writer; + await template.ExecuteAsync(); + } + + string codeSource = sb.ToString(); + + CodeFile codeFile = new CodeFile() + { + CodeConfig = codeConfig, + SourceCode = codeSource, + FileName = fileName + }; + return codeFile; + } + } +} diff --git a/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj b/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj index 8c70e87ec8741b02cc318f08cbd9646a84ab87bd..e7d80575cf64b73b07ccdea2f4df2b4e37c84840 100644 --- a/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj +++ b/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj @@ -1,14 +1,29 @@ - net5.0-windows + net5.0 - - + + + - + + + DataService.cs + + + + + + + + + + <_Parameter1>OSharp.CodeConsoles + + diff --git a/src/OSharp.CodeGeneration/Services/DataPack.cs b/src/OSharp.CodeGeneration/Services/DataPack.cs new file mode 100644 index 0000000000000000000000000000000000000000..0a01300c96ad2e7126747bc00e9018e94e901217 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataPack.cs @@ -0,0 +1,20 @@ +using Microsoft.Extensions.DependencyInjection; + +using OSharp.Core.Packs; + + +namespace OSharp.CodeGeneration.Services +{ + public class DataPack : OsharpPack + { + /// 将模块服务添加到依赖注入服务容器中 + /// 依赖注入服务容器 + /// + public override IServiceCollection AddServices(IServiceCollection services) + { + services.AddScoped(); + + return base.AddServices(services); + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeEntity.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeEntity.cs new file mode 100644 index 0000000000000000000000000000000000000000..a6f182d2d351daa6a2d281b47996dc7a0a1d258f --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeEntity.cs @@ -0,0 +1,126 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-07 1:20 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Extensions; +using OSharp.Mapping; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 代码实体信息查询数据集 + /// + public IQueryable CodeEntities => EntityRepository.QueryAsNoTracking(); + + /// + /// 检查代码实体信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码实体信息编号 + /// 代码实体信息是否存在 + public Task CheckCodeEntityExists(Expression> predicate, Guid id = default) + { + return EntityRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 更新代码实体信息信息 + /// + /// 包含更新信息的代码实体信息DTO信息 + /// 业务操作结果 + public async Task UpdateCodeEntities(params CodeEntity[] entities) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var entity in entities) + { + entity.Validate(); + CodeModule module = await ModuleRepository.GetAsync(entity.ModuleId); + if (module == null) + { + return new OperationResult(OperationResultType.Error, $"编号为“{entity.ModuleId}”的模块信息不存在"); + } + + if (await CheckCodeEntityExists(m => m.Name == entity.Name && m.ModuleId == entity.ModuleId, entity.Id)) + { + return new OperationResult(OperationResultType.Error, $"模块“{module.Name}”中名称为“{entity.Name}”的实体信息已存在"); + } + + int count; + if (entity.Id == default) + { + count = await EntityRepository.InsertAsync(entity); + } + else + { + CodeEntity existing = await EntityRepository.GetAsync(entity.Id); + existing = entity.MapTo(existing); + count = await EntityRepository.UpdateAsync(existing); + } + + if (count > 0) + { + names.Add(entity.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"实体“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除代码实体信息信息 + /// + /// 要删除的代码实体信息编号 + /// 业务操作结果 + public async Task DeleteCodeEntities(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var entity = EntityRepository.Query(m => m.Id == id).Select(m => new { D = m, PropertyCount = m.Properties.Count() }) + .FirstOrDefault(); + if (entity == null) + { + return null; + } + + if (entity.PropertyCount > 0) + { + return new OperationResult(OperationResultType.Error, $"实体“{entity.D.Name}”包含着 {entity.PropertyCount} 个属性,请先删除下属属性信息"); + } + + int count = await EntityRepository.DeleteAsync(entity.D); + if (count > 0) + { + names.Add(entity.D.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"实体“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeForeign.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeForeign.cs new file mode 100644 index 0000000000000000000000000000000000000000..3ea4f9039978fcfdffa62c27f0b91539e9df4f42 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeForeign.cs @@ -0,0 +1,119 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 23:22 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Extensions; +using OSharp.Mapping; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 实体外键信息查询数据集 + /// + public IQueryable CodeForeigns => ForeignRepository.QueryAsNoTracking(); + + /// + /// 检查实体外键信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的实体外键信息编号 + /// 实体外键信息是否存在 + public Task CheckCodeForeignExists(Expression> predicate, Guid id = default) + { + return ForeignRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 更新实体外键信息信息 + /// + /// 包含更新信息的实体外键信息 + /// 业务操作结果 + public async Task UpdateCodeForeigns(params CodeForeign[] foreigns) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var foreign in foreigns) + { + foreign.Validate(); + CodeEntity entity = await EntityRepository.GetAsync(foreign.EntityId); + if (entity == null) + { + return new OperationResult(OperationResultType.Error, $"编号为“{foreign.EntityId}”的实体信息不存在"); + } + if (await CheckCodeForeignExists(m => m.SelfNavigation == foreign.SelfNavigation && m.EntityId == foreign.EntityId, entity.Id)) + { + return new OperationResult(OperationResultType.Error, $"实体“{entity.Name}”中名称为“{foreign.SelfNavigation}”的外键信息已存在"); + } + + int count; + if (foreign.Id == default) + { + count = await ForeignRepository.InsertAsync(foreign); + } + else + { + CodeForeign existing = await ForeignRepository.GetAsync(foreign.Id); + existing = foreign.MapTo(existing); + count = await ForeignRepository.UpdateAsync(existing); + } + + if (count > 0) + { + names.Add($"{entity.Name}-{foreign.SelfNavigation}"); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"导航属性“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除实体外键信息信息 + /// + /// 要删除的实体外键信息编号 + /// 业务操作结果 + public async Task DeleteCodeForeigns(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var entity = ForeignRepository.Query(m => m.Id == id).Select(m => new { D = m, EntityName = m.Entity.Name }).FirstOrDefault(); + if (entity == null) + { + continue; + } + + int count = await ForeignRepository.DeleteAsync(entity.D); + if (count > 0) + { + names.Add($"{entity.EntityName}-{entity.D.SelfNavigation}"); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"实体外键“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeModule.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeModule.cs new file mode 100644 index 0000000000000000000000000000000000000000..d53819aa9abe87b50776363a741c7bf566565849 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeModule.cs @@ -0,0 +1,153 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-06 12:49 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Extensions; +using OSharp.Mapping; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 代码模块信息查询数据集 + /// + public IQueryable CodeModules => ModuleRepository.QueryAsNoTracking(); + + /// + /// 检查代码模块信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码模块信息编号 + /// 代码模块信息是否存在 + public Task CheckCodeModuleExists(Expression> predicate, Guid id = default) + { + return ModuleRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 添加代码模块信息信息 + /// + /// 要添加的代码模块信息 + /// 业务操作结果 + public async Task CreateCodeModules(params CodeModule[] modules) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (CodeModule module in modules) + { + module.Validate(); + CodeProject project = await ProjectRepository.GetAsync(module.ProjectId); + if (project == null) + { + return new OperationResult(OperationResultType.Error, $"编号为“{module.ProjectId}”的项目信息不存在"); + } + + if (await CheckCodeModuleExists(m => m.Name == module.Name && m.ProjectId == module.ProjectId)) + { + return new OperationResult(OperationResultType.Error, $"项目“{project.Name}”中名称为“{module.Name}”的模块信息已存在"); + } + + int count = await ModuleRepository.InsertAsync(module); + if (count > 0) + { + names.Add(module.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"模块“{names.ExpandAndToString()}”创建成功") + : OperationResult.NoChanged; + } + + /// + /// 更新代码模块信息信息 + /// + /// 包含更新信息的代码模块信息 + /// 业务操作结果 + public async Task UpdateCodeModules(params CodeModule[] modules) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (CodeModule module in modules) + { + module.Validate(); + CodeProject project = await ProjectRepository.GetAsync(module.ProjectId); + if (project == null) + { + return new OperationResult(OperationResultType.Error, $"编号为“{module.ProjectId}”的项目信息不存在"); + } + + if (await CheckCodeModuleExists(m => m.Name == module.Name && m.ProjectId == module.ProjectId, module.Id)) + { + return new OperationResult(OperationResultType.Error, $"项目“{project.Name}”中名称为“{module.Name}”的模块信息已存在"); + } + + CodeModule existing = await ModuleRepository.GetAsync(module.Id); + existing = module.MapTo(existing); + int count = await ModuleRepository.UpdateAsync(existing); + if (count > 0) + { + names.Add(module.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"模块“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除代码模块信息信息 + /// + /// 要删除的代码模块信息编号 + /// 业务操作结果 + public async Task DeleteCodeModules(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var module = ModuleRepository.Query(m => m.Id == id).Select(m => new { D = m, EntityCount = m.Entities.Count() }) + .FirstOrDefault(); + if (module == null) + { + return null; + } + + if (module.EntityCount > 0) + { + return new OperationResult(OperationResultType.Error, $"模块“{module.D.Name}”包含着 {module.EntityCount} 个实体,请先删除下属实体信息"); + } + + int count = await ModuleRepository.DeleteAsync(module.D); + if (count > 0) + { + names.Add(module.D.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"模块“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeProject.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeProject.cs new file mode 100644 index 0000000000000000000000000000000000000000..2ba894dcd7825aaa5f9ea9a521ba25849e00de94 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeProject.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Extensions; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 项目信息查询数据集 + /// + public IQueryable CodeProjects => ProjectRepository.QueryAsNoTracking(); + + /// + /// 检查项目信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的项目信息编号 + /// 项目信息是否存在 + public Task CheckCodeProjectExists(Expression> predicate, Guid id = default) + { + return ProjectRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 添加项目信息信息 + /// + /// 要添加的项目信息 + /// 业务操作结果 + public async Task CreateCodeProjects(params CodeProject[] projects) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (CodeProject project in projects) + { + project.Validate(); + if (await CheckCodeProjectExists(m => m.Name == project.Name)) + { + return new OperationResult(OperationResultType.Error, $"名称为“{project.Name}”的项目信息已存在"); + } + + int count = await ProjectRepository.InsertAsync(project); + if (count > 0) + { + names.Add(project.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"项目“{names.ExpandAndToString()}”创建成功") + : OperationResult.NoChanged; + } + + /// + /// 更新项目信息信息 + /// + /// 包含更新信息的项目信息 + /// 业务操作结果 + public async Task UpdateCodeProjects(params CodeProject[] projects) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (CodeProject project in projects) + { + project.Validate(); + if (await CheckCodeProjectExists(m => m.Name == project.Name, project.Id)) + { + return new OperationResult(OperationResultType.Error, $"名称为“{project.Name}”的项目信息已存在"); + } + + int count = await ProjectRepository.UpdateAsync(project); + if (count > 0) + { + names.Add(project.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"项目“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除项目信息信息 + /// + /// 要删除的项目信息编号 + /// 业务操作结果 + public async Task DeleteCodeProjects(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var project = ProjectRepository.Query(m => m.Id == id).Select(m => new { D = m, ModuleCount = m.Modules.Count() }) + .FirstOrDefault(); + if (project == null) + { + return null; + } + + if (project.ModuleCount > 0) + { + return new OperationResult(OperationResultType.Error, $"项目“{project.D.Name}”包含着 {project.ModuleCount} 个模块,请先删除下属模块信息"); + } + + int count = await ProjectRepository.DeleteAsync(project.D); + if (count > 0) + { + names.Add(project.D.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"项目“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeProperty.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeProperty.cs new file mode 100644 index 0000000000000000000000000000000000000000..9b778dce10e8201f85d246ba3ee544b40a4c6840 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeProperty.cs @@ -0,0 +1,120 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 23:10 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Extensions; +using OSharp.Mapping; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 实体属性信息查询数据集 + /// + public IQueryable CodeProperties => PropertyRepository.QueryAsNoTracking(); + + /// + /// 检查实体属性信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的实体属性信息编号 + /// 实体属性信息是否存在 + public Task CheckCodePropertyExists(Expression> predicate, Guid id = default) + { + return PropertyRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 更新实体属性信息信息 + /// + /// 包含更新信息的实体属性信息 + /// 业务操作结果 + public async Task UpdateCodeProperties(params CodeProperty[] properties) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var property in properties) + { + property.Validate(); + CodeEntity entity = await EntityRepository.GetAsync(property.EntityId); + if (entity == null) + { + return new OperationResult(OperationResultType.Error, $"编号为“{property.EntityId}”的实体信息不存在"); + } + + if (await CheckCodePropertyExists(m => m.Name == property.Name && m.EntityId == property.EntityId, property.Id)) + { + return new OperationResult(OperationResultType.Error, $"实体“{entity.Name}”中名称为“{property.Name}”的属性信息已存在"); + } + + int count; + if (property.Id == default) + { + count = await PropertyRepository.InsertAsync(property); + } + else + { + CodeProperty existing = await PropertyRepository.GetAsync(property.Id); + existing = property.MapTo(existing); + count = await PropertyRepository.UpdateAsync(existing); + } + + if (count > 0) + { + names.Add(property.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"属性“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除实体属性信息信息 + /// + /// 要删除的实体属性信息编号 + /// 业务操作结果 + public async Task DeleteCodeProperties(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var property = await PropertyRepository.GetAsync(id); + if (property == null) + { + continue; + } + + int count = await PropertyRepository.DeleteAsync(property); + if (count > 0) + { + names.Add(property.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"属性“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.CodeSetting.cs b/src/OSharp.CodeGeneration/Services/DataService.CodeSetting.cs new file mode 100644 index 0000000000000000000000000000000000000000..62d09eebb493553a74f32bc3cfa045c52df191a7 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.CodeSetting.cs @@ -0,0 +1,120 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 22:45 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Collections; +using OSharp.Data; +using OSharp.Exceptions; +using OSharp.Extensions; +using OSharp.Mapping; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService + { + /// + /// 获取 代码设置信息查询数据集 + /// + public IQueryable CodeSettings => SettingRepository.QueryAsNoTracking(); + + /// + /// 检查代码设置信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码设置信息编号 + /// 代码设置信息是否存在 + public Task CheckCodeSettingExists(Expression> predicate, Guid id = default) + { + return SettingRepository.CheckExistsAsync(predicate, id); + } + + /// + /// 更新代码设置信息信息 + /// + /// 包含更新信息的代码设置信息 + /// 业务操作结果 + public async Task UpdateCodeSettings(params CodeSetting[] entities) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var entity in entities) + { + entity.Validate(); + if (await CheckCodeSettingExists(m=>m.Name == entity.Name, entity.Id)) + { + return new OperationResult(OperationResultType.Error, $"名称为“{entity.Name}”的代码设置已存在"); + } + + int count; + if (entity.Id == default) + { + count = await SettingRepository.InsertAsync(entity); + } + else + { + CodeSetting entity1 = await SettingRepository.GetAsync(entity.Id); + entity1 = entity.MapTo(entity1); + count = await SettingRepository.UpdateAsync(entity1); + } + + if (count > 0) + { + names.Add(entity.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"代码设置“{names.ExpandAndToString()}”更新成功") + : OperationResult.NoChanged; + } + + /// + /// 删除代码设置信息信息 + /// + /// 要删除的代码设置信息编号 + /// 业务操作结果 + public async Task DeleteCodeSettings(params Guid[] ids) + { + List names = new List(); + UnitOfWork.EnableTransaction(); + foreach (var id in ids) + { + var entity = await SettingRepository.GetAsync(id); + if (entity == null) + { + continue; + } + + if (entity.IsSystem) + { + throw new OsharpException($"代码设置“{entity.Name}”是系统设置,不能删除"); + } + + int count = await SettingRepository.DeleteAsync(entity); + if (count > 0) + { + names.Add(entity.Name); + } + } + + await UnitOfWork.CommitAsync(); + return names.Count > 0 + ? new OperationResult(OperationResultType.Success, $"代码设置“{names.ExpandAndToString()}”删除成功") + : OperationResult.NoChanged; + } + } +} diff --git a/src/OSharp.CodeGeneration/Services/DataService.cs b/src/OSharp.CodeGeneration/Services/DataService.cs new file mode 100644 index 0000000000000000000000000000000000000000..4060cd8da5363049d487fc2058c3d2a7a07b7c3a --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/DataService.cs @@ -0,0 +1,34 @@ +using System; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Services +{ + public partial class DataService : IDataContract + { + private readonly IServiceProvider _serviceProvider; + + public DataService(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + protected IUnitOfWork UnitOfWork => _serviceProvider.GetUnitOfWork(); + + protected IRepository ProjectRepository => _serviceProvider.GetService>(); + + protected IRepository ModuleRepository => _serviceProvider.GetService>(); + + protected IRepository EntityRepository => _serviceProvider.GetService>(); + + protected IRepository PropertyRepository => _serviceProvider.GetService>(); + + protected IRepository SettingRepository => _serviceProvider.GetService>(); + + protected IRepository ForeignRepository => _serviceProvider.GetService>(); + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeEntity.cs similarity index 47% rename from src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeEntity.cs index 0140a6a488eff70f82ae44b18b8d87c8699f46aa..73692a96a78ffcf0fc433f22f523703f14a6bbaf 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeEntity.cs @@ -10,39 +10,101 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using OSharp.Entity; +using OSharp.Mapping; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { /// /// 实体类:代码实体信息 /// [Description("代码实体信息")] [TableNamePrefix("CodeGen")] - public class CodeEntity : EntityBase + [MapTo(typeof(CodeEntity))] + public class CodeEntity : EntityBase, ILockable { /// /// 获取或设置 类型名称 /// + [Required(), StringLength(200)] public string Name { get; set; } /// /// 获取或设置 类型显示名称 /// + [Required(), StringLength(200)] public string Display { get; set; } /// /// 获取或设置 主键类型全名 /// + [Required(), StringLength(500)] public string PrimaryKeyTypeFullName { get; set; } + /// + /// 获取或设置 是否可列表 + /// + public bool Listable { get; set; } + + /// + /// 获取或设置 是否可添加 + /// + public bool Addable { get; set; } + + /// + /// 获取或设置 是否可更新 + /// + public bool Updatable { get; set; } + + /// + /// 获取或设置 是否可删除 + /// + public bool Deletable { get; set; } + /// /// 获取或设置 是否数据权限控制 /// public bool IsDataAuth { get; set; } + /// + /// 获取或设置 是否有创建时间 + /// + public bool HasCreatedTime { get; set; } + + /// + /// 获取或设置 是否有锁定 + /// + public bool HasLocked { get; set; } + + /// + /// 获取或设置 是否有软删除 + /// + public bool HasSoftDeleted { get; set; } + + /// + /// 获取或设置 是否有创建审计 + /// + public bool HasCreationAudited { get; set; } + + /// + /// 获取或设置 是否有更新审计 + /// + public bool HasUpdateAudited { get; set; } + + /// + /// 获取或设置 排序号 + /// + public int Order { get; set; } + + /// 获取或设置 创建时间 + public DateTime CreatedTime { get; set; } + + /// 获取或设置 是否锁定当前信息 + public bool IsLocked { get; set; } + /// /// 获取或设置 所属模块编号 /// diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeEntityConfiguration.cs similarity index 95% rename from src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeEntityConfiguration.cs index a137c56b3b92c2aaced48cffed8797806ab0f838..09d7b417531631bf2d5e4257ef5918a1d115c440 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeEntityConfiguration.cs @@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { public class CodeEntityConfiguration : EntityTypeConfigurationBase { diff --git a/src/OSharp.CodeGeneration/Services/Entities/CodeForeign.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeForeign.cs new file mode 100644 index 0000000000000000000000000000000000000000..2c6cb06da1ae64529cafef7301ecc415d5fbb985 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeForeign.cs @@ -0,0 +1,72 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 23:11 +// ----------------------------------------------------------------------- + +using System; +using System.ComponentModel; + +using Microsoft.EntityFrameworkCore; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Services.Entities +{ + /// + /// 实体类:外键信息 + /// + [Description("实体外键")] + [TableNamePrefix("CodeGen")] + public class CodeForeign : EntityBase + { + /// + /// 获取或设置 己方导航属性 + /// + public string SelfNavigation { get; set; } + + /// + /// 获取或设置 己方外键属性 + /// + public string SelfForeignKey { get; set; } + + /// + /// 获取或设置 对方实体 + /// + public string OtherEntity { get; set; } + + /// + /// 获取或设置 对方导航属性 + /// + public string OtherNavigation { get; set; } + + /// + /// 获取或设置 是否必须 + /// + public bool IsRequired { get; set; } + + /// + /// 获取或设置 关系数据删除行为 + /// + public DeleteBehavior? DeleteBehavior { get; set; } + + /// + /// 获取或设置 外键关系 + /// + public ForeignRelation ForeignRelation { get; set; } + + /// + /// 获取或设置 实体编号 + /// + public Guid EntityId { get; set; } + + /// + /// 获取或设置 所属实体信息 + /// + public virtual CodeEntity Entity { get; set; } + } +} diff --git a/src/OSharp.CodeGeneration/Services/Entities/CodeForeignConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeForeignConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..0d639357f6a0daef9f01894e41e90aa5103836f8 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeForeignConfiguration.cs @@ -0,0 +1,28 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 23:13 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Services.Entities +{ + public class CodeForeignConfiguration : EntityTypeConfigurationBase + { + /// 重写以实现实体类型各个属性的数据库配置 + /// 实体类型创建器 + public override void Configure(EntityTypeBuilder builder) + { + + } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeModule.cs similarity index 73% rename from src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeModule.cs index 99f25c4b34190f9366d53a97a1967cccc00b43dc..2ba80b8253a3811b7bb245706ef37b6114554720 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeModule.cs @@ -10,29 +10,43 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { /// /// 实体类:代码模块信息 /// [Description("代码模块信息")] [TableNamePrefix("CodeGen")] - public class CodeModule : EntityBase + public class CodeModule : EntityBase, ICreatedTime, ILockable { /// /// 获取或设置 模块名称 /// + [Required(), StringLength(200)] public string Name { get; set; } /// /// 获取或设置 模块显示名称 /// + [Required(), StringLength(200)] public string Display { get; set; } + /// + /// 获取或设置 排序号 + /// + public int Order { get; set; } + + /// 获取或设置 创建时间 + public DateTime CreatedTime { get; set; } + + /// 获取或设置 是否锁定当前信息 + public bool IsLocked { get; set; } + /// /// 获取或设置 所属项目编号 /// diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeModuleConfiguration.cs similarity index 95% rename from src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeModuleConfiguration.cs index d40ffc5a774ed5ecca21429059dac5c0539ebacf..57e3922700f4438564431ecda7bbcd6cc00cbac7 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeModuleConfiguration.cs @@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { public class CodeModuleConfiguration : EntityTypeConfigurationBase { diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeProject.cs similarity index 79% rename from src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeProject.cs index 2f4da4101011f0bd8eab8523eb5061f6c45cfa69..6af2f140a97efd6e638a555c150493562a70bdcc 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeProject.cs @@ -10,19 +10,20 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using OSharp.Data; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { /// /// 实体类:代码项目信息 /// [Description("代码项目信息")] [TableNamePrefix("CodeGen")] - public class CodeProject : EntityBase + public class CodeProject : EntityBase, ICreatedTime { public CodeProject() { @@ -32,36 +33,46 @@ namespace OSharp.CodeGeneration.Entities /// /// 获取或设置 项目名称 /// + [Required(), StringLength(200)] public string Name { get; set; } /// - /// 获取或设置 公司 + /// 获取或设置 项目命名空间前缀,通常形如“公司.项目” /// - public string Company { get; set; } + [Required(), StringLength(200)] + public string NamespacePrefix { get; set; } /// - /// 获取或设置 项目命名空间前缀,通常形如“公司.项目” + /// 获取或设置 公司 /// - public string NamespacePrefix { get; set; } + [StringLength(200)] + public string Company { get; set; } /// /// 获取或设置 站点地址 /// + [StringLength(500)] public string SiteUrl { get; set; } /// /// 获取或设置 创建者 /// + [StringLength(200)] public string Creator { get; set; } /// /// 获取或设置 Copyright /// + [StringLength(500)] public string Copyright { get; set; } + /// 获取或设置 创建时间 + public DateTime CreatedTime { get; set; } + /// /// 获取或设置 模块信息集合 /// public virtual ICollection Modules { get; set; } = new List(); + } } diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeProjectConfiguration.cs similarity index 92% rename from src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeProjectConfiguration.cs index 07aaa43cdf83f7a653b884f795e93064fd192a04..bc24e2e543aa85efc8d73c10352c823032dba482 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeProjectConfiguration.cs @@ -14,13 +14,14 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { public class CodeProjectConfiguration : EntityTypeConfigurationBase { /// 重写以实现实体类型各个属性的数据库配置 /// 实体类型创建器 public override void Configure(EntityTypeBuilder builder) - { } + { + } } } diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeProperty.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeProperty.cs similarity index 60% rename from src/OSharp.CodeGeneration/Data/Entities/CodeProperty.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeProperty.cs index 76991c8baddfb75e0684a02c489aa6fb1565b617..8937317ab12947030a1cb7c507d0c49e6e601cf4 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodeProperty.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeProperty.cs @@ -9,49 +9,68 @@ using System; using System.ComponentModel; +using System.ComponentModel.DataAnnotations; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { /// /// 实体类:代码实体属性信息 /// [Description("代码实体属性")] [TableNamePrefix("CodeGen")] - public class CodeProperty : EntityBase + public class CodeProperty : EntityBase, ICreatedTime, ILockable { /// /// 获取或设置 属性名称 /// + [Required(), StringLength(200)] public string Name { get; set; } + /// + /// 获取或设置 显示名称 + /// + [StringLength(200)] + public string Display { get; set; } + /// /// 获取或设置 属性类型名称 /// + [Required(), StringLength(500)] public string TypeName { get; set; } /// - /// 获取或设置 显示名称 + /// 获取或设置 是否可更新 /// - public string Display { get; set; } + public bool Updatable { get; set; } /// - /// 获取或设置 是否必须 + /// 获取或设置 是否可排序 /// - public bool? IsRequired { get; set; } + public bool Sortable { get; set; } /// - /// 获取或设置 最大长度 + /// 获取或设置 是否可筛选 /// - public int? MaxLength { get; set; } + public bool Filterable { get; set; } + + /// + /// 获取或设置 是否必须 + /// + public bool? IsRequired { get; set; } /// /// 获取或设置 最小长度 /// public int? MinLength { get; set; } + /// + /// 获取或设置 最大长度 + /// + public int? MaxLength { get; set; } + /// /// 获取或设置 是否值类型可空 /// @@ -67,6 +86,21 @@ namespace OSharp.CodeGeneration.Entities /// public bool IsForeignKey { get; set; } + /// + /// 获取或设置 是否导航属性 + /// + public bool IsNavigation { get; set; } + + /// + /// 获取或设置 关联实体 + /// + public string RelateEntity { get; set; } + + /// + /// 获取或设置 数据权限标识 + /// + public string DataAuthFlag { get; set; } + /// /// 获取或设置 是否包含在输入Dto /// @@ -77,6 +111,22 @@ namespace OSharp.CodeGeneration.Entities /// public bool IsOutputDto { get; set; } = true; + /// + /// 获取或设置 默认值 + /// + public string DefaultValue { get; set; } + + /// + /// 获取或设置 排序号 + /// + public int Order { get; set; } + + /// 获取或设置 创建时间 + public DateTime CreatedTime { get; set; } + + /// 获取或设置 是否锁定当前信息 + public bool IsLocked { get; set; } + /// /// 获取或设置 实体编号 /// @@ -86,5 +136,6 @@ namespace OSharp.CodeGeneration.Entities /// 获取或设置 所属实体信息 /// public virtual CodeEntity Entity { get; set; } + } } diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodePropertyConfiguration.cs similarity index 95% rename from src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodePropertyConfiguration.cs index 30083b81270b1b038efb58da4320c1e677692e98..7b354fc56d80203fb3496150a3f6032e9261d53a 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodePropertyConfiguration.cs @@ -14,7 +14,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; using OSharp.Entity; -namespace OSharp.CodeGeneration.Entities +namespace OSharp.CodeGeneration.Services.Entities { public class CodePropertyConfiguration : EntityTypeConfigurationBase { diff --git a/src/OSharp.CodeGeneration/Services/Entities/CodeSetting.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeSetting.cs new file mode 100644 index 0000000000000000000000000000000000000000..815282c700df2d19388b9752f5bae45082e3817c --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeSetting.cs @@ -0,0 +1,103 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 22:30 +// ----------------------------------------------------------------------- + +using System; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +using OSharp.CodeGeneration.Generates; +using OSharp.Entity; +using OSharp.Extensions; + + +namespace OSharp.CodeGeneration.Services.Entities +{ + /// + /// 实体类:代码设置 + /// + [Description("代码设置")] + [TableNamePrefix("CodeGen")] + public class CodeSetting : EntityBase, ILockable + { + /// + /// 获取或设置 配置名称 + /// + [Required, StringLength(200)] + public string Name { get; set; } + + /// + /// 获取或设置 元数据类型 + /// + public MetadataType MetadataType { get; set; } + + /// + /// 获取或设置 模板文件,默认内置,也可以由用户自定义加载 + /// + [Required, StringLength(500)] + public string TemplateFile { get; set; } + + /// + /// 获取或设置 排序 + /// + public int Order { get; set; } + + /// + /// 获取或设置 代码输出文件名格式 + /// + [Required, StringLength(300)] + public string OutputFileFormat { get; set; } + + /// + /// 获取或设置 是否只生成一次 + /// + public bool IsOnce { get; set; } + + /// + /// 获取或设置 系统类型 + /// + public bool IsSystem { get; set; } + + /// 获取或设置 是否锁定当前信息 + public bool IsLocked { get; set; } + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeProject project) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", project.NamespacePrefix) + .Replace("{Project.Name:Lower}", project.Name.UpperToLowerAndSplit()) + .Replace("{Project.Name}", project.Name); + return fileName; + } + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeModule module) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", module.Project.NamespacePrefix) + .Replace("{Module.Name:Lower}", module.Name.UpperToLowerAndSplit()) + .Replace("{Module.Name}", module.Name); + return fileName; + } + + /// + /// 获取项目代码输出文件名 + /// + public string GetCodeFileName(CodeEntity entity) + { + string fileName = OutputFileFormat.Replace("{Project.NamespacePrefix}", entity.Module.Project.NamespacePrefix) + .Replace("{Module.Name:Lower}", entity.Module.Name.UpperToLowerAndSplit()) + .Replace("{Entity.Name:Lower}", entity.Name.UpperToLowerAndSplit()) + .Replace("{Module.Name}", entity.Module.Name).Replace("{Entity.Name}", entity.Name); + return fileName; + } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs b/src/OSharp.CodeGeneration/Services/Entities/CodeSettingConfiguration.cs similarity index 55% rename from src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs rename to src/OSharp.CodeGeneration/Services/Entities/CodeSettingConfiguration.cs index ab5a80b4d0a311fc82769b93d0f1799249e9dc04..a42c521adbf3761f188b9a5fb0e891c02785ddce 100644 --- a/src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs +++ b/src/OSharp.CodeGeneration/Services/Entities/CodeSettingConfiguration.cs @@ -1,27 +1,26 @@ // ----------------------------------------------------------------------- -// -// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. // // http://www.osharp.org // 郭明锋 -// 2020-05-05 0:00 +// 2021-04-08 22:31 // ----------------------------------------------------------------------- using System; using Microsoft.EntityFrameworkCore.Metadata.Builders; -using OSharp.Core.Systems; using OSharp.Entity; -namespace OSharp.CodeGeneration.Data.Entities +namespace OSharp.CodeGeneration.Services.Entities { - public class KeyValueConfiguration : EntityTypeConfigurationBase + public class CodeSettingConfiguration : EntityTypeConfigurationBase { /// 重写以实现实体类型各个属性的数据库配置 /// 实体类型创建器 - public override void Configure(EntityTypeBuilder builder) + public override void Configure(EntityTypeBuilder builder) { } } } diff --git a/src/OSharp.CodeGeneration/Services/Entities/ForeignRelation.cs b/src/OSharp.CodeGeneration/Services/Entities/ForeignRelation.cs new file mode 100644 index 0000000000000000000000000000000000000000..20c3a3d3cfb03352ddb480c7edbd86cb44918043 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/Entities/ForeignRelation.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-07 22:26 +// ----------------------------------------------------------------------- + +namespace OSharp.CodeGeneration.Services.Entities +{ + /// + /// 外键关系 + /// + public enum ForeignRelation + { + /// + /// 多对一 + /// + ManyToOne, + + /// + /// 一对多 + /// + OneToMany, + + /// + /// 一对一 + /// + OneToOne, + + /// + /// 拥有单个子项关系 + /// + OwnsOne, + + /// + /// 拥有多个子项关系 + /// + OwnsMany + } +} diff --git a/src/OSharp.CodeGeneration/Services/IDataContract.cs b/src/OSharp.CodeGeneration/Services/IDataContract.cs new file mode 100644 index 0000000000000000000000000000000000000000..45680284108702dab20a9e7f691ce5b71f2b85d9 --- /dev/null +++ b/src/OSharp.CodeGeneration/Services/IDataContract.cs @@ -0,0 +1,229 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-06 12:45 +// ----------------------------------------------------------------------- + +using System; +using System.Linq; +using System.Linq.Expressions; +using System.Threading.Tasks; + +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Data; + + +namespace OSharp.CodeGeneration.Services +{ + /// + /// 数据服务契约 + /// + public interface IDataContract + { + #region 项目信息业务 + + /// + /// 获取 项目信息查询数据集 + /// + IQueryable CodeProjects { get; } + + /// + /// 检查项目信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的项目信息编号 + /// 项目信息是否存在 + Task CheckCodeProjectExists(Expression> predicate, Guid id = default); + + /// + /// 添加项目信息信息 + /// + /// 要添加的项目信息 + /// 业务操作结果 + Task CreateCodeProjects(params CodeProject[] projects); + + /// + /// 更新项目信息信息 + /// + /// 包含更新信息的项目信息 + /// 业务操作结果 + Task UpdateCodeProjects(params CodeProject[] projects); + + /// + /// 删除项目信息信息 + /// + /// 要删除的项目信息编号 + /// 业务操作结果 + Task DeleteCodeProjects(params Guid[] ids); + + #endregion + + #region 代码模块信息业务 + + /// + /// 获取 代码模块信息查询数据集 + /// + IQueryable CodeModules { get; } + + /// + /// 检查代码模块信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码模块信息编号 + /// 代码模块信息是否存在 + Task CheckCodeModuleExists(Expression> predicate, Guid id = default); + + /// + /// 添加代码模块信息信息 + /// + /// 要添加的代码模块信息 + /// 业务操作结果 + Task CreateCodeModules(params CodeModule[] modules); + + /// + /// 更新代码模块信息信息 + /// + /// 包含更新信息的代码模块信息 + /// 业务操作结果 + Task UpdateCodeModules(params CodeModule[] modules); + + /// + /// 删除代码模块信息信息 + /// + /// 要删除的代码模块信息编号 + /// 业务操作结果 + Task DeleteCodeModules(params Guid[] ids); + + #endregion + + #region 代码实体信息业务 + + /// + /// 获取 代码实体信息查询数据集 + /// + IQueryable CodeEntities { get; } + + /// + /// 检查代码实体信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码实体信息编号 + /// 代码实体信息是否存在 + Task CheckCodeEntityExists(Expression> predicate, Guid id = default); + + /// + /// 更新代码实体信息信息 + /// + /// 包含更新信息的代码实体信息 + /// 业务操作结果 + Task UpdateCodeEntities(params CodeEntity[] entities); + + /// + /// 删除代码实体信息信息 + /// + /// 要删除的代码实体信息编号 + /// 业务操作结果 + Task DeleteCodeEntities(params Guid[] ids); + + #endregion + + #region 实体属性信息业务 + + /// + /// 获取 实体属性信息查询数据集 + /// + IQueryable CodeProperties { get; } + + /// + /// 检查实体属性信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的实体属性信息编号 + /// 实体属性信息是否存在 + Task CheckCodePropertyExists(Expression> predicate, Guid id = default); + + /// + /// 更新实体属性信息信息 + /// + /// 包含更新信息的实体属性信息 + /// 业务操作结果 + Task UpdateCodeProperties(params CodeProperty[] properties); + + /// + /// 删除实体属性信息信息 + /// + /// 要删除的实体属性信息编号 + /// 业务操作结果 + Task DeleteCodeProperties(params Guid[] ids); + + #endregion + + #region 实体外键信息业务 + + /// + /// 获取 实体外键信息查询数据集 + /// + IQueryable CodeForeigns { get; } + + /// + /// 检查实体外键信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的实体外键信息编号 + /// 实体外键信息是否存在 + Task CheckCodeForeignExists(Expression> predicate, Guid id = default); + + /// + /// 更新实体外键信息信息 + /// + /// 包含更新信息的实体外键信息 + /// 业务操作结果 + Task UpdateCodeForeigns(params CodeForeign[] foreigns); + + /// + /// 删除实体外键信息信息 + /// + /// 要删除的实体外键信息编号 + /// 业务操作结果 + Task DeleteCodeForeigns(params Guid[] ids); + + #endregion + + + #region 代码设置信息业务 + + /// + /// 获取 代码设置信息查询数据集 + /// + IQueryable CodeSettings { get; } + + /// + /// 检查代码设置信息信息是否存在 + /// + /// 检查谓语表达式 + /// 更新的代码设置信息编号 + /// 代码设置信息是否存在 + Task CheckCodeSettingExists(Expression> predicate, Guid id = default); + + /// + /// 更新代码设置信息信息 + /// + /// 包含更新信息的代码设置信息 + /// 业务操作结果 + Task UpdateCodeSettings(params CodeSetting[] settings); + + /// + /// 删除代码设置信息信息 + /// + /// 要删除的代码设置信息编号 + /// 业务操作结果 + Task DeleteCodeSettings(params Guid[] ids); + + #endregion + + + } +} diff --git a/src/OSharp.CodeGeneration/Templates/TestTemplate.cshtml b/src/OSharp.CodeGeneration/Templates/TestTemplate.cshtml new file mode 100644 index 0000000000000000000000000000000000000000..b7d804657d2c187646aaff4fd54143d330fc43ea --- /dev/null +++ b/src/OSharp.CodeGeneration/Templates/TestTemplate.cshtml @@ -0,0 +1,17 @@ +@inherits TemplateBase +@namespace OSharp.CodeGeneration.Templates + +@using System +@using System.Threading.Tasks +@using Microsoft.AspNetCore.Razor.Language.Intermediate +@using Microsoft.EntityFrameworkCore +@using MiniRazor +@using OSharp.Extensions; +@using OSharp.CodeGeneration.Services.Entities +@{ CodeModule module = Model; } +namespace @(module.Namespace) +{ + public particl interface I@(module.Name)Contract + { + } +} diff --git a/src/OSharp.CodeGeneration/Utils/TypeHelper.cs b/src/OSharp.CodeGeneration/Utils/TypeHelper.cs new file mode 100644 index 0000000000000000000000000000000000000000..143ae4799c14bf476c80fe7fb1527bc82d19dcd5 --- /dev/null +++ b/src/OSharp.CodeGeneration/Utils/TypeHelper.cs @@ -0,0 +1,81 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 19:44 +// ----------------------------------------------------------------------- + +using OSharp.Data; + + +namespace OSharp.CodeGeneration.Utils +{ + /// + /// 类型辅助操作 + /// + public static class TypeHelper + { + public static string GetNamespace(string fullName) + { + int index = fullName.LastIndexOf('.'); + if (index > 0) + { + return fullName.Substring(0, index); + } + + return null; + } + + /// + /// 获取属性表示类型的简单类型,如 System.String 返回 string + /// + public static string ToSingleTypeName(string fullName, bool isNullable = false) + { + Check.NotNull(fullName, nameof(fullName)); + int index = fullName.LastIndexOf('.'); + string name = fullName.Substring(index + 1); + switch (fullName) + { + case "System.Byte": + name = "byte"; + break; + case "System.Int32": + name = "int"; + break; + case "System.Int64": + name = "long"; + break; + case "System.Decimal": + name = "decimal"; + break; + case "System.Single": + name = "float"; + break; + case "System.Double": + name = "double"; + break; + case "System.String": + name = "string"; + break; + case "System.Guid": + name = "Guid"; + break; + case "System.Boolean": + name = "bool"; + break; + case "System.DateTime": + name = "DateTime"; + break; + } + + if (isNullable) + { + name = name + "?"; + } + + return name; + } + } +} diff --git a/src/OSharp.CodeGenerator/App.xaml b/src/OSharp.CodeGenerator/App.xaml index 6779d8b03b01dc64df7f73c88eccbcc09e61ce36..34cf1ad861e51dac8ffa046cfe1cfeb0edd4bc9c 100644 --- a/src/OSharp.CodeGenerator/App.xaml +++ b/src/OSharp.CodeGenerator/App.xaml @@ -1,4 +1,4 @@ - - + diff --git a/src/OSharp.CodeGenerator/Bootstrapper.cs b/src/OSharp.CodeGenerator/Bootstrapper.cs index d97bbbf867e2c79bd5067c73b8b4d0498fb0330f..a71d8870d889d2d94c8505e7cbebf7da637502b8 100644 --- a/src/OSharp.CodeGenerator/Bootstrapper.cs +++ b/src/OSharp.CodeGenerator/Bootstrapper.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2020 OSharp. All rights reserved. // @@ -10,6 +10,8 @@ using Microsoft.Extensions.DependencyInjection; using OSharp.CodeGenerator.Views; +using OSharp.CodeGenerator.Views.Modules; +using OSharp.CodeGenerator.Views.Projects; using OSharp.Wpf.Data; using OSharp.Wpf.Stylet; @@ -33,5 +35,17 @@ namespace OSharp.CodeGenerator MainViewModel main = IoC.Get(); Output.StatusBar = msg => main.StatusBar.Message = msg; } + + /// Called just after the root View has been displayed + protected override void OnLaunch() + { + ProjectListViewModel projectList = IoC.Get(); + ModuleListViewModel moduleList = IoC.Get(); + + if (moduleList.Project == null && !projectList.IsShow) + { + projectList.Show(); + } + } } } diff --git a/src/OSharp.CodeGenerator/Data/AutoMapperConfiguration.cs b/src/OSharp.CodeGenerator/Data/AutoMapperConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..42f80840e7348d95ef1f9b17bc50d2f54ffb297a --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/AutoMapperConfiguration.cs @@ -0,0 +1,48 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-06 13:13 +// ----------------------------------------------------------------------- + +using System; +using System.Runtime.Serialization; + +using AutoMapper.Configuration; + +using OSharp.AutoMapper; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Views; +using OSharp.CodeGenerator.Views.Entities; +using OSharp.CodeGenerator.Views.Modules; +using OSharp.CodeGenerator.Views.Properties; + + +namespace OSharp.CodeGenerator.Data +{ + public class AutoMapperConfiguration : AutoMapperTupleBase + { + /// 创建对象映射 + public override void CreateMap() + { + CreateMap().ForMember(e => e.ProjectId, opt => opt.MapFrom(vm => vm.Project.Id)) + .ForMember(e => e.Project, opt => opt.Ignore()); + CreateMap().ForMember(vm => vm.Namespace, opt => opt.Ignore()) + .ForMember(vm => vm.Project, opt => opt.Ignore()); + CreateMap().ForMember(vm => vm.Namespace, opt => opt.Ignore()) + .ForMember(vm => vm.Project, opt => opt.Ignore()); + + CreateMap().ForMember(e => e.ModuleId, opt => opt.MapFrom(vm => vm.Module.Id)) + .ForMember(e => e.Module, opt => opt.Ignore()); + CreateMap().ForMember(vm => vm.Module, opt => opt.Ignore()); + CreateMap().ForMember(vm => vm.Module, opt => opt.Ignore()); + + CreateMap().ForMember(e => e.EntityId, opt => opt.MapFrom(vm => vm.Entity.Id)) + .ForMember(e=>e.Entity, opt=>opt.Ignore()); + CreateMap().ForMember(vm => vm.Entity, opt => opt.Ignore()); + CreateMap().ForMember(vm => vm.Entity, opt => opt.Ignore()); + } + } +} diff --git a/src/OSharp.CodeGenerator/Data/Helper.cs b/src/OSharp.CodeGenerator/Data/Helper.cs new file mode 100644 index 0000000000000000000000000000000000000000..cc3fde506bcc364321bea9d566fc217baa3bddb7 --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/Helper.cs @@ -0,0 +1,62 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-07 19:29 +// ----------------------------------------------------------------------- + +using System; + +using Notifications.Wpf.Core; + +using OSharp.CodeGenerator.Views; +using OSharp.Data; +using OSharp.Wpf.Stylet; + + +namespace OSharp.CodeGenerator.Data +{ + public static class Helper + { + /// + /// 输出信息到状态栏 + /// + /// 消息 + public static void Output(string message) + { + IoC.Get().Message = message; + } + + /// + /// 消息提示 + /// + public static void Notify(OperationResult result) + { + NotificationType type; + switch (result.ResultType) + { + case OperationResultType.NoChanged: + type = NotificationType.Information; + break; + case OperationResultType.Success: + type = NotificationType.Success; + break; + default: + type = NotificationType.Error; + break; + } + Notify(result.Message, type); + } + + /// + /// 消息提示 + /// + public static void Notify(string message, NotificationType type, string title = "消息提示") + { + MainViewModel main = IoC.Get(); + main.Notify(message, type, title); + } + } +} diff --git a/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs b/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs deleted file mode 100644 index e5d169e322f181d3b0943f64573dba4840c82b49..0000000000000000000000000000000000000000 --- a/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using Microsoft.Extensions.DependencyInjection; -using OSharp.Entity; - - -namespace OSharp.CodeGenerator.Data -{ - public class SqliteDesignTimeDefaultDbContextFactory : DesignTimeDbContextFactoryBase - { - public SqliteDesignTimeDefaultDbContextFactory() : base(null) - { } - - public SqliteDesignTimeDefaultDbContextFactory(IServiceProvider serviceProvider) - : base(serviceProvider) - { } - - protected override IServiceProvider CreateDesignTimeServiceProvider() - { - IServiceCollection services = new ServiceCollection(); - Startup startup = new Startup(); - startup.ConfigureServices(services); - IServiceProvider provider = services.BuildServiceProvider(); - return provider; - } - } -} diff --git a/src/OSharp.CodeGenerator/Data/Startup.cs b/src/OSharp.CodeGenerator/Data/Startup.cs deleted file mode 100644 index bc0e8f93c433f0745730d6819f57e64e0fe5d5ce..0000000000000000000000000000000000000000 --- a/src/OSharp.CodeGenerator/Data/Startup.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.Extensions.DependencyInjection; - -namespace OSharp.CodeGenerator.Data -{ - class Startup - { - public void ConfigureServices(IServiceCollection services) - { - } - } -} diff --git a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs b/src/OSharp.CodeGenerator/Migrations/20210403122046_Init.Designer.cs similarity index 81% rename from src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs rename to src/OSharp.CodeGenerator/Migrations/20210403122046_Init.Designer.cs index 507b666c9a5aa197791d8eabc321487c82fc382c..42b02ce9fa47629b97542941d3de6a360d97f5bd 100644 --- a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs +++ b/src/OSharp.CodeGenerator/Migrations/20210403122046_Init.Designer.cs @@ -9,14 +9,14 @@ using OSharp.Entity; namespace OSharp.CodeGenerator.Migrations { [DbContext(typeof(DefaultDbContext))] - [Migration("20200826024343_Init")] + [Migration("20210403122046_Init")] partial class Init { protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.7"); + .HasAnnotation("ProductVersion", "5.0.4"); modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => { @@ -43,7 +43,7 @@ namespace OSharp.CodeGenerator.Migrations b.HasIndex("TypeName") .IsUnique() - .HasName("ClassFullNameIndex"); + .HasDatabaseName("ClassFullNameIndex"); b.ToTable("Auth_EntityInfo"); }); @@ -90,6 +90,9 @@ namespace OSharp.CodeGenerator.Migrations b.Property("IsLocked") .HasColumnType("INTEGER"); + b.Property("IsSlaveDatabase") + .HasColumnType("INTEGER"); + b.Property("Name") .HasColumnType("TEXT"); @@ -97,7 +100,7 @@ namespace OSharp.CodeGenerator.Migrations b.HasIndex("Area", "Controller", "Action") .IsUnique() - .HasName("AreaControllerActionIndex"); + .HasDatabaseName("AreaControllerActionIndex"); b.ToTable("Auth_Function"); }); @@ -109,6 +112,8 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("TEXT"); b.Property("Display") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("IsDataAuth") @@ -118,9 +123,13 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("PrimaryKeyTypeFullName") + .IsRequired() + .HasMaxLength(500) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -137,9 +146,13 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("TEXT"); b.Property("Display") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("ProjectId") @@ -159,21 +172,29 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("TEXT"); b.Property("Company") + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("Copyright") + .HasMaxLength(500) .HasColumnType("TEXT"); b.Property("Creator") + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("NamespacePrefix") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("SiteUrl") + .HasMaxLength(500) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -188,6 +209,8 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("TEXT"); b.Property("Display") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("EntityId") @@ -218,9 +241,13 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("INTEGER"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("TypeName") + .IsRequired() + .HasMaxLength(500) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -251,6 +278,10 @@ namespace OSharp.CodeGenerator.Migrations b.HasKey("Id"); + b.HasIndex("Key") + .IsUnique() + .HasDatabaseName("KeyIndex"); + b.ToTable("Systems_KeyValue"); }); @@ -261,6 +292,8 @@ namespace OSharp.CodeGenerator.Migrations .HasForeignKey("ModuleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Module"); }); modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => @@ -270,6 +303,8 @@ namespace OSharp.CodeGenerator.Migrations .HasForeignKey("ProjectId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Project"); }); modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => @@ -279,6 +314,23 @@ namespace OSharp.CodeGenerator.Migrations .HasForeignKey("EntityId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.Navigation("Properties"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.Navigation("Entities"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProject", b => + { + b.Navigation("Modules"); }); #pragma warning restore 612, 618 } diff --git a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs b/src/OSharp.CodeGenerator/Migrations/20210403122046_Init.cs similarity index 51% rename from src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs rename to src/OSharp.CodeGenerator/Migrations/20210403122046_Init.cs index d3bb02f2232f6bec256b2b000ba50f6162a4b7e8..f02818bfeb927ee63e3595239d9c58f1fb2c3dc1 100644 --- a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs +++ b/src/OSharp.CodeGenerator/Migrations/20210403122046_Init.cs @@ -11,11 +11,11 @@ namespace OSharp.CodeGenerator.Migrations name: "Auth_EntityInfo", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: false), - TypeName = table.Column(nullable: false), - AuditEnabled = table.Column(nullable: false), - PropertyJson = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: false), + TypeName = table.Column(type: "TEXT", nullable: false), + AuditEnabled = table.Column(type: "INTEGER", nullable: false), + PropertyJson = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -26,20 +26,21 @@ namespace OSharp.CodeGenerator.Migrations name: "Auth_Function", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - Area = table.Column(nullable: true), - Controller = table.Column(nullable: true), - Action = table.Column(nullable: true), - IsController = table.Column(nullable: false), - IsAjax = table.Column(nullable: false), - AccessType = table.Column(nullable: false), - IsAccessTypeChanged = table.Column(nullable: false), - AuditOperationEnabled = table.Column(nullable: false), - AuditEntityEnabled = table.Column(nullable: false), - CacheExpirationSeconds = table.Column(nullable: false), - IsCacheSliding = table.Column(nullable: false), - IsLocked = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", nullable: true), + Area = table.Column(type: "TEXT", nullable: true), + Controller = table.Column(type: "TEXT", nullable: true), + Action = table.Column(type: "TEXT", nullable: true), + IsController = table.Column(type: "INTEGER", nullable: false), + IsAjax = table.Column(type: "INTEGER", nullable: false), + AccessType = table.Column(type: "INTEGER", nullable: false), + IsAccessTypeChanged = table.Column(type: "INTEGER", nullable: false), + AuditOperationEnabled = table.Column(type: "INTEGER", nullable: false), + AuditEntityEnabled = table.Column(type: "INTEGER", nullable: false), + CacheExpirationSeconds = table.Column(type: "INTEGER", nullable: false), + IsCacheSliding = table.Column(type: "INTEGER", nullable: false), + IsSlaveDatabase = table.Column(type: "INTEGER", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -50,13 +51,13 @@ namespace OSharp.CodeGenerator.Migrations name: "CodeGen_CodeProject", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - Company = table.Column(nullable: true), - NamespacePrefix = table.Column(nullable: true), - SiteUrl = table.Column(nullable: true), - Creator = table.Column(nullable: true), - Copyright = table.Column(nullable: true) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + NamespacePrefix = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Company = table.Column(type: "TEXT", maxLength: 200, nullable: true), + SiteUrl = table.Column(type: "TEXT", maxLength: 500, nullable: true), + Creator = table.Column(type: "TEXT", maxLength: 200, nullable: true), + Copyright = table.Column(type: "TEXT", maxLength: 500, nullable: true) }, constraints: table => { @@ -67,11 +68,11 @@ namespace OSharp.CodeGenerator.Migrations name: "Systems_KeyValue", columns: table => new { - Id = table.Column(nullable: false), - ValueJson = table.Column(nullable: true), - ValueType = table.Column(nullable: true), - Key = table.Column(nullable: false), - IsLocked = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + ValueJson = table.Column(type: "TEXT", nullable: true), + ValueType = table.Column(type: "TEXT", nullable: true), + Key = table.Column(type: "TEXT", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false) }, constraints: table => { @@ -82,10 +83,10 @@ namespace OSharp.CodeGenerator.Migrations name: "CodeGen_CodeModule", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - Display = table.Column(nullable: true), - ProjectId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Display = table.Column(type: "TEXT", maxLength: 200, nullable: false), + ProjectId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -102,12 +103,12 @@ namespace OSharp.CodeGenerator.Migrations name: "CodeGen_CodeEntity", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - Display = table.Column(nullable: true), - PrimaryKeyTypeFullName = table.Column(nullable: true), - IsDataAuth = table.Column(nullable: false), - ModuleId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + Display = table.Column(type: "TEXT", maxLength: 200, nullable: false), + PrimaryKeyTypeFullName = table.Column(type: "TEXT", maxLength: 500, nullable: false), + IsDataAuth = table.Column(type: "INTEGER", nullable: false), + ModuleId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -124,19 +125,19 @@ namespace OSharp.CodeGenerator.Migrations name: "CodeGen_CodeProperty", columns: table => new { - Id = table.Column(nullable: false), - Name = table.Column(nullable: true), - TypeName = table.Column(nullable: true), - Display = table.Column(nullable: true), - IsRequired = table.Column(nullable: true), - MaxLength = table.Column(nullable: true), - MinLength = table.Column(nullable: true), - IsNullable = table.Column(nullable: false), - IsVirtual = table.Column(nullable: false), - IsForeignKey = table.Column(nullable: false), - IsInputDto = table.Column(nullable: false), - IsOutputDto = table.Column(nullable: false), - EntityId = table.Column(nullable: false) + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + TypeName = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Display = table.Column(type: "TEXT", maxLength: 200, nullable: false), + IsRequired = table.Column(type: "INTEGER", nullable: true), + MaxLength = table.Column(type: "INTEGER", nullable: true), + MinLength = table.Column(type: "INTEGER", nullable: true), + IsNullable = table.Column(type: "INTEGER", nullable: false), + IsVirtual = table.Column(type: "INTEGER", nullable: false), + IsForeignKey = table.Column(type: "INTEGER", nullable: false), + IsInputDto = table.Column(type: "INTEGER", nullable: false), + IsOutputDto = table.Column(type: "INTEGER", nullable: false), + EntityId = table.Column(type: "TEXT", nullable: false) }, constraints: table => { @@ -175,6 +176,12 @@ namespace OSharp.CodeGenerator.Migrations name: "IX_CodeGen_CodeProperty_EntityId", table: "CodeGen_CodeProperty", column: "EntityId"); + + migrationBuilder.CreateIndex( + name: "KeyIndex", + table: "Systems_KeyValue", + column: "Key", + unique: true); } protected override void Down(MigrationBuilder migrationBuilder) diff --git a/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.Designer.cs b/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..57d1de5d5fe5c8bcbfaf86b46c4a69b5be0428d4 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.Designer.cs @@ -0,0 +1,359 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OSharp.Entity; + +namespace OSharp.CodeGenerator.Migrations +{ + [DbContext(typeof(DefaultDbContext))] + [Migration("20210404022217_entity")] + partial class entity + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.4"); + + modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AuditEnabled") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PropertyJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TypeName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TypeName") + .IsUnique() + .HasDatabaseName("ClassFullNameIndex"); + + b.ToTable("Auth_EntityInfo"); + }); + + modelBuilder.Entity("OSharp.Authorization.Functions.Function", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AccessType") + .HasColumnType("INTEGER"); + + b.Property("Action") + .HasColumnType("TEXT"); + + b.Property("Area") + .HasColumnType("TEXT"); + + b.Property("AuditEntityEnabled") + .HasColumnType("INTEGER"); + + b.Property("AuditOperationEnabled") + .HasColumnType("INTEGER"); + + b.Property("CacheExpirationSeconds") + .HasColumnType("INTEGER"); + + b.Property("Controller") + .HasColumnType("TEXT"); + + b.Property("IsAccessTypeChanged") + .HasColumnType("INTEGER"); + + b.Property("IsAjax") + .HasColumnType("INTEGER"); + + b.Property("IsCacheSliding") + .HasColumnType("INTEGER"); + + b.Property("IsController") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsSlaveDatabase") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Area", "Controller", "Action") + .IsUnique() + .HasDatabaseName("AreaControllerActionIndex"); + + b.ToTable("Auth_Function"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsDataAuth") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("ModuleId") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("PrimaryKeyTypeFullName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ModuleId"); + + b.ToTable("CodeGen_CodeEntity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("ProjectId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("CodeGen_CodeModule"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Copyright") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("NamespacePrefix") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("SiteUrl") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeProject"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("IsForeignKey") + .HasColumnType("INTEGER"); + + b.Property("IsInputDto") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsNullable") + .HasColumnType("INTEGER"); + + b.Property("IsOutputDto") + .HasColumnType("INTEGER"); + + b.Property("IsRequired") + .HasColumnType("INTEGER"); + + b.Property("IsVirtual") + .HasColumnType("INTEGER"); + + b.Property("MaxLength") + .HasColumnType("INTEGER"); + + b.Property("MinLength") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("TypeName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("EntityId"); + + b.ToTable("CodeGen_CodeProperty"); + }); + + modelBuilder.Entity("OSharp.Core.Systems.KeyValue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Key") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ValueJson") + .HasColumnType("TEXT"); + + b.Property("ValueType") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique() + .HasDatabaseName("KeyIndex"); + + b.ToTable("Systems_KeyValue"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeModule", "Module") + .WithMany("Entities") + .HasForeignKey("ModuleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Module"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeProject", "Project") + .WithMany("Modules") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeEntity", "Entity") + .WithMany("Properties") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.Navigation("Properties"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.Navigation("Entities"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProject", b => + { + b.Navigation("Modules"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.cs b/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.cs new file mode 100644 index 0000000000000000000000000000000000000000..65032b33c5e85365d4baec77565c2fe55673db5c --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210404022217_entity.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OSharp.CodeGenerator.Migrations +{ + public partial class entity : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CreatedTime", + table: "CodeGen_CodeProperty", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "IsLocked", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "CreatedTime", + table: "CodeGen_CodeProject", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "CreatedTime", + table: "CodeGen_CodeModule", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "IsLocked", + table: "CodeGen_CodeModule", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "CreatedTime", + table: "CodeGen_CodeEntity", + type: "TEXT", + nullable: false, + defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified)); + + migrationBuilder.AddColumn( + name: "IsLocked", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CreatedTime", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "IsLocked", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "CreatedTime", + table: "CodeGen_CodeProject"); + + migrationBuilder.DropColumn( + name: "CreatedTime", + table: "CodeGen_CodeModule"); + + migrationBuilder.DropColumn( + name: "IsLocked", + table: "CodeGen_CodeModule"); + + migrationBuilder.DropColumn( + name: "CreatedTime", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "IsLocked", + table: "CodeGen_CodeEntity"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.Designer.cs b/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..cd17ebaf7117c45e7682f3c9b49fe25e4865aeb7 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.Designer.cs @@ -0,0 +1,415 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OSharp.Entity; + +namespace OSharp.CodeGenerator.Migrations +{ + [DbContext(typeof(DefaultDbContext))] + [Migration("20210408061345_AddOrder")] + partial class AddOrder + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.5"); + + modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AuditEnabled") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PropertyJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TypeName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TypeName") + .IsUnique() + .HasDatabaseName("ClassFullNameIndex"); + + b.ToTable("Auth_EntityInfo"); + }); + + modelBuilder.Entity("OSharp.Authorization.Functions.Function", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AccessType") + .HasColumnType("INTEGER"); + + b.Property("Action") + .HasColumnType("TEXT"); + + b.Property("Area") + .HasColumnType("TEXT"); + + b.Property("AuditEntityEnabled") + .HasColumnType("INTEGER"); + + b.Property("AuditOperationEnabled") + .HasColumnType("INTEGER"); + + b.Property("CacheExpirationSeconds") + .HasColumnType("INTEGER"); + + b.Property("Controller") + .HasColumnType("TEXT"); + + b.Property("IsAccessTypeChanged") + .HasColumnType("INTEGER"); + + b.Property("IsAjax") + .HasColumnType("INTEGER"); + + b.Property("IsCacheSliding") + .HasColumnType("INTEGER"); + + b.Property("IsController") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsSlaveDatabase") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Area", "Controller", "Action") + .IsUnique() + .HasDatabaseName("AreaControllerActionIndex"); + + b.ToTable("Auth_Function"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Addable") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Deletable") + .HasColumnType("INTEGER"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("HasCreatedTime") + .HasColumnType("INTEGER"); + + b.Property("HasCreationAudited") + .HasColumnType("INTEGER"); + + b.Property("HasLocked") + .HasColumnType("INTEGER"); + + b.Property("HasSoftDeleted") + .HasColumnType("INTEGER"); + + b.Property("HasUpdateAudited") + .HasColumnType("INTEGER"); + + b.Property("IsDataAuth") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Listable") + .HasColumnType("INTEGER"); + + b.Property("ModuleId") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("PrimaryKeyTypeFullName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Updatable") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ModuleId"); + + b.ToTable("CodeGen_CodeEntity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("ProjectId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("CodeGen_CodeModule"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Copyright") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("NamespacePrefix") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("SiteUrl") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeProject"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("DataAuthFlag") + .HasColumnType("TEXT"); + + b.Property("DefaultValue") + .HasColumnType("TEXT"); + + b.Property("Display") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("Filterable") + .HasColumnType("INTEGER"); + + b.Property("IsForeignKey") + .HasColumnType("INTEGER"); + + b.Property("IsInputDto") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsNavigation") + .HasColumnType("INTEGER"); + + b.Property("IsNullable") + .HasColumnType("INTEGER"); + + b.Property("IsOutputDto") + .HasColumnType("INTEGER"); + + b.Property("IsRequired") + .HasColumnType("INTEGER"); + + b.Property("IsVirtual") + .HasColumnType("INTEGER"); + + b.Property("MaxLength") + .HasColumnType("INTEGER"); + + b.Property("MinLength") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("RelateEntity") + .HasColumnType("TEXT"); + + b.Property("Sortable") + .HasColumnType("INTEGER"); + + b.Property("TypeName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Updatable") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("EntityId"); + + b.ToTable("CodeGen_CodeProperty"); + }); + + modelBuilder.Entity("OSharp.Core.Systems.KeyValue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Key") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ValueJson") + .HasColumnType("TEXT"); + + b.Property("ValueType") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique() + .HasDatabaseName("KeyIndex"); + + b.ToTable("Systems_KeyValue"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeModule", "Module") + .WithMany("Entities") + .HasForeignKey("ModuleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Module"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeProject", "Project") + .WithMany("Modules") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeEntity", "Entity") + .WithMany("Properties") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.Navigation("Properties"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Navigation("Entities"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => + { + b.Navigation("Modules"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.cs b/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.cs new file mode 100644 index 0000000000000000000000000000000000000000..9eade27ae8916b6486755668f47a4450f6c05b57 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210408061345_AddOrder.cs @@ -0,0 +1,241 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OSharp.CodeGenerator.Migrations +{ + public partial class AddOrder : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Display", + table: "CodeGen_CodeProperty", + type: "TEXT", + maxLength: 200, + nullable: true, + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 200); + + migrationBuilder.AddColumn( + name: "DataAuthFlag", + table: "CodeGen_CodeProperty", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "DefaultValue", + table: "CodeGen_CodeProperty", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "Filterable", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "IsNavigation", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Order", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "RelateEntity", + table: "CodeGen_CodeProperty", + type: "TEXT", + nullable: true); + + migrationBuilder.AddColumn( + name: "Sortable", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Updatable", + table: "CodeGen_CodeProperty", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Order", + table: "CodeGen_CodeModule", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Addable", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Deletable", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HasCreatedTime", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HasCreationAudited", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HasLocked", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HasSoftDeleted", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "HasUpdateAudited", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Listable", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "Order", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: 0); + + migrationBuilder.AddColumn( + name: "Updatable", + table: "CodeGen_CodeEntity", + type: "INTEGER", + nullable: false, + defaultValue: false); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "DataAuthFlag", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "DefaultValue", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "Filterable", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "IsNavigation", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "Order", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "RelateEntity", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "Sortable", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "Updatable", + table: "CodeGen_CodeProperty"); + + migrationBuilder.DropColumn( + name: "Order", + table: "CodeGen_CodeModule"); + + migrationBuilder.DropColumn( + name: "Addable", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "Deletable", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "HasCreatedTime", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "HasCreationAudited", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "HasLocked", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "HasSoftDeleted", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "HasUpdateAudited", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "Listable", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "Order", + table: "CodeGen_CodeEntity"); + + migrationBuilder.DropColumn( + name: "Updatable", + table: "CodeGen_CodeEntity"); + + migrationBuilder.AlterColumn( + name: "Display", + table: "CodeGen_CodeProperty", + type: "TEXT", + maxLength: 200, + nullable: false, + defaultValue: "", + oldClrType: typeof(string), + oldType: "TEXT", + oldMaxLength: 200, + oldNullable: true); + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.Designer.cs b/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..2fea93dc3633c27e3068aea4be9e36bfd4feefb0 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.Designer.cs @@ -0,0 +1,504 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OSharp.Entity; + +namespace OSharp.CodeGenerator.Migrations +{ + [DbContext(typeof(DefaultDbContext))] + [Migration("20210408161331_SettingForeign")] + partial class SettingForeign + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "5.0.5"); + + modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AuditEnabled") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("PropertyJson") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("TypeName") + .IsRequired() + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("TypeName") + .IsUnique() + .HasDatabaseName("ClassFullNameIndex"); + + b.ToTable("Auth_EntityInfo"); + }); + + modelBuilder.Entity("OSharp.Authorization.Functions.Function", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("AccessType") + .HasColumnType("INTEGER"); + + b.Property("Action") + .HasColumnType("TEXT"); + + b.Property("Area") + .HasColumnType("TEXT"); + + b.Property("AuditEntityEnabled") + .HasColumnType("INTEGER"); + + b.Property("AuditOperationEnabled") + .HasColumnType("INTEGER"); + + b.Property("CacheExpirationSeconds") + .HasColumnType("INTEGER"); + + b.Property("Controller") + .HasColumnType("TEXT"); + + b.Property("IsAccessTypeChanged") + .HasColumnType("INTEGER"); + + b.Property("IsAjax") + .HasColumnType("INTEGER"); + + b.Property("IsCacheSliding") + .HasColumnType("INTEGER"); + + b.Property("IsController") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsSlaveDatabase") + .HasColumnType("INTEGER"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Area", "Controller", "Action") + .IsUnique() + .HasDatabaseName("AreaControllerActionIndex"); + + b.ToTable("Auth_Function"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Addable") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Deletable") + .HasColumnType("INTEGER"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("HasCreatedTime") + .HasColumnType("INTEGER"); + + b.Property("HasCreationAudited") + .HasColumnType("INTEGER"); + + b.Property("HasLocked") + .HasColumnType("INTEGER"); + + b.Property("HasSoftDeleted") + .HasColumnType("INTEGER"); + + b.Property("HasUpdateAudited") + .HasColumnType("INTEGER"); + + b.Property("IsDataAuth") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Listable") + .HasColumnType("INTEGER"); + + b.Property("ModuleId") + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("PrimaryKeyTypeFullName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Updatable") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("ModuleId"); + + b.ToTable("CodeGen_CodeEntity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeForeign", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("DeleteBehavior") + .HasColumnType("INTEGER"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("ForeignRelation") + .HasColumnType("INTEGER"); + + b.Property("IsRequired") + .HasColumnType("INTEGER"); + + b.Property("OtherEntity") + .HasColumnType("TEXT"); + + b.Property("OtherNavigation") + .HasColumnType("TEXT"); + + b.Property("SelfForeignKey") + .HasColumnType("TEXT"); + + b.Property("SelfNavigation") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("EntityId"); + + b.ToTable("CodeGen_CodeForeign"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Display") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("ProjectId") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("CodeGen_CodeModule"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Company") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Copyright") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("NamespacePrefix") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("SiteUrl") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeProject"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("DataAuthFlag") + .HasColumnType("TEXT"); + + b.Property("DefaultValue") + .HasColumnType("TEXT"); + + b.Property("Display") + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("Filterable") + .HasColumnType("INTEGER"); + + b.Property("IsForeignKey") + .HasColumnType("INTEGER"); + + b.Property("IsInputDto") + .HasColumnType("INTEGER"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsNavigation") + .HasColumnType("INTEGER"); + + b.Property("IsNullable") + .HasColumnType("INTEGER"); + + b.Property("IsOutputDto") + .HasColumnType("INTEGER"); + + b.Property("IsRequired") + .HasColumnType("INTEGER"); + + b.Property("IsVirtual") + .HasColumnType("INTEGER"); + + b.Property("MaxLength") + .HasColumnType("INTEGER"); + + b.Property("MinLength") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("RelateEntity") + .HasColumnType("TEXT"); + + b.Property("Sortable") + .HasColumnType("INTEGER"); + + b.Property("TypeName") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("Updatable") + .HasColumnType("INTEGER"); + + b.HasKey("Id"); + + b.HasIndex("EntityId"); + + b.ToTable("CodeGen_CodeProperty"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsOnce") + .HasColumnType("INTEGER"); + + b.Property("IsSystem") + .HasColumnType("INTEGER"); + + b.Property("MetadataType") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("OutputFileFormat") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT"); + + b.Property("TemplateFile") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeSetting"); + }); + + modelBuilder.Entity("OSharp.Core.Systems.KeyValue", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Key") + .IsRequired() + .HasColumnType("TEXT"); + + b.Property("ValueJson") + .HasColumnType("TEXT"); + + b.Property("ValueType") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique() + .HasDatabaseName("KeyIndex"); + + b.ToTable("Systems_KeyValue"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeModule", "Module") + .WithMany("Entities") + .HasForeignKey("ModuleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Module"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeForeign", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeEntity", "Entity") + .WithMany() + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeProject", "Project") + .WithMany("Modules") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Project"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeEntity", "Entity") + .WithMany("Properties") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.Navigation("Properties"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Navigation("Entities"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => + { + b.Navigation("Modules"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.cs b/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.cs new file mode 100644 index 0000000000000000000000000000000000000000..c83455179f63dfa88d6ecef4543cee37c2afbc48 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20210408161331_SettingForeign.cs @@ -0,0 +1,69 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OSharp.CodeGenerator.Migrations +{ + public partial class SettingForeign : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "CodeGen_CodeForeign", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + SelfNavigation = table.Column(type: "TEXT", nullable: true), + SelfForeignKey = table.Column(type: "TEXT", nullable: true), + OtherEntity = table.Column(type: "TEXT", nullable: true), + OtherNavigation = table.Column(type: "TEXT", nullable: true), + IsRequired = table.Column(type: "INTEGER", nullable: false), + DeleteBehavior = table.Column(type: "INTEGER", nullable: true), + ForeignRelation = table.Column(type: "INTEGER", nullable: false), + EntityId = table.Column(type: "TEXT", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeForeign", x => x.Id); + table.ForeignKey( + name: "FK_CodeGen_CodeForeign_CodeGen_CodeEntity_EntityId", + column: x => x.EntityId, + principalTable: "CodeGen_CodeEntity", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "CodeGen_CodeSetting", + columns: table => new + { + Id = table.Column(type: "TEXT", nullable: false), + Name = table.Column(type: "TEXT", maxLength: 200, nullable: false), + MetadataType = table.Column(type: "INTEGER", nullable: false), + TemplateFile = table.Column(type: "TEXT", maxLength: 500, nullable: false), + Order = table.Column(type: "INTEGER", nullable: false), + OutputFileFormat = table.Column(type: "TEXT", maxLength: 300, nullable: false), + IsOnce = table.Column(type: "INTEGER", nullable: false), + IsSystem = table.Column(type: "INTEGER", nullable: false), + IsLocked = table.Column(type: "INTEGER", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeSetting", x => x.Id); + }); + + migrationBuilder.CreateIndex( + name: "IX_CodeGen_CodeForeign_EntityId", + table: "CodeGen_CodeForeign", + column: "EntityId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "CodeGen_CodeForeign"); + + migrationBuilder.DropTable( + name: "CodeGen_CodeSetting"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs b/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs index 3bffb77c94648944a625f2be8c1a18e0e049e7de..26e55577c1fedcad57bdbb85b0b02d73d2af4862 100644 --- a/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs +++ b/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs @@ -14,7 +14,7 @@ namespace OSharp.CodeGenerator.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "3.1.7"); + .HasAnnotation("ProductVersion", "5.0.5"); modelBuilder.Entity("OSharp.Authorization.EntityInfos.EntityInfo", b => { @@ -41,7 +41,7 @@ namespace OSharp.CodeGenerator.Migrations b.HasIndex("TypeName") .IsUnique() - .HasName("ClassFullNameIndex"); + .HasDatabaseName("ClassFullNameIndex"); b.ToTable("Auth_EntityInfo"); }); @@ -88,6 +88,9 @@ namespace OSharp.CodeGenerator.Migrations b.Property("IsLocked") .HasColumnType("INTEGER"); + b.Property("IsSlaveDatabase") + .HasColumnType("INTEGER"); + b.Property("Name") .HasColumnType("TEXT"); @@ -95,32 +98,74 @@ namespace OSharp.CodeGenerator.Migrations b.HasIndex("Area", "Controller", "Action") .IsUnique() - .HasName("AreaControllerActionIndex"); + .HasDatabaseName("AreaControllerActionIndex"); b.ToTable("Auth_Function"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("TEXT"); + b.Property("Addable") + .HasColumnType("INTEGER"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("Deletable") + .HasColumnType("INTEGER"); + b.Property("Display") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); + b.Property("HasCreatedTime") + .HasColumnType("INTEGER"); + + b.Property("HasCreationAudited") + .HasColumnType("INTEGER"); + + b.Property("HasLocked") + .HasColumnType("INTEGER"); + + b.Property("HasSoftDeleted") + .HasColumnType("INTEGER"); + + b.Property("HasUpdateAudited") + .HasColumnType("INTEGER"); + b.Property("IsDataAuth") .HasColumnType("INTEGER"); + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("Listable") + .HasColumnType("INTEGER"); + b.Property("ModuleId") .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); + b.Property("Order") + .HasColumnType("INTEGER"); + b.Property("PrimaryKeyTypeFullName") + .IsRequired() + .HasMaxLength(500) .HasColumnType("TEXT"); + b.Property("Updatable") + .HasColumnType("INTEGER"); + b.HasKey("Id"); b.HasIndex("ModuleId"); @@ -128,18 +173,68 @@ namespace OSharp.CodeGenerator.Migrations b.ToTable("CodeGen_CodeEntity"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeForeign", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("TEXT"); + b.Property("DeleteBehavior") + .HasColumnType("INTEGER"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("ForeignRelation") + .HasColumnType("INTEGER"); + + b.Property("IsRequired") + .HasColumnType("INTEGER"); + + b.Property("OtherEntity") + .HasColumnType("TEXT"); + + b.Property("OtherNavigation") + .HasColumnType("TEXT"); + + b.Property("SelfForeignKey") + .HasColumnType("TEXT"); + + b.Property("SelfNavigation") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("EntityId"); + + b.ToTable("CodeGen_CodeForeign"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("CreatedTime") + .HasColumnType("TEXT"); + b.Property("Display") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); + b.Property("IsLocked") + .HasColumnType("INTEGER"); + b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); + b.Property("Order") + .HasColumnType("INTEGER"); + b.Property("ProjectId") .HasColumnType("TEXT"); @@ -150,28 +245,39 @@ namespace OSharp.CodeGenerator.Migrations b.ToTable("CodeGen_CodeModule"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProject", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("TEXT"); b.Property("Company") + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("Copyright") + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.Property("CreatedTime") .HasColumnType("TEXT"); b.Property("Creator") + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("NamespacePrefix") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("SiteUrl") + .HasMaxLength(500) .HasColumnType("TEXT"); b.HasKey("Id"); @@ -179,24 +285,43 @@ namespace OSharp.CodeGenerator.Migrations b.ToTable("CodeGen_CodeProject"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => { b.Property("Id") .ValueGeneratedOnAdd() .HasColumnType("TEXT"); + b.Property("CreatedTime") + .HasColumnType("TEXT"); + + b.Property("DataAuthFlag") + .HasColumnType("TEXT"); + + b.Property("DefaultValue") + .HasColumnType("TEXT"); + b.Property("Display") + .HasMaxLength(200) .HasColumnType("TEXT"); b.Property("EntityId") .HasColumnType("TEXT"); + b.Property("Filterable") + .HasColumnType("INTEGER"); + b.Property("IsForeignKey") .HasColumnType("INTEGER"); b.Property("IsInputDto") .HasColumnType("INTEGER"); + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsNavigation") + .HasColumnType("INTEGER"); + b.Property("IsNullable") .HasColumnType("INTEGER"); @@ -216,11 +341,27 @@ namespace OSharp.CodeGenerator.Migrations .HasColumnType("INTEGER"); b.Property("Name") + .IsRequired() + .HasMaxLength(200) .HasColumnType("TEXT"); + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("RelateEntity") + .HasColumnType("TEXT"); + + b.Property("Sortable") + .HasColumnType("INTEGER"); + b.Property("TypeName") + .IsRequired() + .HasMaxLength(500) .HasColumnType("TEXT"); + b.Property("Updatable") + .HasColumnType("INTEGER"); + b.HasKey("Id"); b.HasIndex("EntityId"); @@ -228,6 +369,47 @@ namespace OSharp.CodeGenerator.Migrations b.ToTable("CodeGen_CodeProperty"); }); + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeSetting", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("IsLocked") + .HasColumnType("INTEGER"); + + b.Property("IsOnce") + .HasColumnType("INTEGER"); + + b.Property("IsSystem") + .HasColumnType("INTEGER"); + + b.Property("MetadataType") + .HasColumnType("INTEGER"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(200) + .HasColumnType("TEXT"); + + b.Property("Order") + .HasColumnType("INTEGER"); + + b.Property("OutputFileFormat") + .IsRequired() + .HasMaxLength(300) + .HasColumnType("TEXT"); + + b.Property("TemplateFile") + .IsRequired() + .HasMaxLength(500) + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeSetting"); + }); + modelBuilder.Entity("OSharp.Core.Systems.KeyValue", b => { b.Property("Id") @@ -249,34 +431,70 @@ namespace OSharp.CodeGenerator.Migrations b.HasKey("Id"); + b.HasIndex("Key") + .IsUnique() + .HasDatabaseName("KeyIndex"); + b.ToTable("Systems_KeyValue"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => { - b.HasOne("OSharp.CodeGeneration.Entities.CodeModule", "Module") + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeModule", "Module") .WithMany("Entities") .HasForeignKey("ModuleId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Module"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeForeign", b => + { + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeEntity", "Entity") + .WithMany() + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Entity"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => { - b.HasOne("OSharp.CodeGeneration.Entities.CodeProject", "Project") + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeProject", "Project") .WithMany("Modules") .HasForeignKey("ProjectId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Project"); }); - modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProperty", b => { - b.HasOne("OSharp.CodeGeneration.Entities.CodeEntity", "Entity") + b.HasOne("OSharp.CodeGeneration.Services.Entities.CodeEntity", "Entity") .WithMany("Properties") .HasForeignKey("EntityId") .OnDelete(DeleteBehavior.Cascade) .IsRequired(); + + b.Navigation("Entity"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeEntity", b => + { + b.Navigation("Properties"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeModule", b => + { + b.Navigation("Entities"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Services.Entities.CodeProject", b => + { + b.Navigation("Modules"); }); #pragma warning restore 612, 618 } diff --git a/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj b/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj index a4d7f41eeb26cc8495a1b7d555ded53993ba0330..6f7165408000a34b65989cc94fde919e3556ee23 100644 --- a/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj +++ b/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj @@ -9,15 +9,16 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + + diff --git a/src/OSharp.CodeGenerator/Resources/SomeStyles.xaml b/src/OSharp.CodeGenerator/Resources/SomeStyles.xaml new file mode 100644 index 0000000000000000000000000000000000000000..6e9e0c83be318bd59ab491da9b804e312be5c75f --- /dev/null +++ b/src/OSharp.CodeGenerator/Resources/SomeStyles.xaml @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Startup.cs b/src/OSharp.CodeGenerator/Startup.cs index 90955df75d88af95a5eedac4c32911ddc691a1e8..e2277032a313e181dfb25c40bd2f4228391a2396 100644 --- a/src/OSharp.CodeGenerator/Startup.cs +++ b/src/OSharp.CodeGenerator/Startup.cs @@ -1,4 +1,4 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2020 OSharp. All rights reserved. // @@ -12,6 +12,7 @@ using System; using Microsoft.Extensions.DependencyInjection; using OSharp.AutoMapper; +using OSharp.CodeGeneration.Services; using OSharp.CodeGenerator.Data; using OSharp.CodeGenerator.Views; using OSharp.Log4Net; @@ -27,7 +28,8 @@ namespace OSharp.CodeGenerator .AddPack() .AddPack() .AddPack() - .AddPack(); + .AddPack() + .AddPack(); } public void Configure(IServiceProvider provider) diff --git a/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml b/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..858813a9e3812954910e86ed421f03b44532b2f5 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml @@ -0,0 +1,100 @@ + + + + + + 实体列表 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml.cs b/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..7f0a1a41a0c710ec0980a2397bbe132520e08172 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Entities/EntityListView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OSharp.CodeGenerator.Views.Entities +{ + /// + /// EntityListView.xaml 的交互逻辑 + /// + public partial class EntityListView : UserControl + { + public EntityListView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/Entities/EntityListViewModel.cs b/src/OSharp.CodeGenerator/Views/Entities/EntityListViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..da5886b64e0129d6946e98c71aec6268005c5b8c --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Entities/EntityListViewModel.cs @@ -0,0 +1,112 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-06 19:10 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; + +using Microsoft.Extensions.DependencyInjection; + +using Notifications.Wpf.Core; + +using OSharp.CodeGeneration.Services; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views.Modules; +using OSharp.Data; +using OSharp.Exceptions; +using OSharp.Mapping; +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views.Entities +{ + [Singleton] + public class EntityListViewModel : Screen + { + private readonly IServiceProvider _provider; + + public EntityListViewModel(IServiceProvider provider) + { + _provider = provider; + } + + public ModuleViewModel Module { get; set; } + + public IObservableCollection Entities { get; } = new BindableCollection(); + + public void Init() + { + if (Module == null) + { + throw new OsharpException($"当前模块为空,请点击模块列表选择一行"); + } + + List entities = new List(); + _provider.ExecuteScopedWork(provider => + { + IDataContract contract = provider.GetRequiredService(); + entities = contract.CodeEntities.Where(m => m.ModuleId == Module.Id).OrderBy(m => m.Order).ToList(); + }); + Entities.Clear(); + foreach (CodeEntity entity in entities) + { + EntityViewModel model = _provider.GetRequiredService(); + model = entity.MapTo(model); + model.Module = Module; + Entities.Add(model); + } + Helper.Output($"模块“{Module.Display}”的实体列表刷新成功,共{Entities.Count}个实体"); + } + + public void New() + { + EntityViewModel entity = _provider.GetRequiredService(); + entity.Module = Module; + Entities.Add(entity); + } + + public bool CanSave => Entities.All(m => !m.HasErrors); + + public async void Save() + { + if (!CanSave) + { + Helper.Notify("实体信息验证失败", NotificationType.Warning); + return; + } + + CodeEntity[] entities = Entities.Select(m => m.ToEntity()).ToArray(); + OperationResult result = null; + await _provider.ExecuteScopedWorkAsync(async provider => + { + IDataContract contract = provider.GetRequiredService(); + result = await contract.UpdateCodeEntities(entities); + }); + Helper.Notify(result); + if (!result.Succeeded) + { + return; + } + Init(); + } + + /// + /// Called whenever the error state of any properties changes. Calls NotifyOfPropertyChange("HasErrors") by default + /// + /// List of property names which have changed validation state + protected override void OnValidationStateChanged(IEnumerable changedProperties) + { + base.OnValidationStateChanged(changedProperties); + NotifyOfPropertyChange(() => CanSave); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/EntityViewModel.cs b/src/OSharp.CodeGenerator/Views/Entities/EntityViewModel.cs similarity index 63% rename from src/OSharp.CodeGenerator/Views/EntityViewModel.cs rename to src/OSharp.CodeGenerator/Views/Entities/EntityViewModel.cs index 907a225fe48e4bb5684bd6600dceee56f0f884e9..de83ac9020bcd035ecab1e9009455d93b71a66fb 100644 --- a/src/OSharp.CodeGenerator/Views/EntityViewModel.cs +++ b/src/OSharp.CodeGenerator/Views/Entities/EntityViewModel.cs @@ -7,32 +7,40 @@ // 2020-05-07 1:11 // ----------------------------------------------------------------------- +using System; + using FluentValidation; -using OSharp.CodeGeneration.Entities; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views.Modules; +using OSharp.CodeGenerator.Views.Properties; using OSharp.Mapping; using Stylet; -namespace OSharp.CodeGenerator.Views +namespace OSharp.CodeGenerator.Views.Entities { [MapTo(typeof(CodeEntity))] + [MapFrom(typeof(CodeEntity))] public class EntityViewModel : Screen { + private readonly IServiceProvider _provider; + /// /// 初始化一个类型的新实例 /// - public EntityViewModel(IModelValidator validator) + public EntityViewModel(IModelValidator validator, IServiceProvider provider) : base(validator) { + _provider = provider; Validate(); - Properties = new BindableCollection(); } public ModuleViewModel Module { get; set; } - - public IObservableCollection Properties { get; set; } + + public Guid Id { get; set; } public string Name { get; set; } @@ -60,15 +68,46 @@ namespace OSharp.CodeGenerator.Views public bool HasUpdateAudited { get; set; } + public int Order { get; set; } + public CodeEntity ToEntity() { CodeEntity entity = this.MapTo(); return entity; } + + public void Expanded() + { + Helper.Output($"“{Name}” - Expanded"); + } + + public void Collapsed() + { + Helper.Output($"“{Name}” - Collapsed"); + } + + public void ForeignKey() + { + Helper.Output($"“{Name}” - ForeignKey"); + } + + public void Up() + { + Helper.Output($"“{Name}” - Up"); + } + + public void Down() + { + Helper.Output($"“{Name}” - Down"); + } + public void Delete() + { + Helper.Output($"“{Name}” - Delete"); + } } - public class EntityViewModelValidator : AbstractValidator + public class EntityViewModelValidator : AbstractValidator { public EntityViewModelValidator() { diff --git a/src/OSharp.CodeGenerator/Views/MainMenuView.xaml b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml index fe3c472acf3980ddd0d529f21379270ce278970f..7407456d723848a1ffe5bbcfbe9a89f3b7f2187c 100644 --- a/src/OSharp.CodeGenerator/Views/MainMenuView.xaml +++ b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml @@ -11,7 +11,7 @@ d:DataContext="{d:DesignInstance local:MainMenuViewModel}" d:DesignHeight="29" d:DesignWidth="400"> - + + + + + diff --git a/src/OSharp.CodeGenerator/Views/Modules/ModuleEditView.xaml.cs b/src/OSharp.CodeGenerator/Views/Modules/ModuleEditView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..e2a1566c5c936dd0c976b0d3aa33b3b6e5127c53 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Modules/ModuleEditView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OSharp.CodeGenerator.Views.Modules +{ + /// + /// ModuleEditView.xaml 的交互逻辑 + /// + public partial class ModuleEditView : UserControl + { + public ModuleEditView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml b/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..fcc35c5f7e78702cd03a8710ecf4c19e21a5fe93 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml @@ -0,0 +1,61 @@ + + + + + + 模块列表 + + + + + + + + + + + + + + + + + [] + + + + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml.cs b/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..de371d35ada1ef2dc039dd84126fd28d502f0ea3 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Modules/ModuleListView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OSharp.CodeGenerator.Views.Modules +{ + /// + /// ModuleListView.xaml 的交互逻辑 + /// + public partial class ModuleListView : UserControl + { + public ModuleListView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/Modules/ModuleListViewModel.cs b/src/OSharp.CodeGenerator/Views/Modules/ModuleListViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..27e6134cd74e4a924b5665c040fa35d4179110c0 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Modules/ModuleListViewModel.cs @@ -0,0 +1,106 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-06 12:33 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Controls; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.CodeGeneration.Services; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views.Entities; +using OSharp.CodeGenerator.Views.Projects; +using OSharp.Exceptions; +using OSharp.Mapping; +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views.Modules +{ + [Singleton] + public class ModuleListViewModel : Screen + { + private readonly IServiceProvider _provider; + + public ModuleListViewModel(IServiceProvider provider) + { + _provider = provider; + } + + public ProjectViewModel Project { get; set; } + + public IObservableCollection Modules { get; } = new BindableCollection(); + + public string EditTitle { get; set; } + + public bool IsShowEdit { get; set; } + + public ModuleViewModel EditingModel { get; set; } + + public void Init() + { + if (Project == null) + { + throw new OsharpException("当前项目为空,请先通过菜单“项目-项目管理”加载项目"); + } + List entities = new List(); + _provider.ExecuteScopedWork(provider => + { + IDataContract contract = provider.GetRequiredService(); + entities = contract.CodeModules.Where(m => m.ProjectId == Project.Id).OrderBy(m => m.Order).ToList(); + }); + Modules.Clear(); + foreach (CodeModule entity in entities) + { + ModuleViewModel model = _provider.GetRequiredService(); + model = entity.MapTo(model); + model.Project = Project; + Modules.Add(model); + } + Helper.Output($"模块列表刷新成功,共{Modules.Count}个模块"); + } + + public void New() + { + if (Project == null) + { + throw new OsharpException("当前项目为空,请先通过菜单“项目-项目管理”加载项目"); + } + ModuleViewModel model = IoC.Get(); + model.Project = Project; + EditingModel = model; + EditTitle = $"新增模块,项目:{Project.Name}"; + IsShowEdit = true; + } + + public void Select(SelectionChangedEventArgs e) + { + if (e.AddedItems.Count == 0) + { + return; + } + + ModuleViewModel module = e.AddedItems[0] as ModuleViewModel; + if (module == null) + { + return; + } + + EntityListViewModel list = IoC.Get(); + list.Module = module; + list.Init(); + Helper.Output($"切换到“{module.Name} [{module.Display}]”模块"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/ModuleViewModel.cs b/src/OSharp.CodeGenerator/Views/Modules/ModuleViewModel.cs similarity index 32% rename from src/OSharp.CodeGenerator/Views/ModuleViewModel.cs rename to src/OSharp.CodeGenerator/Views/Modules/ModuleViewModel.cs index ebd88986d4ed96e94776ce997e33f811dcaffc45..126a247cba8a1d153b4faef5aadb1c586aa61cf6 100644 --- a/src/OSharp.CodeGenerator/Views/ModuleViewModel.cs +++ b/src/OSharp.CodeGenerator/Views/Modules/ModuleViewModel.cs @@ -7,43 +7,145 @@ // 2020-05-07 0:17 // ----------------------------------------------------------------------- +using System; +using System.Collections.Generic; +using System.Windows; + +using AutoMapper; + using FluentValidation; -using OSharp.CodeGeneration.Entities; +using Microsoft.Extensions.DependencyInjection; + +using Notifications.Wpf.Core; + +using OSharp.CodeGeneration.Services; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views.Projects; +using OSharp.Data; using OSharp.Mapping; +using OSharp.Wpf.Stylet; using Stylet; -namespace OSharp.CodeGenerator.Views +namespace OSharp.CodeGenerator.Views.Modules { [MapTo(typeof(CodeModule))] + [MapFrom(typeof(CodeModule))] public class ModuleViewModel : Screen { + private readonly IServiceProvider _provider; + /// /// 初始化一个类型的新实例 /// - public ModuleViewModel(IModelValidator validator) : base(validator) + public ModuleViewModel(IModelValidator validator, IServiceProvider provider) : base(validator) { + _provider = provider; Validate(); - Entities = new BindableCollection(); } - public ProjectViewModel Project { get; set; } - - public IObservableCollection Entities { get; set; } + public Guid Id { get; set; } public string Name { get; set; } public string Display { get; set; } + public int Order { get; set; } + public string Namespace => $"{(Project == null ? "" : Project.NamespacePrefix + ".")}{Name}"; + public ProjectViewModel Project { get; set; } + public CodeModule ToModule() { CodeModule module = this.MapTo(); return module; } + + public void Edit() + { + ModuleListViewModel model = IoC.Get(); + model.EditingModel = this; + model.EditTitle = $"模块编辑 - {Name}[{Display}]"; + model.IsShowEdit = true; + } + + public async void Delete() + { + if (MessageBox.Show($"是否删除模块“{Name}[{Display}]”?", "请确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel) + { + return; + } + + OperationResult result = null; + await _provider.ExecuteScopedWorkAsync(async provider => + { + IDataContract contract = provider.GetRequiredService(); + result = await contract.DeleteCodeModules(Id); + }); + MainViewModel main = IoC.Get(); + Helper.Notify(result); + if (!result.Succeeded) + { + return; + } + + main.ModuleList.Init(); + } + + public bool CanEditSave => !HasErrors; + + public async void EditSave() + { + MainViewModel main = IoC.Get(); + if (!await ValidateAsync()) + { + main.Notify("项目信息验证失败", NotificationType.Warning); + return; + } + + CodeModule module = ToModule(); + OperationResult result = null; + await _provider.ExecuteScopedWorkAsync(async provider => + { + IDataContract contract = provider.GetRequiredService(); + result = module.Id == default + ? await contract.CreateCodeModules(module) + : await contract.UpdateCodeModules(module); + }); + Helper.Notify(result); + if (!result.Succeeded) + { + return; + } + + ModuleListViewModel list = main.ModuleList; + list.EditingModel = null; + list.IsShowEdit = false; + list.Init(); + } + + public void EditCancel() + { + var list = IoC.Get(); + list.EditingModel = null; + list.IsShowEdit = false; + list.Init(); + } + + /// + /// Called whenever the error state of any properties changes. Calls NotifyOfPropertyChange("HasErrors") by default + /// + /// List of property names which have changed validation state + protected override void OnValidationStateChanged(IEnumerable changedProperties) + { + base.OnValidationStateChanged(changedProperties); + NotifyOfPropertyChange(() => CanEditSave); + } + } diff --git a/src/OSharp.CodeGenerator/Views/ProjectView.xaml b/src/OSharp.CodeGenerator/Views/ProjectView.xaml deleted file mode 100644 index 3d6da74636ef9588c7e4e9e7b08dc1402b8ab8b8..0000000000000000000000000000000000000000 --- a/src/OSharp.CodeGenerator/Views/ProjectView.xaml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml b/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..e9b85163d64af6874fc6b928c0b1c4428a84d855 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml.cs b/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..2f6455ac2e83bba450beed2523e6f784359bd5f2 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectEditView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OSharp.CodeGenerator.Views.Projects +{ + /// + /// ProjectEditView.xaml 的交互逻辑 + /// + public partial class ProjectEditView : UserControl + { + public ProjectEditView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml b/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..a40e42120514c5674f4e088a499c90412e45ddfe --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml @@ -0,0 +1,97 @@ + + + + + + + 项目列表 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml.cs b/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..f5c81301a3562bbaac1ad0ce31b0fc604c1e9cdd --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectListView.xaml.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace OSharp.CodeGenerator.Views.Projects +{ + /// + /// ProjectListView.xaml 的交互逻辑 + /// + public partial class ProjectListView : UserControl + { + public ProjectListView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/Projects/ProjectListViewModel.cs b/src/OSharp.CodeGenerator/Views/Projects/ProjectListViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..fd6fcb20f9d00340bb11bb0f4e51936f8d493315 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectListViewModel.cs @@ -0,0 +1,78 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-04 0:32 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.Linq; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.CodeGeneration.Services; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.Mapping; +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views.Projects +{ + [Singleton] + public class ProjectListViewModel : Screen + { + private readonly IServiceProvider _provider; + + public ProjectListViewModel(IServiceProvider provider) + { + _provider = provider; + } + + public bool IsShow { get; set; } + + public IObservableCollection Projects { get; } = new BindableCollection(); + + public string EditTitle { get; set; } + + public bool IsShowEdit { get; set; } + + public ProjectViewModel EditingModel { get; set; } + + public void Show() + { + Init(); + IsShow = true; + } + + public void Init() + { + List projects = new List(); + _provider.ExecuteScopedWork(provider => + { + Projects.Clear(); + IDataContract contract = provider.GetRequiredService(); + projects = contract.CodeProjects.ToList(); + }); + foreach (CodeProject project in projects) + { + ProjectViewModel model = _provider.GetRequiredService(); + model = project.MapTo(model); + Projects.Add(model); + } + } + + public void New() + { + ProjectListViewModel model = IoC.Get(); + model.EditingModel = IoC.Get(); + model.EditTitle = "新增项目"; + model.IsShowEdit = true; + } + } + +} diff --git a/src/OSharp.CodeGenerator/Views/ProjectViewModel.cs b/src/OSharp.CodeGenerator/Views/Projects/ProjectViewModel.cs similarity index 43% rename from src/OSharp.CodeGenerator/Views/ProjectViewModel.cs rename to src/OSharp.CodeGenerator/Views/Projects/ProjectViewModel.cs index b96c27c21505b1c660f4c4b641615ec836ec8362..4cd7f224afbcea8cca10c28aff5ce21f45c48380 100644 --- a/src/OSharp.CodeGenerator/Views/ProjectViewModel.cs +++ b/src/OSharp.CodeGenerator/Views/Projects/ProjectViewModel.cs @@ -10,68 +10,136 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.IO; +using System.Windows; + +using AutoMapper; using FluentValidation; +using Microsoft.Extensions.DependencyInjection; + using Notifications.Wpf.Core; -using OSharp.CodeGeneration.Entities; +using OSharp.CodeGeneration.Services; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views.Modules; +using OSharp.Data; using OSharp.Extensions; -using OSharp.Json; using OSharp.Mapping; using OSharp.Wpf.Stylet; using Stylet; -namespace OSharp.CodeGenerator.Views +namespace OSharp.CodeGenerator.Views.Projects { [MapTo(typeof(CodeProject))] + [MapFrom(typeof(CodeProject))] public class ProjectViewModel : Screen { - public ProjectViewModel(IModelValidator validator) : base(validator) + private readonly IServiceProvider _serviceProvider; + + public ProjectViewModel(IModelValidator validator, IServiceProvider serviceProvider) : base(validator) { + _serviceProvider = serviceProvider; Validate(); - Modules = new BindableCollection(); } + + public Guid Id { get; set; } + + public string Name { get; set; } - public IObservableCollection Modules { get; set; } + public string NamespacePrefix { get; set; } - public string Name { get; set; } = "示例项目"; + public string Company { get; set; } - public string NamespacePrefix { get; set; } = "Liuliu.Demo"; + public string SiteUrl { get; set; } - public string Company { get; set; } = "柳柳软件"; + public string Creator { get; set; } - public string SiteUrl { get; set; } = "https://www.osharp.org"; + public string Copyright { get; set; } - public string Creator { get; set; } = "郭明锋"; + public DateTime CreatedTime { get; set; } + + public void Load() + { + MainViewModel main = IoC.Get(); + main.DisplayName = $"OSharp代码生成器 - {Name}"; + ModuleListViewModel moduleList = IoC.Get(); + moduleList.Project = this; + moduleList.Init(); + main.ProjectList.IsShow = false; + main.StatusBar.Message = $"项目“{Name}”加载成功"; + } - public string Copyright { get; set; } = "Copyright OSHARP.ORG @2020"; + public void Edit() + { + ProjectListViewModel model = IoC.Get(); + model.EditingModel = this; + model.EditTitle = $"项目编辑 - {Name}"; + model.IsShowEdit = true; + } + + public async void Delete() + { + if (MessageBox.Show($"是否删除项目“{Name}”?", "请确认", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.Cancel) + { + return; + } + OperationResult result = null; + await _serviceProvider.ExecuteScopedWorkAsync(async provider => + { + IDataContract contract = provider.GetRequiredService(); + result = await contract.DeleteCodeProjects(Id); + }); + Helper.Notify(result); + if (!result.Succeeded) + { + return; + } + MainViewModel main = IoC.Get(); + main.ProjectList.Init(); + } - public bool CanSaveProject => !HasErrors; + public bool CanEditSave => !HasErrors; - public void SaveProject() + public async void EditSave() { MainViewModel main = IoC.Get(); - if (!Validate()) + if (!await ValidateAsync()) { main.Notify("项目信息验证失败", NotificationType.Warning); return; } CodeProject project = ToProject(); - string json = project.ToJsonString(); - File.WriteAllText("1.txt", json); - main.Notify($"项目“{Name}[{NamespacePrefix}]”保存成功", NotificationType.Success); - main.IsProjectOpen = false; + OperationResult result = null; + await _serviceProvider.ExecuteScopedWorkAsync(async provider => + { + IDataContract contract = provider.GetRequiredService(); + result = project.Id == default + ? await contract.CreateCodeProjects(project) + : await contract.UpdateCodeProjects(project); + }); + Helper.Notify(result); + if (!result.Succeeded) + { + return; + } + + ProjectListViewModel list = main.ProjectList; + list.EditingModel = null; + list.IsShowEdit = false; + list.Init(); } - public void CloseProject() + public void EditCancel() { - MainViewModel main = IoC.Get(); - main.IsProjectOpen = false; + var list = IoC.Get(); + list.EditingModel = null; + list.IsShowEdit = false; + list.Init(); } /// @@ -83,7 +151,7 @@ namespace OSharp.CodeGenerator.Views base.OnValidationStateChanged(changedProperties); // Fody 无法编织其他组件,所以我们必须手动提高这个值 - this.NotifyOfPropertyChange(() => CanSaveProject); + this.NotifyOfPropertyChange(() => CanEditSave); } public CodeProject ToProject() diff --git a/src/OSharp.CodeGenerator/Views/Properties/PropertyListViewModel.cs b/src/OSharp.CodeGenerator/Views/Properties/PropertyListViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..d999257dbd24a5565c0ec8e67e02e78d15a51955 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/Properties/PropertyListViewModel.cs @@ -0,0 +1,26 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2021 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2021-04-08 13:44 +// ----------------------------------------------------------------------- + +using System; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views.Properties +{ + public class PropertyListViewModel : Screen + { + private readonly IServiceProvider _provider; + + public PropertyListViewModel(IServiceProvider provider) + { + _provider = provider; + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/PropertyViewModel.cs b/src/OSharp.CodeGenerator/Views/Properties/PropertyViewModel.cs similarity index 77% rename from src/OSharp.CodeGenerator/Views/PropertyViewModel.cs rename to src/OSharp.CodeGenerator/Views/Properties/PropertyViewModel.cs index a5ba29262014fb35e2de21ef45a35fe0abd2ac34..ad20820ef6edfbad8c2ed86796506588d275ca5b 100644 --- a/src/OSharp.CodeGenerator/Views/PropertyViewModel.cs +++ b/src/OSharp.CodeGenerator/Views/Properties/PropertyViewModel.cs @@ -9,21 +9,23 @@ using FluentValidation; -using OSharp.CodeGeneration.Entities; +using OSharp.CodeGeneration.Services.Entities; +using OSharp.CodeGenerator.Views.Entities; using OSharp.Mapping; using Stylet; -namespace OSharp.CodeGenerator.Views +namespace OSharp.CodeGenerator.Views.Properties { [MapTo(typeof(CodeProperty))] + [MapFrom(typeof(CodeProperty))] public class PropertyViewModel : Screen { /// /// 初始化一个类型的新实例 /// - public PropertyViewModel(IModelValidatorvalidator) : base(validator) + public PropertyViewModel(IModelValidator validator) : base(validator) { Validate(); } @@ -52,6 +54,8 @@ namespace OSharp.CodeGenerator.Views public bool IsNullable { get; set; } + public bool IsVirtual { get; set; } + public bool IsForeignKey { get; set; } public bool IsNavigation { get; set; } @@ -66,6 +70,8 @@ namespace OSharp.CodeGenerator.Views public string DefaultValue { get; set; } + public int Order { get; set; } + public CodeProperty ToProperty() { CodeProperty property = this.MapTo(); @@ -74,13 +80,14 @@ namespace OSharp.CodeGenerator.Views } - public class PropertyViewModelValidator : AbstractValidator + public class PropertyViewModelValidator : AbstractValidator { public PropertyViewModelValidator() { RuleFor(m => m.Name) - .NotEmpty().WithMessage("实体类名称不能为空") - .Matches("^[a-zA-Z_\u2E80-\u9FFF][0-9a-zA-Z_\u2E80-\u9FFF]*$").WithMessage("实体名称不符合标识符命名规则,只能是字母、数值、下划线、汉字,并且不能以数值开关"); + .NotEmpty().WithMessage("属性名称不能为空") + .Matches("^[a-zA-Z_\u2E80-\u9FFF][0-9a-zA-Z_\u2E80-\u9FFF]*$").WithMessage("属性名称不符合标识符命名规则,只能是字母、数值、下划线、汉字,并且不能以数值开关"); + RuleFor(m => m.TypeName).NotEmpty().WithMessage("属性类型名不能为空"); } } } diff --git a/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs b/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs index c67699725e1e0846cc0884033ef7878871d6490c..7d2565097daf39e178daec2c4f69a58765c8efc5 100644 --- a/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs +++ b/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs @@ -1,19 +1,50 @@ // ----------------------------------------------------------------------- // -// Copyright (c) 2014-2020 OSharp. All rights reserved. +// Copyright (c) 2014-2021 OSharp. All rights reserved. // // http://www.osharp.org // 郭明锋 -// 2020-05-05 23:51 +// 2021-04-07 22:24 // ----------------------------------------------------------------------- -using OSharp.Wpf.Stylet; +using System; + +using Microsoft.EntityFrameworkCore; + +using OSharp.CodeGeneration.Services.Entities; namespace OSharp.CodeGenerator.Views { public class ViewModelLocator { - public MainViewModel Main => IoC.Get(); + /// + /// 获取 实体主键类型数据源 + /// + public string[] EntityKeys { get; } = + { + typeof(int).FullName, + typeof(Guid).FullName, + typeof(string).FullName, + typeof(long).FullName + }; + + public string[] TypeNames { get; } = + { + typeof(string).FullName, + typeof(int).FullName, + typeof(bool).FullName, + typeof(double).FullName, + typeof(DateTime).FullName, + typeof(Guid).FullName, + typeof(long).FullName, + "ICollection<>" + }; + + public ForeignRelation[] ForeignRelations { get; } = { ForeignRelation.ManyToOne, ForeignRelation.OneToMany, ForeignRelation.OneToOne, ForeignRelation.OwnsOne, ForeignRelation.OwnsMany }; + + public DeleteBehavior?[] DeleteBehaviors { get; } = + { null, DeleteBehavior.ClientSetNull, DeleteBehavior.Restrict, DeleteBehavior.SetNull, DeleteBehavior.Cascade }; + } } diff --git a/src/OSharp.CodeGenerator/Views/ViewModelPack.cs b/src/OSharp.CodeGenerator/Views/ViewModelPack.cs index 274c688a50dcd31ba259935981171818d68664fd..8c05ed4035d8086e57c0478883dbf92be59ec3c3 100644 --- a/src/OSharp.CodeGenerator/Views/ViewModelPack.cs +++ b/src/OSharp.CodeGenerator/Views/ViewModelPack.cs @@ -11,7 +11,10 @@ using System.Reflection; using Microsoft.Extensions.DependencyInjection; +using OSharp.AutoMapper; +using OSharp.CodeGenerator.Data; using OSharp.Core.Packs; +using OSharp.Mapping; using OSharp.Wpf.Stylet; @@ -29,6 +32,8 @@ namespace OSharp.CodeGenerator.Views services.AddViewModels(assembly); services.AddViews(assembly); + services.AddSingleton(); + return services; } } diff --git a/src/OSharp.CodeGenerator/osharp-code-generator.db b/src/OSharp.CodeGenerator/osharp-code-generator.db new file mode 100644 index 0000000000000000000000000000000000000000..9d952f8369783353af83157c437988fde208a63b Binary files /dev/null and b/src/OSharp.CodeGenerator/osharp-code-generator.db differ