Exemplo n.º 1
0
        private void DeserializeAstronomers()
        {
            var astronomerDtos = JsonFileOperations.DeserializeJsonCollection <AstronomerDto>(Constants.AstronomerJsonFile);

            using (PlanetHuntersContext ctx = new PlanetHuntersContext())
            {
                AstronomerRepo repo = new AstronomerRepo(ctx);

                foreach (var dto in astronomerDtos)
                {
                    if (dto.FirstName != null && dto.LastName != null)
                    {
                        var a = new Astronomer();
                        Mapper.Map(dto, a);
                        repo.Insert(a);
                        this.DebugLog.AppendLine($"Record {dto.FirstName} {dto.LastName} successfully imported.");
                    }
                    else
                    {
                        this.DebugLog.AppendLine(Constants.InvalidDataFormat);
                    }
                }

                DbUtil.ExecTransaction(ctx);
            }
        }
Exemplo n.º 2
0
        private void DeserializeTelescopes()
        {
            var telescopeDtos = JsonFileOperations.DeserializeJsonCollection <TelescopeDto>(Constants.TelescopeJsonFile);

            using (PlanetHuntersContext ctx = new PlanetHuntersContext())
            {
                TelescopeRepo repo = new TelescopeRepo(ctx);

                foreach (var dto in telescopeDtos)
                {
                    if (dto.Name != null && dto.Location != null)
                    {
                        if (dto.MirrorDiameter != null && dto.MirrorDiameter <= 0)
                        {
                            continue;
                        }

                        var t = new Telescope();
                        Mapper.Map(dto, t);
                        repo.Insert(t);
                        this.DebugLog.AppendLine($"Record {dto.Name} successfully imported.");
                    }
                    else
                    {
                        this.DebugLog.AppendLine(Constants.InvalidDataFormat);
                    }
                }

                DbUtil.ExecTransaction(ctx);
            }
        }
Exemplo n.º 3
0
        private void DeserializePlanets()
        {
            var planetDtos = JsonFileOperations.DeserializeJsonCollection <PlanetDto>(Constants.PlanetJsonFile);

            using (PlanetHuntersContext ctx = new PlanetHuntersContext())
            {
                StarSystemRepo stRepo = new StarSystemRepo(ctx);
                PlanetRepo     plRepo = new PlanetRepo(ctx);

                foreach (var dto in planetDtos)
                {
                    if (dto.Mass > 0 && dto.Name != null && dto.StarSystem != null)
                    {
                        var planet = new Planet();
                        Mapper.Map(dto, planet);

                        var starSystem = stRepo.SearchFor(s => s.Name == dto.StarSystem).FirstOrDefault();

                        if (starSystem == null)
                        {
                            starSystem = new StarSystem()
                            {
                                Name = dto.StarSystem
                            }
                        }
                        ;

                        starSystem.Planets.Add(planet);
                        planet.HostStarSystem = starSystem;

                        plRepo.Insert(planet);
                        ctx.SaveChanges();

                        this.DebugLog.AppendLine($"Record {dto.Name} successfully imported.");
                    }
                    else
                    {
                        this.DebugLog.AppendLine(Constants.InvalidDataFormat);
                    }
                }
            }
        }