internal static void ImportAnomalies()
        {
            var json      = File.ReadAllText("../../../datasets/anomalies.json");
            var anomalies = JsonConvert.DeserializeObject <IEnumerable <AnomalyDto> >(json);

            AnomalyStore.AddAnomalies(anomalies);
        }
Beispiel #2
0
        public static void ImportAnomalies()
        {
            XDocument xml       = XDocument.Load("../../../datasets/new-anomalies.xml");
            var       anomalies = xml.Root.Elements();
            var       result    = new List <AnomalyWithVictimsDto>();

            foreach (var anomaly in anomalies)
            {
                try
                {
                    var anomalyDto = new AnomalyWithVictimsDto
                    {
                        OriginPlanet   = anomaly.Attribute("origin-planet").Value,
                        TeleportPlanet = anomaly.Attribute("teleport-planet").Value,
                        Victims        = anomaly.Element("victims").Elements().Select(e => e.Attribute("name").Value).ToList()
                    };

                    result.Add(anomalyDto);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Error: Invalid data.");
                }
            }

            AnomalyStore.AddAnomaliesWithVictims(result);
        }
        internal static void ImportVictims()
        {
            var json    = File.ReadAllText("../../../datasets/anomaly-victims.json");
            var victims = JsonConvert.DeserializeObject <IEnumerable <VictimDto> >(json);

            AnomalyStore.AddVictims(victims);
        }
        public static void ImportAnomalyVictims()
        {
            string json           = File.ReadAllText("../../../datasets/anomaly-victims.json");
            var    anomalyVictims = JsonConvert.DeserializeObject <IEnumerable <AnomalyVictimDto> >(json);

            AnomalyStore.AddAnomalyVictims(anomalyVictims);
        }
Beispiel #5
0
        public static void ExportAnomaliesAndVictims()
        {
            List <AnomaliesWithVictimsExportDto> anomalies = AnomalyStore.GetAnomaliesWithVictims();

            XDocument xmlDoc       = new XDocument();
            XElement  anomaliesXml = new XElement("anomalies");

            foreach (var anomaly in anomalies)
            {
                // Anomaly XML
                XElement anomalyXml = new XElement("anomaly");
                anomalyXml.SetAttributeValue("id", anomaly.Id);
                anomalyXml.SetAttributeValue("origin-planet", anomaly.OriginPlanet);
                anomalyXml.SetAttributeValue("teleport-planet", anomaly.TeleportPlanet);

                // Victims XML
                XElement victims = new XElement("victims");
                foreach (var victim in anomaly.Victims)
                {
                    XElement victimXml = new XElement("victim");
                    victimXml.SetAttributeValue("name", victim);
                    victims.Add(victimXml);
                }

                anomalyXml.Add(victims);
                anomaliesXml.Add(anomalyXml);
            }
            xmlDoc.Add(anomaliesXml);

            xmlDoc.Save("../../Export/anomalies.xml");
        }
Beispiel #6
0
        internal static void ExportAnomaliesWithMaxVictims()
        {
            List <AnomalyExportDto> anomaly = AnomalyStore.GetAnomalyWithMaxVictims();
            string json = JsonConvert.SerializeObject(
                anomaly.Select(a => new
            {
                Id             = a.Id,
                OriginPlanet   = new { Name = a.OriginPlanet },
                TeleportPlanet = new { Name = a.TeleportPlanet },
                VictimsCount   = a.VictimsCount
            }),
                Formatting.Indented);

            File.WriteAllText("../../Export/anomaly.json", json);
        }
Beispiel #7
0
        public static void ImportAnomalyVictims()
        {
            XDocument xml = XDocument.Load("../../../datasets/new-anomalies.xml");
            IEnumerable <XElement> anomalies = xml.Root.Elements();

            var anomaliesWithVictims = new List <AnomalyWithVictimDto>();

            foreach (XElement anomaly in anomalies)
            {
                var anomalyWithVictims = new AnomalyWithVictimDto()
                {
                    OriginPlanet   = anomaly.Attribute("origin-planet")?.Value,
                    TeleportPlanet = anomaly.Attribute("teleport-planet")?.Value,
                    Victims        = anomaly.Element("victims")
                                     .Elements() // victim
                                     .Select(e => e.Attribute("name").Value)
                                     .ToList()
                };
                anomaliesWithVictims.Add(anomalyWithVictims);
            }

            AnomalyStore.AddNewAnomaliesWithVictims(anomaliesWithVictims);
        }