/// <summary> /// 获取用户的会话,不要在构造函数使用 /// </summary> /// <returns></returns> public UserSession GetSession() { if (Token != null) { return(Consts.Get <SessionProvider>().Get(Token)); } return(null); }
/// <summary> /// 获取用户的会话,不要在构造函数使用 /// </summary> /// <returns></returns> protected async Task <UserSession> GetSessionAsync() { if (Token != null) { return(await Consts.Get <SessionProvider>().Get(Token)); } return(null); }
/// <summary> /// 通用导出成Excel v0.2.0+ /// </summary> /// <param name="key"></param> /// <param name="param"></param> /// <returns></returns> public async Task <Stream> GetExcelStreamAsync(string key, Dictionary <string, object> param) { DataGateKey gkey = GetDataGate(key); var result = await QueryForExportAsync(gkey, param); var defaultGate = Consts.Get <DefaultExportGate>(); DataTable dt = defaultGate.OnExport(gkey, result); gkey.DataGate.OnExport(gkey, dt); return(ExcelHelper.ExportByEPPlus(dt)); }
public DefaultExportGate() { DataGateService service = Consts.Get <DataGateService>(); DataTable dt = (DataTable)service.QueryAsync("GetSysDict", new { }).Result; Dict = dt.Rows.Cast <DataRow>().Select(dr => new { parentCode = dr.ToStr("parentCode"), code = dr.ToStr("code"), name = dr.ToStr("name") }).GroupBy(g => g.parentCode) .ToDictionary(g => g.Key, g => g.ToDictionary(c => c.code, c => c.name)); }
internal static LogInfo GetLogInfo(FilterContext context) { LogInfo logInfo = Consts.Get <LogInfo>(); var action = context.ActionDescriptor as ControllerActionDescriptor; var httpContext = context.HttpContext; logInfo.UserAgent = httpContext.Request.Headers["User-Agent"]; logInfo.Action = action.ActionName; logInfo.ClientIP = httpContext.Connection.RemoteIpAddress?.ToString(); logInfo.Module = action.ControllerName; logInfo.OpTime = DateTime.Now; logInfo.LogLevel = LogType.Info; logInfo.Request = httpContext.Request.Method + " " + httpContext.Request.QueryString.ToString(); // context.ActionDescriptor.Properties[LogSaveKey] = logInfo; return(logInfo); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public virtual void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseHttpsRedirection().UseCors(builder => builder.AllowAnyOrigin() .AllowAnyMethod().AllowAnyHeader());//.WithOrigins("http://example.com")); //GlobalDiagnosticsContext.Set("configDir", Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs")); //GlobalDiagnosticsContext.Set("connectionString", Configuration.GetConnectionString("Default")); loggerFactory.AddNLog(); LogHelper.Init(Consts.Get <ILogManager>(), "*"); app.UseMvc(routes => { //批量保存增删改结果 routes.MapRoute(name: "datagate-save", template: "api/dg/s/{key}", defaults: new { controller = "DataGate", action = "Submit" }); //获取某key值对应的数据表的metatata routes.MapRoute(name: "datagate-metadata", template: "api/dg/m/{key}", defaults: new { controller = "DataGate", action = "Metadata" }); //非查询执行数据库操作 routes.MapRoute(name: "datagate-nonquery", template: "api/dg/n/{key}", defaults: new { controller = "DataGate", action = "NonQuery" }); //导出Excel的路由 routes.MapRoute(name: "datagate-export", template: "api/dg/x/{key}", defaults: new { controller = "DataGate", action = "Export" }); //文件上传的路由 routes.MapRoute(name: "datagate-upload", template: "api/dg/u", defaults: new { controller = "Files", action = "Upload" }); //文件下载的路由,如果通过a链接下载,可能要带上?token=用户的Token作为身份标识 routes.MapRoute(name: "datagate-download", template: "api/dg/d/{id}/{filename?}", defaults: new { controller = "Files", action = "DownById" }); //通用的数据查询路由 routes.MapRoute(name: "datagate-query", template: "api/dg/{key}", defaults: new { controller = "DataGate", action = "Query" }); AddRoutes(routes); // routes.MapRoute(name: "api-default", //template: "api/[controller]/[action]"); routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }).UseStaticFiles(); //访问wwwroot下的静态文件 }