|
ScriptsMatter Getting Started HOWTO. - Synchronous mode. |
|
|
|
|
Page 2 of 3
Synchronous mode.
- Create new console application project in Visual Studio and call it GettingStarted:

- Add reference to ScriptsMatter.dll library.
- Set “Copy Local” option for ScriptsMatter library to “True”
- Add ScriptsMatter library license file to the project and rename it:
- Right-click on the project in Solution Explorer window.
- Select Add->Existing Item…
- For non-commercial license select ScriptsMatter.lic file that is part of the distributive:

- Rename it to match template <YourExecutableNameWithExtention>.ScriptsMatter.lic:

- Change Copy to Output Directory property of GettingStarted.exe.ScriptsMatter.lic file to “Copy always” value:

- Put this code inside Module1.vb of GettingStarted project:
Imports System
Imports System.Reflection
Namespace GettingStarted
Module Module1
Sub Main()
Dim ScriptBody As String = _
"Imports System" & Environment.NewLine & _
"Public Class ScriptingMainClass" & Environment.NewLine & _
"Public Shared Function Main(ByVal Host As SSB.Examples.GettingStarted.MyScriptingHost) As Object" & Environment.NewLine & _
" Host.Log(""Evaluating expression..."")" & Environment.NewLine & _
" Return 5+5" & Environment.NewLine & _
"End Function" & Environment.NewLine & _
"End Class" & Environment.NewLine
Try
Dim Result As Object = SSB.Runtime.Scripting.Engine(Of Object, MyScriptingHost).CompileAndRun( _
New MyScriptingHost(), "VisualBasic", ScriptBody, _
New String() {"system.dll", "mscorlib.dll", Assembly.GetExecutingAssembly.Location})
Console.WriteLine("Script completed and returned result {0}", Result)
Catch ex As Exception
Console.WriteLine("Exception during script execution: {0}", ex)
End Try
Console.WriteLine("Press Enter to exit...")
Console.ReadLine()
End Sub
End Module
Public Class MyScriptingHost
Inherits MarshalByRefObject
Public Sub Log(ByVal message As String)
Console.WriteLine(message)
End Sub
End Class
End Namespace
- Compile and run the project. You should get the output like this:
Evaluating expression...
Script completed and returned result 10
Press Enter to exit...
Congratulations! You are able to embed script support in your application and execute them in synchronous mode.
|