Пример #1
0
        public static IApplicationBuilder UseErp(this IApplicationBuilder app, List <JobType> additionalJobTypes = null, string configFolder = null)
        {
            using (var secCtx = SecurityContext.OpenSystemScope())
            {
                IConfiguration      configuration = app.ApplicationServices.GetService <IConfiguration>();
                IHostingEnvironment env           = app.ApplicationServices.GetService <IHostingEnvironment>();

                string configPath = "config.json";
                if (!string.IsNullOrWhiteSpace(configFolder))
                {
                    configPath = System.IO.Path.Combine(configFolder, configPath);
                }

                var configurationBuilder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile(configPath);
                ErpSettings.Initialize(configurationBuilder.Build());

                IErpService service = null;
                try
                {
                    DbContext.CreateContext(ErpSettings.ConnectionString);

                    service = app.ApplicationServices.GetService <IErpService>();

                    var cfg = ErpAutoMapperConfiguration.MappingExpressions;                     // var cfg = new AutoMapper.Configuration.MapperConfigurationExpression();
                    ErpAutoMapperConfiguration.Configure(cfg);
                    ErpWebAutoMapperConfiguration.Configure(cfg);

                    //this method append plugin automapper configuration
                    service.SetAutoMapperConfiguration();

                    //this should be called after plugin init
                    AutoMapper.Mapper.Initialize(cfg);

                    service.InitializeSystemEntities();

                    CheckCreateHomePage();

                    service.InitializeBackgroundJobs(additionalJobTypes);

                    ErpAppContext.Init(app.ApplicationServices);

                    //this is called after automapper setup
                    service.InitializePlugins(app.ApplicationServices);
                }
                finally
                {
                    DbContext.CloseContext();
                }

                if (service != null)
                {
                    service.StartBackgroundJobProcess();
                }


                return(app);
            }
        }
Пример #2
0
        public static IApplicationBuilder UseErp(this IApplicationBuilder app, List <JobType> additionalJobTypes = null, string configFolder = null)
        {
            using (var secCtx = SecurityContext.OpenSystemScope())
            {
                IConfiguration      configuration = app.ApplicationServices.GetService <IConfiguration>();
                IHostingEnvironment env           = app.ApplicationServices.GetService <IHostingEnvironment>();

                string configPath = "config.json";
                if (!string.IsNullOrWhiteSpace(configFolder))
                {
                    configPath = System.IO.Path.Combine(configFolder, configPath);
                }

                var configurationBuilder = new ConfigurationBuilder().SetBasePath(env.ContentRootPath).AddJsonFile(configPath);
                ErpSettings.Initialize(configurationBuilder.Build());

                var defaultThreadCulture   = CultureInfo.DefaultThreadCurrentCulture;
                var defaultThreadUICulture = CultureInfo.DefaultThreadCurrentUICulture;

                CultureInfo customCulture = new CultureInfo("en-US");
                customCulture.NumberFormat.NumberDecimalSeparator = ".";

                IErpService service = null;
                try
                {
                    DbContext.CreateContext(ErpSettings.ConnectionString);

                    service = app.ApplicationServices.GetService <IErpService>();

                    var cfg = ErpAutoMapperConfiguration.MappingExpressions;                     // var cfg = new AutoMapper.Configuration.MapperConfigurationExpression();
                    ErpAutoMapperConfiguration.Configure(cfg);
                    ErpWebAutoMapperConfiguration.Configure(cfg);

                    //this method append plugin automapper configuration
                    service.SetAutoMapperConfiguration();

                    //this should be called after plugin init
                    AutoMapper.Mapper.Initialize(cfg);

                    //we used en-US based culture settings for initialization and patch execution
                    {
                        CultureInfo.DefaultThreadCurrentCulture   = customCulture;
                        CultureInfo.DefaultThreadCurrentUICulture = customCulture;

                        service.InitializeSystemEntities();

                        CultureInfo.DefaultThreadCurrentCulture   = defaultThreadCulture;
                        CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture;
                    }

                    CheckCreateHomePage();

                    service.InitializeBackgroundJobs(additionalJobTypes);

                    ErpAppContext.Init(app.ApplicationServices);

                    {
                        //switch culture for patch executions and initializations
                        CultureInfo.DefaultThreadCurrentCulture   = customCulture;
                        CultureInfo.DefaultThreadCurrentUICulture = customCulture;

                        //this is called after automapper setup
                        service.InitializePlugins(app.ApplicationServices);

                        CultureInfo.DefaultThreadCurrentCulture   = defaultThreadCulture;
                        CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture;
                    }
                }
                finally
                {
                    DbContext.CloseContext();
                    CultureInfo.DefaultThreadCurrentCulture   = defaultThreadCulture;
                    CultureInfo.DefaultThreadCurrentUICulture = defaultThreadUICulture;
                }

                if (service != null)
                {
                    service.StartBackgroundJobProcess();
                }

                return(app);
            }
        }
