Ejemplo n.º 1
0
        public static void UpdateAuctions(Database db, string realmName, IBlizzardProgress bp)
        {
            Configuration cfg = db.Configurations.First();
            if (db.Configurations.First().SelectedRealm != realmName)
            {
                cfg.SelectedRealm = realmName;
                cfg.lastUpdate = 0;
                db.Auctions.DeleteAllOnSubmit(db.Auctions);
                db.SubmitChanges();
            }

            string realmSlug = db.Realms.Single(realm => realm.Name == realmName).Slug;
            string url = "http://us.battle.net/api/wow/auction/data/" + realmSlug;
            JsonValue status = JSON.JsonDecode(GetWebString(url));

            if (status.Object.ContainsKey("files"))
            {
                long lastModified = status.Object["files"].Array[0].Object["lastModified"].Long;
                if (cfg.lastUpdate != lastModified)
                {
                    cfg.lastUpdate = lastModified;
                    db.SubmitChanges();

                    url = status.Object["files"].Array[0].Object["url"].String;
                    status = JSON.JsonDecode(GetWebString(url));

                    Dictionary<long, bool> webIds = new Dictionary<long, bool>();
                    UpdateAuctions(db, status, AuctionFaction.Alliance, webIds, bp);
                    UpdateAuctions(db, status, AuctionFaction.Horde, webIds, bp);
                    UpdateAuctions(db, status, AuctionFaction.Neutral, webIds, bp);
                    CloseAuctions(db, webIds, bp);
                }
            }
        }
Ejemplo n.º 2
0
        private static void UpdateAuctions(Database db, JsonValue status, AuctionFaction faction, Dictionary<long, bool> webIds, IBlizzardProgress bp)
        {
            string factionName = (faction == AuctionFaction.Alliance) ? "alliance" :
                                 (faction == AuctionFaction.Horde) ? "horde" :
                                 "neutral";

            if (status.Object.ContainsKey(factionName))
            {
                var query = from auction in status.Object[factionName].Object["auctions"].Array
                            select new Auction()
                            {
                                AuctionId = auction.Object["auc"].Long,
                                ItemId = auction.Object["item"].Long,
                                Owner = auction.Object["owner"].String,
                                Bid = auction.Object["bid"].Long,
                                Buyout = auction.Object["buyout"].Long,
                                Quantity = auction.Object["quantity"].Long,
                                TimeLeft = (auction.Object["timeLeft"].String == "VERY_LONG") ? AuctionTimeLeft.VeryLong :
                                           (auction.Object["timeLeft"].String == "LONG") ? AuctionTimeLeft.Long :
                                           (auction.Object["timeLeft"].String == "MEDIUM") ? AuctionTimeLeft.Medium :
                                        AuctionTimeLeft.Short,
                                Faction = faction,
                                Status = AuctionStatus.Active,
                                FirstSeen = DateTime.Now,
                                LastSeen = DateTime.Now
                            };

                int progressCurrent = 0;
                int progressCount = query.Count();
                bp.UpdateProgress(progressCurrent, progressCount);

                foreach (Auction webAuction in query)
                {
                    Auction dbAuction = db.Auctions.SingleOrDefault(auction => auction.AuctionId == webAuction.AuctionId);
                    if (dbAuction != null)
                    {
                        dbAuction.LastSeen = DateTime.Now;
                        dbAuction.TimeLeft = webAuction.TimeLeft;
                    }
                    else
                    {
                        db.Auctions.InsertOnSubmit(webAuction);
                    }

                    webIds[webAuction.AuctionId] = true;

                    progressCurrent++;
                    if (progressCurrent % 1000 == 0)
                    {
                        bp.UpdateProgress(progressCurrent, progressCount);
                        db.SubmitChanges();
                    }
                }

                bp.UpdateProgress(progressCount, progressCount);
                db.SubmitChanges();
            }
        }
Ejemplo n.º 3
0
        private static void CloseAuctions(Database db, Dictionary<long, bool> webIds, IBlizzardProgress bp)
        {
            var activeAuctions = (from auction in db.Auctions where auction.Status == AuctionStatus.Active select auction).ToList();

            int progressCurrent = 0;
            int progressCount = activeAuctions.Count;
            bp.UpdateProgress(progressCurrent, progressCount);

            foreach (Auction dbAuction in activeAuctions)
            {
                if (!webIds.ContainsKey(dbAuction.AuctionId))
                {
                    dbAuction.Status = GetAuctionStatus(dbAuction.TimeLeft, dbAuction.LastSeen);
                }

                progressCurrent++;
                if (progressCurrent % 1000 == 0)
                {
                    bp.UpdateProgress(progressCurrent, progressCount);
                    db.SubmitChanges();
                }
            }
            db.SubmitChanges();
        }