Skip to content

Commit

Permalink
shell持久化ef core实现
Browse files Browse the repository at this point in the history
  • Loading branch information
china-live committed Jan 25, 2018
1 parent ba728d2 commit c32a3eb
Show file tree
Hide file tree
Showing 19 changed files with 950 additions and 60 deletions.

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions src/Dome.Modules/XCore.Migrator/Migrations/20180112170815_addShell.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;

namespace XCore.Migrator.Migrations
{
public partial class addShell : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "XCore_ShellDescriptor",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
SerialNumber = table.Column<int>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_XCore_ShellDescriptor", x => x.Id);
});

migrationBuilder.CreateTable(
name: "XCore_ShellState",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn)
},
constraints: table =>
{
table.PrimaryKey("PK_XCore_ShellState", x => x.Id);
});

migrationBuilder.CreateTable(
name: "ShellFeature",
columns: table => new
{
Id = table.Column<string>(nullable: false),
ShellDescriptorId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ShellFeature", x => x.Id);
table.ForeignKey(
name: "FK_ShellFeature_XCore_ShellDescriptor_ShellDescriptorId",
column: x => x.ShellDescriptorId,
principalTable: "XCore_ShellDescriptor",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateTable(
name: "ShellParameter",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
Component = table.Column<string>(nullable: true),
Name = table.Column<string>(nullable: true),
ShellDescriptorId = table.Column<int>(nullable: true),
Value = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ShellParameter", x => x.Id);
table.ForeignKey(
name: "FK_ShellParameter_XCore_ShellDescriptor_ShellDescriptorId",
column: x => x.ShellDescriptorId,
principalTable: "XCore_ShellDescriptor",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateTable(
name: "ShellFeatureState",
columns: table => new
{
Id = table.Column<string>(nullable: false),
EnableState = table.Column<int>(nullable: false),
InstallState = table.Column<int>(nullable: false),
ShellStateId = table.Column<int>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_ShellFeatureState", x => x.Id);
table.ForeignKey(
name: "FK_ShellFeatureState_XCore_ShellState_ShellStateId",
column: x => x.ShellStateId,
principalTable: "XCore_ShellState",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});

migrationBuilder.CreateIndex(
name: "IX_ShellFeature_ShellDescriptorId",
table: "ShellFeature",
column: "ShellDescriptorId");

migrationBuilder.CreateIndex(
name: "IX_ShellFeatureState_ShellStateId",
table: "ShellFeatureState",
column: "ShellStateId");

migrationBuilder.CreateIndex(
name: "IX_ShellParameter_ShellDescriptorId",
table: "ShellParameter",
column: "ShellDescriptorId");
}

protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "ShellFeature");

migrationBuilder.DropTable(
name: "ShellFeatureState");

migrationBuilder.DropTable(
name: "ShellParameter");

migrationBuilder.DropTable(
name: "XCore_ShellState");

migrationBuilder.DropTable(
name: "XCore_ShellDescriptor");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.EntityFrameworkCore.Storage.Internal;
using System;
using XCore.EntityFrameworkCore;
using XCore.Environment.Shell.State;

namespace XCore.Migrator.Migrations
{
Expand Down Expand Up @@ -111,6 +112,80 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("XCore_TencentVods");
});

modelBuilder.Entity("XCore.Environment.Shell.Descriptor.Models.ShellDescriptor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<int>("SerialNumber");

b.HasKey("Id");

b.ToTable("XCore_ShellDescriptor");
});

modelBuilder.Entity("XCore.Environment.Shell.Descriptor.Models.ShellFeature", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();

b.Property<int?>("ShellDescriptorId");

b.HasKey("Id");

b.HasIndex("ShellDescriptorId");

b.ToTable("ShellFeature");
});

modelBuilder.Entity("XCore.Environment.Shell.Descriptor.Models.ShellParameter", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.Property<string>("Component");

b.Property<string>("Name");

b.Property<int?>("ShellDescriptorId");

b.Property<string>("Value");

b.HasKey("Id");

b.HasIndex("ShellDescriptorId");

b.ToTable("ShellParameter");
});

modelBuilder.Entity("XCore.Environment.Shell.State.ShellFeatureState", b =>
{
b.Property<string>("Id")
.ValueGeneratedOnAdd();

b.Property<int>("EnableState");

b.Property<int>("InstallState");

b.Property<int?>("ShellStateId");

b.HasKey("Id");

b.HasIndex("ShellStateId");

b.ToTable("ShellFeatureState");
});

modelBuilder.Entity("XCore.Environment.Shell.State.ShellState", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();

b.HasKey("Id");

b.ToTable("XCore_ShellState");
});

modelBuilder.Entity("XCore.Identity.Role", b =>
{
b.Property<string>("Id")
Expand Down Expand Up @@ -275,6 +350,27 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.ToTable("XCore_UserTokens");
});

modelBuilder.Entity("XCore.Environment.Shell.Descriptor.Models.ShellFeature", b =>
{
b.HasOne("XCore.Environment.Shell.Descriptor.Models.ShellDescriptor")
.WithMany("Features")
.HasForeignKey("ShellDescriptorId");
});

modelBuilder.Entity("XCore.Environment.Shell.Descriptor.Models.ShellParameter", b =>
{
b.HasOne("XCore.Environment.Shell.Descriptor.Models.ShellDescriptor")
.WithMany("Parameters")
.HasForeignKey("ShellDescriptorId");
});

