public static IScriptCommand IfEquals <T>(string variable = "{variable}", T value = default(T), IScriptCommand trueCommand = null, IScriptCommand otherwiseCommand = null) { string ifEqualValueProperty = "{IfEquals-Value}"; return (ScriptCommands.Assign(ifEqualValueProperty, value, IfValue(ComparsionOperator.Equals, variable, ifEqualValueProperty, trueCommand, otherwiseCommand))); }
public static IScriptCommand RunICommand(ICommand command, string parameterVariable, bool throwIfError = false, IScriptCommand nextCommand = null) { string commandVariable = "{" + string.Format("Command{0}", new Random().Next()) + "}"; return(ScriptCommands.Assign(commandVariable, command, ScriptCommands.RunICommand(commandVariable, parameterVariable, throwIfError, nextCommand))); }
///// <summary> ///// Add variables (using Expression) to destination. ///// </summary> ///// <param name="sourceObjectVariable"></param> ///// <param name="addValues"></param> ///// <param name="destinationVariable"></param> ///// <param name="nextCommand"></param> ///// <returns></returns> //public static IScriptCommand Add(string sourceObjectVariable = "{Source}", // object[] addValues = null, // string destinationVariable = "{Destination}", IScriptCommand nextCommand = null) //{ // string valueConverterVariable = ParameterDicUtils.CombineVariable(sourceObjectVariable, "Converter"); // return AssignValueConverter(ValueConverterType.AddValue, valueConverterVariable, // ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable, // destinationVariable, false, nextCommand), addValues); //} /// <summary> /// Concat array to destination /// </summary> /// <param name="sourceObjectVariable"></param> /// <param name="addValues"></param> /// <param name="destinationVariable"></param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand ConcatArray(string sourceObjectVariable = "{Source}", object[] addValues = null, string destinationVariable = "{Destination}", IScriptCommand nextCommand = null) { string valueConverterVariable = ParameterDicUtils.CombineVariable(sourceObjectVariable, "Converter"); return(AssignValueConverter(ValueConverterType.ConcatArray, valueConverterVariable, ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable, destinationVariable, nextCommand), addValues)); }
/// <summary> /// Set property of an object in ParameterDic to another object in ParameterDic. /// <example> /// ScriptCommands.SetProperty("{PSI}", "FileName", "{Value}") /// </example> /// </summary> /// <param name="sourceObjectVariable"></param> /// <param name="propertyName"></param> /// <param name="valueVariable"></param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand SetProperty(string sourceObjectVariable = "{Source}", string propertyName = "Property", string valueVariable = "{Value}", IScriptCommand nextCommand = null) { string valueConverterVariable = ParameterDicUtils.CombineVariable(sourceObjectVariable, "Converter"); return(AssignValueConverter(ValueConverterType.SetProperty, valueConverterVariable, ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable, valueVariable, nextCommand), propertyName)); }
public static IScriptCommand AddValue <T>(string value1Variable = "{Value1}", T[] value2 = null, string destinationVariable = "{Destination}", IScriptCommand nextCommand = null) { value2 = value2 ?? new T[] {}; string value2Variable = ParameterDicUtils.RandomVariable(); return(ScriptCommands.Assign(value2Variable, value2, Add(value1Variable, value2Variable, destinationVariable, nextCommand))); }
/// <summary> /// Serializable, Run IfValue comparsion based on the length of an array in ParameterDic. /// </summary> /// <param name="op"></param> /// <param name="arrayVariable"></param> /// <param name="valueVariable"></param> /// <param name="trueCommand"></param> /// <param name="otherwiseCommand"></param> /// <returns></returns> public static IScriptCommand IfArrayLength(ComparsionOperator op, string arrayVariable = "{array}", string valueVariable = "{value}", IScriptCommand trueCommand = null, IScriptCommand otherwiseCommand = null) { return (ScriptCommands.IfAssigned(arrayVariable, ScriptCommands.AssignValueConverter(ValueConverterType.GetProperty, "{GetPropertyConverter}", ScriptCommands.Reassign(arrayVariable, "{GetPropertyConverter}", "{ArrayLength}", ScriptCommands.PrintLogger(LogLevel.Debug, "Length of array is {ArrayLength}", ScriptCommands.IfValue(op, "{ArrayLength}", valueVariable, trueCommand, otherwiseCommand))), "Length"), otherwiseCommand)); }
public override IScriptCommand Execute(IParameterDic pm) { IScriptCommand command = pm.Get <IScriptCommand>(CommandKey); if (command == null && ThrowIfError) { return(ResultCommand.Error(new ArgumentNullException(CommandKey))); } command = command ?? ResultCommand.NoError; log.Info("Running " + CommandKey); return(ScriptCommands.RunQueue(NextCommand, command)); }
/// <summary> /// Serializable, do switch...case code by using multiple IfValue. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="variable"></param> /// <param name="caseLookup"></param> /// <param name="otherwiseCommand"></param> /// <returns></returns> public static IScriptCommand Switch <T>(string variable = "{variable}", Dictionary <T, IScriptCommand> caseLookup = null, IScriptCommand otherwiseCommand = null, IScriptCommand nextCommnad = null) { IScriptCommand cmd = null; foreach (var key in caseLookup.Keys) { cmd = cmd == null?IfEquals <T>(variable, key, caseLookup[key], otherwiseCommand) : IfEquals <T>(variable, key, caseLookup[key], cmd); } return(ScriptCommands.RunSequence(nextCommnad, cmd)); }
/// <summary> /// Serializable, shortcut method for [AssignValueConverter], which obtains method result of a property from a variable and assign to another variable. /// </summary> /// <param name="sourceObjectVariable"></param> /// <param name="methodName"></param> /// <param name="parameters"></param> /// <param name="destinationVariable"></param> /// <param name="nextCommand"></param> /// <returns></returns> public static IScriptCommand ExecuteFunc(string sourceObjectVariable = "{Source}", string methodName = "Method", object[] parameters = null, string destinationVariable = "{Destination}", IScriptCommand nextCommand = null) { string valueConverterVariable = ParameterDicUtils.CombineVariable(sourceObjectVariable, "Converter"); List <object> methodParams = new List <object>(); methodParams.Add(methodName); if (parameters != null) { methodParams.AddRange(parameters); } return(AssignValueConverter(ValueConverterType.ExecuteMethod, valueConverterVariable, ScriptCommands.Reassign(sourceObjectVariable, valueConverterVariable, destinationVariable, nextCommand), methodParams.ToArray())); }
public override async Task <IScriptCommand> ExecuteAsync(IParameterDic pm) { switch (Mode) { case RunMode.Parallel: await Task.WhenAll(ScriptCommands.Select(cmd => ScriptRunner.RunScriptAsync(pm.Clone(), cmd))); break; case RunMode.Queue: await ScriptRunner.RunScriptAsync(pm, ScriptCommands) .ConfigureAwait(this.ContinueOnCaptureContext); break; case RunMode.Sequence: foreach (var cmd in ScriptCommands) { await ScriptRunner.RunScriptAsync(pm, cmd) .ConfigureAwait(this.ContinueOnCaptureContext); if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } } break; default: return(ResultCommand.Error(new NotSupportedException(Mode.ToString()))); } if (pm.Error() != null) { return(ResultCommand.Error(pm.Error())); } else { return(NextCommand); } }
public override IScriptCommand Execute(IParameterDic pm) { object value = Value; if (ValueFunc != null) { value = ValueFunc(); } if (!(value is string)) { value = value.ToString(); } else { value = pm.ReplaceVariableInsideBracketed((string)value); } return(ScriptCommands.Assign( VariableKey, value, NextCommand).IfExists(SkipIfExists)); }
public override bool CanExecute(IParameterDic pm) { return(ScriptCommands.Length == 0 || ScriptCommands.First().CanExecute(pm)); }
public static IScriptCommand Substring(string sourceObjectVariable, object startIdx, string destinationVariable = "{Destination}", IScriptCommand nextCommand = null) { return(ScriptCommands.ExecuteFunc(sourceObjectVariable, "Substring", new object[] { startIdx }, destinationVariable, nextCommand)); }
/// <summary> /// Assign using multiple expression, variable name based on input of variable name. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="nextCommand"></param> /// <param name="memberExpressions"></param> /// <example>ScriptCommands.AssignMulti(ResultCommand.OK, () => val1, () => val2), pm));</example> /// <returns></returns> public static IScriptCommand AssignMulti <T>(IScriptCommand nextCommand, params Expression <Func <T> >[] memberExpressions) { return(ScriptCommands.RunSequence(nextCommand, memberExpressions.Select( (me) => Assign(me, null)).ToArray())); }
public static IScriptCommand Reset(string variable, IScriptCommand nextCommand) { return(ScriptCommands.Assign(variable, null)); }
/// <summary> /// Serializable, remove a variable from ParameterDic. /// </summary> /// <param name="nextCommand"></param> /// <param name="variables"></param> /// <returns></returns> public static IScriptCommand Reset(IScriptCommand nextCommand = null, params string[] variables) { return(ScriptCommands.Run(RunMode.Parallel, nextCommand, variables.Select(v => ScriptCommands.Assign(v, null)).ToArray())); }