Beispiel #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);
            }
        }
Beispiel #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);
            }
        }