static void Main(string[] args)
        {
            var manifestUrl = BungieApi.GetManifestUrl();

            var dbConnection = new SQLiteConnection($"Data Source={args[0]};Version=3;");

            dbConnection.Open();

            //var db = new DestinySqlEntities();

            //Console.WriteLine("Processing Combatants");
            //ProcessCombantants(dbConnection, db);

            //Console.WriteLine("Processing Activities");
            //ProcessManifestActivities(dbConnection, db);

            //Console.WriteLine("Processing Items");
            //ProcessInventoryItems(dbConnection, db);

            var db2 = new DestinyDaily2Entities();

            Console.WriteLine("Processing Emblems");
            ProcessInventoryItems(dbConnection, db2, "Emblem");

            Console.WriteLine("Processing Sparrows");
            ProcessInventoryItems(dbConnection, db2, "Sparrow");

            Console.WriteLine("Processing Ships");
            ProcessInventoryItems(dbConnection, db2, "Ship");

            Console.WriteLine("Finished");
            Console.ReadLine();
        }
 public XurManager()
 {
     db  = new DestinySqlEntities();
     db2 = new DestinyDaily2Entities();
 }
Exemple #3
0
 public NightFallManager()
 {
     db  = new DestinySqlEntities();
     db2 = new DestinyDaily2Entities();
 }
        private static void ProcessInventoryItems(SQLiteConnection dbConnection, DestinyDaily2Entities db, string type)
        {
            var added    = 0;
            var existing = 0;

            var sql = "SELECT quote(json) FROM DestinyInventoryItemDefinition";

            if (type == "Emblem")
            {
                sql = $"{sql} WHERE quote(json) LIKE '%Emblem%';";
            }
            else if (type == "Sparrow")
            {
                sql = $"{sql} WHERE quote(json) LIKE '%\"itemTypeDisplayName\":\"Vehicle\"%';";
            }
            else if (type == "Ship")
            {
                sql = $"{sql} WHERE quote(json) LIKE '%\"itemTypeDisplayName\":\"Ship\"%';";
            }

            var command = new SQLiteCommand(sql, dbConnection);
            var reader  = command.ExecuteReader();

            while (reader.Read())
            {
                var jsonStripped  = ((string)reader["quote(json)"]).Replace("'{", "{").Replace("}'", "}");
                var inventoryItem = JsonConvert.DeserializeObject <InventoryItemDefinition>(jsonStripped);

                if (type == "Emblem")
                {
                    var mappedItem = db.InventoryEmblems.FirstOrDefault(i => i.id == inventoryItem.hash);
                    if (mappedItem == null)
                    {
                        mappedItem = new InventoryEmblem()
                        {
                            id               = inventoryItem.hash,
                            name             = inventoryItem.displayProperties.name.Replace("''", "'"),
                            icon             = inventoryItem.displayProperties.icon,
                            secondaryIcon    = inventoryItem.secondaryIcon,
                            secondaryOverlay = inventoryItem.secondaryOverlay,
                            secondarySpecial = inventoryItem.secondarySpecial,
                            screenshot       = inventoryItem.screenshot,
                            rarity           = inventoryItem.inventory.tierTypeName
                        };

                        db.InventoryEmblems.Add(mappedItem);
                        added++;

                        if (added % 500 == 0)
                        {
                            Console.WriteLine($"Saving first {added} records");
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        mappedItem.id               = inventoryItem.hash;
                        mappedItem.name             = inventoryItem.displayProperties.name.Replace("''", "'");
                        mappedItem.icon             = inventoryItem.displayProperties.icon;
                        mappedItem.secondaryIcon    = inventoryItem.secondaryIcon;
                        mappedItem.secondaryOverlay = inventoryItem.secondaryOverlay;
                        mappedItem.secondarySpecial = inventoryItem.secondarySpecial;
                        mappedItem.screenshot       = inventoryItem.screenshot;
                        mappedItem.rarity           = inventoryItem.inventory.tierTypeName;

                        existing++;
                    }
                }

                if (type == "Sparrow")
                {
                    var mappedItem = db.InventorySparrows.FirstOrDefault(i => i.id == inventoryItem.hash);
                    if (mappedItem == null)
                    {
                        mappedItem = new InventorySparrow()
                        {
                            id          = inventoryItem.hash,
                            name        = inventoryItem.displayProperties.name.Replace("''", "'"),
                            description = inventoryItem.displayProperties.description.Replace("''", "'"),
                            icon        = inventoryItem.displayProperties.icon,
                            screenshot  = inventoryItem.screenshot,
                            rarity      = inventoryItem.inventory.tierTypeName
                        };

                        db.InventorySparrows.Add(mappedItem);
                        added++;

                        if (added % 500 == 0)
                        {
                            Console.WriteLine($"Saving first {added} records");
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        mappedItem.id          = inventoryItem.hash;
                        mappedItem.name        = inventoryItem.displayProperties.name.Replace("''", "'");
                        mappedItem.description = inventoryItem.displayProperties.description.Replace("''", "'");
                        mappedItem.icon        = inventoryItem.displayProperties.icon;
                        mappedItem.screenshot  = inventoryItem.screenshot;
                        mappedItem.rarity      = inventoryItem.inventory.tierTypeName;

                        existing++;
                    }
                }

                if (type == "Ship")
                {
                    var mappedItem = db.InventoryShips.FirstOrDefault(i => i.id == inventoryItem.hash);
                    if (mappedItem == null)
                    {
                        mappedItem = new InventoryShip()
                        {
                            id          = inventoryItem.hash,
                            name        = inventoryItem.displayProperties.name.Replace("''", "'"),
                            description = inventoryItem.displayProperties.description.Replace("''", "'"),
                            icon        = inventoryItem.displayProperties.icon,
                            screenshot  = inventoryItem.screenshot,
                            rarity      = inventoryItem.inventory.tierTypeName
                        };

                        db.InventoryShips.Add(mappedItem);
                        added++;

                        if (added % 500 == 0)
                        {
                            Console.WriteLine($"Saving first {added} records");
                            db.SaveChanges();
                        }
                    }
                    else
                    {
                        mappedItem.id          = inventoryItem.hash;
                        mappedItem.name        = inventoryItem.displayProperties.name.Replace("''", "'");
                        mappedItem.description = inventoryItem.displayProperties.description.Replace("''", "'");
                        mappedItem.icon        = inventoryItem.displayProperties.icon;
                        mappedItem.screenshot  = inventoryItem.screenshot;
                        mappedItem.rarity      = inventoryItem.inventory.tierTypeName;

                        existing++;
                    }
                }
            }
            try { db.SaveChanges(); }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            Console.WriteLine($"{added} Added & {existing} Updated");
        }