// GET: Home public ActionResult Index() { var dao = ServiceResolve.ResolveOwinFactory(HttpContext.GetOwinContext()).GetRequiredService <IDao>(); ViewBag.Message = dao.Println(); return(View()); }
public (bool, string) Import(System.Data.DataTable dt, long userId) { if (dt.IsNullDt()) { return(false, PubConst.Import1); } var validator = new CustomerFluent(); var list = new List <Wms_Customer>(); string[] header = { "客户编号", "客户名称", "电话", "邮箱", "联系人", "地址" }; foreach (var item in header) { if (!dt.Columns.Contains(item)) { return(false, "不包含Excel表头:" + string.Join(",", header)); } } int dtCount = dt.Rows.Count; for (int i = 0; i < dtCount; i++) { var model = new Wms_Customer { CustomerNo = dt.Rows[i]["客户编号"].ToString(), CustomerName = dt.Rows[i]["客户名称"].ToString(), Address = dt.Rows[i]["地址"].ToString(), Tel = dt.Rows[i]["电话"].ToString(), Email = dt.Rows[i]["邮箱"].ToString(), CustomerPerson = dt.Rows[i]["联系人"].ToString(), }; var results = validator.Validate(model); var success = results.IsValid; if (!success) { string msg = results.Errors.Aggregate("", (current, item) => (item.ErrorMessage + "</br>")); return(false, msg); } if (_repository.IsAny(c => c.CustomerNo == model.CustomerNo)) { return(false, PubConst.Customer1); } model.CustomerId = PubId.SnowflakeId; model.CreateBy = userId; list.Add(model); } var flag = _repository.InsertTran(list); if (flag.IsSuccess) { return(true, PubConst.Import2); } else { var _nlog = ServiceResolve.Resolve <ILogUtil>(); _nlog.Debug(flag.ErrorMessage); return(false, PubConst.Import3); } }
public void Run() { var _nlog = ServiceResolve.Resolve <ILogUtil>(); GC.Collect(); }
//IServiceProvider This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(option => { option.Filters.Add <BaseExceptionAttribute>(); //option.Filters.Add<FilterXSSAttribute>(); option.Conventions.Add(new ApplicationDescription("keywords", Configuration["sys:keywords"])); option.Conventions.Add(new ApplicationDescription("description", Configuration["sys:description"])); option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"])); option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"])); }).SetCompatibilityVersion(CompatibilityVersion.Latest); //services.Configure<CookiePolicyOptions>(options => //{ // // This lambda determines whether user consent for non-essential cookies is needed for a given request. // options.CheckConsentNeeded = context => true; // options.MinimumSameSitePolicy = SameSiteMode.None; //}); services.AddTimedJob(); services.AddOptions(); services.AddXsrf(); services.AddXss(); services.AddAuthentication(c => { c.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; c.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(cfg => { cfg.LoginPath = "/Login/Index"; cfg.LogoutPath = "/Login/Logout"; //cfg.ExpireTimeSpan = TimeSpan.FromDays(1); //cfg.Cookie.Expiration = TimeSpan.FromDays(1); cfg.Cookie.Name = CookieAuthenticationDefaults.AuthenticationScheme; cfg.Cookie.Path = "/"; cfg.Cookie.HttpOnly = true; //cfg.SlidingExpiration = true; }); var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration); services.AddSqlSugarClient <SqlSugarClient>(config => { config.ConnectionString = sqlSugarConfig.Item2; config.DbType = sqlSugarConfig.Item1; config.IsAutoCloseConnection = true; config.InitKeyType = InitKeyType.Attribute; //config.IsShardSameThread = true; }); services.AddJson(o => { o.JsonType = JsonType.Jil; }); //services.AddDIProperty(); services.AddHttpContextAccessor(); services.AddHtmlEncoder(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); services.AddBr(); //br压缩 services.AddResponseCompression(); //添加压缩 services.AddResponseCaching(); //响应式缓存 services.AddMemoryCache(); services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly); //@1 DependencyInjection 注册 services.AddNlog(); //添加Nlog RegisterBase(services); //services.AddScoped(provider => //{ // Func<string, SqlSugarClient> func = key => // { // switch (key) // { // case "1": // return new SqlSugarClient(new ConnectionConfig() // { // ConfigId = "111", // ConnectionString = sqlSugarConfig.Item2, // DbType = sqlSugarConfig.Item1, // IsAutoCloseConnection = true, // InitKeyType = InitKeyType.Attribute, // }); // case "2": // return new SqlSugarClient(new ConnectionConfig() // { // ConfigId = "222", // ConnectionString = sqlSugarConfig.Item2, // DbType = sqlSugarConfig.Item1, // IsAutoCloseConnection = true, // InitKeyType = InitKeyType.Attribute, // }); // default: // throw new NotSupportedException($"Not Support key : {key}"); // } // }; // return func; //}); ServiceExtension.RegisterAssembly(services, "Services"); ServiceExtension.RegisterAssembly(services, "Repository"); var bulid = services.BuildServiceProvider(); ServiceResolve.SetServiceResolve(bulid); }
protected void Page_Load(object sender, EventArgs e) { var dao = ServiceResolve.ResolveHttpFactory(HttpContext.Current).GetRequiredService <IDao>(); Response.Write(dao.Println()); }
//IServiceProvider This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(option => { option.Filters.Add <BaseExceptionAttribute>(); //option.Filters.Add<FilterXSSAttribute>(); option.Conventions.Add(new ApplicationDescription("title", Configuration["sys:title"])); option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"])); option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"])); }).SetCompatibilityVersion(CompatibilityVersion.Latest); //services.Configure<CookiePolicyOptions>(options => //{ // // This lambda determines whether user consent for non-essential cookies is needed for a given request. // options.CheckConsentNeeded = context => true; // options.MinimumSameSitePolicy = SameSiteMode.None; //}); services.AddTimedJob(); services.AddOptions(); services.AddXsrf(); services.AddXss(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, cfg => { cfg.LoginPath = "/Login/Index"; cfg.ExpireTimeSpan = TimeSpan.FromDays(1); cfg.Cookie.Expiration = TimeSpan.FromDays(1); cfg.Cookie.Name = CookieAuthenticationDefaults.AuthenticationScheme; cfg.Cookie.Path = "/"; cfg.Cookie.HttpOnly = true; cfg.SlidingExpiration = true; }); var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration); services.AddSqlSugarClient <SqlSugarClient>(config => { config.ConnectionString = sqlSugarConfig.Item2; config.DbType = sqlSugarConfig.Item1; config.IsAutoCloseConnection = true; config.InitKeyType = InitKeyType.Attribute; //config.IsShardSameThread = true; }); services.AddJson(o => { o.JsonType = JsonType.Jil; }); services.AddHttpContextAccessor(); services.AddHtmlEncoder(); //Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); services.AddBr(); //br压缩 services.AddResponseCompression(); //添加压缩 services.AddResponseCaching(); //响应式缓存 services.AddMemoryCache(); //@1 DependencyInjection 注册 services.AddNlog(); //添加Nlog RegisterBase(services); ServiceExtension.RegisterAssembly(services, "Services"); ServiceExtension.RegisterAssembly(services, "Repository"); var bulid = services.BuildServiceProvider(); ServiceResolve.SetServiceResolve(bulid); }
//IServiceProvider This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { WCSApiAccessor.Host = Configuration["Host:WCS"]; MESApiAccessor.Host = Configuration["Host:MES"]; WMSBaseApiAccessor.WMSProxy = Configuration["Host:WMSPROXY"]; services.AddMvc(option => { option.Filters.Add <BaseExceptionAttribute>(); //option.Filters.Add<FilterXSSAttribute>(); option.Conventions.Add(new ApplicationDescription("title", Configuration["sys:title"])); option.Conventions.Add(new ApplicationDescription("company", Configuration["sys:company"])); option.Conventions.Add(new ApplicationDescription("customer", Configuration["sys:customer"])); }).SetCompatibilityVersion(CompatibilityVersion.Latest); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "API", Version = "v1" }); }); //services.Configure<CookiePolicyOptions>(options => //{ // // This lambda determines whether user consent for non-essential cookies is needed for a given request. // options.CheckConsentNeeded = context => true; // options.MinimumSameSitePolicy = SameSiteMode.None; //}); services.AddTimedJob(); services.AddOptions(); services.AddXsrf(); services.AddXss(); services.AddAuthentication(c => { c.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; c.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; }).AddCookie(cfg => { cfg.LoginPath = "/Login/Index"; cfg.LogoutPath = "/Login/Logout"; //cfg.ExpireTimeSpan = TimeSpan.FromDays(1); //cfg.Cookie.Expiration = TimeSpan.FromDays(1); cfg.Cookie.Name = CookieAuthenticationDefaults.AuthenticationScheme; cfg.Cookie.Path = "/"; cfg.Cookie.HttpOnly = true; //cfg.SlidingExpiration = true; }); var sqlSugarConfig = SqlSugarConfig.GetConnectionString(Configuration); services.AddSqlSugarClient <SqlSugarClient>(config => { config.ConnectionString = sqlSugarConfig.Item2; config.DbType = sqlSugarConfig.Item1; config.IsAutoCloseConnection = true; config.InitKeyType = InitKeyType.Attribute; //config.IsShardSameThread = false; }); services.AddJson(o => { o.JsonType = JsonType.Jil; }); services.AddSoapCore(); services.AddDIProperty(); services.AddHttpContextAccessor(); services.AddHtmlEncoder(); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); services.AddBr(); //br压缩 services.AddResponseCompression(); //添加压缩 services.AddResponseCaching(); //响应式缓存 services.AddMemoryCache(); services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly); //@1 DependencyInjection 注册 services.AddNlog(); //添加Nlog RegisterBase(services); ServiceExtension.RegisterAssembly(services, "Services"); ServiceExtension.RegisterAssembly(services, "Repository"); var bulid = services.BuildServiceProvider(); ServiceResolve.SetServiceResolve(bulid); SqlSugarClient db = new SqlSugarClient(new ConnectionConfig() { DbType = sqlSugarConfig.Item1, ConnectionString = sqlSugarConfig.Item2, InitKeyType = InitKeyType.Attribute, IsAutoCloseConnection = true, }); //OutputDataBase(db); InitDataBase(db); InitSystemData(db); db.Close(); }