Esempio n. 1
0
        private async Task SeedDBUsingSQLScriptsAsync(string targetDirectory)
        {
            try
            {
                string[] fileEntries = Directory.GetFiles(targetDirectory);

                foreach (string fileName in fileEntries)
                {
                    await _appDbContext.Database.ExecuteSqlRawAsync(
                        File.ReadAllText(fileName).Replace(_configurationSection["EntityPrefixFrom"], _configurationSection["EntityPrefixTo"])
                        );
                }
            }
            catch (Exception e)
            {
                _machineLogger.LogDetails(LogLevel.Error, e.Message);
            }
        }
        public async Task <Unit> Handle(SeedDBCommand request, CancellationToken cancellationToken)
        {
            try
            {
                IConfigurationSection sqlSection = _configuration.GetSection("SQL");

                if (sqlSection == null)
                {
                    throw new Exception("No SQL Section provided in appsettings.json. Kindly provide one");
                }

                AppDbSeeder appDbSeeder = new(_appDbContext, _configuration.GetSection("SQL"), _machineLogger, _machineDateTime);
                await appDbSeeder.SeedAllAsync(request.FolderKey);
            }
            catch (Exception e)
            {
                _machineLogger.LogDetails(LogLevel.Error, e.Message);
            }
            return(Unit.Value);
        }