protected BestSystemService(
     IItemsService itemsService,
     EveEchoesPlanetaryProductionApiDbContext dbContext)
 {
     this.ItemsService = itemsService;
     this.DbContext    = dbContext;
 }
Esempio n. 2
0
        public async Task SeedAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, [NotNull] IServiceProvider serviceProvider)
        {
            if (await dbContext.ItemTypes.AnyAsync())
            {
                return;
            }

            var logger = serviceProvider
                         .GetService <ILoggerFactory>()
                         .CreateLogger(typeof(ItemTypeSeeder));

            await using var dbContextTransaction = await dbContext.Database.BeginTransactionAsync();

            try
            {
                await SeedItemTypesAsync(dbContext);
                await AddTypeToItems(dbContext);

                await dbContextTransaction.CommitAsync();
            }
            catch (Exception ex)
            {
                logger.LogCritical($"Seeder ItemTypeSeeder failed with error: {ex.Message}");
            }
        }
        private static async Task SeedItemsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.ItemsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var itemArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var item = await CreateItem(itemArgs, dbContext);

                if (item is null)
                {
                    var name = itemArgs[1];

                    logger.LogWarning(string.Format(DatabaseConstants.SeedingConstants.ItemErrorParseMessage, name));
                    logger.LogWarning(line);

                    continue;
                }

                if (await dbContext.Items.AnyAsync(i => i.Id.Equals(item.Id)))
                {
                    continue;
                }

                await dbContext.AddAsync(item);
            }

            await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext.Items));
        }
        private static async Task SeedRegionsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.RegionsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var success    = long.TryParse(lineArgs[0], out var regionId);
                var regionName = lineArgs[1];

                if (!success)
                {
                    logger.LogWarning(string.Format(DatabaseConstants.SeedingConstants.RegionErrorParseMessage, regionName));
                    logger.LogWarning(line);
                    continue;
                }

                var region = new Region()
                {
                    Id   = regionId,
                    Name = regionName,
                };

                await dbContext.AddAsync(region);
            }

            await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext
                                                                              .Regions));
        }
        private static async Task SeedBlueprintsResources(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            var csvValues = new[]
            {
                "Name", "Type", "Tech Level", "Tritanium", "Pyerite", "Mexallon", "Isogen", "Nocxium", "Zydrine",
                "Megacyte", "Morphite", "Lustering Alloy", "Sheen Compound", "Gleaming Alloy", "Condensed Alloy",
                "Precious Alloy", "Motley Compound", "Fiber Composite", "Lucent Compound", "Opulent Compound",
                "Glossy Compound", "Crystal Compound", "Dark Compound", "Base Metals", "Heavy Metals",
                "Reactive Metals", "Noble Metals", "Toxic Metals", "Reactive Gas", "Noble Gas", "Industrial Fibers",
                "Supertensile Plastics", "Polyaramids", "Coolant", "Condensates", "Construction Blocks", "Nanites",
                "Silicate Glass", "Smartfab Units", "Charred Micro Circuit", "Fried Interface Circuit",
                "Tripped Power Circuit", "Smashed Trigger Unit", "Damaged Close-in Weapon System",
                "Scorched Telemetry Processor", "Contaminated Lorentz Fluid", "Conductive Polymer",
                "Contaminated Nanite Polymer", "Defective Current Pump", "Production Cost", "Production Time",
                "Production Count",
            };

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.BluePrintsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                await SeedCurrentBlueprintResources(dbContext, logger, lineArgs, csvValues);
            }
        }
 public RegionsService(
     IMemoryCache memoryCache,
     IItemsService itemsService,
     EveEchoesPlanetaryProductionApiDbContext dbContext)
     : base(itemsService, dbContext)
 {
     this.memoryCache = memoryCache;
 }
