Exemplo n.º 1
0
 private ShipsData DeserializeShips(string filePath = null)
 {
     if (String.IsNullOrEmpty(filePath))
     {
         filePath = dataFileName;
     }
     if (!File.Exists(filePath))
     {
         return null;
     }
     ShipsData results = new ShipsData();
     string json = File.ReadAllText(filePath);
     results = JsonConvert.DeserializeObject<ShipsData>(json);
     return results;
 }
Exemplo n.º 2
0
        private ShipsData GetAllShips(string json)
        {
            ShipsData results = new ShipsData();

            JObject d = JObject.Parse(json);

            Dictionary<string, JToken> ships2 = d["data"].ToObject<Dictionary<string, JToken>>();

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            foreach (string key in ships2.Keys)
            {
                Ship ship = new Ship(key, ships2[key]);
                Console.WriteLine("CheckShip");
            }
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            Dictionary<string, JObject> ships = d["data"].ToObject<Dictionary<string, JObject>>();

            HashSet<String> allTiers = new HashSet<string>();
            HashSet<String> allTypes = new HashSet<string>();
            HashSet<String> allNations = new HashSet<string>();
            Dictionary<long, Ship> allShips = new Dictionary<long, Ship>();

            foreach (var key in ships.Keys)
            {
                Ship ship = new Ship(key, ships[key]);
                ship = SetShipAttributes(ship);
                allShips[ship.ID] = ship;
                if (!allTiers.Contains(ship.Tier.ToString()))
                    allTiers.Add(ship.Tier.ToString());
                if (!allTypes.Contains(ship.Type))
                    allTypes.Add(ship.Type);
                if (!allNations.Contains(ship.Nation))
                    allNations.Add(ship.Nation);

            }
            results.AllShips = allShips;
            results.AllNations = allNations.ToList();
            results.AllNations.Sort();
            results.AllTypes = allTypes.ToList();
            results.AllTypes.Sort();
            results.AllTiers = allTiers.ToList();
            results.AllTiers.Sort();
            results.DataCreatedAt = DateTime.Now.ToUniversalTime();
            return results;
        }