Пример #3
0
        public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider)
        {
            //TODO Create db context
            CultureInfo.DefaultThreadCurrentCulture   = CultureInfo.GetCultureInfo("en-US");
            CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo("en-US");
            Settings.Initialize(Configuration);

            IErpService service = null;

            try
            {
                DbContext.CreateContext(Settings.ConnectionString);

                service = app.ApplicationServices.GetService <IErpService>();
                AutoMapperConfiguration.Configure();
                service.InitializeSystemEntities();
                service.InitializeBackgroundJobs();

                app.UseErpMiddleware();

                //IHostingEnvironment env = app.ApplicationServices.GetService<IHostingEnvironment>();
                //if (env.IsDevelopment())
                app.UseDeveloperExceptionPage();

                IPluginService      pluginService      = app.ApplicationServices.GetService <IPluginService>();
                IHostingEnvironment hostingEnvironment = app.ApplicationServices.GetRequiredService <IHostingEnvironment>();
                pluginService.Initialize(serviceProvider);

                IWebHookService webHookService = app.ApplicationServices.GetService <IWebHookService>();
                webHookService.Initialize(pluginService);

                NotificationContext.Initialize();
                NotificationContext.Current.SendNotification(new Notification {
                    Channel = "*", Message = "ERP configuration loaded and completed."
                });
            }
            finally
            {
                DbContext.CloseContext();
            }

            if (service != null)
            {
                service.StartBackgroundJobProcess();
            }

            //Enable CORS
            //app.Use((context, next) =>
            //{
            //	context.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            //	context.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "*" });
            //	context.Response.Headers.Add("Access-Control-Allow-Methods", new[] { "*" });
            //	return next();
            //});

            //app.Run(async context =>
            //{
            //    IErpService service = app.ApplicationServices.GetService<IErpService>();
            //    service.Run();
            //    context.Response.ContentType = "text/html";
            //    context.Response.StatusCode = 200;
            //    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            //    byte[] buffer = encoding.GetBytes("<h1>test</h1>");
            //    await context.Response.Body.WriteAsync(buffer, 0, buffer.Length);
            //});

            // Add the following to the request pipeline only in development environment.
            if (string.Equals(hostingEnviroment.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseExceptionHandler("/Home/Error");
            }

            //TODO Check what was done here in RC1
            //app.UseIISPlatformHandler(options => options.AutomaticAuthentication = false);

            //Should be before Static files
            app.UseResponseCompression();

            // Add static files to the request pipeline. Should be last middleware.
            app.UseStaticFiles(new StaticFileOptions
            {
                OnPrepareResponse = ctx =>
                {
                    const int durationInSeconds = 60 * 60 * 24 * 30;                     //30 days caching of these resources
                    ctx.Context.Response.Headers[HeaderNames.CacheControl] =
                        "public,max-age=" + durationInSeconds;
                }
            });

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Home", action = "Index" });

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });
        }