public static void ImportDiscoveries() { XDocument xmlDoc = LoadXmlFile("discoveries"); var discoveries = xmlDoc.Root.Elements(); List <DiscoveryDto> discoveriesDto = new List <DiscoveryDto>(); foreach (XElement discovery in discoveries) { var discoveryDto = new DiscoveryDto() { DateMade = discovery.Attribute("DateMade")?.Value, Telescope = discovery.Attribute("Telescope")?.Value, Stars = discovery.Element("Stars") .Elements() .Select(e => e?.Value) .ToList(), Planets = discovery.Element("Planets") .Elements() .Select(e => e?.Value) .ToList(), Pioneers = discovery.Element("Pioneers") .Elements() .Select(e => e?.Value) .ToList(), Observers = discovery.Element("Observers") .Elements() .Select(e => e?.Value) .ToList() }; discoveriesDto.Add(discoveryDto); } DiscoveryStore.AddDiscoveries(discoveriesDto); }
public static void ImportDiscoveries() { XDocument discoveriesXml = XDocument.Load(discoveriesDataPath); var discoveries = discoveriesXml.Root.Elements() .Select(e => new DiscoveryDto() { DateMade = DateTime.Parse(e.Attribute("DateMade").Value), Telescope = e.Attribute("Telescope").Value, Stars = e.Element("Stars").Elements() .Select(s => s.Value) .ToList(), Planets = e.Element("Planets").Elements() .Select(p => p.Value) .ToList(), Pioneers = e.Element("Pioneers").Elements() .Select(p => new AstronomerDto() { FirstName = p.Value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)[0], LastName = p.Value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)[1], }) .ToList(), Observers = e.Element("Observers").Elements() .Select(o => new AstronomerDto() { FirstName = o.Value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)[0], LastName = o.Value.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)[1], }) .ToList() }); DiscoveryStore.AddDiscoveries(discoveries); }
public static void ImportDiscoveries() { var xmlDoc = XDocument.Load("../../datasets/discoveries.xml"); var discoveries = xmlDoc.Root.Elements(); DiscoveryStore.AddDiscoveries(discoveries); }
public static void ImportDiscoveries() { var xml = XDocument.Load("../../../datasets/discoveries.xml"); var discoveries = xml.Root.Elements().Select(d => new DiscoveryImportDto { DateMade = d.Attribute("DateMade").Value, Telescope = d.Attribute("Telescope").Value, Pioneers = d.Element("Pioneers").Elements().Select(p => p.Value).ToList(), Observers = d.Element("Observers").Elements().Select(o => o.Value).ToList(), Stars = d.Element("Stars").Elements().Select(s => s.Value).ToList(), Planets = d.Element("Planets").Elements().Select(p => p.Value).ToList(), }).ToList(); DiscoveryStore.AddDiscoveries(discoveries); }