Example #1
0
        public void GetItemDetailsTest(int item_id, bool ignoreCache)
        {
            var actual   = GwApi.GetItemDetails(item_id, ignoreCache);
            var expected = TestData.ItemDetailsExpected.Single(i => i.ItemId == item_id);

            VerifyItemDetails(expected, actual);
        }
Example #2
0
        public void CachePerformanceLoadTest()
        {
            Stopwatch watch = new Stopwatch();
            var       items = ResponseCache.Cache.Get("ItemsDictionary") as EntryDictionary <int, ItemDetailsEntry>;

            if (items == null)
            {
                return;
            }
            int count = 0;

            Console.WriteLine("Time to complete {0} {1}", count, watch.Elapsed.TotalSeconds.ToString("0.0000000"));
            List <Task <ItemDetailsEntry> > addTask = new List <Task <ItemDetailsEntry> >();

            watch.Start();
            var items2 = new EntryDictionary <int, ItemDetailsEntry>();

            foreach (var item in items)
            {
                var i = GwApi.GetItemDetails(item.Key);
                items2.Add(i.ItemId, i);
                count++;
            }
            watch.Stop();
            string output = string.Format("Time to complete {0} {1}", items2.Count,
                                          watch.Elapsed.TotalSeconds.ToString("0.0000000"));

            Console.WriteLine(output);
        }
        public void ItemDetailsExample()
        {
            GwApi.Network = new NetworkHandler();

            // Lets get the details of my awesome item.
            var           item = GwApi.GetItemDetails(39276);
            StringBuilder sb   = new StringBuilder(string.Format("{0} - Item Detail\n", item.ItemId));

            sb.AppendFormat("Name: {0}\n", item.Name);
            sb.AppendFormat("{0}\n", item.Description);
            sb.AppendFormat("Level: {0}\n", item.Level);
            sb.AppendFormat("Rarity: {0}\n", item.Rarity);
            sb.AppendFormat("Type: {0}\n", item.ItemType);
            sb.AppendFormat("Value: {0}\n", item.VendorValue);
            sb.AppendFormat("Buffs:\n");
            sb.AppendFormat("{0}\n", item.TrinketDetails.InfixUpgrade.Buff.Description);
            sb.AppendFormat("Attributes:\n");
            foreach (var attr in item.TrinketDetails.InfixUpgrade.Attributes)
            {
                sb.AppendFormat("\t{0}:{1}\n", attr.Attribute, attr.Modifier);
            }
            sb.AppendFormat("Infusion Slots ({0}):\n", item.TrinketDetails.InfusionSlots.Count);
            for (int i = 0; i < item.TrinketDetails.InfusionSlots.Count; i++)
            {
                sb.AppendFormat("\tType: {1} - {0}\n", item.TrinketDetails.InfusionSlots[i].Item ?? "Unused", string.Join(",", item.TrinketDetails.InfusionSlots[i].Flags));
            }

            Console.WriteLine(sb.ToString());
        }
Example #4
0
        private void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var idList = e.Argument as IList <int>;
            var items  = Items ?? new EntryDictionary <int, ItemDetailsEntry>();

            e.Result = items;
            lock (_downloadLock)
            {
                e.Result      = items;
                DownloadTotal = idList.Count;
                for (int i = 0; i < idList.Count; i++)
                {
                    var item = GwApi.GetItemDetails(idList[i]);
                    try
                    {
                        items.Add(item.ItemId, item);
                    }
                    catch (Exception)
                    {
                    }
                    DownloadCount    = i;
                    DownloadProgress = (int)(100 * ((double)i / idList.Count));
                    //_worker.ReportProgress((int) (100*((double) i/idList.Count)));
                    if (e.Cancel)
                    {
                        return;
                    }
                }
            }
        }
Example #5
0
        public override string ToString()
        {
            var sb   = new StringBuilder();
            var item = GwApi.GetItemDetails(ItemId);

            sb.AppendFormat("{0} x{1}", item.Name, Count);
            return(sb.ToString());
        }
Example #6
0
        private static async Task <ItemDetailsEntry> DownloadItemDetails(int id, bool ignoreCache = false)
        {
            var item = await Task.Run(
                () => GwApi.GetItemDetails(id, ignoreCache));

            Items[id] = item;
            return(item);
        }
        public void RenderServiceExample2()
        {
            // Lets get an item
            var item = GwApi.GetItemDetails(39276);
            // Now lets download it's icon image
            var image = GwApi.GetRenderServiceAssetEntry(item.IconFileSignature, item.IconFileId, "jpg");

            image.Asset.Save(item.ItemId + ".jpg");

            // Lets open the image in a default image viewer
            Process.Start(item.ItemId + ".jpg");
        }
        public void ExampleRecipeDetails()
        {
            var           recipe = GwApi.GetRecipeDetails(1482);
            StringBuilder sb     = new StringBuilder(string.Format("{0} - Recipe\n", recipe.RecipeId));

            sb.AppendFormat("Diciplines: {0}\n", string.Join(",", recipe.Diciplines));
            sb.AppendFormat("{0} x{1}\n", GwApi.GetItemDetails(recipe.OutputItemId).Name, recipe.OutputCount);
            sb.AppendFormat("Min Skill Needed: {0}\n", recipe.MinRating);
            sb.AppendFormat("Type: {0}\n", recipe.RecipeType);
            sb.AppendFormat("Crafting Time: {0:#.###}s\n", recipe.TimeToCraftMsec / 1000.0);
            sb.AppendFormat("Ingredients:\n");
            foreach (var ing in recipe.Ingredients)
            {
                sb.AppendFormat("\t{0} x{1}\n", GwApi.GetItemDetails(ing.ItemId).Name, ing.Count);
            }

            Console.WriteLine(sb.ToString());
        }
        public override string ToString()
        {
            var sb = new StringBuilder();
            ItemDetailsEntry outputItem = GwApi.GetItemDetails(OutputItemId);

            sb.AppendFormat("{0}: {1} x{2}\n", "Name", outputItem.Name, OutputCount);
            sb.AppendFormat(_defaultPropertyFormat, "Type", RecipeType);
            sb.AppendFormat(_defaultPropertyFormat, "Skill Needed", MinRating);
            sb.AppendFormat(_defaultPropertyFormat, "Craft Time(s)", TimeToCraftMsec / 1000.0);
            sb.AppendLine("Diciplines:");
            foreach (var dicipline in Diciplines)
            {
                sb.AppendFormat("  {0}", dicipline);
            }
            sb.AppendLine("Flags: " + string.Join(", ", Flags));
            sb.AppendLine("Ingredients:");
            foreach (var ingredient in Ingredients)
            {
                sb.AppendLine("  " + ingredient);
            }
            return(sb.ToString());
        }
Example #10
0
        public void requesttest()
        {
            var item = GwApi.GetItemDetails(39276, true);

            Console.WriteLine(item.TrinketDetails.SuffixId);
        }
        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);
            }
        }