public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            _connectionString = connectionString;

            services.AddDbContext <AppointmentPnDbContext>(o => o.UseMySql(connectionString, new MariaDbServerVersion(
                                                                               new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));

            AppointmentPnContextFactory contextFactory = new AppointmentPnContextFactory();
            var context = contextFactory.CreateDbContext(new[] { connectionString });

            context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);

            string temp = context.PluginConfigurationValues
                          .SingleOrDefault(x => x.Name == "AppointmentBaseSettings:MaxParallelism")?.Value;

            _maxParallelism = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

            temp = context.PluginConfigurationValues
                   .SingleOrDefault(x => x.Name == "AppointmentBaseSettings:NumberOfWorkers")?.Value;
            _numberOfWorkers = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);
        }
        public PluginPermissionsManager GetPermissionsManager(string connectionString)
        {
            var contextFactory = new AppointmentPnContextFactory();
            var context        = contextFactory.CreateDbContext(new[] { connectionString });

            return(new PluginPermissionsManager(context));
        }
        private void GetContext(string connectionStr)
        {
            AppointmentPnContextFactory contextFactory = new AppointmentPnContextFactory();

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

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
        public void SeedDatabase(string connectionString)
        {
            var contextFactory = new AppointmentPnContextFactory();

            using (var context = contextFactory.CreateDbContext(new [] { connectionString }))
            {
                AppointmentPluginSeed.SeedData(context);
            }
        }
        public void AddPluginConfig(IConfigurationBuilder builder, string connectionString)
        {
            var seedData       = new AppointmentConfigurationSeedData();
            var contextFactory = new AppointmentPnContextFactory();

            builder.AddPluginConfiguration(
                connectionString,
                seedData,
                contextFactory);

            // Add handlers
            //CaseUpdateDelegates.CaseUpdateDelegate += CaseUpdatePluginHandler.Handle;
        }
Ejemplo n.º 6
0
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("ServiceAppointmentPlugin start called");
            try
            {
                //InstallCA();

                var dbNameSection = Regex.Match(sdkConnectionString, @"(Database=\w*;)").Groups[0].Value;
                var dbPrefix      = Regex.Match(sdkConnectionString, @"Database=(\d*)_").Groups[1].Value;

                string pluginDbName     = $"Initial Catalog={dbPrefix}_eform-angular-appointment-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");
                    }

                    AppointmentPnContextFactory contextFactory = new AppointmentPnContextFactory();

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

                    _coreAvailable    = true;
                    _coreStatChanging = false;

                    startSdkCoreSqlOnly(sdkConnectionString);

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


                    _bus = _container.Resolve <IBus>();

                    ConfigureScheduler();
                }
                Console.WriteLine("ServiceAppointmentPlugin started");
                return(true);
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.DarkRed;
                Console.WriteLine("Start failed " + ex.Message);
                throw;
            }
        }