Beispiel #1
0
        public static AppFunc OwinApp(IDictionary <string, object> startupEnv = null)
        {
            var app =
                new List <Func <AppFunc, AppFunc> >()
                .Use(H5bp.IeEdgeChromeFrameHeader())
                .Use(H5bp.RemovePoweredBy())
                .Use(H5bp.CrossDomainRules())
                .Use(JsonBodyParser.Middleware())
                .Use(UrlEncoded.Middleware())
                .Use(MethodOverride.Middleware());

            var router   = new RegexRouter(app);
            var template = new RazorEngine.Templating.TemplateService();

            router.Get("/", next =>
                       async env =>
            {
                await env.GetResponseBody()
                .WriteStringAsync("hi");
            });

            template.Compile("Hi @Model.name", typeof(DynamicObject), "/hi");
            router.Get(@"/hi/(?<name>((.)*))$", next =>
                       async env =>
            {
                var routeParameters = env.GetSimpleOwinRouteParameters();

                string html = template.Run("/hi", new { name = routeParameters["name"] }.ToDynamicObject());

                await env.GetResponseBody()
                .WriteStringAsync(html);
            });

            router.Get("/hello", next =>
                       async env =>
            {
                await env.GetResponseBody()
                .WriteStringAsync("Hello");
            });

            router.All("*", NotFound.Middleware());

            return(app.ToOwinApp());
        }
        public static AppFunc OwinApp(IDictionary<string, object> startupEnv = null)
        {
            var app =
                new List<Func<AppFunc, AppFunc>>()
                    .Use(H5bp.IeEdgeChromeFrameHeader())
                    .Use(H5bp.RemovePoweredBy())
                    .Use(H5bp.CrossDomainRules())
                    .Use(JsonBodyParser.Middleware())
                    .Use(UrlEncoded.Middleware())
                    .Use(MethodOverride.Middleware());

            var router = new RegexRouter(app);
            var template = new RazorEngine.Templating.TemplateService();

            router.Get("/", next =>
                           async env =>
                           {
                               await env.GetResponseBody()
                                   .WriteStringAsync("hi");
                           });

            template.Compile("Hi @Model.name", typeof(DynamicObject), "/hi");
            router.Get(@"/hi/(?<name>((.)*))$", next =>
                            async env =>
                            {
                                var routeParameters = env.GetSimpleOwinRouteParameters();

                                string html = template.Run("/hi", new { name = routeParameters["name"] }.ToDynamicObject());

                                await env.GetResponseBody()
                                    .WriteStringAsync(html);
                            });

            router.Get("/hello", next =>
                                async env =>
                                {
                                    await env.GetResponseBody()
                                        .WriteStringAsync("Hello");
                                });

            router.All("*", NotFound.Middleware());

            return app.ToOwinApp();
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                System.IO.File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\razortester.txt", tbData.Text);
                System.IO.File.WriteAllText(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\razortester2.txt", tbTemplate.Text);
                data = new JsonReader().Read(tbData.Text);


                RazorEngine.Templating.TemplateService svc = new RazorEngine.Templating.TemplateService();
                tbCompiled.Text = svc.Parse(tbTemplate.Text, data, null, null);

                webBrowser1.DocumentText = tbCompiled.Text;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                tbOutput.Text = ex.ToString();
            }
        }
Beispiel #4
0
        public IHttpActionResult GetForgotPassword(UserMail userMail)
        {
            if (userMail == null || string.IsNullOrEmpty(userMail.Mail) || string.IsNullOrWhiteSpace(userMail.Mail))
            {
                return(NotFound());
            }

            var user = db.Users.FirstOrDefault(u => u.Email.Trim().ToLower() == userMail.Mail.Trim().ToLower());

            if (user == null)
            {
                return(NotFound());
            }
            EmailService             emailService = new EmailService();
            ForgotPasswordEmailModel model        = new ForgotPasswordEmailModel
            {
                Name     = user.UserName,
                Password = Protector.Decrypt(user.Password)
            };

            var templateService  = new RazorEngine.Templating.TemplateService();
            var templateFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Services", "Email", "ForgotPasswordEmailTemplate.cshtml");
            var emailHtmlBody    = templateService.Parse(File.ReadAllText(templateFilePath), model, null, null);

            try
            {
                IdentityMessage msg = new IdentityMessage();
                msg.Subject     = "Loglig";
                msg.Body        = emailHtmlBody;
                msg.Destination = user.Email;
                emailService.SendAsync(msg);
            }
            catch (Exception ex)
            {
                return(InternalServerError());
            }
            return(Ok());
        }
Beispiel #5
0
 public StartProcessor(ISiteContext context, RazorEngine.Configuration.TemplateServiceConfiguration config)
 {
     _context = context;
     _startTemplateService = new RazorEngine.Templating.TemplateService(config);
 }
Beispiel #6
0
        private static void tep_mail(string to_name, string to_email_address, string email_subject, string email_text, string from_email_name, string from_email_address, string file_location = "", string file_name = "", bool bcc
            = false)
        {
            try
            {
                //var emailHtmlBody = templateService.Parse(welcomeEmailTemplate, model, null, "WelcomeEmail");
                if (bcc == true)
                {

                   string bcc_email_address = BCC_EMAIL_ADDRESS;

                    //send mail
                }
                else
                {

                   //send mail

                }

                if (EMAIL_USE_HTML == "true")
                {

                }
                else
                {

                }
                // Send the process report.
                RazorEngine.Templating.TemplateService razor = new RazorEngine.Templating.TemplateService();
                MailMessage message = new MailMessage();
                SmtpClient server = new SmtpClient(ConfigurationManager.AppSettings["emailServer"]);

                message.From = new MailAddress("*****@*****.**");
                message.To.Add(ConfigurationManager.AppSettings["reportEmailRecipients"]);
                message.Subject = string.Format("Razor Email Test");
                message.IsBodyHtml = true;

                Model.UserDetail model = new Model.UserDetail()
                {
                    Name = "Gene Buryakovsky",
                    Address = ""
                };

                message.Body = razor.Parse(File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Template", "RenewalEmailTemplate.cshtml")), model, null, null);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                EventLog.WriteEntry(sSource, e.Message);
                //return string.Empty;
            }
        }
Beispiel #7
0
 public StartProcessor(ISiteContext context, RazorEngine.Configuration.TemplateServiceConfiguration config)
 {
     _context = context;
     _startTemplateService = new RazorEngine.Templating.TemplateService(config);
 }