An advice.

Have some feedback and input to share?
Don't be shy and drop us a note. We want to hear from you and strive to make our site better and more user friendly for our guests and members a like.
Post Reply
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

An advice.

Post by softdevo@tiscali.it »

Hi to all,
In my web application I have a page that is built dynamically with the instructions contained in a table.
In the page I can insert Label, TextBox, Dropdownlist, Button and more.
For the Button I currently indicate in the table the name of the method to be called when the Button is pressed. The method is now in a DLL.
I wonder: do you think I could put the method and its code in a column of the same table and execute this code using X# scripts? Are the scripts reliable? Is it possible to write everything or are there limits? do you have any example? thanks and sorry again.
Thank's to all
Danilo
User avatar
SHirsch
Posts: 286
Joined: Tue Jan 30, 2018 8:23 am
Location: Germany

An advice.

Post by SHirsch »

Hello Danilo,

scripting is very powerful and reliable. It's compiled as an in-memory dll.
If you have many script functions memory consumption increase rapidly, because every compile need its memory. I had the same issue. So if your scripts won't change at runtime you could collect all your scripts merge them into one big script. This is a bit tricky because you have the merge USINGs and create LOCAL FUNCTIONS or CLASSes. Than compile this big script and than you can call your functions from this big script.
Attached a small sample. The xs files are the single scripts. The merged.xsx is the merged script. To give you an idea how this could look like. Instead of compiling and calling the single script the merged script is compiled an then a function from is called. As you see the function name is name of the (I have all scripts as files).

Stefan
Attachments
scripts.zip
(2.05 KiB) Downloaded 171 times
User avatar
softdevo@tiscali.it
Posts: 191
Joined: Wed Sep 30, 2015 1:30 pm

An advice.

Post by softdevo@tiscali.it »

Thanks, but do you know where I can find some example of code reading and subsequent execution? some small application that at runtime reads and executes scripts?

Danilo
User avatar
robert
Posts: 4540
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

An advice.

Post by robert »

Danilo,
For scripting there are 2 possibilities:
1) use the "old" scripting that is based on the Roslyn Scripting. This is very powerful and allows you to even declare classes and methods in the script. These scripts are compiled into in memory assemblies and cannot be unloaded. So if you have a component that keeps running, this may cause memory problems after a while.
You will find some examples in the c:UsersPublicDocumentsXSharpScriptingXIDE folder on your machine. this is based on a session that Nikos did a few years ago on a conference
2) use the new "ExecScript()" function in the runtime. This allows you to execute a list of statements stored inside a string. You could see this list of statements as a method without header. You can receive parameters inside the script with the LPARAMETERS statement (this declares locals) or with the PARAMETERS statement (this declares privates).
The macro compiler will compile this into dynamic methods, that will be unloaded automatically when no longer in uses. So this uses less memory. I showed some examples of this in my online session about scripting.
You can declare locals with a type and also use VAR to derive the type at runtime. variables declared with LPARAMETERS are untyped, but you can assign these to typed locals if you want for better performance

Unfortunately there is not much to "read" about this. Maybe there is a volunteer that wants to write something ?

I think the example from STEFAN was based on the "old" scripting engine, since his merged file contains FUNCTION declarations.

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
Post Reply