예제 #1
0
파일: XmlImport.cs 프로젝트: nayots/SoftUni
        public static void Stars()
        {
            XDocument starsXML = XDocument.Load(@"..\..\..\PlanetHunters.Import\ImportFiles\stars.xml");

            StringBuilder sb = new StringBuilder();

            foreach (var starEle in starsXML.Root.Elements())
            {
                var nameEle        = starEle.Element("Name");
                var temperatureELe = starEle.Element("Temperature");
                var starSEle       = starEle.Element("StarSystem");

                if (nameEle != null && temperatureELe != null && starEle != null)
                {
                    int temperature = int.Parse(temperatureELe.Value);

                    if (temperature < 2400)
                    {
                        sb.AppendLine("Invalid data format.");
                        continue;
                    }
                    else
                    {
                        ImportQueries.ImportStar(nameEle.Value, temperature, starSEle.Value);
                        sb.AppendLine($"Record {nameEle.Value} successfully imported.");
                    }
                }
                else
                {
                    sb.AppendLine("Invalid data format.");
                }
            }

            Console.WriteLine(sb.ToString());
        }
예제 #2
0
        public static void Planets()
        {
            var json = File.ReadAllText(@"..\..\..\PlanetHunters.Import\ImportFiles\planets.json");

            List <PlanetDTO> planetsDTOs = new List <PlanetDTO>();

            planetsDTOs = JsonConvert.DeserializeObject <List <PlanetDTO> >(json);

            StringBuilder sb = new StringBuilder();

            List <Planet> planets = new List <Planet>();

            foreach (var planetDTO in planetsDTOs)
            {
                if (planetDTO.Name != null && planetDTO.Mass != null && planetDTO.StarSystem != null)
                {
                    if (planetDTO.Mass <= 0.00)
                    {
                        sb.AppendLine("Invalid data format.");
                        continue;
                    }
                    else
                    {
                        ImportQueries.ImportPlanet(planetDTO.Name, (double)planetDTO.Mass, planetDTO.StarSystem);
                        sb.AppendLine($"Record {planetDTO.Name} successfully imported.");
                    }
                }
                else
                {
                    sb.AppendLine("Invalid data format.");
                }
            }

            Console.WriteLine(sb.ToString());
        }
예제 #3
0
        public static void Telescopes()
        {
            var json = File.ReadAllText(@"..\..\..\PlanetHunters.Import\ImportFiles\telescopes.json");

            List <TelescopeDTO> telescopesDTOs = new List <TelescopeDTO>();

            telescopesDTOs = JsonConvert.DeserializeObject <List <TelescopeDTO> >(json);

            StringBuilder sb = new StringBuilder();

            List <Telescope> telescopes = new List <Telescope>();

            foreach (var telescopeDTO in telescopesDTOs)
            {
                if (telescopeDTO.Name != null && telescopeDTO.Location != null)
                {
                    if (telescopeDTO.Name.Length > 255 || telescopeDTO.Location.Length > 255)
                    {
                        sb.AppendLine("Invalid data format.");
                    }
                    else
                    {
                        Telescope telescope = new Telescope
                        {
                            Name     = telescopeDTO.Name,
                            Location = telescopeDTO.Location
                        };

                        if (telescopeDTO.MirrorDiameter != null)
                        {
                            if (telescopeDTO.MirrorDiameter <= 0.00)
                            {
                                sb.AppendLine("Invalid data format.");
                                continue;
                            }
                            else
                            {
                                telescope.MirrorDiameter = telescopeDTO.MirrorDiameter;
                            }
                        }

                        telescopes.Add(telescope);
                        sb.AppendLine($"Record {telescope.Name} successfully imported.");
                    }
                }
                else
                {
                    sb.AppendLine("Invalid data format.");
                }
            }

            ImportQueries.ImportTelescopes(telescopes);

            Console.WriteLine(sb.ToString());
        }
