/// <summary>
        ///
        /// </summary>
        /// <param name="classExpression"></param>
        /// <param name="projectPath"></param>
        /// <param name="name_space"></param>
        /// <param name="listUIElements"></param>
        /// <param name="mapAliasWithNode"></param>
        /// <param name="myLog"></param>
        /// <param name="instanceName"></param>
        /// <returns>relative file path</returns>
        private string GenerateClassExpScripts(ClassExpression classExpression, string projectPath, string name_space,
                                               ListUIElements listUIElements, Dictionary <string, string> mapAliasWithNode, MyLog myLog, string instanceName)
        {
            if (classExpression.getName() == null || classExpression.getListFunction() == null ||
                classExpression.getListFunction().Count <= 0)
            {
                return(null);
            }
            string functionsScripts = "";

            foreach (FunctionExpression func in classExpression.getListFunction())
            {
                if (functionsScripts != "")
                {
                    functionsScripts += NEW_LINE;
                }
                functionsScripts += GenerateFunctionExpScripts(func, listUIElements, mapAliasWithNode, myLog, instanceName);
            }
            // create new file
            string classContent = GetTemplateUCClassContent()
                                  //.Replace(GLOBAL_REPLACE, "") disabled by @duongtd 05/29
                                  .Replace(CLASS_REPLACE, classExpression.getName())
                                  .Replace(CONTENT_REPLACE, functionsScripts);
            string filePath            = Path.Combine(classExpression.GetCorrectWorkspace(), classExpression.getName() + ".cs");
            string fileContentTemplate = GetTemplateRunCsFileContent()
                                         .Replace(NAMESPACE_REPLACE, name_space);

            CreateNewFile(fileContentTemplate, classContent, Path.Combine(projectPath, filePath));
            return(filePath);
        }
Ejemplo n.º 2
0
 public static void MergeClassesExpression(List <ClassExpression> @base, ClassExpression addition)
 {
     foreach (ClassExpression existed in @base.ToList())
     {
         if (existed.getName() == addition.getName())
         {
             List <FunctionExpression> newListFuncs = addition.getListFunction();
             if (newListFuncs != null)
             {
                 foreach (FunctionExpression newFunc in newListFuncs.ToList())
                 {
                     if (newFunc != null)
                     {
                         MergeFunctions(existed.getListFunction(), newFunc);
                     }
                 }
             }
             return;
         }
     }
     if (addition != null)
     {
         @base.Add(addition);
     }
 }
Ejemplo n.º 3
0
 public static void MergeClasses(List <ClassExpression> classes, ClassExpression class2)
 {
     if (classes == null)
     {
         classes = new List <ClassExpression> {
             class2
         };
         return;
     }
     if (class2 == null || class2.getName() == null)
     {
         return;
     }
     foreach (ClassExpression cl in classes)
     {
         // add new functions to existed class
         if (cl.getName() == class2.getName())
         {
             var newListFunc = class2.getListFunction();
             if (newListFunc != null && newListFunc.Count > 0)
             {
                 foreach (var newFunc in newListFunc)
                 {
                     MergeFunctions(cl.getListFunction(), newFunc);
                 }
             }
             return;
         }
     }
     // add new class
     NormalizeClass(class2);
     classes.Add(class2);
 }
Ejemplo n.º 4
0
        public static void NormalizeClass(ClassExpression cl)
        {
            List <FunctionExpression> listFunc = cl.getListFunction();

            if (listFunc == null)
            {
                return;
            }
            List <FunctionExpression> newListFunc = new List <FunctionExpression>();

            foreach (FunctionExpression func in listFunc)
            {
                MergeFunctions(newListFunc, func);
            }
            cl.setListFunction(newListFunc);
        }
 public virtual ScriptsExpression HandleAndGenScripts(IScriptGenerationParams scriptGenerationParams, ScriptType scriptType = ScriptType.Normal)
 {
     if (scriptGenerationParams is UserCodeScriptGenerationParams ucParams)
     {
         Regex regex = new Regex("(?<class_group>.*?)\\.(?<func_group>.*)");
         Match match = regex.Match(expression);
         if (match.Success)
         {
             string   className   = match.Groups["class_group"].Value;
             string   funcName    = match.Groups["func_group"].Value;
             Regex    regex2      = new Regex("(?<func_group>.*)\\((?<params_group>.*)\\)$");
             Match    match2      = regex2.Match(funcName);
             int      paramsCount = 0;
             string[] _params     = null;
             if (match2.Success && match2.Groups["params_group"] != null &&
                 match2.Groups["params_group"].Value.Trim() != "")
             {
                 funcName    = match2.Groups["func_group"].Value;
                 _params     = match2.Groups["params_group"].Value.Split(',');
                 paramsCount = _params.Count();
             }
             bool voidReturn = true;
             if (Regex.IsMatch(ucParams.SpecNode.Expression, USER_CODE_WITH_VARIABLE_DECLARE))
             {
                 voidReturn = false;
             }
             else if (!Regex.IsMatch(ucParams.SpecNode.Expression, AbstractSpecUserAction.USER_CODE))
             {
                 logger.Error("Incorrect Expression: " + ucParams.SpecNode.Expression);
             }
             var re   = new UserCodeScriptsExpression();
             var pair = CheckFunctionExisted(ucParams.ClassExpressions, className, funcName, paramsCount, voidReturn);
             if (!pair.Item1)
             {
                 FunctionExpression func = new FunctionExpression(funcName);
                 if (_params != null)
                 {
                     foreach (string param in _params)
                     {
                         ParameterExpression parameterExpression = new ParameterExpression();
                         parameterExpression.setName(param);
                         if (func.getParams() == null)
                         {
                             func.setParams(new List <ParameterExpression>());
                         }
                         func.getParams().Add(parameterExpression);
                     }
                 }
                 func.setReturnDescription("no description");
                 ClassExpression classExpExisted = pair.Item2;
                 // if  class existed
                 if (classExpExisted != null)
                 {
                     Utils.MergeFunctions(classExpExisted.getListFunction(), func);
                 }
                 else
                 {
                     re.AppendNewAdditionFunc(className, func);
                 }
             }
             DoGenRawScripts(className, funcName, _params, voidReturn, ucParams, re, scriptType);
             return(re);
         }
         else
         {
             throw new NotImplementedException();
         }
     }
     else
     {
         throw new NotImplementedException();
     }
 }