diff --git a/.editorconfig b/.editorconfig index 29d1335653564ab081cfe3a7a06a6754ff193fa2..8c63803a4ac8d028d140e8933ceeb4b396361101 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,24 +2,24 @@ root = true [*] -#񣺿ո +#缩进风格:空格 indent_style = space -#С2 +#缩进大小2 indent_size = 4 -#зlf +#换行符lf end_of_line = lf -#ַutf-8 +#字符集utf-8 charset = utf-8 -#ǷɾβĿո +#是否删除行尾的空格 trim_trailing_whitespace = true -#Ƿļһ +#是否在文件的最后插入一个空行 insert_final_newline = true -[*.xaml] +[*.{xaml,json,csproj}] indent_size = 2 [*.md] trim_trailing_whitespace = false [Makefile] -indent_style = tab \ No newline at end of file +indent_style = tab diff --git a/OSharp.CodeGenerator.sln b/OSharp.CodeGenerator.sln index 091618660ebf108c4f2e88914156ea25904e34a9..ef756fbd6f9e952dec5e4df3eb9e55958dd35831 100644 --- a/OSharp.CodeGenerator.sln +++ b/OSharp.CodeGenerator.sln @@ -10,7 +10,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{CE0E16CA EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{87C5555B-87C3-46FE-9BF0-ACA575890EC6}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OSharp.CodeGenerator", "src\OSharp.CodeGenerator\OSharp.CodeGenerator.csproj", "{5AF55A1E-7A19-4886-B4B0-D840694AA997}" +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}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -22,12 +24,17 @@ Global {5AF55A1E-7A19-4886-B4B0-D840694AA997}.Debug|Any CPU.Build.0 = Debug|Any CPU {5AF55A1E-7A19-4886-B4B0-D840694AA997}.Release|Any CPU.ActiveCfg = Release|Any CPU {5AF55A1E-7A19-4886-B4B0-D840694AA997}.Release|Any CPU.Build.0 = Release|Any CPU + {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution {5AF55A1E-7A19-4886-B4B0-D840694AA997} = {87C5555B-87C3-46FE-9BF0-ACA575890EC6} + {B05EB364-E7CA-4EB5-93EA-3FD33BCAAFAA} = {87C5555B-87C3-46FE-9BF0-ACA575890EC6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AFCE6A5E-D5ED-4BAA-8CCF-45A229EF3405} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs new file mode 100644 index 0000000000000000000000000000000000000000..0140a6a488eff70f82ae44b18b8d87c8699f46aa --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeEntity.cs @@ -0,0 +1,61 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.ComponentModel; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + /// + /// 实体类:代码实体信息 + /// + [Description("代码实体信息")] + [TableNamePrefix("CodeGen")] + public class CodeEntity : EntityBase + { + /// + /// 获取或设置 类型名称 + /// + public string Name { get; set; } + + /// + /// 获取或设置 类型显示名称 + /// + public string Display { get; set; } + + /// + /// 获取或设置 主键类型全名 + /// + public string PrimaryKeyTypeFullName { get; set; } + + /// + /// 获取或设置 是否数据权限控制 + /// + public bool IsDataAuth { get; set; } + + /// + /// 获取或设置 所属模块编号 + /// + public Guid ModuleId { get; set; } + + /// + /// 获取或设置 所属模块 + /// + public virtual CodeModule Module { get; set; } + + /// + /// 获取或设置 实体的属性集合 + /// + public virtual ICollection Properties { get; set; } = new List(); + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..a137c56b3b92c2aaced48cffed8797806ab0f838 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeEntityConfiguration.cs @@ -0,0 +1,28 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + public class CodeEntityConfiguration : EntityTypeConfigurationBase + { + /// 重写以实现实体类型各个属性的数据库配置 + /// 实体类型创建器 + public override void Configure(EntityTypeBuilder builder) + { + builder.HasOne(m => m.Module).WithMany(n => n.Entities).HasForeignKey(m => m.ModuleId).IsRequired(); + } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs new file mode 100644 index 0000000000000000000000000000000000000000..99f25c4b34190f9366d53a97a1967cccc00b43dc --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeModule.cs @@ -0,0 +1,56 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.ComponentModel; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + /// + /// 实体类:代码模块信息 + /// + [Description("代码模块信息")] + [TableNamePrefix("CodeGen")] + public class CodeModule : EntityBase + { + /// + /// 获取或设置 模块名称 + /// + public string Name { get; set; } + + /// + /// 获取或设置 模块显示名称 + /// + public string Display { get; set; } + + /// + /// 获取或设置 所属项目编号 + /// + public Guid ProjectId { get; set; } + + /// + /// 获取或设置 所属项目 + /// + public virtual CodeProject Project { get; set; } + + /// + /// 获取或设置 模块的实体集合 + /// + public virtual ICollection Entities { get; set; } = new List(); + + /// + /// 获取 模块命名空间,由“项目命名空间前缀.模块名称”组成 + /// + public string Namespace => $"{(Project == null ? "" : Project.NamespacePrefix + ".")}{Name}"; + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..d40ffc5a774ed5ecca21429059dac5c0539ebacf --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeModuleConfiguration.cs @@ -0,0 +1,28 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + public class CodeModuleConfiguration : EntityTypeConfigurationBase + { + /// 重写以实现实体类型各个属性的数据库配置 + /// 实体类型创建器 + public override void Configure(EntityTypeBuilder builder) + { + builder.HasOne(m => m.Project).WithMany(n => n.Modules).HasForeignKey(m => m.ProjectId).IsRequired(); + } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs new file mode 100644 index 0000000000000000000000000000000000000000..2f4da4101011f0bd8eab8523eb5061f6c45cfa69 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeProject.cs @@ -0,0 +1,67 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.ComponentModel; + +using OSharp.Data; +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + /// + /// 实体类:代码项目信息 + /// + [Description("代码项目信息")] + [TableNamePrefix("CodeGen")] + public class CodeProject : EntityBase + { + public CodeProject() + { + Id = SequentialGuid.Create(DatabaseType.Sqlite); + } + + /// + /// 获取或设置 项目名称 + /// + public string Name { get; set; } + + /// + /// 获取或设置 公司 + /// + public string Company { get; set; } + + /// + /// 获取或设置 项目命名空间前缀,通常形如“公司.项目” + /// + public string NamespacePrefix { get; set; } + + /// + /// 获取或设置 站点地址 + /// + public string SiteUrl { get; set; } + + /// + /// 获取或设置 创建者 + /// + public string Creator { get; set; } + + /// + /// 获取或设置 Copyright + /// + public string Copyright { get; set; } + + /// + /// 获取或设置 模块信息集合 + /// + public virtual ICollection Modules { get; set; } = new List(); + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs b/src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..07aaa43cdf83f7a653b884f795e93064fd192a04 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeProjectConfiguration.cs @@ -0,0 +1,26 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.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/Data/Entities/CodeProperty.cs new file mode 100644 index 0000000000000000000000000000000000000000..76991c8baddfb75e0684a02c489aa6fb1565b617 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodeProperty.cs @@ -0,0 +1,90 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; +using System.ComponentModel; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + /// + /// 实体类:代码实体属性信息 + /// + [Description("代码实体属性")] + [TableNamePrefix("CodeGen")] + public class CodeProperty : EntityBase + { + /// + /// 获取或设置 属性名称 + /// + public string Name { get; set; } + + /// + /// 获取或设置 属性类型名称 + /// + public string TypeName { get; set; } + + /// + /// 获取或设置 显示名称 + /// + public string Display { get; set; } + + /// + /// 获取或设置 是否必须 + /// + public bool? IsRequired { get; set; } + + /// + /// 获取或设置 最大长度 + /// + public int? MaxLength { get; set; } + + /// + /// 获取或设置 最小长度 + /// + public int? MinLength { get; set; } + + /// + /// 获取或设置 是否值类型可空 + /// + public bool IsNullable { get; set; } + + /// + /// 获取或设置 是否虚属性 + /// + public bool IsVirtual { get; set; } + + /// + /// 获取或设置 是否外键 + /// + public bool IsForeignKey { get; set; } + + /// + /// 获取或设置 是否包含在输入Dto + /// + public bool IsInputDto { get; set; } = true; + + /// + /// 获取或设置 是否包含在输出Dto + /// + public bool IsOutputDto { get; set; } = true; + + /// + /// 获取或设置 实体编号 + /// + public Guid EntityId { get; set; } + + /// + /// 获取或设置 所属实体信息 + /// + public virtual CodeEntity Entity { get; set; } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs b/src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..30083b81270b1b038efb58da4320c1e677692e98 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/CodePropertyConfiguration.cs @@ -0,0 +1,28 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 23:06 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Entities +{ + public class CodePropertyConfiguration : EntityTypeConfigurationBase + { + /// 重写以实现实体类型各个属性的数据库配置 + /// 实体类型创建器 + public override void Configure(EntityTypeBuilder builder) + { + builder.HasOne(m => m.Entity).WithMany(n => n.Properties).HasForeignKey(m => m.EntityId).IsRequired(); + } + } +} diff --git a/src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs b/src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..ab5a80b4d0a311fc82769b93d0f1799249e9dc04 --- /dev/null +++ b/src/OSharp.CodeGeneration/Data/Entities/KeyValueConfiguration.cs @@ -0,0 +1,27 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-05 0:00 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +using OSharp.Core.Systems; +using OSharp.Entity; + + +namespace OSharp.CodeGeneration.Data.Entities +{ + public class KeyValueConfiguration : EntityTypeConfigurationBase + { + /// 重写以实现实体类型各个属性的数据库配置 + /// 实体类型创建器 + public override void Configure(EntityTypeBuilder builder) + { } + } +} diff --git a/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj b/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj new file mode 100644 index 0000000000000000000000000000000000000000..8c70e87ec8741b02cc318f08cbd9646a84ab87bd --- /dev/null +++ b/src/OSharp.CodeGeneration/OSharp.CodeGeneration.csproj @@ -0,0 +1,14 @@ + + + + net5.0-windows + + + + + + + + + + diff --git a/src/OSharp.CodeGenerator/App.xaml b/src/OSharp.CodeGenerator/App.xaml index 9cd9d8b00fb07dddcb25ca9d2d1c077327f3259a..6779d8b03b01dc64df7f73c88eccbcc09e61ce36 100644 --- a/src/OSharp.CodeGenerator/App.xaml +++ b/src/OSharp.CodeGenerator/App.xaml @@ -1,20 +1,26 @@ - + xmlns:local="clr-namespace:OSharp.CodeGenerator" + xmlns:views="clr-namespace:OSharp.CodeGenerator.Views"> - - + + + + + + diff --git a/src/OSharp.CodeGenerator/App.xaml.cs b/src/OSharp.CodeGenerator/App.xaml.cs index bd803a463a27419411d3ee24a919860f3c0dc08e..5ef7c248d40bfd5e35b659024328c744a4f3a210 100644 --- a/src/OSharp.CodeGenerator/App.xaml.cs +++ b/src/OSharp.CodeGenerator/App.xaml.cs @@ -1,10 +1,13 @@ -using System; +using System; using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; using System.Threading.Tasks; using System.Windows; +using System.Windows.Threading; + +using Microsoft.Extensions.Logging; + +using OSharp.Collections; +using OSharp.Dependency; namespace OSharp.CodeGenerator { @@ -13,5 +16,87 @@ namespace OSharp.CodeGenerator /// public partial class App : Application { + private ILogger _logger; + + /// + /// 初始化一个类型的新实例 + /// + public App() + { + //注册全局事件 + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + DispatcherUnhandledException += App_DispatcherUnhandledException; + TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; + } + + private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs args) + { + const string msg = "主线程异常"; + try + { + if (args.ExceptionObject is Exception && Dispatcher != null) + { + Dispatcher.Invoke(() => + { + Exception ex = (Exception)args.ExceptionObject; + HandleException(msg, ex); + }); + } + } + catch (Exception ex) + { + HandleException(msg, ex); + } + } + + private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs args) + { + const string msg = "子线程异常"; + try + { + HandleException(msg, args.Exception); + args.Handled = true; + } + catch (Exception ex) + { + HandleException(msg, ex); + } + } + + private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs args) + { + const string msg = "异步异常"; + try + { + HandleException(msg, args.Exception); + args.SetObserved(); + } + catch (Exception ex) + { + HandleException(msg, ex); + } + } + + private void HandleException(string msg, Exception ex) + { + if (_logger == null) + { + _logger = ServiceLocator.Instance.GetLogger(typeof(App)); + } + + List lines = new List(); + Exception innerEx = ex; + while (innerEx != null) + { + lines.Add(innerEx.Message); + innerEx = innerEx.InnerException; + } + + string detail = lines.ExpandAndToString("\r\n---"); + msg = $"{msg}: {detail}"; + _logger?.LogCritical(ex, msg); + MessageBox.Show($"错误消息:{detail}", "错误提示", MessageBoxButton.OK, MessageBoxImage.Error); + } + } } diff --git a/src/OSharp.CodeGenerator/Bootstrapper.cs b/src/OSharp.CodeGenerator/Bootstrapper.cs index e77ee3ae9025ad956d4f353da6db892876444f80..d97bbbf867e2c79bd5067c73b8b4d0498fb0330f 100644 --- a/src/OSharp.CodeGenerator/Bootstrapper.cs +++ b/src/OSharp.CodeGenerator/Bootstrapper.cs @@ -1,19 +1,37 @@ -// ----------------------------------------------------------------------- +// ----------------------------------------------------------------------- // // Copyright (c) 2014-2020 OSharp. All rights reserved. // // http://www.osharp.org // 郭明锋 -// 2020-05-03 14:58 +// 2020-08-26 10:41 // ----------------------------------------------------------------------- -using OSharp.CodeGenerator.Views; +using Microsoft.Extensions.DependencyInjection; -using Stylet; +using OSharp.CodeGenerator.Views; +using OSharp.Wpf.Data; +using OSharp.Wpf.Stylet; namespace OSharp.CodeGenerator { - public class Bootstrapper : Bootstrapper - { } + public class Bootstrapper : ServiceProviderBootstrapper + { + private readonly Startup _startup = new Startup(); + + protected override void ConfigureIoC(IServiceCollection services) + { + _startup.ConfigureServices(services); + } + + /// Hook called after the IoC container has been set up + protected override void Configure() + { + _startup.Configure(ServiceProvider); + IoC.Initialize(ServiceProvider); + MainViewModel main = IoC.Get(); + Output.StatusBar = msg => main.StatusBar.Message = msg; + } + } } diff --git a/src/OSharp.CodeGenerator/Data/DesignTimeDefaultDbContextFactory.cs b/src/OSharp.CodeGenerator/Data/DesignTimeDefaultDbContextFactory.cs new file mode 100644 index 0000000000000000000000000000000000000000..9d6dbac9890d5dd46bc178f004b2a5e83344e490 --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/DesignTimeDefaultDbContextFactory.cs @@ -0,0 +1,42 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-08-25 23:16 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.Entity; + + +namespace OSharp.CodeGenerator.Data +{ + public class DesignTimeDefaultDbContextFactory : DesignTimeDbContextFactoryBase + { + public DesignTimeDefaultDbContextFactory() + : base(null) + { } + + public DesignTimeDefaultDbContextFactory(IServiceProvider serviceProvider) + : base(serviceProvider) + { } + + /// + /// 创建设计时使用的ServiceProvider,主要用于执行 Add-Migration 功能 + /// + /// + 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/SqliteDefaultDbContextMigrationPack.cs b/src/OSharp.CodeGenerator/Data/SqliteDefaultDbContextMigrationPack.cs new file mode 100644 index 0000000000000000000000000000000000000000..9940d7e7f1e0be31885d7d8252bde06f0774f267 --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/SqliteDefaultDbContextMigrationPack.cs @@ -0,0 +1,39 @@ +using System; +using System.ComponentModel; + +using OSharp.Core.Packs; +using OSharp.Entity; +using OSharp.Entity.Sqlite; + + +namespace OSharp.CodeGenerator.Data +{ + /// + /// Sqlite-DefaultDbContext迁移模块 + /// + [DependsOnPacks(typeof(SqliteEntityFrameworkCorePack))] + [Description("Sqlite-DefaultDbContext迁移模块")] + public class SqliteDefaultDbContextMigrationPack : MigrationPackBase + { + /// + /// 获取 模块启动顺序,模块启动的顺序先按级别启动,级别内部再按此顺序启动, + /// 级别默认为0,表示无依赖,需要在同级别有依赖顺序的时候,再重写为>0的顺序值 + /// + public override int Order => 2; + + /// + /// 获取 数据库类型 + /// + protected override DatabaseType DatabaseType => DatabaseType.Sqlite; + + /// + /// 重写实现获取数据上下文实例 + /// + /// 服务提供者 + /// + protected override DefaultDbContext CreateDbContext(IServiceProvider scopedProvider) + { + return new DesignTimeDefaultDbContextFactory(scopedProvider).CreateDbContext(new string[0]); + } + } +} diff --git a/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs b/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs new file mode 100644 index 0000000000000000000000000000000000000000..e5d169e322f181d3b0943f64573dba4840c82b49 --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/SqliteDesignTimeDefaultDbContextFactory.cs @@ -0,0 +1,26 @@ +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 new file mode 100644 index 0000000000000000000000000000000000000000..bc0e8f93c433f0745730d6819f57e64e0fe5d5ce --- /dev/null +++ b/src/OSharp.CodeGenerator/Data/Startup.cs @@ -0,0 +1,16 @@ +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/FodyWeavers.xsd b/src/OSharp.CodeGenerator/FodyWeavers.xsd index 221aeb8a5477a7077cac281ed052333d6e8f094f..69dbe488cee79454bf999f336aa11c7dd4321892 100644 --- a/src/OSharp.CodeGenerator/FodyWeavers.xsd +++ b/src/OSharp.CodeGenerator/FodyWeavers.xsd @@ -11,6 +11,16 @@ Used to control if the On_PropertyName_Changed feature is enabled. + + + Used to control if the Dependent properties feature is enabled. + + + + + Used to control if the IsChanged property feature is enabled. + + Used to change the name of the method that fires the notify event. This is a string that accepts multiple values in a comma separated form. diff --git a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs b/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs new file mode 100644 index 0000000000000000000000000000000000000000..507b666c9a5aa197791d8eabc321487c82fc382c --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.Designer.cs @@ -0,0 +1,286 @@ +// +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("20200826024343_Init")] + partial class Init + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); + + 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() + .HasName("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("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Area", "Controller", "Action") + .IsUnique() + .HasName("AreaControllerActionIndex"); + + b.ToTable("Auth_Function"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Display") + .HasColumnType("TEXT"); + + b.Property("IsDataAuth") + .HasColumnType("INTEGER"); + + b.Property("ModuleId") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("PrimaryKeyTypeFullName") + .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("Display") + .HasColumnType("TEXT"); + + b.Property("Name") + .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") + .HasColumnType("TEXT"); + + b.Property("Copyright") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NamespacePrefix") + .HasColumnType("TEXT"); + + b.Property("SiteUrl") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeProject"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Display") + .HasColumnType("TEXT"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("IsForeignKey") + .HasColumnType("INTEGER"); + + b.Property("IsInputDto") + .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") + .HasColumnType("TEXT"); + + b.Property("TypeName") + .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.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(); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeProject", "Project") + .WithMany("Modules") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeEntity", "Entity") + .WithMany("Properties") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs b/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs new file mode 100644 index 0000000000000000000000000000000000000000..d3bb02f2232f6bec256b2b000ba50f6162a4b7e8 --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/20200826024343_Init.cs @@ -0,0 +1,204 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace OSharp.CodeGenerator.Migrations +{ + public partial class Init : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Auth_EntityInfo", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Auth_Function", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeProject", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_Systems_KeyValue", x => x.Id); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeModule", x => x.Id); + table.ForeignKey( + name: "FK_CodeGen_CodeModule_CodeGen_CodeProject_ProjectId", + column: x => x.ProjectId, + principalTable: "CodeGen_CodeProject", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeEntity", x => x.Id); + table.ForeignKey( + name: "FK_CodeGen_CodeEntity_CodeGen_CodeModule_ModuleId", + column: x => x.ModuleId, + principalTable: "CodeGen_CodeModule", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + 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) + }, + constraints: table => + { + table.PrimaryKey("PK_CodeGen_CodeProperty", x => x.Id); + table.ForeignKey( + name: "FK_CodeGen_CodeProperty_CodeGen_CodeEntity_EntityId", + column: x => x.EntityId, + principalTable: "CodeGen_CodeEntity", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ClassFullNameIndex", + table: "Auth_EntityInfo", + column: "TypeName", + unique: true); + + migrationBuilder.CreateIndex( + name: "AreaControllerActionIndex", + table: "Auth_Function", + columns: new[] { "Area", "Controller", "Action" }, + unique: true); + + migrationBuilder.CreateIndex( + name: "IX_CodeGen_CodeEntity_ModuleId", + table: "CodeGen_CodeEntity", + column: "ModuleId"); + + migrationBuilder.CreateIndex( + name: "IX_CodeGen_CodeModule_ProjectId", + table: "CodeGen_CodeModule", + column: "ProjectId"); + + migrationBuilder.CreateIndex( + name: "IX_CodeGen_CodeProperty_EntityId", + table: "CodeGen_CodeProperty", + column: "EntityId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Auth_EntityInfo"); + + migrationBuilder.DropTable( + name: "Auth_Function"); + + migrationBuilder.DropTable( + name: "CodeGen_CodeProperty"); + + migrationBuilder.DropTable( + name: "Systems_KeyValue"); + + migrationBuilder.DropTable( + name: "CodeGen_CodeEntity"); + + migrationBuilder.DropTable( + name: "CodeGen_CodeModule"); + + migrationBuilder.DropTable( + name: "CodeGen_CodeProject"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs b/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs new file mode 100644 index 0000000000000000000000000000000000000000..3bffb77c94648944a625f2be8c1a18e0e049e7de --- /dev/null +++ b/src/OSharp.CodeGenerator/Migrations/DefaultDbContextModelSnapshot.cs @@ -0,0 +1,284 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using OSharp.Entity; + +namespace OSharp.CodeGenerator.Migrations +{ + [DbContext(typeof(DefaultDbContext))] + partial class DefaultDbContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.7"); + + 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() + .HasName("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("Name") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.HasIndex("Area", "Controller", "Action") + .IsUnique() + .HasName("AreaControllerActionIndex"); + + b.ToTable("Auth_Function"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeEntity", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Display") + .HasColumnType("TEXT"); + + b.Property("IsDataAuth") + .HasColumnType("INTEGER"); + + b.Property("ModuleId") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("PrimaryKeyTypeFullName") + .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("Display") + .HasColumnType("TEXT"); + + b.Property("Name") + .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") + .HasColumnType("TEXT"); + + b.Property("Copyright") + .HasColumnType("TEXT"); + + b.Property("Creator") + .HasColumnType("TEXT"); + + b.Property("Name") + .HasColumnType("TEXT"); + + b.Property("NamespacePrefix") + .HasColumnType("TEXT"); + + b.Property("SiteUrl") + .HasColumnType("TEXT"); + + b.HasKey("Id"); + + b.ToTable("CodeGen_CodeProject"); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("TEXT"); + + b.Property("Display") + .HasColumnType("TEXT"); + + b.Property("EntityId") + .HasColumnType("TEXT"); + + b.Property("IsForeignKey") + .HasColumnType("INTEGER"); + + b.Property("IsInputDto") + .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") + .HasColumnType("TEXT"); + + b.Property("TypeName") + .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.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(); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeModule", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeProject", "Project") + .WithMany("Modules") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("OSharp.CodeGeneration.Entities.CodeProperty", b => + { + b.HasOne("OSharp.CodeGeneration.Entities.CodeEntity", "Entity") + .WithMany("Properties") + .HasForeignKey("EntityId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj b/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj index e0b80fda89cfd1a94cc65c4e3249571dc6df8ae5..a4d7f41eeb26cc8495a1b7d555ded53993ba0330 100644 --- a/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj +++ b/src/OSharp.CodeGenerator/OSharp.CodeGenerator.csproj @@ -2,19 +2,56 @@ WinExe - netcoreapp3.1 + net5.0-windows true + OSharp.CodeGenerator + Resources\osharp128-2.ico - - - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + - + + + + + + + + + + + Always + + + + + + + + + + + + + + + + + + Always + \ No newline at end of file diff --git a/src/OSharp.CodeGenerator/Resources/osharp128-2.ico b/src/OSharp.CodeGenerator/Resources/osharp128-2.ico new file mode 100644 index 0000000000000000000000000000000000000000..bc7aee97423b6d7a6e1b164a5df1d87bfa712db8 Binary files /dev/null and b/src/OSharp.CodeGenerator/Resources/osharp128-2.ico differ diff --git a/src/OSharp.CodeGenerator/Resources/osharp128-2.png b/src/OSharp.CodeGenerator/Resources/osharp128-2.png new file mode 100644 index 0000000000000000000000000000000000000000..e42b7e6a69b663a357c591c925f3dce3e4c17eae Binary files /dev/null and b/src/OSharp.CodeGenerator/Resources/osharp128-2.png differ diff --git a/src/OSharp.CodeGenerator/Resources/osharp128.ico b/src/OSharp.CodeGenerator/Resources/osharp128.ico new file mode 100644 index 0000000000000000000000000000000000000000..bfa41dd6889597e814ac0ac84fb77e538d34741a Binary files /dev/null and b/src/OSharp.CodeGenerator/Resources/osharp128.ico differ diff --git a/src/OSharp.CodeGenerator/Resources/osharp128.png b/src/OSharp.CodeGenerator/Resources/osharp128.png new file mode 100644 index 0000000000000000000000000000000000000000..d7f068d9091a863e4c275aba659e23bc0ac18db7 Binary files /dev/null and b/src/OSharp.CodeGenerator/Resources/osharp128.png differ diff --git a/src/OSharp.CodeGenerator/Resources/osharp128.svg b/src/OSharp.CodeGenerator/Resources/osharp128.svg new file mode 100644 index 0000000000000000000000000000000000000000..86c2455d8fd8c84ed278a4637a1a47dcb65bd95b --- /dev/null +++ b/src/OSharp.CodeGenerator/Resources/osharp128.svg @@ -0,0 +1,9 @@ + + + + + + + \ No newline at end of file diff --git a/src/OSharp.CodeGenerator/Startup.cs b/src/OSharp.CodeGenerator/Startup.cs new file mode 100644 index 0000000000000000000000000000000000000000..90955df75d88af95a5eedac4c32911ddc691a1e8 --- /dev/null +++ b/src/OSharp.CodeGenerator/Startup.cs @@ -0,0 +1,38 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-08-26 10:26 +// ----------------------------------------------------------------------- + +using System; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.AutoMapper; +using OSharp.CodeGenerator.Data; +using OSharp.CodeGenerator.Views; +using OSharp.Log4Net; + + +namespace OSharp.CodeGenerator +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + services.AddOSharp() + .AddPack() + .AddPack() + .AddPack() + .AddPack(); + } + + public void Configure(IServiceProvider provider) + { + provider.UseOsharp(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/EntityViewModel.cs b/src/OSharp.CodeGenerator/Views/EntityViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..907a225fe48e4bb5684bd6600dceee56f0f884e9 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/EntityViewModel.cs @@ -0,0 +1,80 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-07 1:11 +// ----------------------------------------------------------------------- + +using FluentValidation; + +using OSharp.CodeGeneration.Entities; +using OSharp.Mapping; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + [MapTo(typeof(CodeEntity))] + public class EntityViewModel : Screen + { + /// + /// 初始化一个类型的新实例 + /// + public EntityViewModel(IModelValidator validator) + : base(validator) + { + Validate(); + Properties = new BindableCollection(); + } + + public ModuleViewModel Module { get; set; } + + public IObservableCollection Properties { get; set; } + + public string Name { get; set; } + + public string Display { get; set; } + + 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 CodeEntity ToEntity() + { + CodeEntity entity = this.MapTo(); + return entity; + } + } + + + public class EntityViewModelValidator : AbstractValidator + { + public EntityViewModelValidator() + { + RuleFor(m => m.Name) + .NotEmpty().WithMessage("实体类名称不能为空") + .Matches("^[a-zA-Z_\u2E80-\u9FFF][0-9a-zA-Z_\u2E80-\u9FFF]*$").WithMessage("实体名称不符合标识符命名规则,只能是字母、数值、下划线、汉字,并且不能以数值开关"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/MainMenuView.xaml b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..fe3c472acf3980ddd0d529f21379270ce278970f --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml @@ -0,0 +1,74 @@ + + + + + + + + diff --git a/src/OSharp.CodeGenerator/Views/MainMenuView.xaml.cs b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..3cbdc864314296e57795134ab596beebadad0f77 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/MainMenuView.xaml.cs @@ -0,0 +1,56 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-06 2:03 +// ----------------------------------------------------------------------- + +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; + +using MahApps.Metro.Controls; + + +namespace OSharp.CodeGenerator.Views +{ + /// + /// MainMenuView.xaml 的交互逻辑 + /// + public partial class MainMenuView + { + public MainMenuView() + { + InitializeComponent(); + } + + private void MenuButton_OnInitialized(object sender, EventArgs e) + { + if (!(sender is Button)) + { + return; + } + + Button btn = (Button)sender; + btn.ContextMenu = null; + } + + private void MenuButton_OnClick(object sender, RoutedEventArgs e) + { + if (!(sender is Button)) + { + return; + } + Button btn = (Button)sender; + string name = btn.Name.Replace("Btn", "Menu"); + if (btn.FindName(name) is ContextMenu menu) + { + menu.PlacementTarget = btn; + menu.IsOpen = true; + } + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/MainMenuViewModel.cs b/src/OSharp.CodeGenerator/Views/MainMenuViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..6c93d51a09c5d7c796999268bec944e32526ebe5 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/MainMenuViewModel.cs @@ -0,0 +1,105 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-03 18:09 +// ----------------------------------------------------------------------- + +using System; +using System.Windows; + +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + [Singleton] + public class MainMenuViewModel : Screen + { + private readonly IWindowManager _windowManager; + private readonly StatusBarViewModel _statusBar; + + public MainMenuViewModel(IWindowManager windowManager) + { + _windowManager = windowManager; + _statusBar = IoC.Get(); + } + + #region 文件 + + public void New() + { + //_windowManager.ShowDialog(IoC.Get().Project); + MainViewModel main = IoC.Get(); + main.IsProjectOpen = true; + } + + public void Open() + { + _statusBar.Message = "打开项目"; + } + + public void Save() + { + _statusBar.Message = "保存项目"; + } + + public void SaveAs() + { + _statusBar.Message = "项目另存为"; + } + + public void Exit() + { + Application.Current.MainWindow?.Close(); + } + + #endregion + + #region 项目 + + public void Project() + { + + } + + public void Module() + { + + } + + public void Template() + { + + } + + #endregion + + #region 设置 + + public void GlobalTemplate() + { + + } + + #endregion + + #region 帮助 + + public void Github() + { + + } + + public void About() + { + + } + + #endregion + } +} diff --git a/src/OSharp.CodeGenerator/Views/MainView.xaml b/src/OSharp.CodeGenerator/Views/MainView.xaml index 7cdbadeab30c6f1fe52ead91be8c5f7e1391ec86..fd537b8e328ab50c6764d27dd43baeb5feefc68f 100644 --- a/src/OSharp.CodeGenerator/Views/MainView.xaml +++ b/src/OSharp.CodeGenerator/Views/MainView.xaml @@ -1,19 +1,52 @@ - - - - + + + + + diff --git a/src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs b/src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs new file mode 100644 index 0000000000000000000000000000000000000000..0c64a256dd7ce3155d73a534ed6ae9c9155e31e9 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/ProjectView.xaml.cs @@ -0,0 +1,25 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-05 12:38 +// ----------------------------------------------------------------------- + +using OSharp.Wpf.Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + /// + /// ProjectView.xaml 的交互逻辑 + /// + public partial class ProjectView + { + public ProjectView() + { + InitializeComponent(); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/ProjectViewModel.cs b/src/OSharp.CodeGenerator/Views/ProjectViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..b96c27c21505b1c660f4c4b641615ec836ec8362 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/ProjectViewModel.cs @@ -0,0 +1,108 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 10:54 +// ----------------------------------------------------------------------- + +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.IO; + +using FluentValidation; + +using Notifications.Wpf.Core; + +using OSharp.CodeGeneration.Entities; +using OSharp.Extensions; +using OSharp.Json; +using OSharp.Mapping; +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + [MapTo(typeof(CodeProject))] + public class ProjectViewModel : Screen + { + public ProjectViewModel(IModelValidator validator) : base(validator) + { + Validate(); + Modules = new BindableCollection(); + } + + public IObservableCollection Modules { get; set; } + + public string Name { get; set; } = "示例项目"; + + public string NamespacePrefix { get; set; } = "Liuliu.Demo"; + + public string Company { get; set; } = "柳柳软件"; + + public string SiteUrl { get; set; } = "https://www.osharp.org"; + + public string Creator { get; set; } = "郭明锋"; + + public string Copyright { get; set; } = "Copyright OSHARP.ORG @2020"; + + public bool CanSaveProject => !HasErrors; + + public void SaveProject() + { + MainViewModel main = IoC.Get(); + if (!Validate()) + { + 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; + } + + public void CloseProject() + { + MainViewModel main = IoC.Get(); + main.IsProjectOpen = false; + } + + /// + /// 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); + + // Fody 无法编织其他组件,所以我们必须手动提高这个值 + this.NotifyOfPropertyChange(() => CanSaveProject); + } + + public CodeProject ToProject() + { + CodeProject project = this.MapTo(); + return project; + } + } + + + public class ProjectViewModelValidator : AbstractValidator + { + public ProjectViewModelValidator() + { + RuleFor(m => m.Name) + .NotEmpty().WithMessage("项目名称不能为空") + .Matches("^[a-zA-Z_\u2E80-\u9FFF][0-9a-zA-Z_\u2E80-\u9FFF]*$").WithMessage("项目名称不符合标识符命名规则,只能是字母、数值、下划线、汉字,并且不能以数值开关"); + RuleFor(m => m.NamespacePrefix).NotEmpty().WithMessage("命名空间前缀不能为空"); + RuleFor(m => m.SiteUrl).Must(m => m.IsNullOrEmpty() || new UrlAttribute().IsValid(m)).WithMessage("网站Url不符合URL格式"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/PropertyViewModel.cs b/src/OSharp.CodeGenerator/Views/PropertyViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..a5ba29262014fb35e2de21ef45a35fe0abd2ac34 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/PropertyViewModel.cs @@ -0,0 +1,86 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-07 1:27 +// ----------------------------------------------------------------------- + +using FluentValidation; + +using OSharp.CodeGeneration.Entities; +using OSharp.Mapping; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + [MapTo(typeof(CodeProperty))] + public class PropertyViewModel : Screen + { + /// + /// 初始化一个类型的新实例 + /// + public PropertyViewModel(IModelValidatorvalidator) : base(validator) + { + Validate(); + } + + public EntityViewModel Entity { get; set; } + + public string Name { get; set; } + + public string Display { get; set; } + + public string TypeName { get; set; } + + public bool Readonly { get; set; } + + public bool Updatable { get; set; } + + public bool Sortable { get; set; } + + public bool Filterable { get; set; } + + public bool IsRequired { get; set; } + + public int? MinLength { get; set; } + + public int? MaxLength { get; set; } + + public bool IsNullable { get; set; } + + public bool IsForeignKey { get; set; } + + public bool IsNavigation { get; set; } + + public string RelateEntity { get; set; } + + public string DataAuthFlag { get; set; } + + public bool IsInputDto { get; set; } + + public bool IsOutputDto { get; set; } + + public string DefaultValue { get; set; } + + public CodeProperty ToProperty() + { + CodeProperty property = this.MapTo(); + return property; + } + } + + + 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("实体名称不符合标识符命名规则,只能是字母、数值、下划线、汉字,并且不能以数值开关"); + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/StatusBarViewModel.cs b/src/OSharp.CodeGenerator/Views/StatusBarViewModel.cs new file mode 100644 index 0000000000000000000000000000000000000000..cc08dd13bb6f16c15ad8c0ebabf35eaf5a1c66a3 --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/StatusBarViewModel.cs @@ -0,0 +1,25 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-04 11:32 +// ----------------------------------------------------------------------- + +using OSharp.Wpf.Stylet; + +using Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + [Singleton] + public class StatusBarViewModel : Screen + { + /// + /// 获取或设置 状态栏消息 + /// + public string Message { get; set; } + } +} diff --git a/src/OSharp.CodeGenerator/Views/StatusbarView.xaml b/src/OSharp.CodeGenerator/Views/StatusbarView.xaml new file mode 100644 index 0000000000000000000000000000000000000000..7f8b1736c16aa135191be9b18df57ff645285d4f --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/StatusbarView.xaml @@ -0,0 +1,13 @@ + + + + + diff --git a/src/OSharp.CodeGenerator/Data/SingletonAttribute.cs b/src/OSharp.CodeGenerator/Views/StatusbarView.xaml.cs similarity index 55% rename from src/OSharp.CodeGenerator/Data/SingletonAttribute.cs rename to src/OSharp.CodeGenerator/Views/StatusbarView.xaml.cs index 49ed613c9a9779dc0250d1e4f38c584565a1ef11..f9220449a8428413ca598e6ae3ed8aa18056e833 100644 --- a/src/OSharp.CodeGenerator/Data/SingletonAttribute.cs +++ b/src/OSharp.CodeGenerator/Views/StatusbarView.xaml.cs @@ -1,21 +1,25 @@ // ----------------------------------------------------------------------- -// +// // Copyright (c) 2014-2020 OSharp. All rights reserved. // // http://www.osharp.org // 郭明锋 -// 2020-05-03 14:52 +// 2020-05-04 11:27 // ----------------------------------------------------------------------- -using System; +using System.Windows.Controls; namespace OSharp.CodeGenerator.Views { /// - /// 标注类型的注册到IoC的生命周期为Singleton + /// StatusBarView.xaml 的交互逻辑 /// - [AttributeUsage(AttributeTargets.Class)] - public class SingletonAttribute : Attribute - { } + public partial class StatusBarView + { + public StatusBarView() + { + InitializeComponent(); + } + } } diff --git a/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs b/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs new file mode 100644 index 0000000000000000000000000000000000000000..c67699725e1e0846cc0884033ef7878871d6490c --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/ViewModelLocator.cs @@ -0,0 +1,19 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-05 23:51 +// ----------------------------------------------------------------------- + +using OSharp.Wpf.Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + public class ViewModelLocator + { + public MainViewModel Main => IoC.Get(); + } +} diff --git a/src/OSharp.CodeGenerator/Views/ViewModelPack.cs b/src/OSharp.CodeGenerator/Views/ViewModelPack.cs new file mode 100644 index 0000000000000000000000000000000000000000..274c688a50dcd31ba259935981171818d68664fd --- /dev/null +++ b/src/OSharp.CodeGenerator/Views/ViewModelPack.cs @@ -0,0 +1,35 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) 2014-2020 OSharp. All rights reserved. +// +// http://www.osharp.org +// 郭明锋 +// 2020-05-05 15:38 +// ----------------------------------------------------------------------- + +using System.Reflection; + +using Microsoft.Extensions.DependencyInjection; + +using OSharp.Core.Packs; +using OSharp.Wpf.Stylet; + + +namespace OSharp.CodeGenerator.Views +{ + public class ViewModelPack : OsharpPack + { + /// 将模块服务添加到依赖注入服务容器中 + /// 依赖注入服务容器 + /// + public override IServiceCollection AddServices(IServiceCollection services) + { + Assembly assembly = Assembly.GetExecutingAssembly(); + services.AddValidators(assembly); + services.AddViewModels(assembly); + services.AddViews(assembly); + + return services; + } + } +} diff --git a/src/OSharp.CodeGenerator/Views/ViewModelsModule.cs b/src/OSharp.CodeGenerator/Views/ViewModelsModule.cs deleted file mode 100644 index ad7c76ca2315f14e7ce268e1c5f9a05e4b08d496..0000000000000000000000000000000000000000 --- a/src/OSharp.CodeGenerator/Views/ViewModelsModule.cs +++ /dev/null @@ -1,53 +0,0 @@ -// ----------------------------------------------------------------------- -// -// Copyright (c) 2014-2020 OSharp. All rights reserved. -// -// http://www.osharp.org -// 郭明锋 -// 2020-05-03 15:04 -// ----------------------------------------------------------------------- - -using System; -using System.Linq; -using System.Reflection; - -using FluentValidation; - -using OSharp.Reflection; -using OSharp.Wpf.FluentValidation; - -using Stylet; - -using StyletIoC; - - -namespace OSharp.CodeGenerator.Views -{ - public class ViewModelsModule : StyletIoCModule - { - /// - /// Override, and use 'Bind' to add bindings to the module - /// - protected override void Load() - { - // Validator - Bind(typeof(IValidator<>)).ToAllImplementations(); - Bind(typeof(IModelValidator<>)).To(typeof(FluentModelValidator<>)); - - // ViewModels - Type baseType = typeof(Screen); - Type[] types = Assembly.GetExecutingAssembly().GetTypes().Where(m => !m.IsAbstract && m.IsBaseOn(baseType)).ToArray(); - Type[] singletonTypes = types.Where(m => m.HasAttribute()).ToArray(); - - foreach (Type type in singletonTypes) - { - Bind(type).ToSelf().InSingletonScope(); - } - - foreach (Type type in types.Except(singletonTypes)) - { - Bind(type).ToSelf(); - } - } - } -} diff --git a/src/OSharp.CodeGenerator/appsettings.json b/src/OSharp.CodeGenerator/appsettings.json new file mode 100644 index 0000000000000000000000000000000000000000..2607c17a6afa68c59412093c759ad69aebdfb2d4 --- /dev/null +++ b/src/OSharp.CodeGenerator/appsettings.json @@ -0,0 +1,14 @@ +{ + "OSharp": { + "DbContexts": { + "Sqlite": { + "DbContextTypeName": "OSharp.Entity.DefaultDbContext,OSharp.EntityFrameworkCore", + "ConnectionString": "data source=osharp-code-generator.db", + "DatabaseType": "Sqlite", + "LazyLoadingProxiesEnabled": true, + "AuditEntityEnabled": true, + "AutoMigrationEnabled": true + } + } + } +} diff --git a/src/OSharp.CodeGenerator/log4net.config b/src/OSharp.CodeGenerator/log4net.config new file mode 100644 index 0000000000000000000000000000000000000000..b98cb821af587c3295abba7ced1261b4c5886ff1 --- /dev/null +++ b/src/OSharp.CodeGenerator/log4net.config @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file