예제 #1
0
        /// <summary>
        /// Download Recipes
        /// </summary>
        /// <param name="idlist">list of recipe ids to download</param>
        /// <returns>Dictionary of Recipes downloaded, keyed by the recipe id</returns>
        public Task <EntryDictionary <int, RecipeDetailsEntry> > DownloadRecipesAsync(IList <int> idlist)
        {
            var tsk     = new TaskCompletionSource <EntryDictionary <int, RecipeDetailsEntry> >();
            var recipes = new EntryDictionary <int, RecipeDetailsEntry>();
            List <Exception> exceptions = new List <Exception>();

            ThreadPool.QueueUserWorkItem(o =>
            {
                try
                {
                    TotalDownloadCount = idlist.Count;
                    DownloadCount      = 0;
                    foreach (var id in idlist)
                    {
                        try
                        {
                            var recipe = GwApi.GetRecipeDetails(id);
                            recipes.Add(id, recipe);
                            DownloadCount++;
                        }
                        catch (Exception e)
                        {
                            exceptions.Add(e);
                        }
                    }
                    tsk.TrySetResult(recipes);
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                    tsk.TrySetException(e);
                }
            });
            return(tsk.Task);
        }
예제 #2
0
        public void GetRecipeDetailsTest(int recipe_id, bool ignoreCache)
        {
            var actual   = GwApi.GetRecipeDetails(recipe_id, ignoreCache);
            var expected = TestData.RecipeDetailsExpected.Single(r => r.RecipeId == recipe_id);

            VerifyRecipeDetails(expected, actual);
        }
예제 #3
0
        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());
        }
예제 #4
0
        private Task <RecipeDetailsEntry> DownloadRecipe(int id)
        {
            var tsk = new TaskCompletionSource <RecipeDetailsEntry>();

            ThreadPool.QueueUserWorkItem(
                o =>
            {
                try
                {
                    var recipe  = GwApi.GetRecipeDetails(id);
                    Recipes[id] = recipe;
                    tsk.TrySetResult(recipe);
                }
                catch (Exception e)
                {
                    tsk.TrySetException(e);
                }
            }
                );
            return(tsk.Task);
        }
예제 #5
0
        public void DownloadRecipes()
        {
            ResponseCache.Cache.Load("RecipeDetailsDictionary.bin");
            EntryDictionary <int, RecipeDetailsEntry> recipes =
                ResponseCache.Cache.Get("RecipeDetailsDictionary") as EntryDictionary <int, RecipeDetailsEntry> ??
                new EntryDictionary <int, RecipeDetailsEntry>();
            MockNetHandler handler = new MockNetHandler();
            var            ids     = GwApi.GetRecipeIds(true);

            ResponseCache.Cache.Save("RecipeDetailsDictionary.bin");
            GwApi.Network = handler;
            recipes.Url   = "RecipeDetailsDictionary";
            foreach (var id in ids)
            {
                if (recipes.ContainsKey(id) == false)
                {
                    var recipe = GwApi.GetRecipeDetails(id);
                    recipes[recipe.RecipeId] = recipe;
                }
            }
            ResponseCache.Cache.Add("RecipeDetailsDictionary", recipes);
            ResponseCache.Cache.Save("RecipeDetailsDictionary.bin");
        }