示例#1
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();
        }
        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();
        }
示例#3
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();
        }
示例#4
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.");
            }
        }
示例#6
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();
        }
示例#7
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();
            }
        }