示例#1
0
        private void CreateRealmList(List <ConnectedRealm> realms, string region)
        {
            List <ConnectedRealm> select = null;

            selected.TryGetValue(region, out select);
            select = select ?? new List <ConnectedRealm>();

            /*int regionIndex = -1;
             * REGION_INDICES.TryGetValue(region, out regionIndex);
             * RealmItem regionRealm = new RealmItem(new ConnectedRealm()
             * {
             *  id = regionIndex,
             *  realms = new List<Realm>(new Realm[] { new Realm() { id = regionIndex, name = new Dictionary<string, string>() { { "us", region } } } })
             * }, region, select.Find(m => m.id == regionIndex) != null);
             * regionRealm.OnSelect += Item_OnSelect;
             * regionRealm.OnUnselect += Item_OnUnselect;
             * listViewItems.Children.Add(regionRealm);
             * items.Add(regionRealm);*/

            for (int i = 0; i < realms.Count; ++i)
            {
                ConnectedRealm r = realms[i];

                bool      isSelected = select.Find(m => m.id == r.id) != null;
                RealmItem item       = new RealmItem(r, region, isSelected);
                item.OnSelect   += Item_OnSelect;
                item.OnUnselect += Item_OnUnselect;
                listViewItems.Children.Add(item);
                items.Add(item);
            }
        }
示例#2
0
        // == METHOD(S)
        // ======================================================================

        public async Task <JObject> getAuctionList(ConnectedRealm cr)
        {
            JObject retValue    = null;
            String  qpRegion    = "us";
            String  qpNamespace = "dynamic-us";
            String  qpLocale    = "en_us";
            String  accessToken = await getClientAccessToken();

            String endpoint = $"https://{qpRegion}.api.blizzard.com/data/wow/connected-realm/{cr.Id}/auctions?namespace={qpNamespace}&locale={qpLocale}&access_token={accessToken}";

            HttpRequestMessage httpRequest = new HttpRequestMessage(HttpMethod.Get, endpoint);
            HttpClient         httpClient  = this._httpClientFactory.CreateClient();

            var response = await httpClient.SendAsync(httpRequest);

            if (response.IsSuccessStatusCode)
            {
                retValue = JObject.Parse(await response.Content.ReadAsStringAsync());
            }
            else
            {
                throw new AuctionMasterBlizzardException(ExceptionType.FATAL, await response.Content.ReadAsStringAsync());
            }

            return(retValue);
        }
示例#3
0
        public RealmItem(ConnectedRealm r, string region, bool selected = false)
        {
            InitializeComponent();
            Realm  = r;
            Region = region;

            activeCheck.IsChecked = selected;

            UpdateTimeInfo();
        }
        public async Task <ConnectedRealm> GetConnectedRealmById(ulong blizzardId, bool forceUpdate = false)
        {
            ConnectedRealm connectedRealm = forceUpdate? null : await GetFromDbByBlizzardId <ConnectedRealm>(blizzardId).ConfigureAwait(false);

            bool update = forceUpdate || await CheckDbData(connectedRealm).ConfigureAwait(false);

            if (update)
            {
                connectedRealm = await DbInsertFromApi <ConnectedRealm, ConnectedRealmJson>($"data/wow/connected-realm/{blizzardId}", Namespace.Dynamic).ConfigureAwait(false);
            }
            return(connectedRealm);
        }
示例#5
0
        private void Item_OnSelect(string region, ConnectedRealm r)
        {
            List <ConnectedRealm> select = null;

            selected.TryGetValue(region, out select);
            select           = select ?? new List <ConnectedRealm>();
            selected[region] = select;
            select.Add(r);

            Task.Run(() =>
            {
                DataSource.Store(selected);
            });

            Sync(r, region);
        }
