public ActionResult Execute([Bind(Prefix = "")]ExecuteRequest request)
        {
            var result = new ExecuteResult();

            var template = request.Template;
            var templateParams = TemplateCompilationParameters.CreateFromLanguage(request.Language);
            var compiler = new TemplateCompiler(templateParams);

            dynamic inputModel = null;

            GeneratorResults generatorResults;
            using (var writer = new StringWriter())
            {
                generatorResults = compiler.GenerateCode(template, writer, new RazorPadMvcEngineHost(request.RazorLanguage));
                result.SetGeneratorResults(generatorResults);
                result.GeneratedCode = writer.ToString();
            }

            if (generatorResults != null && generatorResults.Success)
            {
                CompilerResults compilerResults = compiler.Compile(generatorResults);

                result.SetCompilerResults(compilerResults);

                if (!compilerResults.Errors.HasErrors)
                {
                    result.TemplateOutput = Sandbox.Execute(request.Language, template, inputModel);
                }

                result.Success = true;
            }

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public RazorTemplateEditorViewModel(string filename = null)
        {
            TemplateCompiler = new TemplateCompiler();

            if(!string.IsNullOrWhiteSpace(filename))
                LoadFromFile(filename);

            TemplateModelProperties = new RazorTemplateModelPropertiesViewModel(typeof(object));
            TemplateModelProperties.PropertiesUpdated += (x, y) => Refresh();

            Execute();
        }
        public ActionResult Parse([Bind(Prefix = "")]ParseRequest request)
        {
            var result = new ParseResult();

            using (var writer = new StringWriter())
            {
                var generatorResults = new TemplateCompiler().GenerateCode(request.Template, writer);
                result.SetGeneratorResults(generatorResults);
                result.GeneratedCode = writer.ToString();
            }

            return Json(result, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 4
0
        public RazorTemplateViewModel(RazorDocument document = null, ModelBuilders modelBuilderFactory = null, ModelProviders modelProviders = null)
        {
            _document = document ?? new RazorDocument();
            _modelBuilderFactory = modelBuilderFactory;
            _modelProviderFactory = modelProviders;
            _savedModels = new Dictionary<Type, string>();

            var modelProviderNames = _modelProviderFactory.Providers.Select(x => (string)new ModelProviderFactoryName(x.Value));
            AvailableModelProviders = new ObservableCollection<string>(modelProviderNames);
            _selectedModelProvider = new ModelProviderName(_document.ModelProvider);

            Errors = new ObservableCollection<RazorPadError>();
            Messages = new ObservableTextWriter();
            TemplateCompiler = new TemplateCompiler();

            AttachToModelProviderEvents(_document.ModelProvider);
        }
Exemplo n.º 5
0
 public void TestInitialize()
 {
     _loader = new RazorDocumentManager(new XmlRazorDocumentSource(new RazorPad.Core.Tests.Stubs.ModelProvidersStub()));
     _templateCompiler = new TemplateCompiler();
 }
Exemplo n.º 6
0
 public void TestInitialize()
 {
     _templateCompiler = new TemplateCompiler();
 }