Пример #1
0
        /// <summary>
        /// Serializable, shortcut method for [AssignValueConverter], which a specific item from an array from a variable and assign to another variable.
        /// </summary>
        /// <param name="arrayVariable"></param>
        /// <param name="id"></param>
        /// <param name="destinationVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand GetArrayItem(string arrayVariable       = "{Array}", int id = 0,
                                                  string destinationVariable = "{Destination}", IScriptCommand nextCommand = null)
        {
            string valueConverterVariable = ParameterDicUtils.CombineVariable(arrayVariable, "Converter");

            return(AssignValueConverter(ValueConverterType.GetArrayItem, valueConverterVariable,
                                        ScriptCommands.Reassign(arrayVariable, valueConverterVariable,
                                                                destinationVariable, nextCommand), id));
        }
Пример #2
0
        /// <summary>
        /// Given an array filter using IfValue, and store matched item to destination variable.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sourceArrayVariable"></param>
        /// <param name="property"></param>
        /// <param name="op"></param>
        /// <param name="value"></param>
        /// <param name="destinationArrayVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand FilterArray <T>(string sourceArrayVariable      = "{SourceArray}", string property   = "Property",
                                                     ComparsionOperator op           = ComparsionOperator.Equals, T value = default(T),
                                                     string destinationArrayVariable = "{DestinationArray}", IScriptCommand nextCommand = null)
        {
            string valueVariable = ParameterDicUtils.CombineVariable(sourceArrayVariable, "ValueCompare");

            return(Assign(valueVariable, value,
                          FilterArray(sourceArrayVariable, property, op, valueVariable, destinationArrayVariable, nextCommand)));
        }
Пример #3
0
        /// <summary>
        /// Iterate an IEnumeration and return true if anyone's property equals to the value.
        /// <example>
        /// IScriptCommand iterateCommand2 =
        ///      ScriptCommands.ForEachIfAnyValue<DateTime>("{Items}", null, ComparsionOperator.Equals, DateTime.Today,
        ///	    ScriptCommands.PrintDebug("True"), ScriptCommands.PrintDebug("False"));
        /// </example>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="itemsVariable"></param>
        /// <param name="property"></param>
        /// <param name="op"></param>
        /// <param name="value"></param>
        /// <param name="nextCommand"></param>
        /// <param name="otherwiseCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ForEachIfAnyValue <T>(string itemsVariable       = "{Items}", string property            = null,
                                                           ComparsionOperator op      = ComparsionOperator.Equals, T value    = default(T),
                                                           IScriptCommand nextCommand = null, IScriptCommand otherwiseCommand = null)
        {
            string compareVariable = ParameterDicUtils.CombineVariable(itemsVariable.Replace(".", ""), "Compare");

            return(Assign(compareVariable, value,
                          ForEachIfAnyValue(itemsVariable, property, op, compareVariable, nextCommand, otherwiseCommand)));
        }
Пример #4
0
        ///// <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));
        }
Пример #5
0
        /// <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));
        }
Пример #6
0
        /// <summary>
        /// Serializable, Use Reassign to obtain a property of a vaiable in ParameterDic and use IfEquals to compare, and run different command based on result.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="variable"></param>
        /// <param name="propertyName"></param>
        /// <param name="value"></param>
        /// <param name="trueCommand"></param>
        /// <param name="otherwiseCommand"></param>
        /// <returns></returns>
        public static IScriptCommand IfPropertyEquals <T>(string variable                 = "{variable}", string propertyName = "Property",
                                                          T value                         = default(T),
                                                          IScriptCommand trueCommand      = null,
                                                          IScriptCommand otherwiseCommand = null)
        {
            string variableProperty = ParameterDicUtils.CombineVariable(variable, propertyName);
            string valueProperty    = "{IfPropertyEquals-Value}";

            return(GetProperty(variable, propertyName, valueProperty,
                               IfEquals <T>(valueProperty, value, trueCommand, otherwiseCommand)));
        }
Пример #7
0
        /// <summary>
        /// Given an array filter using IfValue, and store matched item to destination variable.
        /// </summary>
        /// <param name="sourceArrayVariable"></param>
        /// <param name="property"></param>
        /// <param name="op"></param>
        /// <param name="valueVariable"></param>
        /// <param name="destinationArrayVariable"></param>
        /// <param name="nextCommand"></param>
        /// <returns></returns>
        public static IScriptCommand FilterArray(string sourceArrayVariable      = "{SourceArray}", string property                 = "Property",
                                                 ComparsionOperator op           = ComparsionOperator.Equals, string valueVariable  = "{Value}",
                                                 string destinationArrayVariable = "{DestinationArray}", IScriptCommand nextCommand = null)
        {
            string currentItemVariable     = ParameterDicUtils.CombineVariable(sourceArrayVariable, "Current");
            string currentPropertyVariable = ParameterDicUtils.CombineVariable(sourceArrayVariable, "Current" +
                                                                               (property == null ? "" : "." + property));
            string tempArrayVariable = ParameterDicUtils.CombineVariable(sourceArrayVariable, "Temp");

            return(ForEach(sourceArrayVariable, currentItemVariable,
                           IfValue(op, currentPropertyVariable, valueVariable,
                                   ConcatArray(tempArrayVariable, new object[] { currentItemVariable }, tempArrayVariable)),
                           Assign(destinationArrayVariable, tempArrayVariable, nextCommand)));
        }
Пример #8
0
        /// <summary>
        /// Iterate an IEnumeration and return true if anyone's property equals to the specified variable.
        /// </summary>
        /// <example>
        /// IScriptCommand iterateCommand2 =
        ///    ScriptCommands.ForEachIfAnyValue<DateTime>("{Items}", "Day", ComparsionOperator.Equals, "Today.Day",
        ///	   ScriptCommands.PrintDebug("True"), ScriptCommands.PrintDebug("False"));
        /// </example>
        /// <param name="itemsVariable"></param>
        /// <param name="property"></param>
        /// <param name="op"></param>
        /// <param name="compareVariable"></param>
        /// <param name="nextCommand"></param>
        /// <param name="otherwiseCommand"></param>
        /// <returns></returns>
        public static IScriptCommand ForEachIfAnyValue(string itemsVariable       = "{Items}", string property = null,
                                                       ComparsionOperator op      = ComparsionOperator.Equals, string compareVariable = "{Variable}",
                                                       IScriptCommand nextCommand = null, IScriptCommand otherwiseCommand             = null)
        {
            string currentItemVariable     = ParameterDicUtils.CombineVariable(itemsVariable.Replace(".", ""), "Current");
            string currentPropertyVariable = ParameterDicUtils.CombineVariable(itemsVariable.Replace(".", ""), "Current" +
                                                                               ((property == null) ? "" : "." + property));
            string resultVariable = ParameterDicUtils.CombineVariable(itemsVariable.Replace(".", ""), "Result");

            return
                (Assign(resultVariable, false,
                        ForEach(itemsVariable, currentItemVariable, resultVariable,
                                IfValue(op, currentPropertyVariable, compareVariable,
                                        Assign(resultVariable, true)),
                                IfTrue(resultVariable, nextCommand, otherwiseCommand))));
        }
Пример #9
0
        /// <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()));
        }