示例#6
0
        private void Item_OnUnselect(string region, ConnectedRealm r)
        {
            List <ConnectedRealm> select = null;

            if (selected.TryGetValue(region, out select))
            {
                int idx = select.FindIndex(m => m.id == r.id);
                if (idx > -1)
                {
                    select.RemoveAt(idx);
                }

                Task.Run(() =>
                {
                    DataSource.Store(selected);
                });
            }

            Sync(r, region);
        }
示例#7
0
        public void UpdateTimeInfo()
        {
            ConnectedRealm r      = Realm;
            string         region = Region;

            string lastUpdate = "";


            if (DataSource.HasLocalData(r.id, region))
            {
                DateTime time = DataSource.GetLocalDataModified(r.id, region);
                TimeSpan diff = new TimeSpan(DateTime.UtcNow.Ticks - time.Ticks);
                lastUpdate = " - Updated " + FormatTime(ref diff) + " ago";
            }

            if (region.Equals(r.realms.JoinNames()) || r.id < 0)
            {
                serverName.Text = DataSource.REGION_KEY + " - " + region.ToUpper() + lastUpdate;
            }
            else
            {
                serverName.Text = region.ToUpper() + " - " + r.realms.JoinNames() + lastUpdate;
            }
        }
示例#8
0
        protected override void onExecute(JObject param, CancellationToken cancellationToken)
        {
            base.onExecute(param, cancellationToken);

            // OBTAIN A LIST OF CONNECTED REALM REGION

            List <ConnectedRealmRegion> realmRegions = this._databaseContext.ConnectedRealmRegion.OrderBy(crr => crr.Id).ToList <ConnectedRealmRegion>();

            this._databaseTransaction = this._databaseContext.Database.BeginTransaction();

            // LOOP OVER THE REGIONS

            foreach (ConnectedRealmRegion connectedRealmRegion in realmRegions)
            {
                // OBTAINS THE LIST OF CONNECTED REALMS

                Task <JObject> taskConnectedRealmList = this._blizzardRealmService.getConnectedRealmList(connectedRealmRegion.Code);
                taskConnectedRealmList.Wait();

                JObject cRealmList = taskConnectedRealmList.Result;

                // LOOP OVER THE CONNECTED REALM LIST

                foreach (JObject cRealmListHref in cRealmList.Value <JArray>("connected_realms").Children())
                {
                    this._connectedRealmCount++;

                    String href = cRealmListHref.Value <String>("href");
                    int    id   = Convert.ToInt32(Regex.Match(href, @"\d+").Value);

                    // GET CONNECTED REALM INFORMATION

                    Task <JObject> taskConnectedRealmInfo = this._blizzardRealmService.getConnectedRealmInformation(id, connectedRealmRegion.Code);
                    taskConnectedRealmInfo.Wait();

                    JObject connectedRealmInfo = taskConnectedRealmInfo.Result;

                    // WRITES THE DATA IN THE DATABASE

                    bool           update = true;
                    ConnectedRealm cRealm = this._databaseContext.ConnectedRealm.Find(connectedRealmInfo.Value <int>("id"));

                    if (cRealm == null)
                    {
                        update             = false;
                        cRealm             = new ConnectedRealm();
                        cRealm.Id          = connectedRealmInfo.Value <int>("id");
                        cRealm.RealmRegion = connectedRealmRegion.Id;
                        this._databaseContext.Entry(cRealm).State = EntityState.Added;
                    }
                    else
                    {
                        this._databaseContext.Entry(cRealm).State = EntityState.Modified;
                    }

                    JObject realmChanges = new JObject();

                    foreach (JObject cRealmChildren in connectedRealmInfo.Value <JArray>("realms").Children())
                    {
                        Realm realm = this._databaseContext.Realm.Find(cRealmChildren.Value <int>("id"));

                        if (realm == null)
                        {
                            realm          = new Realm();
                            realm.Id       = cRealmChildren.Value <int>("id");
                            realm.Name     = cRealmChildren.Value <String>("name");
                            realm.Locale   = cRealmChildren.Value <String>("locale");
                            realm.Timezone = cRealmChildren.Value <String>("timezone");
                            realm.Category = cRealmChildren.Value <String>("category");
                            this._databaseContext.Entry(realm).State = EntityState.Added;

                            realmChanges.Add(realm.Name, "ADDED");
                        }
                        else
                        {
                            realm.Name     = cRealmChildren.Value <String>("name");
                            realm.Locale   = cRealmChildren.Value <String>("locale");
                            realm.Timezone = cRealmChildren.Value <String>("timezone");
                            realm.Category = cRealmChildren.Value <String>("category");
                            this._databaseContext.Entry(realm).State = EntityState.Modified;

                            realmChanges.Add(realm.Name, "UPDATED");
                        }

                        cRealm.Realm.Add(realm);
                        this._RealmCount++;
                    }

                    if (!update)
                    {
                        this._databaseContext.ConnectedRealm.Add(cRealm);

                        this._logService.writeLine(LogType.INFO, $"Connected Realm ({cRealm.Id}) from US has been added: \n{realmChanges.ToString()}");
                    }
                    else
                    {
                        this._databaseContext.ConnectedRealm.Update(cRealm);

                        this._logService.writeLine(LogType.INFO, $"Connected Realm ({cRealm.Id}) from US has been updated: \n{realmChanges.ToString()}");
                    }

                    this._databaseContext.SaveChanges();
                }
            }

            this._databaseTransaction.Commit();
        }
        private void fullAuctionHouseScan(int connectedRealmID)
        {
            ConnectedRealm connectedRealm = this._databaseContext.ConnectedRealm.Find(connectedRealmID);

            if (connectedRealm != null)
            {
                Task <JObject> auctionTask = this._blizzardAuctionHouseService.getAuctionList(connectedRealm);
                auctionTask.Wait();

                JObject auctionList = auctionTask.Result;

                // == PROCESSING AUCTION HOUSE INFORMATION

                foreach (JObject requestAuction in auctionList.Value <JArray>("auctions"))
                {
                    // == ITEM TREATMENT

                    JObject auctionItem = requestAuction.Value <JObject>("item");
                    Item    item        = this._databaseContext.Item.Find(auctionItem.Value <int>("id"));

                    if (item == null)
                    {
                        this._logService.writeLine(LogType.INFO, $"Requesting information about item {requestAuction.Value<JObject>("item") }");

                        // GET ITEM INFORMATION FROM BLIZZARD

                        Task <JObject> itemTask = this._blizzardItemService.getItem(auctionItem.Value <int>("id"));
                        itemTask.Wait();

                        auctionItem = itemTask.Result;

                        // CREATES THE ITEM IN THE DATABASE

                        item           = new Item();
                        item.Id        = auctionItem.Value <int>("id");
                        item.Name      = auctionItem.Value <string>("name");
                        item.Quality   = 1;
                        item.Stackable = (auctionItem.Value <Boolean>("is_stackable") == true ? Convert.ToSByte(1) : Convert.ToSByte(0));
                        //item.Levelreq;
                        //item.PurchasePrice;
                        //item.SellPrice;

                        this._logService.writeLine(LogType.INFO, $"Item ( {item.Id} ) information obtained: {item.Name}");
                    }
                    else
                    {
                        this._databaseContext.Entry(item).State = EntityState.Modified;
                    }

                    // == CREATE AUCTION ENTRY

                    Auction auction = new Auction();
                    auction.ScheduledTaskLog = this._taskLog.Id;
                    auction.ItemNavigation   = item;
                    auction.ConnectedRealm   = connectedRealm.Id;

                    if (requestAuction.ContainsKey("buyout"))
                    {
                        auction.Buyout = requestAuction.Value <long>("buyout");
                    }

                    if (requestAuction.ContainsKey("unit_price"))
                    {
                        auction.UnitPrice = requestAuction.Value <long>("unit_price");
                    }

                    if (requestAuction.ContainsKey("bid"))
                    {
                        auction.Bid = requestAuction.Value <long>("bid");
                    }

                    auction.Quantity = requestAuction.Value <int>("quantity");

                    this._databaseContext.Auction.Add(auction);
                    this._databaseContext.SaveChanges();

                    this._logService.writeLine(LogType.INFO, $"Auction ( {auction.Id} - {auction.ItemNavigation.Name} ) has been inserted.");
                }
            }
            else
            {
                throw new AuctionMasterTaskException(ExceptionType.FATAL, "Invalid Connected Realm ID. Did you scanned realms before run this task?");
            }
        }