Esempio n. 7
0
 public PlanetaryResourcesService(
     EveEchoesPlanetaryProductionApiDbContext dbContext,
     ISolarSystemsService solarSystemsService,
     IItemsService itemsService)
 {
     this.dbContext           = dbContext;
     this.solarSystemsService = solarSystemsService;
     this.itemsService        = itemsService;
 }
Esempio n. 8
0
        public async Task SeedAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (await dbContext.PlanetTypes.AnyAsync())
            {
                return;
            }

            await SeedPlanetTypesAsync(dbContext);
        }
 public SolarSystemsService(
     IMapper mapper,
     IItemsService itemsService,
     IMemoryCache memoryCache,
     EveEchoesPlanetaryProductionApiDbContext dbContext)
     : base(itemsService, dbContext)
 {
     this.mapper      = mapper;
     this.memoryCache = memoryCache;
 }
 public ItemsService(
     IMemoryCache memoryCache,
     EveEchoesPlanetaryProductionApiDbContext dbContext,
     IItemsPricesService itemsPricesService,
     IMapper mapper)
 {
     this.memoryCache        = memoryCache;
     this.dbContext          = dbContext;
     this.itemsPricesService = itemsPricesService;
     this.mapper             = mapper;
 }
        public async Task SeedAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (await dbContext.Regions.AnyAsync())
            {
                return;
            }

            var logger = serviceProvider
                         .GetService <ILoggerFactory>()
                         .CreateLogger(typeof(EveEchoesPlanetaryProductionApiDbContextSeeder));

            await SeedRegionsAsync(dbContext, logger);
        }
Esempio n. 12
0
        private static async Task SeedSolarSystemsJumpsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            var solarSystemsJumps = new List <SolarSystemJump>();

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.SolarSystemsJumpsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var fromRegionIdSuccess        = long.TryParse(lineArgs[0], out var fromRegionId);
                var fromConstellationIdSuccess = long.TryParse(lineArgs[1], out var fromConstellationId);

                var fromSolarSystemSuccess = long.TryParse(lineArgs[2], out var fromSolarSystemId);
                var toSolarSystemSuccess   = long.TryParse(lineArgs[3], out var toSolarSystemId);

                var toConstellationIdSuccess = long.TryParse(lineArgs[4], out var toConstellationId);
                var toRegionIdSuccess        = long.TryParse(lineArgs[5], out var toRegionId);

                if (!fromRegionIdSuccess ||
                    !toRegionIdSuccess ||
                    !fromConstellationIdSuccess ||
                    !toConstellationIdSuccess ||
                    !fromSolarSystemSuccess ||
                    !toSolarSystemSuccess)
                {
                    logger.LogWarning($"Can't parse solar system jump");
                    logger.LogWarning(line);
                    continue;
                }

                var solarSystemJump = new SolarSystemJump()
                {
                    FromRegionId        = fromRegionId,
                    FromConstellationId = fromConstellationId,
                    FromSolarSystemId   = fromSolarSystemId,
                    ToSolarSystemId     = toSolarSystemId,
                    ToConstellationId   = toConstellationId,
                    ToRegionId          = toRegionId,
                };

                solarSystemsJumps.Add(solarSystemJump);
            }

            await dbContext.AddRangeAsync(solarSystemsJumps);

            await dbContext.SaveChangesAsync();
        }
