Exemplo n.º 1
0
        public PluginPermissionsManager GetPermissionsManager(string connectionString)
        {
            var contextFactory = new ItemsPlanningPnContextFactory();
            var context        = contextFactory.CreateDbContext(new[] { connectionString });

            return(new PluginPermissionsManager(context));
        }
Exemplo n.º 2
0
        public void SeedDatabase(string connectionString)
        {
            // Get DbContext
            var contextFactory = new ItemsPlanningPnContextFactory();

            using var context = contextFactory.CreateDbContext(new[] { connectionString });
            // Seed configuration
            ItemsPlanningPluginSeed.SeedData(context);
        }
        private void GetContext(string connectionStr)
        {
            var contextFactory = new ItemsPlanningPnContextFactory();

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

            DbContext.Database.Migrate();
            DbContext.Database.EnsureCreated();
        }
Exemplo n.º 4
0
        public void AddPluginConfig(IConfigurationBuilder builder, string connectionString)
        {
            var seedData       = new ItemsPlanningConfigurationSeedData();
            var contextFactory = new ItemsPlanningPnContextFactory();

            builder.AddPluginConfiguration(
                connectionString,
                seedData,
                contextFactory);

            //CaseUpdateDelegates.CaseUpdateDelegate += UpdateRelatedCase;
        }
Exemplo n.º 5
0
        public void ConfigureDbContext(IServiceCollection services, string connectionString)
        {
            _connectionString = connectionString;
            services.AddDbContext <ItemsPlanningPnDbContext>(o =>
                                                             o.UseMySql(connectionString, new MariaDbServerVersion(
                                                                            new Version(10, 4, 0)), mySqlOptionsAction: builder =>
            {
                builder.EnableRetryOnFailure();
                builder.MigrationsAssembly(PluginAssembly().FullName);
            }));

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

            context.Database.Migrate();

            // Seed database
            SeedDatabase(connectionString);
        }
        public ItemsPlanningPnDbContext GetDbContext()
        {
            ItemsPlanningPnContextFactory contextFactory = new ItemsPlanningPnContextFactory();

            return(contextFactory.CreateDbContext(new[] { ConnectionString }));
        }
Exemplo n.º 7
0
        public bool Start(string sdkConnectionString, string serviceLocation)
        {
            Console.WriteLine("ServiceItemsPlanningPlugin 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;
                }


                var pluginDbName     = $"Initial Catalog={dbPrefix}_eform-angular-items-planning-plugin;";
                var 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");
                    }

                    ItemsPlanningPnContextFactory contextFactory = new ItemsPlanningPnContextFactory();

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

                    _dbContextHelper = new DbContextHelper(connectionString);

                    _coreAvailable    = true;
                    _coreStatChanging = false;

                    StartSdkCoreSqlOnly(sdkConnectionString);

                    string temp = _dbContext.PluginConfigurationValues
                                  .SingleOrDefault(x => x.Name == "ItemsPlanningBaseSettings:MaxParallelism")?.Value;
                    _maxParallelism = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

                    temp = _dbContext.PluginConfigurationValues
                           .SingleOrDefault(x => x.Name == "ItemsPlanningBaseSettings:NumberOfWorkers")?.Value;
                    _numberOfWorkers = string.IsNullOrEmpty(temp) ? 1 : int.Parse(temp);

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

                    _bus = _container.Resolve <IBus>();

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