Пример #1
0
        public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            _connectionString = connectionString;
            string customersConnectionString = connectionString.Replace(
                "eform-angular-rentableitem-plugin",
                "eform-angular-basecustomer-plugin");

            services.AddDbContext <eFormRentableItemPnDbContext>(o =>
                                                                 o.UseMySql(connectionString, new MariaDbServerVersion(
                                                                                new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));
            services.AddDbContext <CustomersPnDbAnySql>(p =>
                                                        p.UseMySql(customersConnectionString, new MariaDbServerVersion(
                                                                       new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));
            eFormRentableItemPnDbContextFactory contextFactory = new eFormRentableItemPnDbContextFactory();
            var context = contextFactory.CreateDbContext(new[] { connectionString });

            context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);
        }
Пример #2
0
        public PluginPermissionsManager GetPermissionsManager(string connectionString)
        {
            var contextFactory = new eFormRentableItemPnDbContextFactory();
            var context        = contextFactory.CreateDbContext(new[] { connectionString });

            return(new PluginPermissionsManager(context));
        }
Пример #3
0
        private void GetContext(string connectionStr)
        {
            eFormRentableItemPnDbContextFactory contextFactory = new eFormRentableItemPnDbContextFactory();

            DbContext = contextFactory.CreateDbContext(new[] { connectionStr });

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
Пример #4
0
        public void SeedDatabase(string connectionString)
        {
            var contextFactory = new eFormRentableItemPnDbContextFactory();

            using (var context = contextFactory.CreateDbContext(new [] { connectionString }))
            {
                RentableItemPluginSeed.SeedData(context);
            }
        }
Пример #5
0
        public void AddPluginConfig(IConfigurationBuilder builder, string connectionString)
        {
            RentableItemsConfigurationSeedData  seedData       = new RentableItemsConfigurationSeedData();
            eFormRentableItemPnDbContextFactory contextFactory = new eFormRentableItemPnDbContextFactory();

            builder.AddPluginConfiguration(
                connectionString,
                seedData,
                contextFactory);
        }
Пример #6
0
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("[INF] RentableItemsPlugin start called");
            try
            {
                string dbNameSection;
                string dbPrefix;
                if (sdkConnectionString.ToLower().Contains("convert zero datetime"))
                {
                    dbNameSection = Regex.Match(sdkConnectionString, @"(Database=\w*;)").Groups[0].Value;
                    dbPrefix      = Regex.Match(sdkConnectionString, @"Database=(\d*)_").Groups[1].Value;
                }
                else
                {
                    dbNameSection = Regex.Match(sdkConnectionString, @"(Initial Catalog=\w*;)").Groups[0].Value;
                    dbPrefix      = Regex.Match(sdkConnectionString, @"Initial Catalog=(\d*)_").Groups[1].Value;
                }


                string pluginDbName     = $"Initial Catalog={dbPrefix}_eform-angular-rentableitem-plugin;";
                string connectionString = sdkConnectionString.Replace(dbNameSection, pluginDbName);


                if (!_coreAvailable && !_coreStatChanging)
                {
                    _serviceLocation  = serviceLocation;
                    _coreStatChanging = true;

                    if (string.IsNullOrEmpty(_serviceLocation))
                    {
                        throw new ArgumentException("serviceLocation is not allowed to be null or empty");
                    }

                    if (string.IsNullOrEmpty(connectionString))
                    {
                        throw new ArgumentException("serverConnectionString is not allowed to be null or empty");
                    }

                    eFormRentableItemPnDbContextFactory contextFactory = new eFormRentableItemPnDbContextFactory();

                    _dbContext = contextFactory.CreateDbContext(new[] { connectionString });
                    _dbContext.Database.Migrate();

                    _coreAvailable    = true;
                    _coreStatChanging = false;
                    _dbContextHelper  = new DbContextHelper(connectionString);

                    startSdkCoreSqlOnly(sdkConnectionString);

                    _container = new WindsorContainer();
                    _container.Register(Component.For <DbContextHelper>().Instance(_dbContextHelper));
                    _container.Register(Component.For <eFormCore.Core>().Instance(_sdkCore));
                    _container.Install(
                        new RebusHandlerInstaller()
                        , new RebusInstaller(connectionString, _maxParallelism, _numberOfWorkers)
                        );


                    _bus = _container.Resolve <IBus>();
                }
                Console.WriteLine("RentableItemsPlugin started");
                return(true);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Start failed " + ex.Message);
                throw ex;
            }
        }
        public eFormRentableItemPnDbContext GetDbContext()
        {
            eFormRentableItemPnDbContextFactory contextFactory = new eFormRentableItemPnDbContextFactory();

            return(contextFactory.CreateDbContext(new[] { ConnecitonString }));
        }