Esempio n. 13
0
        private static async Task SeedPlanetsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            var planets = new List <Planet>();

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.PlanetsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var planetIdParseSuccess        = long.TryParse(lineArgs[0], out var planetId);
                var regionIdParseSuccess        = long.TryParse(lineArgs[1], out var regionId);
                var constellationIdParseSuccess = long.TryParse(lineArgs[2], out var constellationId);
                var solarSystemIdParseSuccess   = long.TryParse(lineArgs[3], out var solarSystemId);
                var planetName = lineArgs[4];
                var planetTypeIdParseSuccess = long.TryParse(lineArgs[5], out var planetTypeId);

                if (!planetIdParseSuccess ||
                    !regionIdParseSuccess ||
                    !constellationIdParseSuccess ||
                    !solarSystemIdParseSuccess ||
                    !planetTypeIdParseSuccess)
                {
                    logger.LogWarning($"Can't parse planet");
                    logger.LogWarning(line);
                    continue;
                }

                var planet = new Planet()
                {
                    Id              = planetId,
                    RegionId        = regionId,
                    ConstellationId = constellationId,
                    SolarSystemId   = solarSystemId,
                    Name            = planetName,
                    PlanetTypeId    = planetTypeId,
                };

                planets.Add(planet);
            }

            await dbContext.AddRangeAsync(planets);

            await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext
                                                                              .Planets));
        }
        private static async Task SeedCurrentBlueprintResources(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger, string[] lineArgs, string[] csvValues)
        {
            var resourceTasks = new List <ValueTask <EntityEntry <BlueprintResource> > >();

            var name          = lineArgs[0];
            var blueprintName = $"{name} Blueprint";
            var blueprint     = await dbContext.Blueprints.FirstOrDefaultAsync(b => b.BlueprintItem.Name.Equals(blueprintName));

            if (blueprint is null)
            {
                logger.LogError($"Can't find blueprint with name: {name}");
            }

            for (var i = 3; i < 49; i++)
            {
                var itemName            = csvValues[i];
                var itemQuantitySuccess = long.TryParse(lineArgs[i], out var itemQuantity);

                var item = await dbContext.Items.Where(i => i.Name.Equals(itemName)).FirstOrDefaultAsync();

                if (!itemQuantitySuccess ||
                    item is null)
                {
                    logger.LogError("Can't parse blueprint resource");
                    logger.LogError($"Resource: {itemName}, quantity: {itemQuantity}");

                    continue;
                }

                if (itemQuantity == 0)
                {
                    continue;
                }

                var blueprintResource = new BlueprintResource()
                {
                    Blueprint = blueprint,
                    Item      = item,
                    Quantity  = itemQuantity,
                };

                resourceTasks.Add(dbContext.BlueprintsResources.AddAsync(blueprintResource));
            }

            var tasks = resourceTasks.Select(vt => vt.AsTask()).ToArray();
            await Task.WhenAll(tasks);

            await dbContext.SaveChangesAsync();
        }
        public async Task SeedAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, IServiceProvider serviceProvider)
        {
            var logger = serviceProvider
                         .GetService <ILoggerFactory>()
                         .CreateLogger(typeof(EveEchoesPlanetaryProductionApiDbContextSeeder));

            if (await dbContext.Items.AnyAsync())
            {
                await UpdateItems(dbContext, logger, false);

                return;
            }

            await SeedItemsAsync(dbContext, logger);
        }
Esempio n. 16
0
        private static async Task AddTypeToItems(EveEchoesPlanetaryProductionApiDbContext dbContext)
        {
            var items = await dbContext.Items.ToListAsync();

            var itemTypes = await dbContext.ItemTypes.ToDictionaryAsync(x => x.Name, y => y);

            foreach (var item in items)
            {
                var type = GetItemType(item);

                item.ItemType = itemTypes[type];
            }

            await dbContext.SaveChangesAsync();
        }
Esempio n. 17
0
        private static async Task SeedSolarSystemsAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.SolarSystemsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var regionIdParseSuccess      = long.TryParse(lineArgs[0], out var regionId);
                var constellationParseSuccess = long.TryParse(lineArgs[1], out var constellationId);
                var solarSystemSuccess        = long.TryParse(lineArgs[2], out var solarSystemId);
                var solarSystemName           = lineArgs[3];

                var security = double.Parse(lineArgs[21]);

                if (!regionIdParseSuccess ||
                    !constellationParseSuccess ||
                    !solarSystemSuccess)
                {
                    logger.LogWarning(string.Format(
                                          DatabaseConstants.SeedingConstants.SolarSystemErrorParseMessage,
                                          solarSystemName));
                    logger.LogWarning(line);
                    continue;
                }

                var solarSystem = new SolarSystem()
                {
                    RegionId        = regionId,
                    ConstellationId = constellationId,
                    Id       = solarSystemId,
                    Name     = solarSystemName,
                    Security = security,
                };

                await dbContext.AddAsync(solarSystem);
            }

            await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext
                                                                              .SolarSystems));
        }
