/// <summary> /// Try to compile the step /// </summary> /// <param name="errors"></param> /// <returns></returns> public bool TryCompile(out string[] errors) { List <string> aggregatingErrors = new List <string>(); if (IsCompiled) { errors = aggregatingErrors.ToArray(); return(true); } if (_stepDef.OnEntry != null) { string[] onEntryErrors; _onEnter = new CsScriptRuntime(_stepDef.OnEntry); _onEnter.TryCompile(out onEntryErrors); aggregatingErrors.AddRange(onEntryErrors); } if (_stepDef.OnExit != null) { string[] onExitErrors; _onExit = new CsScriptRuntime(_stepDef.OnExit); _onExit.TryCompile(out onExitErrors); aggregatingErrors.AddRange(onExitErrors); } string[] handlerErrors; _handler.TryCompile(out handlerErrors); aggregatingErrors.AddRange(handlerErrors); errors = aggregatingErrors.ToArray(); IsCompiled = true; return(errors.Length == 0); }
/// <summary> /// /// </summary> /// <param name="sd"></param> /// <param name="errors"></param> /// <returns></returns> protected bool TryCompileScript(ScriptDefinition sd, out string[] errors) { List <string> aggregatingErrors = new List <string>(); if (IsCompiled) { errors = aggregatingErrors.ToArray(); return(true); } if (sd != null) { string[] onEntryErrors; _script = new CsScriptRuntime(sd); _script.TryCompile(out onEntryErrors); aggregatingErrors.AddRange(onEntryErrors); } errors = aggregatingErrors.ToArray(); IsCompiled = true; return(errors.Length == 0); }
/// <summary> /// Validates the on enter on exit criteria. /// </summary> /// <param name="env">The env.</param> /// <param name="rt">The rt.</param> /// <param name="f">The f.</param> /// <returns></returns> private async Task <AsyncValidationResult> ValidateOnEnterOnExit(IProcessRuntimeEnvironment env, CsScriptRuntime rt, Func <VariableMapDefinition, bool> f) { if (!IsCompiled) { return(new AsyncValidationResult($"The step Id {_stepDef.StepId} is not compiled.")); } string[] errors; if (!TryValidateVariables(env, _stepDef.VariablesMap?.Where(f) ?? new VariableMapDefinition[] { }, out errors)) { return(new AsyncValidationResult(errors)); } if (rt == null) { return(new AsyncValidationResult()); } int result = await rt.Execute(env); return(result == 1 ? new AsyncValidationResult() : new AsyncValidationResult("Script validation fails")); }
public ScriptHandler(StepRuntime step) { _script = new CsScriptRuntime(step._stepDef.StepHandler.Script); }