/// <summary> /// FreeSql /// </summary> /// <param name="services"></param> public static void AddContext(this IServiceCollection services) { var configuration = services.BuildServiceProvider().GetRequiredService <IConfiguration>(); IConfigurationSection configurationSection = configuration.GetSection("ConnectionStrings:MySql"); IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseEntityPropertyNameConvert(StringConvertType.PascalCaseToUnderscoreWithLower) //全局转换实体属性名方法 https://github.com/2881099/FreeSql/pull/60 .UseAutoSyncStructure(true) //自动迁移实体的结构到数据库 .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); } ) .UseSyncStructureToLower(true) // 转小写同步结构 .Build() .SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = true); //联级保存功能开启(默认为关闭) fsql.Aop.CurdBefore += (s, e) => { }; fsql.Aop.CurdAfter += (s, e) => { if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } services.AddSingleton(fsql); services.AddScoped <IUnitOfWork>(sp => sp.GetService <IFreeSql>().CreateUnitOfWork()); services.AddFreeRepository(filter => { filter.Apply <IDeleteAduitEntity>("IsDeleted", a => a.IsDeleted == false); }, typeof(AuditBaseRepository <>).Assembly); }
/// <summary> /// FreeSql /// </summary> /// <param name="services"></param> public static void AddContext(this IServiceCollection services, IConfiguration configuration) { IConfigurationSection configurationSection = configuration.GetSection("ConnectionStrings:MySql"); IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower) .UseAutoSyncStructure(true) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); } ) .Build() .SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = true);//联级保存功能开启(默认为关闭) fsql.Aop.CurdAfter += (s, e) => { Log.Debug($"ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}: FullName:{e.EntityType.FullName}" + $" ElapsedMilliseconds:{e.ElapsedMilliseconds}ms, {e.Sql}"); if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } services.AddSingleton(fsql); services.AddScoped <UnitOfWorkManager>(); fsql.GlobalFilter.Apply <IDeleteAduitEntity>("IsDeleted", a => a.IsDeleted == false); //在运行时直接生成表结构 fsql.CodeFirst.SyncStructure(ReflexHelper.GetEntityTypes(typeof(IEntity))); services.AddFreeRepository(); }
public Startup(IConfiguration configuration) { Configuration = configuration; IConfigurationSection configurationSection = Configuration.GetSection("ConnectionStrings:Default"); Fsql = new FreeSqlBuilder() .UseConnectionString(DataType.MySql, configurationSection.Value) .UseEntityPropertyNameConvert(StringConvertType.PascalCaseToUnderscoreWithLower) //全局转换实体属性名方法 https://github.com/2881099/FreeSql/pull/60 .UseAutoSyncStructure(true) //自动迁移实体的结构到数据库 .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText); } ) .UseSyncStructureToLower(true) // 转小写同步结构 .Build(); Fsql.Aop.CurdBefore = (s, e) => { }; Fsql.Aop.CurdAfter = (s, e) => { if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (Configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); Fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } }
protected override void Load(ContainerBuilder builder) { IFreeSql fsql = new FreeSqlBuilder() .UseConnectionString(_configuration) .UseNameConvert(NameConvertType.PascalCaseToUnderscoreWithLower) .UseAutoSyncStructure(true) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine(cmd.CommandText + ";"); } ) .Build() .SetDbContextOptions(opt => opt.EnableAddOrUpdateNavigateList = true);//联级保存功能开启(默认为关闭) builder.RegisterInstance(fsql).SingleInstance(); fsql.Aop.CurdAfter += (s, e) => { Log.Debug($"ManagedThreadId:{Thread.CurrentThread.ManagedThreadId}: FullName:{e.EntityType.FullName}" + $" ElapsedMilliseconds:{e.ElapsedMilliseconds}ms, {e.Sql}"); if (e.ElapsedMilliseconds > 200) { //记录日志 //发送短信给负责人 } }; //敏感词处理 if (_configuration["AuditValue:Enable"].ToBoolean()) { IllegalWordsSearch illegalWords = ToolGoodUtils.GetIllegalWordsSearch(); fsql.Aop.AuditValue += (s, e) => { if (e.Column.CsType == typeof(string) && e.Value != null) { string oldVal = (string)e.Value; string newVal = illegalWords.Replace(oldVal); //第二种处理敏感词的方式 //string newVal = oldVal.ReplaceStopWords(); if (newVal != oldVal) { e.Value = newVal; } } }; } //services.AddFreeRepository(); builder.RegisterType(typeof(UnitOfWorkManager)).InstancePerLifetimeScope(); fsql.GlobalFilter.Apply <IDeleteAduitEntity>("IsDeleted", a => a.IsDeleted == false); try { using var objPool = fsql.Ado.MasterPool.Get(); } catch (Exception e) { Log.Logger.Error(e + e.StackTrace + e.Message + e.InnerException); return; } //在运行时直接生成表结构 try { fsql.CodeFirst .SeedData() .SyncStructure(ReflexHelper.GetTypesByTableAttribute()); } catch (Exception e) { Log.Logger.Error(e + e.StackTrace + e.Message + e.InnerException); } }
public static List <IllegalWordsSearchResult> FindAll(string text) { var search = ToolGoodUtils.GetIllegalWordsSearch(); return(search.FindAll(text)); }
public string Get(string text) { var search = ToolGoodUtils.GetIllegalWordsSearch(); return(search.Replace(text)); }