コード例 #1
0
ファイル: RecipeBook.cs プロジェクト: alundgren/irudd-cooking
        public static RecipeBook CreateFromRecipeFolder(IDirectoryContents folder)
        {
            var b = new RecipeBook
            {
                Recipes = new List <Recipe>()
            };

            foreach (var file in folder)
            {
                if (file.Name.EndsWith(".txt"))
                {
                    using (var s = file.CreateReadStream())
                        using (var r = new StreamReader(s, Encoding.UTF8))
                        {
                            var    lines = new List <string>();
                            string line;
                            while ((line = r.ReadLine()) != null)
                            {
                                lines.Add(line);
                            }

                            b.Recipes.Add(CreateFromFileLines(lines, Path.GetFileNameWithoutExtension(file.Name)));
                        }
                }
            }
            b.Tags = b.Recipes.SelectMany(x => x.Tags).Distinct().OrderBy(x => x).ToList();
            return(b);
        }
コード例 #2
0
 public RecipeBook GetRecipeBook(bool forceReload = false)
 {
     if (forceReload || recipeBook == null)
     {
         recipeBook = RecipeBook.CreateFromRecipeFolder(webHostEnvironment.WebRootFileProvider.GetDirectoryContents("recipies"));
     }
     ;
     return(recipeBook);
 }