I have a little piece of code, which gets data from a DB, and I want to parse it into a .cshtml Razor-View-Template. therefor i create a variable of a new TemplateService and execute .parse() on that. Now I want to output the file to the user. What is the best performing function to accomplish this task? I have an MVC application. And as the text above already describes, this is a little template system.
Edit:
For example:
I have a folder templates/default-tpl/, which contains a file index.cshtml
This file contains some Razor-related variables (for example #ViewData["Title"]
Now i have a Controller, which calls the RazorEngine TemplateService's Parse() function with the corresponding ViewData.
Now I have the HTML ready and parsed
So the question is, from this point, how do i output the website the most performant way? Or is there even a complete different approach possible?
Related
In short: I have a method name provided via a JSON configuration file. I'd like to call a method using this provided name. The method (with a matching name) will exist in the backend. What's the best way of going about this?
I am not quite sure what I should be searching for as an example.
To detail: I am working with a legacy application, hence the VB.NET. I am building a single PDF file from multiple PDF sources. Most of these are as is, I simply read the configuration and grab the relevant files and the job is done. However some require processing, I'd like the configuration file to pass in a method name to be called that will perform extra processing on the PDF, whatever that may be.
As there can be a lot of PDF files that can vary, I cannot simply use a property such as "PostProcessing: true".
Any ideas?
You could use reflection to reflect method names back and check them against the name passed from the property in the config file.
Like so
Type magicType = Type.GetType("MagicClass");
MethodInfo magicMethod = magicType.GetMethod("ItsMagic");
object magicValue = magicMethod.Invoke(magicClassObject, new object[]{100});
That would work.. but to be honest, I'd go with a case statement as you'll be hardcoding the method names anyway (because they are code), and it'll be strongly typed (less chance of typos and errors).
I'm writing a piece of code to simulate some stuff of diagnostic.
I've created with CANalyzer, a panel with tons of information that need to be shown using a picklist (called combobox)
What I want to do is to create a giant array of that struct that need to be selected using the SPN combobox (the picklist) , and the other parameters of the struct/object need to populate the other elements of the panel.
Is this possible without doing a tons of SysSetVariableInt or SysSetVariableString for each element?
Before I was doing this stuff using another technique, I parse the file with all the information that are stored in a giant matrix, then I use the method "on sysvar update" on the variable associated to the SPN picklist, to get the index of that, so I search for that index in the matrix, then I use the SysSetVariableInt or others, to set the values to the elements in the panel.
To populate the picklist I've found a pretty nice method "sysSetVariableDescriptionForValue" that helps to add elements, but the problem with this method, is that if you want to change elements, you can just overwrite, and not change all...so, if in a next iteration you push less element in the picklist, you will see also the old ones.
With "sysSetVariableDescriptionForValue" you basically are writing via code, the value table of that sysvariable, and is not possible (according to Vector), be flushed, on runtime... :/
I would love to do this thing using another approach, maybe with the struct is possible...i really don't know.
Any help will be very appreciated!
Regards!
TLDR; build a tool to create a .sysvar file from a structured input (comma-separated for instance), run it, get the .sysvar file and link it to the CANalyzer configuration.
I once had to create the entire testing interface with some components of the software. We didn't have a structured release procedure, and the test environment was rebuilt every time from scratch based on the new internal software interfaces. I too had to add hundreds of variables.
My solution was to generate .sysvar files programatically outside CANalyzer. Links to the .sysvar files are symbolic in the CANalyzer configuration, meaning if a file by the right name is in the right location, that file is going to be loaded.
What I want to do is to create a giant array of that struct that need
to be selected using the SPN combobox (the picklist) , and the other
parameters of the struct/object need to populate the other elements
of the panel. Is this possible without doing a tons of
SysSetVariableInt or SysSetVariableString for each element?
Create an external script to generate the .sysvar file. In the end it is just an xml file, you may study the structure of a demo one you save. Then, import that file in the CANalyzer config. You may need to close/re-open the configuration in case the .sysvar file changes.
PROs: no need to write a complicated CAPL script and update it every time a variable changes.
CONs: you must have a source for all the information, even a simple excel sheet, with all the description and such, and you have to create a tool that accepts the input file (let's assume a .csv file) and turns it into a .xml file with .sysvar extension instead.
We are applying localization in our application by using resx files and using it by calling Resources.Resource.Key and ResourceManager class to get the values of keys. Currently we are facing an issue that in some languages single (') and double quotes (") are appearing while in English resource there is no such thing like that. Problem is that when we calls javascript methods like alert('value') in code then it crashes because single quote within another single quote does not work. I know there is way to handle it by replacing single quote with "\'" but in order to fix this I need to write this code throughout the application. Is there any workaround that whenever I call the resource by calling above ways I mentioned earlier One method automatically called in which I can modify the value return by the resource. Waiting for your valuable suggestions. Thx
Anywhere you're referencing resources you should HTML encode the output. If you're using ASP.NET WebForms you can use <%: Resources.Strings.Something %>. If you're using the Razor view engine then it will be HTML encoded by default.
I have a set of data rendered using ASP.Net (VB.Net) to a web page. I now want to export that data to XML. I have created some code to generate a schema, however, I don't know what to do next. I want to have the schema be in-line with the XML data, and I would like the compiler to check to make sure that the data I'm entering for the XML content validates against the included schema. Anyone know of a way to do this? The idea is for me to be able to open the resultant file in Excel with fields of the correct type.
I've build XML documents before, and this is my first schema document I've created programmatically. However, I've never worked with inline schema's, much less used them to strongly-type the XML being added to the document.
I've read over the following, which were quite helpful, but neither of which addressed the issue I mention above:
http://www.aspfree.com/c/a/XML/Generating-XML-Schema-Dynamically-Using-VBNET-2005-Essentials/
http://blogs.msdn.com/b/kaevans/archive/2007/06/05/inline-an-xml-schema-into-your-xml-document.aspx
I have no idea what you mean by "... I would like the compiler to check to make sure that the data I'm entering for the XML content validates against the included schema."
The compiler never checks that. If you want to validate your XML Document against a schema programmatically, you should probably use http://msdn.microsoft.com/en-us/library/system.xml.schema.xmlschemavalidator.aspx.
But for inlining the schema with your document, you sort of answered your own question. The second link in your question, to http://blogs.msdn.com/b/kaevans/archive/2007/06/05/inline-an-xml-schema-into-your-xml-document.aspx, is exactly what you are trying to do.
You can think of an inline XML Schema as a document-within-a-document. Well, using Kirk's example, the outermost document is more of a container which uses the undefined namespace (no schema). His example uses a document root of "DerekDoc" that belongs to the undefined namespace. You can name yours whatever you want.
Inside that root are essentially two documents. One is the inline XML Schema. You would just add it as a child element of the root. The other is the XML document that you intended to conform to the XML Schema. You will need to use the xmlns attribute to set this element to the namespace defined by your XML Schema (the target namespace of the schema).
It might work (I haven't tried it) to set the root element to the target namespace of the schema, but it might be harder for clients to validate the document since it's a forward reference.
I'm writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I'd prefer not to generate the data in code like this:
var mockData = new Array();
mockData.push(new Foo(1, "abc", "xyz"));
mockData.push(new Foo(2, "def", "xyz"));
...
Rather I'd like to store the data in a file in some format that it can be easily serialized into my strongly-typed value objects (i.e. Foo above). Ideally I'd like to create the data in a self-describing format (i.e. what data type each field is, what class it represents, etc)
Does this make sense? Any suggestions?
I would highly recommend the asx3m library. It easily allows serialization to a very readable XML format like this for an object of class Foo:
<com.example.Foo>
<myVar>Something</myVar>
<myArrList>
<string>one</string>
<string>two</string>
</myArrList>
</com.example.Foo>
The code to de-serialize looks like this:
Asx3mer.instance.fromXML(someXMLObj)
The project site has some good examples and it's not too hard to get this off the ground.
Write a method to serialize an "inflated" version of your object. Put the output of that into a file and load it up as part of your test setup. When you want to edit the values, simply edit the xml file. I dont know if this is possible in flex but I will usually include these files as a resource in my test library so that I do not need to copy the file to any specific location for a test run.