示例#1
0
        public async Task <ActionResult> About()
        {
            var timestamp = DateTime.Now;

            using (var templater = new IsolatedRazor.RazorTemplater(templatePath, 60000))
            {
                ViewBag.Message = await templater.ParseAsync("test", "@Model.Name, your application description page. @DateTime.Now", timestamp, new Person()
                {
                    Name = "CFI"
                });
            }

            return(View());
        }
        public string CreateScheduleEmail(int weekNumber)
        {
            var factory = new ScheduleEmailModelFactory(_dbFactory);
            var templatePath = HttpContext.Current.Server.MapPath("~/Static/PrintSchedule.cshtml");
            //var templatePath = HttpContext.Current.Server.MapPath("~/Views/Main/PrintSchedule.cshtml");
            using (var templater = new IsolatedRazor.RazorTemplater(templatePath))
            {
                var emailContent = templater.ParseAsync(PrintSchedule, File.ReadAllText(templatePath), DateTime.Now, factory.Get(weekNumber)).Result;
                return emailContent;
            }

            //var configuration = new TemplateServiceConfiguration()
            //{
            //    // setting up our custom template manager so we map files on demand
            //    TemplateManager = new SimpleTemplateManager()
            //};
            //var service = RazorEngineService.Create(configuration);

            //var template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/Views/Main/PrintSchedule.cshtml"));
            //var model = new MainController.PrintScheduleViewModel() {Schedule = schedule, SelectedRecipes = selectedRecipes};
            //var emailContent = service.RunCompile(template, PrintSchedule, model.GetType(), model);
            ////var emailContent = Engine.Razor.Run(PrintSchedule, null, new MainController.PrintScheduleViewModel() {Schedule = schedule, SelectedRecipes = selectedRecipes});
            //return emailContent;
        }
        private string CreateShoppingListEmail(int weekNumber, string store)
        {
            using (var db = new FluentQuery(_dbFactory.OpenDbConnection()))
            {
                var accessor = new ShoppingAccessor(db);
                var shoppingList = accessor.GetShoppingListForStore(weekNumber, store);

                //using (var templater = new IsolatedRazor.RazorTemplater(null))
                //{
                //    string result = templater.ParseAsync("MyTemplate", "<div>Hello @Model.Name! It is @DateTime.Now</div>", DateTime.Now, new { Name = "ModelTest" }).Result;
                //}
                //~/Static/PrintShoppingList.cshtml
                //"~/Views/Main/PrintShoppingList.cshtml"
                var templatePath = HttpContext.Current.Server.MapPath("~/Static/PrintShoppingList.cshtml");
                //var templatePath = HttpContext.Current.Server.MapPath("~/Views/Main/PrintShoppingList.cshtml");
                using (var templater = new IsolatedRazor.RazorTemplater(templatePath))
                {
                    var emailContent = templater.ParseAsync(PrintShoppingList, File.ReadAllText(templatePath), DateTime.Now, shoppingList).Result;
                    return emailContent;
                }
            }
        }