예제 #4
0
        public static void Astronomers()
        {
            var json = File.ReadAllText(@"..\..\..\PlanetHunters.Import\ImportFiles\astronomers.json");

            List <AstronomerDTO> astronomersDTOs = new List <AstronomerDTO>();

            astronomersDTOs = JsonConvert.DeserializeObject <List <AstronomerDTO> >(json);

            StringBuilder sb = new StringBuilder();

            List <Astronomer> astronomers = new List <Astronomer>();

            foreach (var astronomerDTO in astronomersDTOs)
            {
                if (astronomerDTO.FirstName != null && astronomerDTO.LastName != null)
                {
                    if (astronomerDTO.FirstName.Length > 50 || astronomerDTO.LastName.Length > 50)
                    {
                        sb.AppendLine("Invalid data format.");
                    }
                    else
                    {
                        Astronomer astro = new Astronomer
                        {
                            FirstName = astronomerDTO.FirstName,
                            LastName  = astronomerDTO.LastName
                        };

                        astronomers.Add(astro);
                        sb.AppendLine($"Record {astro.FullName} successfully imported.");
                    }
                }
                else
                {
                    sb.AppendLine("Invalid data format.");
                }
            }

            ImportQueries.ImportAstronomers(astronomers);

            Console.WriteLine(sb.ToString());
        }
예제 #5
0
파일: XmlImport.cs 프로젝트: nayots/SoftUni
        public static void Discoveries()
        {
            XDocument discoveriesXML = XDocument.Load(@"..\..\..\PlanetHunters.Import\ImportFiles\discoveries.xml");

            StringBuilder sb = new StringBuilder();

            //Must have valid existing : astronomer, planets, stars => continue
            //telescope always exists
            foreach (var discEle in discoveriesXML.Root.Elements())
            {
                var discDateAtr      = discEle.Attribute("DateMade");
                var discTelescopeAtr = discEle.Attribute("Telescope");
                var starsEle         = discEle.Element("Stars");
                var planetsEle       = discEle.Element("Planets");
                var pioneersEle      = discEle.Element("Pioneers");
                var observersEle     = discEle.Element("Observers");

                List <string> starNames      = new List <string>();
                List <string> planetNames    = new List <string>();
                List <string> pioneersNames  = new List <string>();
                List <string> observersNames = new List <string>();

                DateTime date = DateTime.Parse(discDateAtr.Value);

                if (starsEle != null)
                {
                    foreach (var starName in starsEle.Elements())
                    {
                        if (starName != null)
                        {
                            starNames.Add(starName.Value);
                        }
                    }

                    if (starNames.Count > 0)
                    {
                        if (!ImportQueries.ValidateStarsByName(starNames))
                        {
                            continue;
                        }
                    }
                }

                if (planetsEle != null)
                {
                    foreach (var planetName in planetsEle.Elements())
                    {
                        if (planetName != null)
                        {
                            planetNames.Add(planetName.Value);
                        }
                    }

                    if (planetNames.Count > 0)
                    {
                        if (!ImportQueries.ValidatePlanetsByName(planetNames))
                        {
                            continue;
                        }
                    }
                }

                if (pioneersEle != null)
                {
                    foreach (var pioneerName in pioneersEle.Elements())
                    {
                        if (pioneerName != null)
                        {
                            string[] nameArg  = pioneerName.Value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            string   fullName = $"{nameArg[1]} {nameArg[0]}";
                            pioneersNames.Add(fullName);
                        }
                    }

                    if (pioneersNames.Count > 0)
                    {
                        if (!ImportQueries.ValidateAstronomersByName(pioneersNames))
                        {
                            continue;
                        }
                    }
                }

                if (observersEle != null)
                {
                    foreach (var observerName in observersEle.Elements())
                    {
                        if (observerName != null)
                        {
                            string[] nameArg  = observerName.Value.Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            string   fullName = $"{nameArg[1]} {nameArg[0]}";
                            observersNames.Add(fullName);
                        }
                    }

                    if (observersNames.Count > 0)
                    {
                        if (!ImportQueries.ValidateAstronomersByName(observersNames))
                        {
                            continue;
                        }
                    }
                }

                ImportQueries.ImportDiscovery(date, discTelescopeAtr.Value, starNames, planetNames, pioneersNames, observersNames);
                sb.AppendLine($"Discovery ({date.ToString("yyyy'/'MM'/'dd")} - {discTelescopeAtr.Value}) with {starNames.Count} stars, {planetNames.Count} planets, {pioneersNames.Count} pioneers and {observersNames.Count} observers successfully imported.");
            }

            Console.WriteLine(sb.ToString());
            //TODO CHANGE PLURAL FORM for discovered objects and astronomers
        }