public void TestGetDataTableListForMySql() { BuildServiceFoMySql(); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); var tables = dbContext.GetCurrentDatabaseTableList(); Assert.IsNotNull(tables); }
public static ICodeFirst CodeFirst(this IDbContextCore dbContext) { var codeFirst = AspectCoreContainer.Resolve <ICodeFirst>(); if (codeFirst == null) { throw new Exception("请先在Startup.cs文件的ConfigureServices方法中调用UseCodeGenerator方法以注册。"); } return(codeFirst); }
/// <summary> /// 根据数据表生成Model层、Controller层、IRepository层和Repository层代码 /// </summary> /// <param name="ifExsitedCovered">是否覆盖已存在的同名文件</param> /// <param name="selector"></param> internal void GenerateAllCodesFromDatabase(bool ifExsitedCovered = false, Func <DbTable, bool> selector = null) { var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); if (dbContext == null) { throw new Exception("未能获取到数据库上下文,请先注册数据库上下文。"); } GenerateAllCodesFromDatabase(dbContext, ifExsitedCovered, selector); }
public static async void WhileUpdatingAsync(IUpdatingEntry <SysMenu, DbContext> entry) { using (var service = AspectCoreContainer.Resolve <ISysMenuRepository>()) { var parentMenu = await service.GetSingleAsync(entry.Entity.ParentId); entry.Entity.SortIndex = entry.Entity.Id; entry.Entity.MenuPath = (parentMenu?.MenuPath ?? "0") + "," + entry.Entity.Id; } }
public void GenerateAll(bool ifExsitedCovered = false) { var option = AspectCoreContainer.Resolve <IOptions <CodeGenerateOption> >().Value; if (option == null) { throw new Exception("请先注入CodeGenerateOption"); } Instance = new CodeGenerator(option); }
public void TestGetDataTableForSqlServer() { BuildServiceForSqlServer(); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); var dt1 = dbContext.GetCurrentDatabaseAllTables(); foreach (DataRow row in dt1.Rows) { var dt2 = dbContext.GetTableColumns(row["TableName"].ToString()); } }
public void TestCsRedisClient() { BuildServiceForSqlServer(); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); RedisHelper.Set("test_cache_key", JsonConvertor.Serialize(dbContext.GetCurrentDatabaseTableList()), 10 * 60); Thread.Sleep(2000); var content = DistributedCacheManager.Get("test_cache_key"); Assert.IsNotNull(content); }
public static async void AfterInsertedAsync(IInsertedEntry <SysMenu, DbContext> entry) { using (var service = AspectCoreContainer.Resolve <ISysMenuRepository>()) { var parentMenu = await service.GetSingleAsync(entry.Entity.ParentId); entry.Entity.MenuPath = (parentMenu?.MenuPath ?? "0") + "," + entry.Entity.Id; entry.Entity.SortIndex = entry.Entity.Id; service.Update(entry.Entity, false, "MenuPath", "SortIndex"); await DistributedCacheManager.RemoveAsync("Redis_Cache_SysMenu");//插入成功后清除缓存以更新 } }
/// <summary> /// 获取物理路径 /// </summary> /// <param name="relativePath">相对路径</param> public static string GetPhysicalPath(string relativePath) { if (string.IsNullOrWhiteSpace(relativePath)) { return(string.Empty); } var rootPath = AspectCoreContainer.Resolve <IHostingEnvironment>()?.ContentRootPath; if (string.IsNullOrWhiteSpace(rootPath)) { return(System.IO.Path.GetFullPath(relativePath)); } return($"{rootPath}\\{relativePath.Replace("/", "\\").TrimStart('\\')}"); }
/// <summary> /// 渲染视图 /// </summary> protected async Task <string> RenderToStringAsync(ResultExecutingContext context) { string viewName = ""; object model = null; bool isPage = false; if (context.Result is ViewResult result) { viewName = result.ViewName; viewName = string.IsNullOrWhiteSpace(viewName) ? context.RouteData.Values["action"].SafeString() : viewName; model = result.Model; } if (context.Result is PageResult pageResult) { if (context.ActionDescriptor is PageActionDescriptor pageActionDescriptor) { isPage = true; model = pageResult.Model; viewName = pageActionDescriptor.RelativePath; } } var razorViewEngine = AspectCoreContainer.Resolve <IRazorViewEngine>(); var compositeViewEngine = AspectCoreContainer.Resolve <ICompositeViewEngine>(); var tempDataProvider = AspectCoreContainer.Resolve <ITempDataProvider>(); var serviceProvider = AspectCoreContainer.Resolve <IServiceProvider>(); var httpContext = new DefaultHttpContext { RequestServices = serviceProvider }; var actionContext = new ActionContext(httpContext, context.RouteData, new ActionDescriptor()); using (var stringWriter = new StringWriter()) { var viewResult = isPage ? GetView(compositeViewEngine, viewName) : GetView(razorViewEngine, actionContext, viewName); if (viewResult.View == null) { throw new ArgumentNullException($"未找到视图: {viewName}"); } var viewDictionary = new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary()) { Model = model }; var viewContext = new ViewContext(actionContext, viewResult.View, viewDictionary, new TempDataDictionary(actionContext.HttpContext, tempDataProvider), stringWriter, new HtmlHelperOptions()); await viewResult.View.RenderAsync(viewContext); return(stringWriter.ToString()); } }
public static FileModel FileHeaderToModel(FileHeader fileHeader) { IConfiguration config = AspectCoreContainer.Resolve <IConfiguration>(); var filePreUrl = config["FilePreUrl"]; return(new FileModel { Id = fileHeader.Id.ToString(), FileExt = fileHeader.FileExt, Category = fileHeader.Category, Size = fileHeader.Length, FileUrl = $"{filePreUrl}{fileHeader.Id}?tag=client_upload" }); }
/// <summary> /// 静态构造函数:从IoC容器读取配置参数,如果读取失败则会抛出ArgumentNullException异常 /// </summary> static CodeGenerator() { options = AspectCoreContainer.Resolve <IOptions <CodeGenerateOption> >(); if (options == null) { throw new ArgumentNullException(nameof(options)); } var path = AppDomain.CurrentDomain.BaseDirectory; var flag = path.IndexOf("/bin"); if (flag > 0) { Delimiter = "/";//如果可以取到值,修改分割符 } }
public IActionResult DbCreate() { try { //生成数据库表 SugarDbContext db = new SugarDbContext(); db.GetInstance().CodeFirst.SetStringDefaultLength(20).InitTables(typeof(MenuInfo), typeof(UserInfo), typeof(UserRelationRole), typeof(UserRoleInfo), typeof(UserRoleRelateMenu)); var o = AspectCoreContainer.Resolve <IOptions <DbContextOption> >(); return(Json(new { result = "成功生成数据库表", option = o.Value })); } catch (Exception e) { return(Json(new { result = "生成数据库表失败", message = e.Message })); } }
public static void WhileUpdating(IUpdatingEntry <SysMenu, DbContext> entry) { using (var service = AspectCoreContainer.Resolve <ISysMenuRepository>()) { var parentMenu = service.GetSingle(entry.Entity.ParentId); if (string.IsNullOrEmpty(parentMenu?.MenuPath)) { entry.Entity.MenuPath = entry.Entity.Id; } else { entry.Entity.MenuPath = parentMenu.MenuPath + "," + entry.Entity.Id; } } }
public void TestForMongoDb() { BuildServiceForMongoDB(); var context = AspectCoreContainer.Resolve <IDbContextCore>(); Assert.IsTrue(context.Add(new MongoModel() { Age = 28, Birthday = Convert.ToDateTime("1999-01-22"), IsBitch = false, UserName = "******", Wage = 100000000 }) > 0); context.Dispose(); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); new Program().BuildServiceForSqlServer(); //new Program().TestGenerateEntitiesForSqlServer(); //Console.WriteLine("自动代码生成完成,按任意键退出"); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); IFace_UserInfoRepository s = new Face_UserInfoRepository(dbContext); var model = s.GetSingle(1); var t = model.Guid_Id; Console.ReadLine(); }
public void TestGetDataTableForPostgreSql() { BuildServiceForPostgreSql(); var test = AspectCoreContainer.Resolve <IMongoRepository>(); test.Run(); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); var dt1 = dbContext.GetCurrentDatabaseAllTables(); Assert.IsNotNull(dt1); foreach (DataRow row in dt1.Rows) { var dt2 = dbContext.GetTableColumns(row["TableName"].ToString()); Assert.IsNotNull(dt2); } }
public static IServiceCollection RegisterPayMerchant <TGateway, TMerchant>(this IServiceCollection services, TMerchant merchant) where TGateway : GatewayBase, new() where TMerchant : class, IMerchant { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (merchant == null) { throw new ArgumentNullException(nameof(merchant)); } services.AddICanPay(m => { var gateways = AspectCoreContainer.Resolve <IGateways>() ?? new Gateways(); var gateway = (TGateway)Activator.CreateInstance(typeof(TGateway), (object)merchant); gateways.Add(gateway); return(gateways); }); return(services); }
public static void AfterInserted(IInsertedEntry <SysMenu, DbContext> entry) { using (var service = AspectCoreContainer.Resolve <ISysMenuRepository>()) { if (string.IsNullOrEmpty(entry.Entity.ParentId)) { entry.Entity.MenuPath = entry.Entity.Id; } else { var parentMenu = service.GetSingle(entry.Entity.ParentId); if (string.IsNullOrEmpty(parentMenu?.MenuPath)) { entry.Entity.MenuPath = entry.Entity.Id; } else { entry.Entity.MenuPath = parentMenu.MenuPath + "," + entry.Entity.Id; } } service.Update(entry.Entity, false, "MenuPath"); DistributedCacheManager.Remove("Redis_Cache_SysMenu");//����ɹ�����������Ը��� } }
public static IMemoryCache GetInstance() => AspectCoreContainer.Resolve <IMemoryCache>();
public void TestGetDataTableListForSqlServer() { BuildServiceForSqlServer(); var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); var tables = dbContext.GetCurrentDatabaseTableList(); }
protected BaseDbContext(DbContextOption option) { Option = option ?? AspectCoreContainer.Resolve <IOptions <DbContextOption> >().Value; }
public Task <IList <SysMenu> > GetMenusByCacheAsync(Expression <Func <SysMenu, bool> > @where) { return(Task.Factory.StartNew <IList <SysMenu> >( () => AspectCoreContainer.Resolve <IDbContextCore>().Get(where).ToList() )); }
public static void ToGenerateViewModelFile(this DataTable dt, string className) { var dbContext = AspectCoreContainer.Resolve <IDbContextCore>(); dbContext.DbFirst().GenerateViewModel(dt, className); }
public CodeFirst() { Instance = new CodeGenerator(AspectCoreContainer.Resolve <IOptions <CodeGenerateOption> >().Value); }