Exemplo n.º 1
0
        private async void DoFindTemplateRecipe(RecipeItem item)
        {
            var ingredientTable = mEditRecipeParams.CreateDictionary();

            if (ingredientTable.ContainsKey(item?.ItemId ?? string.Empty))
            {
                Inform($"{item.Text} has already been found. You can reset it by clicking the {btnReset.Text} button.");
                return;
            }

            var task  = Task.Run(() => RecipeItemParser.Run(item, mEditRecipeParams.TemplateRecipes));
            var delay = Task.Delay(TimeSpan.FromSeconds(1));

            var completed = await Task.WhenAny(delay, task);

            if (completed == delay)
            {
                splashScreenManager1.ShowWaitForm();
                await task;
                splashScreenManager1.CloseWaitForm();
            }

            var result = task.Result;

            if (result.Success)
            {
                using (var dlg = new RecipeItemParseResultsWizard(mEditRecipeParams.IngredientAdder, result))
                {
                    if (dlg.ShowDialog(this) == DialogResult.OK)
                    {
                        dlg.Commit();
                        gridViewItems.RefreshData();
                    }
                }
            }
            else
            {
                var input = result.SearchText ?? item.Text;
                Inform($"Unable to find '{input}' in the base recipes", "Failed to Find");
            }
        }
Exemplo n.º 2
0
        private async void DoFindIngredients()
        {
            var ingredientTable = mEditRecipeParams.CreateDictionary();
            var items           = recipeItemBindingSource
                                  .OfType <RecipeItem>()
                                  .Where(i => !ingredientTable.ContainsKey(i.ItemId ?? string.Empty))
                                  .ToArray();

            if (!items.Any())
            {
                if (recipeItemBindingSource.Count > 0)
                {
                    Inform($"All of the items in the recipe have been found. You can reset the items by clicking the {btnReset.Text} button.");
                }
                return;
            }

            var task  = Task.Run(() => RecipeItemParser.Run(items, mEditRecipeParams.Ingredients).ToArray());
            var delay = Task.Delay(TimeSpan.FromSeconds(1));

            var completed = await Task.WhenAny(delay, task);

            if (completed == delay)
            {
                splashScreenManager1.ShowWaitForm();
                await task;
                splashScreenManager1.CloseWaitForm();
            }

            var results = task.Result;

            using (var dlg = new RecipeItemParseResultsWizard(mEditRecipeParams.IngredientAdder, results))
            {
                if (dlg.ShowDialog(this) == DialogResult.OK)
                {
                    dlg.Commit();
                    gridViewItems.RefreshData();
                }
            }
        }