Example #1
0
        /// <summary>
        /// レシピ手順インスタンス作成
        /// </summary>
        /// <param name="number">番号</param>
        /// <param name="photoFilePath">写真ファイルパス</param>
        /// <param name="text">手順テキスト</param>
        /// <returns>レシピ手順インスタンス</returns>
        public override IRecipeStep CreateStepInstance(int number, string photoFilePath, string text)
        {
            var step = new CookienRecipeStep(this.Settings, this.Logger);

            step.Number.Value        = number;
            step.PhotoFilePath.Value = photoFilePath;
            step.StepText.Value      = text;
            return(step);
        }
Example #2
0
        /// <summary>
        /// レシピダウンロード
        /// </summary>
        /// <returns></returns>
        public override async Task DownloadRecipeAsync()
        {
            try {
                var htmlString = await this._httpClient.GetStringAsync(this.Url.Value);

                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(htmlString);

                this.Title.Value = htmlDoc.QuerySelector("#content header h1").InnerText.Trim();
                using (var stream = await this._httpClient.GetStreamAsync(new Uri(htmlDoc.QuerySelector("#content img[itemprop=image]").Attributes["src"].Value)))
                    using (var ms = new MemoryStream()) {
                        stream.CopyTo(ms);
                        this.Photo.Value = ms.ToArray();
                    }
                this.Description.Value = htmlDoc.QuerySelector("#content span[itemprop=description]").InnerText.Trim();
                this.Ingredients.Clear();

                var ingredients = new List <CookienRecipeIngredient>();
                foreach (var ingredient in htmlDoc.QuerySelectorAll("#r_contents p"))
                {
                    var item = new CookienRecipeIngredient(this);
                    item.Id.Value = ingredients.Count + 1;                     // 自動採番

                    item.AmountText.Value = ingredient.QuerySelector("span").InnerText.Trim();

                    ingredient.RemoveChild(ingredient.QuerySelector("span"));
                    item.Name.Value = ingredient.InnerText;

                    ingredients.Add(item);
                }
                this.Ingredients.AddRange(ingredients);
                this.Steps.Clear();
                var steps = htmlDoc
                            .QuerySelectorAll("#ins_contents > div")
                            .Select((x, index) => {
                    var step            = new CookienRecipeStep(this.Settings, this.Logger);
                    step.Number.Value   = index + 1;
                    step.StepText.Value = x.QuerySelector("p.ins_des").InnerText.Trim();

                    return(step);
                });
                foreach (var step in steps)
                {
                    this.Steps.Add(step);
                }

                this.ShelfLife.Value = new TimeSpan(int.Parse(htmlDoc.QuerySelector("#content .recipe_info .recipe_info_right span.recipe_info_bold").InnerText.Trim()), 0, 0, 0);

                var memoIndex = 1;
                this.CookienMemos.Clear();
                while (true)
                {
                    var memo = htmlDoc.QuerySelector($"#memo{memoIndex}");
                    if (memo == null)
                    {
                        break;
                    }
                    this.CookienMemos.Add(new CookienMemo(memoIndex, memo.InnerText.Trim(), memo.NextSiblingElement().InnerText.Trim()));
                    memoIndex++;
                }

                this.Yield.Value = Regex.Replace(htmlDoc.QuerySelector("#r_contents h1").InnerText.Trim(), "^.*?((.*?))$", "$1");
            } catch (Exception ex) {
                this._failedNotification.OnNext((this, Behavior.Download, ex));
                return;
            }

            this._completedNotification.OnNext((this, Behavior.Download));
        }