Esempio n. 18
0
        private static async Task SeedPlanetsResourcesAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            var planetsResources = new List <PlanetResource>();

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths
                                                                                 .PlanetsResourcesCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var planetIdParseSuccess = long.TryParse(lineArgs[0], out var planetId);
                var itemId             = (await dbContext.Items.FirstOrDefaultAsync(i => i.Name.Equals(lineArgs[6])))?.Id ?? 0;
                var richnessId         = (await dbContext.Richnesses.FirstOrDefaultAsync(i => i.Name.Equals(lineArgs[7])))?.Id ?? 0;
                var outputParseSuccess = double.TryParse(lineArgs[8], out var output);

                if (!planetIdParseSuccess ||
                    itemId is 0 ||
                    richnessId is 0 ||
                    !outputParseSuccess)
                {
                    logger.LogWarning($"Can't parse planet resource");
                    logger.LogWarning(line);
                    continue;
                }

                var planetResource = new PlanetResource()
                {
                    PlanetId   = planetId,
                    ItemId     = itemId,
                    RichnessId = richnessId,
                    Output     = output,
                };

                planetsResources.Add(planetResource);
            }

            await dbContext.AddRangeAsync(planetsResources);

            await dbContext.SaveChangesAsync();
        }
        public async Task SeedAsync([NotNull] EveEchoesPlanetaryProductionApiDbContext dbContext, [NotNull] IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider
                         .GetService <ILoggerFactory>()
                         .CreateLogger(typeof(EveEchoesPlanetaryProductionApiDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new ItemsSeeder(),
                new RichnessSeeder(),
                new PlanetTypesSeeder(),
                new RegionsSeeder(),
                new ConstellationsSeeder(),
                new SolarSystemsSeeder(),
                new PlanetsSeeder(),
                new PlanetsResourcesSeeder(),
                new RegionsJumpsSeeder(),
                new ConstellationsJumpsSeeder(),
                new SolarSystemsJumpsSeeder(),
                new ItemTypeSeeder(),
                new BlueprintSeeder(),
                new BlueprintsResourcesSeeder(),
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
        public async Task SeedAsync(EveEchoesPlanetaryProductionApiDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (await dbContext.BlueprintsResources.AnyAsync())
            {
                return;
            }

            var logger = serviceProvider
                         .GetService <ILoggerFactory>()
                         .CreateLogger(typeof(BlueprintsResourcesSeeder));

            try
            {
                await SeedBlueprintsResources(dbContext, logger);
            }
            catch (Exception ex)
            {
                logger.LogCritical($"Seeder {nameof(BlueprintSeeder)} failed with error: {ex.Message}");
            }
        }
Esempio n. 21
0
        private static async Task <Item> CreateBlueprint(EveEchoesPlanetaryProductionApiDbContext dbContext, string blueprintName, ItemType productType)
        {
            var type = await dbContext.ItemTypes.Where(t => t.Name.Equals("Blueprint")).FirstOrDefaultAsync();

            var item = new Item()
            {
                ItemType = type,
                Id       = GetBlueprintId(productType),
                Name     = blueprintName,
            };

            using (dbContext.Database.OpenConnectionAsync())
            {
                await dbContext.Items.AddAsync(item);

                await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext.Items));
            }

            return(item);
        }
Esempio n. 22
0
        private static async Task SeedItemTypesAsync(EveEchoesPlanetaryProductionApiDbContext dbContext)
        {
            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.ItemTypesCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs     = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);
                var itemTypeName = lineArgs[0];

                var itemType = new ItemType()
                {
                    Name = itemTypeName,
                };

                await dbContext.AddAsync(itemType);
            }

            await dbContext.SaveChangesAsync();
        }
        private static async Task <Item> CreateItem(string[] itemArgs, EveEchoesPlanetaryProductionApiDbContext dbContext)
        {
            var success = long.TryParse(itemArgs[0], out var itemId);
            var name    = itemArgs[1];

            if (!success)
            {
                return(null);
            }

            var item = new Item()
            {
                Id   = itemId,
                Name = name,
            };

            item.ItemTypeId = await dbContext.ItemTypes
                              .Where(it => it.Name.Equals(ItemTypeSeeder.GetItemType(item)))
                              .Select(x => x.Id)
                              .FirstOrDefaultAsync();

            return(item);
        }
        private static async Task UpdateItems(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger, bool update)
        {
            if (!update)
            {
                return;
            }

            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.ItemsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var itemArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var success = long.TryParse(itemArgs[0], out var itemId);

                if (!success)
                {
                    logger.LogError("Can't parse item");
                    logger.LogError(line);
                    continue;
                }

                if (await dbContext.Items.AnyAsync(i => i.Id.Equals(itemId)))
                {
                    continue;
                }

                var item = await CreateItem(itemArgs, dbContext);

                await dbContext.AddAsync(item);

                await dbContext.SaveChangesWithExplicitIdentityInsertAsync(nameof(EveEchoesPlanetaryProductionApiDbContext.Items));
            }
        }
