예제 #1
0
        public RazorScriptingSampleForm()
        {
            InitializeComponent();

            // Create a custom context we can pass to Template
            CustomContext = new CustomContext();

            // Assign a reference to this form for use within
            // the template
            CustomContext.WinForm = this;
        }
예제 #2
0
        public override void InitializeTemplate(object context, object configurationData)
        {
            Model = Context as CustomContext;
            Config = configurationData as RazorFolderHostTemplateConfiguration;

            // Pick up configuration data and stuff into Request object
            RazorFolderHostTemplateConfiguration config = configurationData as RazorFolderHostTemplateConfiguration;

            this.Request.TemplatePath = config.TemplatePath;
            this.Request.TemplateRelativePath = config.TemplateRelativePath;
        }
예제 #3
0
        private void tbRunRaw_Click(object sender, EventArgs e)
        {
            var engine = new RazorEngine<RazorTemplateBase>();

            // we can pass any object as context - here create a custom context
            var context = new CustomContext()
            {
                WinForm = this,
                Entered = DateTime.Now.AddDays(-10)
            };

            string output = engine.RenderTemplate(this.txtSource.Text,
                                                  new string[] { "System.Windows.Forms.dll" },
                                                  context);

            if (output == null)
                this.txtResult.Text = "*** ERROR:\r\n" + engine.ErrorMessage;
            else
                this.txtResult.Text = output;
        }
예제 #4
0
        private void tbRunLowLevel_Click(object sender, EventArgs e)
        {
            // we can pass any object as context - here create a custom context
            var context = new CustomContext()
            {
                WinForm = this,
                Entered = DateTime.Now.AddDays(-10)
            };

            var engine = new RazorEngine<RazorTemplateBase>();
            string assId = null;

            using (StringReader reader = new StringReader(this.txtSource.Text))
            {
                assId = engine.ParseAndCompileTemplate(new string[] { "System.Windows.Forms.dll" }, reader);
            }

            string output = engine.RenderTemplateFromAssembly(assId, context);

            if (output == null)
                this.txtResult.Text = "*** ERROR:\r\n" + engine.ErrorMessage;
            else
                this.txtResult.Text = output;
        }