-
Notifications
You must be signed in to change notification settings - Fork 2
RunnerApp
In SPCoder you can write C# code and execute it in real time, interactively. In case you need to run some C# code without a GUI, you can use the SPCoder.RunnerApp console application.
This application is usefull in situations when you need to run code as a scheduled task/azure web job. You don't need to compile the code in order to be able to run it. You just need to save your code in one or more .csx
files, and tell the SPCoder.RunnerApp where the code is.
SPCoder.RunnerApp.exe is a console application. When it starts it will look for the Code\init.csx
file and try to execute the code from it using Roslyn.
The path to the default .csx file can be changed in SPCoder.RunnerApp.exe.config
file, by changing the CodePath
parameter
<appSettings>
<add key="CodePath" value="Code\init.csx" />
<add key="WorkingDirectoryPath" value="{{WorkingDirectory}}" />
</appSettings>
The recommended setup for RunnerApp is to use the default init.csx file, add the references to additional assembiles if necessary using the #r
directive (must be added to the top of the file) and register additional .csx files for execution. Those additional csx files should contain your business logic.
//Here you can add references to other assemblies if necessary
//#r "System.Data"
//#r "{{WorkingDirectory}}\mycustomlibrary.dll"
Console.WriteLine("init");
public string __SP_CODER_EXECUTE_NEXT__ = null;
public void execFile(string path)
{
if (!string.IsNullOrEmpty(path))
{
string code = System.IO.File.ReadAllText(path);
if (!string.IsNullOrEmpty(code))
{
__SP_CODER_EXECUTE_NEXT__ = code;
}
}
}
//here you can prepare all the csx files that should be executed
string folder = @"Code\";
FilesRegisteredForExecution.Add(folder + "code.csx");
//FilesRegisteredForExecution.Add(folder + "code1.csx");
//FilesRegisteredForExecution.Add(folder + "code2.csx");
//...
In the code above you can see the way of registering your code files for execution. Just add the paths to the files to
FilesRegisteredForExecution
list.
The default code.csx file contains just a Console.WriteLine call, so you can replace it with your own code that should do something useful.
If you need to use current directory in your scripts, you can use the placeholder {{WorkingDirectory}}
which will be replaced with full path of the application's working directory.
//here you can write your code
Console.WriteLine("code");
Depending on your requirements, SPCoder.RunnerApp can be run in timed intervals by creating the Windows Task Scheduler to run the application, it can be run manually by just starting the SPCoder.RunnerApp.exe or in any other available way. You could also create Azure WebJob and upload the SPCoder.RunnerApp.exe package to Azure so that it runs your code in the Azure cloud.