Friday 5 April 2013

Running Customized C# code loaded from TeamMentor’s UserData repository

A really powerful feature of TeamMentor 3.3. is its ability to run CSharp Scripts included in the mapped UserData repository (script execution is powered by O2 Platform's FluentSharp APIs).

This blog post shows how it works

In an TM User data repository, add the H2Scripts folder

image_thumb[60]

Inside that folder add a FirstScriptToInvoke.h2 file

image_thumb[62]

NOTE: The reason for this special location is that this is where TeamMentor engine will look for the first script:

image_thumb[67]

that should be compiled and executed:

image_thumb[64]

as part of the TeamMentor Setup process:

image_thumb[72]

Invoking First Script

The FirstScriptToInvoke.h2 file is basically a simple C# script:

image_thumb[73]

That can be viewed/executed/tested via this TBot page:

image_thumb[74]

Here are the current FirstScriptToInvoke.h2 script contents:

image_thumb[75]

And the invocation result:

image_thumb[78]

Testing/Coding Script

A good way to test this script, is to open a real-time log viewer (only available if running on Cassini)

image_thumb[79]

Which is a windows Form Gui, that shows real-time log messages (the same log messages available via the Debug.aspx page or DebugInfo Tbot view):

image_thumb[80]

Here is another execution of the original FirstScriptToInvoke.h2 script (note the compilation messages in the LogViewer):

image_thumb[81]

For example, we can easily add messages to this log viewer, by adding these two lines to the FirstScriptToInvoke.h2 file:

image_thumb[82] 

which when re-executed (after refreshing the TBot page), will look like this:

image_thumb[91]

To confirm that the FirstScriptToInvoke.h2 script does execute during startup, reload the cache and note the extra log entries:

image

Use online CSharp REPL to develop scripts to include in FirstScriptToInvoke.h2

When developing scripts it is easier to do them in the CSharp REPL included in the default install of TeamMentor.

You can access it by opening the /csharprepl url

image

which will redirect to:

image

and allow real-time REPL style coding:

image