Esempio n. 25
0
        private static async Task SeedBlueprints(EveEchoesPlanetaryProductionApiDbContext dbContext, ILogger logger)
        {
            await foreach (var line in CsvFileService.ReadCsvDataLineByLineAsync(GlobalConstants.FilePaths.BluePrintsCsvFilePath))
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }

                var lineArgs = line.Split(GlobalConstants.CsvDelimiter, StringSplitOptions.RemoveEmptyEntries);

                var name        = lineArgs[0];
                var type        = lineArgs[1];
                var techSuccess = int.TryParse(lineArgs[2], out var tech);

                var productionCostSuccess  = long.TryParse(lineArgs[49], out var productionCost);
                var productionTimeSuccess  = long.TryParse(lineArgs[50], out var productionTime);
                var productionCountSuccess = long.TryParse(lineArgs[51], out var productionCount);

                var product = await dbContext.Items
                              .Where(i => i.Name.Equals(name))
                              .FirstOrDefaultAsync();

                var productType = await dbContext.ItemTypes
                                  .Where(t => t.Name.Equals(type))
                                  .FirstOrDefaultAsync();

                var blueprintName = $"{name} Blueprint";

                var blueprintItem = await dbContext.Items
                                    .Where(i => i.Name.Equals(blueprintName))
                                    .FirstOrDefaultAsync() ?? await CreateBlueprint(dbContext, blueprintName, productType);

                if (product is null ||
                    productType is null ||
                    blueprintItem is null ||
                    !techSuccess ||
                    !productionCostSuccess ||
                    !productionTimeSuccess ||
                    !productionCountSuccess)
                {
                    logger.LogError("Cant parse blueprint");
                    logger.LogError(line);

                    continue;
                }

                var blueprint = new Blueprint()
                {
                    BlueprintItem   = blueprintItem,
                    Product         = product,
                    ProductType     = productType,
                    TechLevel       = tech,
                    ProductionCost  = productionCost,
                    ProductionTime  = productionTime,
                    ProductionCount = productionCount,
                };

                await dbContext.Blueprints.AddAsync(blueprint);

                await dbContext.SaveChangesAsync();
            }
        }
 public LetsEncryptController(EveEchoesPlanetaryProductionApiDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
 public BlueprintsService(EveEchoesPlanetaryProductionApiDbContext dbContext)
 {
     this.dbContext = dbContext;
 }