Beispiel #1
0
        public void examples()
        {
            GwApi.Network = new NetworkHandler();
            IdList list = GwApi.GetItemIds(true);

            Console.WriteLine("Total Items: {0}", list.Count);
        }
Beispiel #2
0
        public void GetItemIdsTest(bool ignoreCache)
        {
            var actual   = GwApi.GetItemIds(ignoreCache);
            var expected = TestData.ItemIdListExpected;

            CollectionAssert.AreEquivalent(expected, actual);
        }
Beispiel #3
0
        public void DownloadItemDetails()
        {
            GwApi.Network = new NetworkHandler();
            var    itemIds  = GwApi.GetItemIds(true);
            string itemPath = @".\Items";

            Directory.CreateDirectory(itemPath);
            DirectoryInfo itemDir         = new DirectoryInfo(itemPath);
            var           downloadedItems = itemDir.GetFiles("*.txt");
            var           downloadedIds   = _parseItemFileIds(downloadedItems);
            List <string> itemDetails     = new List <string>();
            Stopwatch     watch           = Stopwatch.StartNew();
            string        fileNameFormat  = itemPath + "\\{0}.txt";

            foreach (var id in itemIds)
            {
                if (downloadedIds.Contains(id) == false)
                {
                    string item = null;
                    try
                    {
                        ApiRequest request = new ApiRequest(Constants.item_details);
                        request.AddParameter("item_id", id);
                        item = GwApi.Network.GetResponse(request).ToString();
                        File.WriteAllText(string.Format(fileNameFormat, id), item);
                    }
                    catch (Exception)
                    {
                        File.AppendAllText(string.Format(fileNameFormat, "Failed_on"), id + "\n");
                    }
                }
            }
            watch.Stop();
            Console.WriteLine("Finished in {0}s", watch.Elapsed.TotalSeconds);
            return;
        }
        public void DownloadAllItemDetails()
        {
            // Warning this will take quite a long time.
            // It is highly recommended that you save this information as it is not expected to change often if at all
            // Luckily we can use the ResponseCache to do this for us.
            // Here is an example to download the data/save it, and allow for updates later

            {
                // lets obtain all the currently known item ids
                var itemIds = GwApi.GetItemIds();
                var itemDetailsDictionary = new EntryDictionary <int, ItemDetailsEntry>(itemIds.Count);
                // This could take 20-30 minutes
                // keep in mind there are currently 27,000+ items at the time of writting this
                foreach (var id in itemIds)
                {
                    var item = GwApi.GetItemDetails(id);
                    itemDetailsDictionary.Add(id, item);
                }

                // This is important, We should save this for nice and fast retrival
                // While our individual items are already stored in the ResponseCache
                // The dictionary is not, and it is much more convenient to just grab the entire dictionary
                // This will allow us easy access to search for items
                // We are going to store it using ItemDetailsDictionary
                ResponseCache.Cache.Add("ItemDetailsDictionary", itemDetailsDictionary);
            }

            {
                // lets update our complete dictionary of items we've already downloaded earlier
                // first lets obtain the complete list of item ids
                // notice how we passed (true) this time.  This will skip our response cache and for an update.
                // We want to make sure we have a complete list as of right now, not yesterday
                var itemIds = GwApi.GetItemIds(true);
                // Lets get the item dictionary we already have (Remember we stored it in cache)
                var itemDetailsDictionary =
                    ResponseCache.Cache.Get("ItemDetailsDictionary") as EntryDictionary <int, ItemDetailsEntry> ?? new EntryDictionary <int, ItemDetailsEntry>();
                // This could take 20-30 minutes
                // keep in mind there are currently 27,000+ items at the time of writting this
                foreach (var id in itemIds)
                {
                    if (itemDetailsDictionary.ContainsKey(id) == false)
                    {
                        var item = GwApi.GetItemDetails(id);
                        itemDetailsDictionary.Add(id, item);
                    }
                }

                // Lets update our ResponseCache with our updated item dictionary
                ResponseCache.Cache.Add("ItemDetailsDictionary", itemDetailsDictionary);
            }

            {
                // We have this big dictionary that took a really long time to download
                // What can we do with it?
                // Store it in a DataBase? sure that's not a bad idea.  Could make searching through it easy and quick.
                // We can also use LINQ - this is a great idea for those non-repeated retrival instances
                // First lets get our item dictionary
                var itemDetailsDictionary =
                    ResponseCache.Cache.Get("ItemDetailsDictionary") as EntryDictionary <int, ItemDetailsEntry> ?? new EntryDictionary <int, ItemDetailsEntry>();

                // Search for an item by name
                var item = itemDetailsDictionary.Values.SingleOrDefault(i => i.Name == "Godrock Amulet");
                // Get all lvl 80 items
                var itemsByLevel = itemDetailsDictionary.Values.Where(i => i.Level == 80);
                // What about all lvl 80 weapons
                itemsByLevel = itemDetailsDictionary.Values.Where(i => i.Level == 80 && i.ItemType == ItemType.Weapon);
                // Lets reduce the previous query to all swords; then we'll have all lvl 80 swords
                var swords =
                    itemsByLevel.Where(i => i.WeaponDetails.Type == ItemDetailsEntry.WeaponInfo.WeaponType.Sword);

                // Lets get all swords within 2 levels of 40
                itemsByLevel = itemDetailsDictionary.Values.Where(i => i.ItemType == ItemType.Weapon && i.WeaponDetails.Type == ItemDetailsEntry.WeaponInfo.WeaponType.Sword && i.Level >= 38 && i.Level <= 42);
            }
        }
Beispiel #5
0
 private void _getItemIds(object none)
 {
     ItemIds = GwApi.GetItemIds();
     OnIdListUpdated(ItemIds);
 }