merge
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Ewide.Core\Ewide.Core.csproj" />
|
||||
<ProjectReference Include="..\Ewide.EntityFramework.Core\Ewide.EntityFramework.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -4,6 +4,12 @@
|
||||
<name>Ewide.Application</name>
|
||||
</assembly>
|
||||
<members>
|
||||
<member name="M:Ewide.Application.Service.HouseProjectInfo.XMLHandler.GetDataBase">
|
||||
<summary>
|
||||
读取数据库的所有表 并拿到数据
|
||||
</summary>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="T:Ewide.Application.Service.HouseProjectInfo.HouseProjectInfoService">
|
||||
<summary>
|
||||
项目管理相关服务
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
using Ewide.Application.Service.HouseProjectInfo.Dto;
|
||||
using Ewide.Core;
|
||||
using Ewide.Core.Service;
|
||||
using Ewide.Core.Util;
|
||||
using Ewide.EntityFramework.Core;
|
||||
using Furion;
|
||||
using Furion.DatabaseAccessor;
|
||||
using Furion.DatabaseAccessor.Extensions;
|
||||
using Furion.DependencyInjection;
|
||||
@@ -10,15 +13,67 @@ using Furion.FriendlyException;
|
||||
using Mapster;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
||||
using MySqlConnector;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Application.Service.HouseProjectInfo
|
||||
{
|
||||
[ApiDescriptionSettings(Name = "xml", Order = 3)]
|
||||
public class XMLHandler : IDynamicApiController, ITransient
|
||||
{
|
||||
private readonly DefaultDbContext _db;
|
||||
|
||||
public XMLHandler(DefaultDbContext db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
[HttpGet("/xml/detail")]
|
||||
public async Task XMLDoneAsync()
|
||||
{
|
||||
XmlSerializerUtil xmlHandler = new XmlSerializerUtil();
|
||||
xmlHandler.WriteDataSeed();
|
||||
//拿到数据保存到 XML文件
|
||||
//Dictionary<string, object> dicDataBase = await GetDataBase();
|
||||
//foreach (KeyValuePair<string, object> item in dicDataBase)
|
||||
//{
|
||||
// xmlHandler.WriteXML(item.Value.GetType(), item.Value, item.Key);
|
||||
//}
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取数据库的所有表 并拿到数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private async Task<Dictionary<string, object>> GetDataBase()
|
||||
{
|
||||
Dictionary<string, object> dicDataBase = new Dictionary<string, object>();
|
||||
var defaultConnection = App.Configuration["ConnectionStrings:DefaultConnection"];
|
||||
//获取 所有继承 IEntity 接口的表
|
||||
IEnumerable<IEntityType> entityTypedb = _db.Model.GetEntityTypes().Where(x => typeof(IEntity).IsAssignableFrom(x.ClrType)).ToList();
|
||||
|
||||
foreach (IEntityType item in entityTypedb)
|
||||
{
|
||||
MethodInfo mi = _db.GetType().GetMethods().FirstOrDefault(s => s.Name == "Set");
|
||||
MethodInfo miConstructed = mi.MakeGenericMethod(item.ClrType);
|
||||
object objList = miConstructed.Invoke(_db, null);
|
||||
var objsource = item.ClrType.MakeList(objList);
|
||||
dicDataBase.Add(item.ClrType.Name, objsource);
|
||||
}
|
||||
await _db.Database.CloseConnectionAsync();
|
||||
return dicDataBase;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 项目管理相关服务
|
||||
/// </summary>
|
||||
@@ -51,7 +106,7 @@ namespace Ewide.Application.Service.HouseProjectInfo
|
||||
[HttpPost("/houseProjectInfo/delete")]
|
||||
public async Task DeleteProject(DeleteProjectInput input)
|
||||
{
|
||||
var project = _houseProjectInfoRep.FirstOrDefault(p => p.Id == input.Id) ;
|
||||
var project = _houseProjectInfoRep.FirstOrDefault(p => p.Id == input.Id);
|
||||
await project.DeleteNowAsync();
|
||||
}
|
||||
|
||||
@@ -64,7 +119,7 @@ namespace Ewide.Application.Service.HouseProjectInfo
|
||||
public async Task UpdateProject(UpdateProjectInput input)
|
||||
{
|
||||
var project = input.Adapt<BsHouseProjectInfo>();
|
||||
await project.UpdateExcludeAsync(new[] { nameof(BsHouseProjectInfo.AreaCode) }, true);
|
||||
await project.UpdateExcludeAsync(new[] { nameof(BsHouseProjectInfo.AreaId) }, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -105,7 +160,7 @@ namespace Ewide.Application.Service.HouseProjectInfo
|
||||
{
|
||||
var user = await _houseProjectInfoRep.DetachedEntities.FirstOrDefaultAsync(p => p.Id == input.Id);
|
||||
var userDto = user.Adapt<UserOutput>();
|
||||
|
||||
|
||||
return userDto;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -24,6 +25,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(员工)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysEmp SysEmp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -36,6 +38,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(机构)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysOrg SysOrg { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -48,6 +51,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(职位)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysPos SysPos { get; set; }
|
||||
|
||||
public void Configure(EntityTypeBuilder<SysEmpExtOrgPos> entityBuilder, DbContext dbContext, Type dbContextLocator)
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(员工)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysEmp SysEmp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -19,9 +20,11 @@ namespace Ewide.Core
|
||||
/// </summary>
|
||||
[Comment("角色Id")]
|
||||
public string SysRoleId { get; set; }
|
||||
[XmlIgnore]
|
||||
public SysRole SysRole { get; set; }
|
||||
[Comment("系统使用的区域代码")]
|
||||
public string AreaCode { get; set; }
|
||||
[XmlIgnore]
|
||||
public SysAreaCode Area { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -33,6 +34,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统机构)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysOrg SysOrg { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -21,6 +22,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统用户)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysRole SysRole { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -33,6 +35,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统菜单)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysMenu SysMenu { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -15,10 +16,12 @@ namespace Ewide.Core
|
||||
[Comment("用户Id")]
|
||||
[Column("SysUserId", TypeName = "varchar(36)")]
|
||||
public string SysUserId { get; set; }
|
||||
[XmlIgnore]
|
||||
public SysUser SysUser { get; set; }
|
||||
[Comment("系统使用的区域代码")]
|
||||
[MaxLength(10)]
|
||||
public string AreaCode { get; set; }
|
||||
[XmlIgnore]
|
||||
public SysAreaCode Area { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -21,6 +22,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统用户)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysUser SysUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -33,6 +35,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统机构)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysOrg SysOrg { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Furion.DatabaseAccessor;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace Ewide.Core
|
||||
{
|
||||
@@ -21,6 +22,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统用户)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysUser SysUser { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -33,6 +35,7 @@ namespace Ewide.Core
|
||||
/// <summary>
|
||||
/// 一对一引用(系统角色)
|
||||
/// </summary>
|
||||
[XmlIgnore]
|
||||
public SysRole SysRole { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\PublishProfiles\" />
|
||||
<Folder Include="DataBaseXML\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
28
Api/Ewide.Core/SeedDataXml/SysEmpExtOrgPos.xml
Normal file
28
Api/Ewide.Core/SeedDataXml/SysEmpExtOrgPos.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0"?>
|
||||
<ArrayOfSysEmpExtOrgPos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<SysEmpExtOrgPos>
|
||||
<SysEmpId>d0ead3dc-5096-4e15-bc6d-f640be5301ec</SysEmpId>
|
||||
<SysOrgId>12d888de-f55d-4c88-b0a0-7c3510664d97</SysOrgId>
|
||||
<SysPosId>269236c4-d74e-4e54-9d50-f6f61580a197</SysPosId>
|
||||
</SysEmpExtOrgPos>
|
||||
<SysEmpExtOrgPos>
|
||||
<SysEmpId>d0ead3dc-5096-4e15-bc6d-f640be5301ec</SysEmpId>
|
||||
<SysOrgId>8a2271d6-5bda-4544-bdd3-27e53a8b418e</SysOrgId>
|
||||
<SysPosId>46c68a62-f119-4ff7-b621-0bbd77504538</SysPosId>
|
||||
</SysEmpExtOrgPos>
|
||||
<SysEmpExtOrgPos>
|
||||
<SysEmpId>d0ead3dc-5096-4e15-bc6d-f640be5301ec</SysEmpId>
|
||||
<SysOrgId>127c0a5d-43ac-4370-b313-082361885aca</SysOrgId>
|
||||
<SysPosId>5bd8c466-2bca-4386-a551-daac78e3cee8</SysPosId>
|
||||
</SysEmpExtOrgPos>
|
||||
<SysEmpExtOrgPos>
|
||||
<SysEmpId>d0ead3dc-5096-4e15-bc6d-f640be5301ec</SysEmpId>
|
||||
<SysOrgId>f236ab2d-e1b5-4e9d-844f-a59ec32c20e4</SysOrgId>
|
||||
<SysPosId>d89a3afe-e6ba-4018-bdae-3c98bb47ad66</SysPosId>
|
||||
</SysEmpExtOrgPos>
|
||||
<SysEmpExtOrgPos>
|
||||
<SysEmpId>16a74726-e156-499f-9942-0e0e24ad0c3f</SysEmpId>
|
||||
<SysOrgId>f236ab2d-e1b5-4e9d-844f-a59ec32c20e4</SysOrgId>
|
||||
<SysPosId>269236c4-d74e-4e54-9d50-f6f61580a197</SysPosId>
|
||||
</SysEmpExtOrgPos>
|
||||
</ArrayOfSysEmpExtOrgPos>
|
||||
83
Api/Ewide.Core/Util/TypeHelper.cs
Normal file
83
Api/Ewide.Core/Util/TypeHelper.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Ewide.Core.Util
|
||||
{
|
||||
public static class TypeHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 动态创建List<?> 泛型
|
||||
/// </summary>
|
||||
/// <param name="t">Type类</param>
|
||||
/// <param name="items">数据源</param>
|
||||
/// <returns></returns>
|
||||
public static object MakeList(this Type t, params object[] items)
|
||||
{
|
||||
Type type = typeof(List<>).MakeGenericType(t);
|
||||
object list = Activator.CreateInstance(type);
|
||||
System.Collections.IList ilist = list as System.Collections.IList;
|
||||
foreach (object o in items)
|
||||
ilist.Add(o);
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态创建List<?> 泛型
|
||||
/// </summary>
|
||||
/// <param name="t">Type类</param>
|
||||
/// <param name="objList">数据源</param>
|
||||
/// <returns></returns>
|
||||
public static object MakeList(this Type t, Object objList)
|
||||
{
|
||||
Type type = typeof(List<>).MakeGenericType(t);
|
||||
object list = Activator.CreateInstance(type);
|
||||
System.Collections.IList ilist = list as System.Collections.IList;
|
||||
var collection = objList as System.Collections.IEnumerable;
|
||||
if (collection != null)
|
||||
{
|
||||
foreach (object obj in collection)
|
||||
{
|
||||
ilist.Add(obj);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
/// <summary>
|
||||
/// 动态创建List<?> 泛型s
|
||||
/// </summary>
|
||||
/// <param name="hostType">Type类</param>
|
||||
/// <param name="table">数据源</param>
|
||||
/// <returns></returns>
|
||||
public static object DataTableToList(this Type hostType, DataTable table)
|
||||
{
|
||||
Type type = typeof(List<>).MakeGenericType(hostType);
|
||||
object list = Activator.CreateInstance(type);
|
||||
System.Collections.IList ilist = list as System.Collections.IList;
|
||||
|
||||
object host = Activator.CreateInstance(hostType);
|
||||
string tempName = string.Empty;
|
||||
foreach (DataRow item in table.Rows)
|
||||
{
|
||||
PropertyInfo[] proList = hostType.GetProperties();
|
||||
foreach (PropertyInfo propertyInfo in proList)
|
||||
{
|
||||
tempName = propertyInfo.Name;
|
||||
if (table.Columns.Contains(tempName))
|
||||
{
|
||||
Object value = item[tempName];
|
||||
if (value!=null)
|
||||
{
|
||||
propertyInfo.SetValue(host,value, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
ilist.Add(host);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using Furion;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@@ -15,12 +16,24 @@ namespace Ewide.Core.Util
|
||||
{
|
||||
public class XmlSerializerUtil
|
||||
{
|
||||
static string[] str = AppDomain.CurrentDomain.BaseDirectory.Split("ewide_core");
|
||||
static string path = str[0]+ @"ewide_core\Api\Ewide.Core\SeedDataXml\";
|
||||
/// <summary>
|
||||
/// XML 要读取的路径
|
||||
/// </summary>
|
||||
private string DirPath { set; get; }
|
||||
/// <summary>
|
||||
/// 当前程序集
|
||||
/// </summary>
|
||||
private string currentAssemblyName { get { return "Ewide.Core"; } }
|
||||
/// <summary>
|
||||
/// 读取文件夹下所有XML
|
||||
/// add-migration init -c defaultDbContext 备用数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Dictionary<Type, object> ReaderALL()
|
||||
{
|
||||
string dirPath = CurrentDirPath();
|
||||
Dictionary<Type, object> dic = new Dictionary<Type, object>();
|
||||
DirectoryInfo folder = new DirectoryInfo(path);
|
||||
DirectoryInfo folder = new DirectoryInfo(dirPath);
|
||||
foreach (FileInfo file in folder.GetFiles())
|
||||
{
|
||||
//除去.xml 后缀
|
||||
@@ -34,16 +47,12 @@ namespace Ewide.Core.Util
|
||||
}
|
||||
return dic;
|
||||
}
|
||||
private object Deserialize<T>(string xmlContent, Type[] Arrtype)
|
||||
{
|
||||
object obj = null;
|
||||
using (StringReader sr = new StringReader(xmlContent))
|
||||
{
|
||||
XmlSerializer xmldes = new XmlSerializer(typeof(List<T>), Arrtype);
|
||||
obj = xmldes.Deserialize(sr);
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
/// <summary>
|
||||
/// 反序列化
|
||||
/// </summary>
|
||||
/// <param name="type"></param>
|
||||
/// <param name="xmlContent">XML内容</param>
|
||||
/// <returns></returns>
|
||||
private object Deserialize(Type type, string xmlContent)
|
||||
{
|
||||
object obj = null;
|
||||
@@ -54,20 +63,32 @@ namespace Ewide.Core.Util
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
public string StreamRead(string path)
|
||||
/// <summary>
|
||||
/// 数据流读取
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
private string StreamRead(string path)
|
||||
{
|
||||
using (StreamReader reader = new StreamReader(path, Encoding.Default))
|
||||
{
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 反射 根据类名 反射整个类 得到实例
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
/// <returns></returns>
|
||||
private object AppInfo(string name)
|
||||
{
|
||||
string assemblyName = "Ewide.Core";
|
||||
string nameSpace = "Ewide.Core";
|
||||
string fullName = nameSpace + "." + name;
|
||||
object ect = Assembly.Load(assemblyName).CreateInstance(fullName);
|
||||
return ect;
|
||||
if (name == "BsHouseProjectInfo") //BsHouseProjectInfo 这个类 写在 application 程序集
|
||||
{
|
||||
string fullNamei = string.Join('.', "Ewide.Application.Entity", name);
|
||||
return Assembly.Load("Ewide.Application").CreateInstance(fullNamei);
|
||||
}
|
||||
string fullName = string.Join('.', currentAssemblyName, name);
|
||||
return Assembly.Load(currentAssemblyName).CreateInstance(fullName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -78,13 +99,72 @@ namespace Ewide.Core.Util
|
||||
/// <param name="className">XML名称</param>
|
||||
public void WriteXML(Type type, object data, string className)
|
||||
{
|
||||
|
||||
string writePath = path + className + ".xml";
|
||||
string writePath = CurrentDirPath(className);
|
||||
using (FileStream fs = new FileStream(writePath, FileMode.OpenOrCreate))
|
||||
{
|
||||
XmlSerializer ser = new XmlSerializer(type);
|
||||
ser.Serialize(fs, data);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 要操作的文件夹目录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private string CurrentDirPath()
|
||||
{
|
||||
// 在for 循环里, 不用每次都读取 下面的代码
|
||||
if (DirPath != null)
|
||||
return DirPath;
|
||||
|
||||
string targetPath = String.Empty;
|
||||
string appConfigPath = App.Configuration["WriteXmlPath:ReadSelect"] == "SeedData" ? App.Configuration["WriteXmlPath:SeedData"] : App.Configuration["WriteXmlPath:DataBase"];
|
||||
string path = Directory.GetCurrentDirectory();
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(path);
|
||||
foreach (DirectoryInfo item in dirInfo.Parent.GetDirectories())
|
||||
{
|
||||
if (item.Name == currentAssemblyName)
|
||||
{
|
||||
targetPath = item.GetDirectories(appConfigPath).FirstOrDefault().FullName;
|
||||
break;
|
||||
}
|
||||
}
|
||||
DirPath = targetPath;
|
||||
return targetPath;
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据类名 创建一个XML文件 写入数据
|
||||
/// </summary>
|
||||
/// <param name="className"></param>
|
||||
/// <returns></returns>
|
||||
private string CurrentDirPath(string className)
|
||||
{
|
||||
string path = CurrentDirPath();
|
||||
return string.Join(@"\", path, className + ".xml");
|
||||
}
|
||||
/// <summary>
|
||||
/// 写入种子数据 --不常用
|
||||
/// </summary>
|
||||
public void WriteDataSeed()
|
||||
{
|
||||
Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name.Contains("Ewide.Core"));
|
||||
Type[] types = assembly.GetTypes();
|
||||
foreach (Type type in types)
|
||||
{
|
||||
//if (type.Name.EndsWith("SeedData"))
|
||||
if(type.Name.EndsWith("SysEmpExtOrgPos"))
|
||||
{
|
||||
object obHelper = Activator.CreateInstance(type);
|
||||
MethodInfo methodinfo = type.GetMethod("HasData");
|
||||
object objs = methodinfo.Invoke(obHelper, new object[] { null, null });
|
||||
Type objType = objs.GetType();
|
||||
//if (objType.Name == "SysEmpExtOrgPos[]" || objType.Name == "SysConfig[]" || objType.Name == "SysDictData[]" || objType.Name == "SysDictType[]" || objType.Name == "SysEmpPos[]" || objType.Name == "SysEmp[]" || objType.Name == "SysMenu[]" || objType.Name == "SysOrg[]" || objType.Name == "SysPos[]" || objType.Name == "SysRole[]" || objType.Name == "SysTenant[]" || objType.Name == "SysTimer[]" || objType.Name == "SysUser[]")
|
||||
if (objType.Name == "SysEmpExtOrgPos[]")
|
||||
{
|
||||
string className = objType.Name.Remove(objType.Name.Length - 2, 2);
|
||||
WriteXML(objType, objs, className);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,11 @@
|
||||
"ExpiredTime": 1440, // 过期时间,long 类型,单位分钟,默认20分钟
|
||||
"ClockSkew": 5 // 过期时间容错值,long 类型,单位秒,默认5秒
|
||||
},
|
||||
"WriteXmlPath": {
|
||||
"SeedData": "SeedDataXml",
|
||||
"DataBase": "DataBaseXml",
|
||||
"ReadSelect": "SeedData" // SeedData 和 DataBase 两个中间选
|
||||
},
|
||||
"Cache": {
|
||||
"CacheType": "MemoryCache", // RedisCache
|
||||
"RedisConnectionString": "127.0.0.1:6379,password=,defaultDatabase=2"
|
||||
|
||||
@@ -179,7 +179,10 @@ namespace Ewide.EntityFramework.Core
|
||||
data.Add(obj);
|
||||
}
|
||||
}
|
||||
modelBuilder.Entity(item.Key).HasData(data); ;
|
||||
if (data.Count>0)
|
||||
{
|
||||
modelBuilder.Entity(item.Key).HasData(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"DefaultConnection": "Data Source=localhost;Port=3306;Database=ewide;User ID=root;Password=a45683926;pooling=true;sslmode=none;CharSet=utf8;"
|
||||
"DefaultConnection": "Data Source=localhost;Port=3306;Database=ewide;User ID=root;Password=root;pooling=true;sslmode=none;CharSet=utf8;"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user