/// <summary> /// OnConfiguring /// </summary> /// <param name="optionsBuilder"></param> protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { switch (DBType) { case DBTypeEnum.SqlServer: optionsBuilder.UseSqlServer(CSName); break; case DBTypeEnum.MySql: optionsBuilder.UseMySql(CSName, mySqlOptions => { if (string.IsNullOrEmpty(Version) == false) { mySqlOptions.ServerVersion(Version); } }); break; case DBTypeEnum.PgSql: optionsBuilder.UseNpgsql(CSName); break; case DBTypeEnum.Memory: optionsBuilder.UseInMemoryDatabase(CSName); break; case DBTypeEnum.SQLite: optionsBuilder.UseSqlite(CSName); break; case DBTypeEnum.Oracle: //optionsBuilder.UseOracle(CSName); break; default: break; } try { var Configs = GlobalServices.GetRequiredService <Configs>();//如果是debug模式,将EF生成的sql语句输出到debug输出 if (Configs.IsQuickDebug) { optionsBuilder.EnableDetailedErrors(); optionsBuilder.EnableSensitiveDataLogging(); optionsBuilder.UseLoggerFactory(LoggerFactory); } } catch { } base.OnConfiguring(optionsBuilder); }
public ILogger CreateLogger(string categoryName) { if (cs == null) { var config = GlobalServices.GetRequiredService <Configs>(); cs = config.ConnectionStrings.Where(x => x.Key.ToLower() == "defaultlog").FirstOrDefault(); if (cs == null) { cs = config.ConnectionStrings.Where(x => x.Key.ToLower() == "default").FirstOrDefault(); } if (cs == null) { cs = config.ConnectionStrings.FirstOrDefault(); } } return(new WTMLogger(categoryName, cs)); }
/// <summary> /// OnConfiguring /// </summary> /// <param name="optionsBuilder"></param> protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { switch (DBType) { case DBTypeEnum.SqlServer: optionsBuilder.UseSqlServer(CSName, op => op.UseRowNumberForPaging()); break; case DBTypeEnum.MySql: optionsBuilder.UseMySql(CSName); break; case DBTypeEnum.PgSql: optionsBuilder.UseNpgsql(CSName); break; case DBTypeEnum.Memory: optionsBuilder.UseInMemoryDatabase(CSName); break; case DBTypeEnum.SQLite: optionsBuilder.UseSqlite(CSName); break; case DBTypeEnum.Oracle: optionsBuilder.UseOracle(CSName); break; default: break; } try { var Configs = GlobalServices.GetRequiredService <Configs>();//如果是debug模式,将EF生成的sql语句输出到debug输出 if (Configs.IsQuickDebug) { optionsBuilder.UseLoggerFactory(LoggerFactory); } } catch { } base.OnConfiguring(optionsBuilder); }
public static FrameworkMenu FindMenu(string url) { if (url == null) { return(null); } url = url.ToLower(); var menus = GlobalServices.GetRequiredService <GlobalData>()?.AllMenus; if (menus == null) { return(null); } //寻找菜单中是否有与当前判断的url完全相同的 var menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault(); //如果没有,抹掉当前url的参数,用不带参数的url比对 if (menu == null) { var pos = url.IndexOf("?"); if (pos > 0) { url = url.Substring(0, pos); menu = menus.Where(x => x.Url != null && (x.Url.ToLower() == url || x.Url.ToLower() + "async" == url)).FirstOrDefault(); } } //如果还没找到,则判断url是否为/controller/action/id这种格式,如果是则抹掉/id之后再对比 if (menu == null && url.EndsWith("/index")) { url = url.Substring(0, url.Length - 6); menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault(); } if (menu == null && url.EndsWith("/indexasync")) { url = url.Substring(0, url.Length - 11); menu = menus.Where(x => x.Url != null && x.Url.ToLower() == url).FirstOrDefault(); } return(menu); }
public bool IsEnabled(LogLevel logLevel) { if (this.categoryName != "WalkingTec.Mvvm.Core.ActionLog") { return(false); } var levels = GlobalServices.GetRequiredService <IOptionsMonitor <LoggerFilterOptions> >(); var l = levels.CurrentValue.Rules.Where(x => x.ProviderName == "WTM").Select(x => x.LogLevel).FirstOrDefault(); if (l == null) { l = levels.CurrentValue.MinLevel; } if (logLevel >= l) { return(true); } else { return(false); } }
/// <summary> /// DoLog /// </summary> /// <param name="msg"></param> /// <param name="logtype"></param> public void DoLog(string msg, ActionLogTypesEnum logtype = ActionLogTypesEnum.Debug) { var log = this.Log.GetActionLog(); log.LogType = logtype; log.ActionTime = DateTime.Now; log.Remark = msg; LogLevel ll = LogLevel.Information; switch (logtype) { case ActionLogTypesEnum.Normal: ll = LogLevel.Information; break; case ActionLogTypesEnum.Exception: ll = LogLevel.Error; break; case ActionLogTypesEnum.Debug: ll = LogLevel.Debug; break; default: break; } GlobalServices.GetRequiredService <ILogger <ActionLog> >().Log <ActionLog>(ll, new EventId(), log, null, (a, b) => { return($@" ===WTM Log=== 内容:{a.Remark} 地址:{a.ActionUrl} 时间:{a.ActionTime} ===WTM Log=== "); }); }
public static string GetNugetVersion(string start = null, bool pre = false) { var Cache = GlobalServices.GetRequiredService <IDistributedCache>() as IDistributedCache; if (Cache.TryGetValue("nugetversion", out NugetInfo rv) == false || rv == null) { NugetInfo v = APIHelper.CallAPI <NugetInfo>($"https://api-v2v3search-0.nuget.org/query?q=WalkingTec.Mvvm.Mvc&prerelease={pre.ToString().ToLower()}").Result; var data = v; Cache.Add("nugetversion", data, new DistributedCacheEntryOptions() { SlidingExpiration = new TimeSpan(0, 0, 36000) }); rv = data; } if (string.IsNullOrEmpty(start)) { return(rv.data[0]?.version); } else { return(rv.data[0].versions.Select(x => x.version).Where(x => x.StartsWith(start)).Last()); } }
private byte[] DownLoadZipPackage(string FileName) { //文件根目录 string RootPath = $"{GlobalServices.GetRequiredService<IHostingEnvironment>().WebRootPath}\\{FileName}"; //文件夹目录 string FilePath = $"{RootPath}//FileFolder"; //压缩包目录 string ZipPath = $"{RootPath}//{FileName}.zip"; //打开文件夹 DirectoryInfo FileFolder = new DirectoryInfo(FilePath); if (!FileFolder.Exists) { //创建文件夹 FileFolder.Create(); } else { //清空文件夹 FileSystemInfo[] Files = FileFolder.GetFileSystemInfos(); foreach (var item in Files) { if (item is DirectoryInfo) { DirectoryInfo Directory = new DirectoryInfo(item.FullName); Directory.Delete(true); } else { File.Delete(item.FullName); } } } //放入数据 for (int i = 0; i < ExportExcelCount; i++) { var List = EntityList.Skip(i * ExportMaxCount).Take(ExportMaxCount).ToList(); var WorkBook = GenerateWorkBook(List); string SavePath = $"{FilePath}/{FileName}_{i + 1}.xlsx"; using (FileStream FS = new FileStream(SavePath, FileMode.CreateNew)) { WorkBook.Write(FS); } } //生成压缩包 ZipFile.CreateFromDirectory(FilePath, ZipPath); //读取压缩包 FileStream ZipFS = new FileStream(ZipPath, FileMode.Open, FileAccess.Read); byte[] bt = new byte[ZipFS.Length]; ZipFS.Read(bt, 0, bt.Length); ZipFS.Close(); //删除根目录文件夹 DirectoryInfo RootFolder = new DirectoryInfo(RootPath); if (RootFolder.Exists) { RootFolder.Delete(true); } return(bt); }