modelBuilder.Entity("XCore.Environment.Shell.State.ShellFeatureState", b =>
{
b.HasOne("XCore.Environment.Shell.State.ShellState")
.WithMany("Features")
.HasForeignKey("ShellStateId");
});

modelBuilder.Entity("XCore.Identity.RoleClaim", b =>
{
b.HasOne("XCore.Identity.Role")
Expand Down
10 changes: 7 additions & 3 deletions src/Dome.Modules/XCore.Migrator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public override void Configure(IApplicationBuilder app, IRouteBuilder routes, IS
}
}

// class MyDesignTimeServices : IDesignTimeServices
// {
// public void ConfigureDesignTimeServices(IServiceCollection services)
// => services.AddSingleton<IMigrationsCodeGenerator, MyMigrationsCodeGenerator>()
//}

public class AppContextFactory : IDesignTimeDbContextFactory<AppDbContext>
{
//string conString = "Data Source=www.dming.top;Database=XCore;UID=sa;[email protected];MultipleActiveResultSets=true;";
//string conString = "Data Source=192.168.8.127;Database=TongGenTongMeng;UID=Tong;PWD=123;MultipleActiveResultSets=true;";

public AppDbContext CreateDbContext(string[] args)
{
var configuration = new ConfigurationBuilder()
Expand All @@ -56,6 +59,7 @@ public AppDbContext CreateDbContext(string[] args)
var entityManager = new MigrationEntityManager(); //MigrationEntityManager实现了IEntityManager接口
entityManager.LoadAssemblys("XCore.Identity.EntityFrameworkCore");//加载实现了IEntityTypeConfiguration接口的类所在的程序集
entityManager.LoadAssemblys("XCore.Article.EntityFrameworkCore");
entityManager.LoadAssemblys("XCore.Environment.Shell.EntityFrameworkCore");

return new AppDbContext(optionsBuilder.Options, entityManager);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Dome.Modules/XCore.Migrator/XCore.Migrator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>tonggentongmeng-web</UserSecretsId>
<UserSecretsId>xcore</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -13,11 +13,12 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="$(AspNetCoreVersion)" />
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\XCore\XCore.EntityFrameworkCore\XCore.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Shell.EntityFrameworkCore\XCore.Environment.Shell.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Module.Targets\XCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Article.EntityFrameworkCore\XCore.Article.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Identity.EntityFrameworkCore\XCore.Identity.EntityFrameworkCore.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/Dome/XCore.Mvc.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using XCore.Environment.Extensions;
using XCore.Environment.Shell.Data;
using XCore.DisplayManagement;
using XCore.Environment.Shell;

namespace XCore.Mvc.Web
{
Expand Down
11 changes: 2 additions & 9 deletions src/Dome/XCore.Mvc.Web/XCore.Mvc.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<TypeScriptToolsVersion>2.6</TypeScriptToolsVersion>
<UserSecretsId>xcore</UserSecretsId>
<!--<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>-->
</PropertyGroup>
Expand All @@ -17,15 +18,7 @@
<EmbeddedResource Remove="App_Data\**" />
<None Remove="App_Data\**" />
</ItemGroup>

<ItemGroup>
<Content Remove="Views\_Layout.cshtml" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="Views\_Layout.cshtml" />
</ItemGroup>


<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion src/XCore.Modules/XCore.Commons/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
using XCore.DeferredTasks;
using XCore.DisplayManagement;
using XCore.EntityFrameworkCore;
using XCore.Environment.Shell;
using XCore.Environment.Shell.Data;
using XCore.Environment.Shell.EntityFrameworkCore;
using XCore.Modules;
using XCore.Mvc.Core;
using XCore.ResourceManagement;
Expand All @@ -36,7 +38,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddResourceManagement();
//services.AddGeneratorTagFilter();
//services.AddCaching();
services.AddShellDescriptorStorage();
services.AddShellDescriptorStorage().AddEntityFrameworkStores();
//services.AddExtensionManager();
services.AddTheming();
//services.AddLiquidViews();
Expand Down
3 changes: 2 additions & 1 deletion src/XCore.Modules/XCore.Commons/XCore.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<ProjectReference Include="..\..\XCore\XCore.DisplayManagement\XCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\XCore\XCore.EntityFrameworkCore\XCore.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Extensions\XCore.Environment.Extensions.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Shell.Data\XCore.Environment.Shell.Data.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Shell.EntityFrameworkCore\XCore.Environment.Shell.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Shell\XCore.Environment.Shell.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Module.Targets\XCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Mvc.Core\XCore.Mvc.Core.csproj" />
<ProjectReference Include="..\..\XCore\XCore.ResourceManagement\XCore.ResourceManagement.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/// </summary>
public class ShellParameter
{
public int Id { get; set; }
public string Component { get; set; }
public string Name { get; set; }
public string Value { get; set; }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using XCore.Environment.Shell.Data;

namespace XCore.Environment.Shell.EntityFrameworkCore
{
public static class EntityFrameworkBuilderExtensions
{
public static ShellBuilder AddEntityFrameworkStores(this ShellBuilder builder)
{
builder.AddShellDescriptorStore<ShellDescriptorStore>();
builder.AddShellStateStore<ShellStateStore>();
return builder;
}
}
}
Loading

0 comments on commit c32a3eb

Please sign in to comment.