示例#1
0
        public static string Execute(StringContextContainer context, string template, string[] assemblies)
        {
            string code = ComposeCode(template);

            //System.IO.File.WriteAllText("D:/code.cs", code);

            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }
            List <string> assemblyList = new List <string>(DefaultAssemblies);

            if (assemblies != null && assemblies.Length > 0)
            {
                assemblyList.AddRange(assemblies);
            }

            Assembly assembly = CompileCode(assemblyList.Distinct().ToArray(), code);

            if (assembly == null)
            {
                return(null);
            }
            Type       type   = assembly.GetType("TemplateRunner");
            MethodInfo mInfo  = type.GetMethod("Run", BindingFlags.Static | BindingFlags.Public);
            object     result = mInfo.Invoke(null, new object[] { context });

            return(result?.ToString());
        }
示例#2
0
        public static void CreateItemPool(string spaceName, string outputDir, string templateFilePath)
        {
            Type[] itemTypes = AssemblyUtility.GetDerivedTypes(typeof(ActionItem));
            if (itemTypes == null || itemTypes.Length == 0)
            {
                Debug.LogError($"ActionItemPoolCreator::CreateItemPool->ActionItem is not found!");
                return;
            }

            Dictionary <Type, Type> dataToItemTypeDic = new Dictionary <Type, Type>();

            foreach (var itemType in itemTypes)
            {
                ActionItemBindDataAttribute attr = itemType.GetCustomAttribute <ActionItemBindDataAttribute>();
                if (attr == null)
                {
                    Debug.LogError($"ActionItemPoolCreator::CreateItemPool->Attribute is not found.itemType = {itemType.FullName}");
                    continue;
                }

                dataToItemTypeDic.Add(attr.DataType, itemType);
            }

            StringContextContainer context = new StringContextContainer();

            context.Add("spaceName", spaceName);
            context.Add("dataToItemTypeDic", dataToItemTypeDic);

            string templateContent = File.ReadAllText(templateFilePath);

            string outputFilePath = $"{outputDir}/ActionItemPoolRegister.cs";
            string outputContent  = TemplateEngine.Execute(context, templateContent, new string[0]);

            File.WriteAllText(outputFilePath, outputContent);
        }
示例#3
0
        public static void GenerateFile(string filePath, StringContextContainer context, string templateContent, string[] assemblyNames = null, EntryConfig config = null)
        {
            string result = Generate(context, templateContent, assemblyNames, config);

            if (!string.IsNullOrEmpty(result))
            {
                File.WriteAllText(filePath, result);
            }
        }
示例#4
0
        private static string WriteToLua(WDBSheet sheet, string templateContent, string[] assemblyNames, EntryConfig config)
        {
            StringContextContainer context = new StringContextContainer();

            context.Add("__sheet__", sheet);
            string content = TemplateEngine.Generate(context, templateContent, assemblyNames, config);

            context.Remove("__sheet__");
            return(content);
        }
示例#5
0
        public void Process()
        {
            string[] assets = Filter.GetResults();
            if (assets != null && assets.Length > 0)
            {
                StringContextContainer context = new StringContextContainer();
                context.Add(AssetPostContextKeys.ASSET_FILTER_KEY, Filter);
                context.Add(AssetPostContextKeys.ASSET_FILTER_RESULT_KEY, assets);

                foreach (var ruler in Rulers)
                {
                    context.InjectTo(ruler);
                    {
                        ruler.Execute();
                    }
                    context.ExtractFrom(ruler);
                }

                context.Clear();
            }
        }
示例#6
0
        public static string Generate(StringContextContainer context, string templateContent, string[] assemblyNames = null, EntryConfig config = null)
        {
            config = config ?? EntryConfig.Default;
            if (string.IsNullOrEmpty(config.ClassName) || string.IsNullOrEmpty(config.MethodName))
            {
                return(null);
            }

            string code = ComposeCode(templateContent);

            if (string.IsNullOrEmpty(code))
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(config.CodeOutputPath))
            {
                File.WriteAllText($"{config.CodeOutputPath}/{config.ClassName}.cs", code);
            }

            List <string> assemblyList = new List <string>(DefaultAssemblies);

            if (assemblyNames != null && assemblyNames.Length > 0)
            {
                assemblyList.AddRange(assemblyNames);
            }

            Assembly assembly = CompileCode(assemblyList.Distinct().ToArray(), code);

            if (assembly == null)
            {
                return(null);
            }
            Type       type   = assembly.GetType(config.ClassName);
            MethodInfo mInfo  = type.GetMethod(config.MethodName, BindingFlags.Static | BindingFlags.Public);
            object     result = mInfo.Invoke(null, new object[] { context });

            return(result?.ToString());
        }
示例#7
0
 public static string Execute(StringContextContainer context, string templateContent, string[] assemblyNames)
 {
     return(Generate(context, templateContent, assemblyNames));
 }
示例#8
0
        public bool Verify(ref List <string> errors)
        {
            if (string.IsNullOrEmpty(Name))
            {
                errors.Add(WDBConst.VERIFY_SHEET_NAME_EMPTY_ERR);
                return(false);
            }
            if (!Regex.IsMatch(Name, WDBConst.VERIFY_SHEET_NAME_REGEX))
            {
                errors.Add(string.Format(WDBConst.VERIFY_SHEET_NAME_REGEX_ERR, Name));
                return(false);
            }

            if (FieldCount == 0)
            {
                errors.Add(string.Format(WDBConst.VERIFY_SHEET_NO_FIELD_ERR, Name));
                return(false);
            }
            if (RowCount == 0)
            {
                errors.Add(string.Format(WDBConst.VERIFY_SHEET_NO_ROW_ERR, Name));
                return(false);
            }

            bool result = true;

            foreach (var field in fields)
            {
                if (!field.Verify(ref errors))
                {
                    if (result)
                    {
                        result = false;
                    }
                }
            }
            if (!result)
            {
                return(false);
            }

            StringContextContainer context = new StringContextContainer();

            context.Add(WDBConst.CONTEXT_SHEET_NAME, this);
            context.Add(WDBConst.CONTEXT_ERRORS_NAME, errors);
            foreach (var row in rows)
            {
                if (row.CellCount != FieldCount)
                {
                    if (result)
                    {
                        result = false;
                    }
                    errors.Add(string.Format(WDBConst.VERIFY_SHEET_FIELD_ROW_ERR, FieldCount, row.Row));
                }
            }

            if (!result)
            {
                return(false);
            }

            for (int i = 0; i < fields.Count; ++i)
            {
                var field = fields[i];
                context.Add(WDBConst.CONTEXT_FIELD_NAME, field);
                foreach (var row in rows)
                {
                    var cell = row.GetCellByIndex(i);
                    if (cell.Col != field.Col)
                    {
                        if (result)
                        {
                            result = false;
                        }
                        errors.Add(string.Format(WDBConst.VERIFY_CELL_COL_NOTSAME_ERR, cell.Row, cell.Col));
                    }
                    else
                    {
                        context.Add(WDBConst.CONTEXT_CELL_NAME, cell);
                        foreach (var cellValidation in field.Validations)
                        {
                            context.InjectTo(cellValidation);
                        }
                        context.Remove(WDBConst.CONTEXT_CELL_NAME);
                    }
                }
                context.Remove(WDBConst.CONTEXT_FIELD_NAME);
            }
            return(errors.Count == 0);
        }