示例#10
0
        private void Sync()
        {
            syncing = true;
            Dispatcher.UIThread.Post(() =>
            {
                statusText.Text = "Syncing";
            });

            List <string> updated = new List <string>();

            Task.Run(async() =>
            {
                int totalCount = selected.Count + 1;
                int c          = 0;

                HashSet <string> regionDownloaded = new HashSet <string>();

                foreach (string k in selected.Keys)
                {
                    List <ConnectedRealm> realms = selected[k];
                    totalCount += realms.Count;
                    ++c;

                    try
                    {
                        if (!regionDownloaded.Contains(k))
                        {
                            if (includeRegionData && GetLatest(REGION_INDICES[k.ToUpper()], k))
                            {
                                updated.Add(k);
                            }

                            regionDownloaded.Add(k);
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e.ToString());
                    }

                    for (int i = 0; i < realms.Count; ++i)
                    {
                        ConnectedRealm r = realms[i];
                        ++c;

                        try
                        {
                            if (GetLatest(r.id, k))
                            {
                                //if (r.id < 0)
                                //{
                                //    updated.Add(DataSource.REGION_KEY + " - " + r.realms.JoinNames());
                                //}
                                //else
                                //{
                                updated.Add(k + " - " + r.realms.JoinNames());
                                //}
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine(e.ToString());
                        }

                        Dispatcher.UIThread.Post(() =>
                        {
                            statusProgress.Value = (float)c / (float)totalCount;
                        });
                    }
                }

                //if (updated.Count > 0)
                //{
                Dispatcher.UIThread.Post(() =>
                {
                    statusText.Text = "Finalizing";
                });

                CreateLua();
                //}

                Dispatcher.UIThread.Post(() =>
                {
                    statusText.Text      = "";
                    statusProgress.Value = 0;
                });

                if (sysIcon != null && sysIcon.IsActive)
                {
                    for (int i = 0; i < updated.Count; ++i)
                    {
                        string msg = updated[i];
                        Dispatcher.UIThread.Post(() =>
                        {
                            sysIcon.ShowInfo(msg);
                        });
                        await Task.Delay(2000);
                    }
                }

                syncing = false;
            });
        }
示例#11
0
        private void Sync(ConnectedRealm r, string region)
        {
            syncing = true;

            Dispatcher.UIThread.Post(() =>
            {
                statusText.Text      = "Syncing";
                statusProgress.Value = 0;
            });

            List <string> updated = new List <string>();

            Task.Run(() =>
            {
                try
                {
                    if (includeRegionData && GetLatest(REGION_INDICES[region.ToUpper()], region))
                    {
                        updated.Add(region);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }

                try {
                    if (GetLatest(r.id, region))
                    {
                        if (r.id < 0)
                        {
                            updated.Add(DataSource.REGION_KEY + " - " + r.realms.JoinNames());
                        }
                        else
                        {
                            updated.Add(region + " - " + r.realms.JoinNames());
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.ToString());
                }

                if (updated.Count > 0)
                {
                    Dispatcher.UIThread.Post(() =>
                    {
                        statusText.Text = "Finalizing";
                    });

                    CreateLua();

                    if (sysIcon != null && sysIcon.IsActive)
                    {
                        Dispatcher.UIThread.Post(() =>
                        {
                            sysIcon.ShowInfo(updated[0]);
                        });
                    }
                }

                Dispatcher.UIThread.Post(() =>
                {
                    statusText.Text      = "";
                    statusProgress.Value = 0;
                });

                syncing = false;
            });
        }