That said I probably would suggest a webservice instead, keeping the templates on the server (Razor) and calling that service via javascript instead of a client side templating solution.

I have never heard of somebody doing anything similar so you are probably completely on your own (no need to say that it sounds like a really difficult/impossible thing to do)

hoborg91

@hoborg91

@matthid

any C# code

Since one follows the ViewModel template, usually anything except direct properties access and basic code control constructions (if-else, for, foreach, switch) are not expected. Thus the task is becoming easier.

calling that service via javascript instead of a client side templating solution

You are right, but I would like to minimize the load on the server and transfer some work to the client side. And simultaneously I would like to consider a situation when JS is blocked by the client.

So, I intend to inherit from RazorEngine.Compilation.CompilerServiceBase and implement... yet do not know what. Would you be so kind to point me to the reference or say what should I do after implementation? I have expected some parser class where an instance of type ICompilerService must be supplied. Am I correct?

You should start by compiling from source and marking the methods you want to overwrite as virtual (if needed) and implement what you are trying to achieve. I would certainly accept a pull request later on. You should figure out exactly what you want to do and what you expect after compiling a template. The C# code? the JS Code? both? And how to integrate that with the remaining architecture of RazorEngine (for the start it is probably enough to have a CompilerService that outputs JS and run it standalone whenever you need it)

hoborg91

@hoborg91

@matthid Thanks for the directions. I shall investigate this approach.

Matthias Dittrich

@matthid

Hope it helps :)

ABerg

@ABergBN

Hi matthid,

do you have any experience with the Engine in a wcf service? Are there any advises how to handle the calls? I want to build a service which build me an htmtl/plain text email.I think there can come up some issues on a concurrent call to the service.

Matthias Dittrich

@matthid

@ABergBN Concurrent calls shouldn't be an issue, RazorEngine "should" be thread-safe. If you run into problems open an issue ;)

Josh

@joshgo

Hi... I'm running unit tests, and for some reason I keep getting "The same key was already used for another template!". However, I'm only calling the RunCompile() once in my test. I have another test where that doesn't happen. Any suggestions? Clear Cache?

Josh

@joshgo

Looking to use this for non HTML templates... I saw you had something called "MarkupParser" to handle non HTML-like pages. Is this still a work in progress, are there docs/examples? Would love to use razor syntax for flat text templates.

Matthias Dittrich

@matthid

@joshgo I think the problem is that you are using the static singleton RazorEngine instance for all your tests, try to create a new instance for every test.

@joshgo No there is no such thing as non-HTML or vanilla XML templates currently implemented. It would be a nice addition and is up-for-grabs (Antaris/RazorEngine#223).

ABerg

@ABergBN

@joshgo For non HTML-like Pages you can use PlanText-tags's Like <text>I'm Plaintext</text>

In my application I use it to generate PlainText Emails.

Matthias Dittrich

@matthid

@ABergBN Yes that works fine up to the point when you include some special html things in your "Plaintext", for example <Link>@(Model.LinkName)</Link> (see linked issue). That's just something to keep in mind. Once you trigger something special tag like this it is really hard to debug.

You might want to use Razor directly (without RazorEngine), we might provide API in the future to get the source code (and transform it with Roslyn), but never such a visitor API... The reason is quite simple: First we at RazorEngine try to abstract away the concrete Razor version for you. And secondly Razor 4 is changing dramatically and maintaining such an API is an additional headache...You can however look into the RazorEngine source code to get an idea how to use the Razor classes (see DirectCompilerServiceBase for example)

Richard Bogle

@Boggin

I've been trying to implement the MvcTemplateBase<> as shown in Issues #26 and #29 but I get a null for the HttpContext.Current and I can't figure out why. I'm using the fluent config to set the BaseTemplateType = typeof(MvcTemplateBase<>). Is this going to work or have I got lost! RazorEngine v.3.7.2

Richard Bogle

@Boggin

Hang on. WebAPI ...

Nikola Sivkov

@aviatrix

hey @matthid , are you around ?

Matthias Dittrich

@matthid

Hey, yes whats up?

Nikola Sivkov

@aviatrix

Can you tell me if you recall, in versions prior to 3.5 did RE store the compiled templates on disk or in memory ?

Matthias Dittrich

@matthid

In memory (which has some downsides), but you can still to it with DisableTempFileLocking (so I basically changed the default)

Nikola Sivkov

@aviatrix

i have a theory on why using linq methods on dynamic properties blows up now and it didn't before

ah, i see

Matthias Dittrich

@matthid

why would it matter on linq methods?

Nikola Sivkov

@aviatrix

something to do with parts of anon/dynamic objects being internal

and since they are stored outside of the memory now, they are different assembly

and executing assembly not being able to see the internal stuff and blowing up