예제 #1
0
        private static async Task ToDb(List <SaveAuction> auctions)
        {
            auctions = auctions.Distinct(new AuctionComparer()).ToList();
            lock (nameof(highestPlayerId))
            {
                if (highestPlayerId == 1)
                {
                    LoadFromDB();
                }
            }

            using (var context = new HypixelContext())
            {
                Dictionary <string, SaveAuction> inDb = await GetExistingAuctions(auctions, context);

                var comparer = new BidComparer();

                foreach (var auction in auctions)
                {
                    ProcessAuction(context, inDb, comparer, auction);
                }


                //Program.AddPlayers (context, playerIds);

                await context.SaveChangesAsync();

                context.Dispose();
            }
        }
예제 #2
0
        private static void UpdateAuction(HypixelContext context, BidComparer comparer, SaveAuction auction, SaveAuction dbauction)
        {
            if (auction.AuctioneerId == null)
            {
                // an ended auction
                dbauction.End = auction.End;
                context.Auctions.Update(dbauction);
                return;
            }
            SubscribeEngine.Instance.NewBids(auction);
            foreach (var bid in auction.Bids)
            {
                bid.Auction = dbauction;
                if (!dbauction.Bids.Contains(bid, comparer))
                {
                    context.Bids.Add(bid);
                    dbauction.HighestBidAmount = auction.HighestBidAmount;
                }
            }
            if (auction.Bin)
            {
                dbauction.Bin = true;
            }
            if (dbauction.ItemName == null)
            {
                dbauction.ItemName = auction.ItemName;
            }
            if (dbauction.ProfileId == null)
            {
                dbauction.ProfileId = auction.ProfileId;
            }
            if (dbauction.Start == default(DateTime))
            {
                dbauction.Start = auction.Start;
            }
            dbauction.End = auction.End;
            if (dbauction.Category == Category.UNKNOWN)
            {
                dbauction.Category = auction.Category;
            }

            // update
            context.Auctions.Update(dbauction);
        }
예제 #3
0
        private static void ProcessAuction(HypixelContext context, Dictionary <string, SaveAuction> inDb, BidComparer comparer, SaveAuction auction)
        {
            try
            {
                var id = auction.Uuid;
                MigrateAuction(auction);

                if (inDb.TryGetValue(id, out SaveAuction dbauction))
                {
                    UpdateAuction(context, comparer, auction, dbauction);
                }
                else
                {
                    if (auction.AuctioneerId == null)
                    {
                        Logger.Instance.Error($"auction removed bevore in db " + auction.Uuid);
                        return;
                    }
                    context.Auctions.Add(auction);
                    try
                    {
                        auction.NBTLookup = NBT.CreateLookup(auction.NbtData);
                    }
                    catch (Exception e)
                    {
                        Logger.Instance.Error($"Error on CreateLookup: {e.Message} \n{e.StackTrace} \n{JSON.Stringify(auction.NbtData.Data)}");
                        throw e;
                    }
                }

                count++;
                if (!minimumOutput && count % 5 == 0)
                {
                    Console.Write($"\r         Indexed: {count} Saved: {StorageManager.SavedOnDisc} \tcache: {StorageManager.CacheItems}  NameRequests: {Program.RequestsSinceStart}");
                }
            }
            catch (Exception e)
            {
                Logger.Instance.Error($"Error {e.Message} on {auction.ItemName} {auction.Uuid} from {auction.AuctioneerId}");
                Logger.Instance.Error(e.StackTrace);
            }
        }