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