예제 #1
0
        private void AddNewItem(Auction a, string name, string tag, DBItem existingItem = null)
        {
            var i = new Item();

            i.Id       = tag;
            i.AltNames = new HashSet <string>()
            {
                name
            };
            i.Tier          = a.Tier;
            i.Category      = a.Category;
            i.Description   = a.ItemLore;
            i.Extra         = a.Extra;
            i.MinecraftType = MinecraftTypeParser.Instance.Parse(a);

            //Console.WriteLine($"New: {name} ({i.MinecraftType})" );
            SetIconUrl(a, i);

            Items[name] = i;
            var newItem = new DBItem(i);

            System.Threading.Tasks.Task.Run(async() =>
            {
                if (existingItem == null)
                {
                    AddItemToDB(newItem);
                }
                else
                {
                    await UpdateItem(existingItem, newItem);
                }
            }).ConfigureAwait(false);;
        }
예제 #2
0
        public int GetOrCreateItemIdForAuction(SaveAuction auction, HypixelContext context)
        {
            var clearedName = ItemReferences.RemoveReforgesAndLevel(auction.ItemName);
            var tag         = GetIdForName(auction.Tag ?? clearedName);

            if (tag != null && TagLookup.TryGetValue(tag, out int value))
            {
                return(value);
            }

            Console.WriteLine($"Creating item {clearedName} ({auction.ItemName},{auction.Tag})");
            // doesn't exist yet, create it
            var itemByTag = context.Items.Where(item => item.Tag == auction.Tag).FirstOrDefault();

            if (itemByTag != null)
            {
                // new alternative name
                if (clearedName != null)
                {
                    this.ReverseNames[clearedName] = auction.Tag;
                }
                TagLookup.Add(auction.Tag, itemByTag.Id);
                var exists = context.AltItemNames
                             .Where(name => name.Name == clearedName && name.DBItemId == itemByTag.Id)
                             .Any();
                if (!exists)
                {
                    context.AltItemNames.Add(new AlternativeName()
                    {
                        DBItemId = itemByTag.Id, Name = clearedName
                    });
                }
                return(itemByTag.Id);
            }
            Console.WriteLine($"!! completely new !! {JsonConvert.SerializeObject(auction)}");
            // new Item
            //var tempAuction = new Hypixel.NET.SkyblockApi.Auction(){Category=auction.Category,};
            //AddNewItem(tempAuction,auction.ItemName,auction.Tag,null);
            var item = new DBItem()
            {
                Tag   = auction.Tag,
                Name  = auction.ItemName,
                Names = new List <AlternativeName>()
                {
                    new AlternativeName()
                    {
                        Name = auction.ItemName
                    }
                }
            };

            if (item.Tag == null)
            {
                // unindexable item
                return(MAX_MEDIUM_INT);
            }
            ToFillDetails[item.Tag] = item;
            return(AddItemToDB(item));
            //throw new CoflnetException("can_add","can't add this item");
        }
예제 #3
0
        internal int GetOrCreateItemByTag(string tag)
        {
            var id = GetItemIdForName(tag, false);

            if (id != 0)
            {
                return(id);
            }

            using (var context = new HypixelContext())
            {
                id = context.Items.Where(i => i.Tag == tag).Select(i => i.Id).FirstOrDefault();
                if (id != 0)
                {
                    TagLookup[tag] = id;
                    return(id);
                }
            }
            Console.WriteLine($"Adding Tag {tag}");
            var name    = TagToName(tag);
            var newItem = new DBItem()
            {
                Tag   = tag,
                Name  = name,
                Names = new List <AlternativeName>()
                {
                    new AlternativeName()
                    {
                        Name = name
                    }
                }
            };

            return(AddItemToDB(newItem));
        }
예제 #4
0
 private static string AddAlternativeNames(DBItem i)
 {
     if (i.Names == null || i.Names.Count == 0)
     {
         return("");
     }
     return(". Found this item with the following names: " + i.Names.Select(n => n.Name).Aggregate((a, b) => $"{a}, {b}").TrimEnd(' ', ',')
            + ". This are all names under wich we found auctins for this item in the ah. It may be historical names or names in a different language.");
 }
예제 #5
0
        private async Task UpdateItem(DBItem existingItem, DBItem newItem)
        {
            await Task.Delay(5000);

            Console.WriteLine("updating item");
            using (var context = new HypixelContext())
            {
                newItem.Id = existingItem.Id;
                context.Items.Update(newItem);
                await context.SaveChangesAsync();
            }
        }
예제 #6
0
 private int AddItemToDB(DBItem item)
 {
     using (var context = new HypixelContext())
     {
         // make sure it doesn't exist
         if (!context.Items.Where(i => i.Tag == item.Tag).Any())
         {
             context.Items.Add(item);
         }
         try
         {
             context.SaveChanges();
         }
         catch (Exception)
         {
             Console.WriteLine($"Ran into an error while saving {JsonConvert.SerializeObject(item)}");
             throw;
         }
         return(item.Id);
     }
 }
예제 #7
0
 private static string CreateCanoicalPath(string[] urlParts, DBItem i)
 {
     return($"/item/{i.Tag}");
 }