Get script and agent settings

Add TSLab.DataModel.dll and TSLab.ScriptEngine.dll to the External script block.

using System.Text;
using TSLab.DataModel;
using TSLab.Script;
using TSLab.Script.Handlers;
using TSLab.ScriptExecution.Realtime;

namespace MyLib
{
    public class TestSettings: IExternalScript
    {
        public void Execute (IContext ctx, ISecurity sec)
        {
            // TSLab.DataModel.dll, TSLab.ScriptExecution.dll must be added to the 'External script' block.
                        
            // Get script settings
            var labOptions = ctx.GetLabOptions ();
            if (labOptions! = null)
            {
                var sb = new StringBuilder ();
                sb.AppendLine ($ "=== LabOptions ===");
                sb.AppendLine ($ "Date from: ({labOptions.UseDateFrom}) {labOptions.DateFromEdit}");
                sb.AppendLine ($ "Date to: ({labOptions.UseDateTo}) {labOptions.DateToEdit}");
                ctx.Log (sb.ToString (), MessageType.Info, true);
            }

            // Get agent settings
            var rtOptions = ctx.GetRtOptions ();
            if (rtOptions! = null)
            {
                var sb = new StringBuilder ();
                sb.AppendLine ($ "=== RtOptions ===");
                sb.AppendLine ($ "Execute entries immediately: {rtOptions.DefEntryApprove}");
                sb.AppendLine ($ "Execute exits immediately: {rtOptions.DefExitApprove}");
                ctx.Log (sb.ToString (), MessageType.Info, true);
            }
        }
    }

    public static class TSLabExtensions
    {
        public static LabOptions GetLabOptions (this IContext ctx)
        {
            var fi = ctx.Runtime.GetType (). GetProperty ("Options");
            return fi? .GetValue (ctx.Runtime) as LabOptions;
        }

        public static RealtimeScriptOptions GetRtOptions (this IContext ctx)
        {
            var fi = ctx.Runtime.GetType (). GetProperty ("Manager");
            var val = fi? .GetValue (ctx.Runtime) as RealtimeDataManager;
            return val? .RtData? .Options;
        }
    }
}

Full list of agent settings:

Last updated

Was this helpful?