Exemplo n.º 1
0
    private static List <string> GetFieldInfo(string fieldName, TemplateFieldTranslator.CStringFieldInfo info, bool ignoreTranslateTxt)
    {
        List <STranslateField> transFields = new List <STranslateField>();

        GetFieldInfo(transFields, fieldName, info, ignoreTranslateTxt);

        List <string> listFields = new List <string>();

        foreach (STranslateField transfield in transFields)
        {
            listFields.Add(string.Format("{0}.{1}", transfield.parentMemberName, transfield.propName));
        }

        return(listFields);
    }
Exemplo n.º 2
0
    //入口, 输出哪些字段
    public static Dictionary <string, List <string> > GetAllFieldInfos(bool ignoreTranslateTxt)
    {
        SortedDictionary <string, TemplateFieldTranslator.CStringFieldInfo> dicTempFields = TemplateFieldTranslator.GetOutputFields();

        Dictionary <string, List <string> > dicFields = new Dictionary <string, List <string> >();

        foreach (var kv in dicTempFields)
        {
            string template_Name = kv.Key;
            TemplateFieldTranslator.CStringFieldInfo info = kv.Value;

            List <string> listFields = GetFieldInfo(template_Name, info, ignoreTranslateTxt);
            dicFields.Add(template_Name, listFields);
        }
        return(dicFields);
    }
Exemplo n.º 3
0
    static string Get_GenerateTranlateValues_CS()
    {
        string strText = "";

        SortedDictionary <string, TemplateFieldTranslator.CStringFieldInfo> dicTempFields = TemplateFieldTranslator.GetOutputFields();

        foreach (var kv in dicTempFields)
        {
            //每个template
            string template_Name = kv.Key;
            TemplateFieldTranslator.CStringFieldInfo info = kv.Value;

            //if (template_Name != "Actor")
            //    continue;

            strText += "Console.WriteLine(\"" + template_Name + "...\");";

            strText += string.Format(@"
            GenerateTranlateValues_{0}();
", template_Name);
        }

        return(strText);
    }
Exemplo n.º 4
0
    static string Get_GenerateTranslateValues_Template_CS(string template_Name, TemplateFieldTranslator.CStringFieldInfo info, bool ignoreTranslateTxt)
    {
        string strText = string.Format(@"
    public static void GenerateTranlateValues_{0}()", template_Name);

        strText += @"
{";

        strText += string.Format(@"
    _ListTranslateValue.Clear();
");

        //得到如 [[[ExecutionUnit][Event]][AddFightSpeciality]]
        List <STranslateField> transFields = new List <STranslateField>();

        GetFieldInfo(transFields, template_Name, info, ignoreTranslateTxt);

        //strText += string.Format("//{0}\n", template_Name);
        //strText += string.Format("//Template.{0}Module.Manager\n", template_Name);

        strText += string.Format(@"
//{0}
foreach (var kv in Template.{1}Module.Manager.Instance.GetTemplateMap())", template_Name, template_Name);

        strText += @"
{";

        strText += string.Format(@"
    int tid = kv.Key;
    var v_{0} = kv.Value;
", template_Name);

        //读取每个字段
        foreach (var transfield in transFields)
        {
            //字段简称
            string field = string.Format("{0}.{1}", transfield.parentMemberName, transfield.propName);

            strText += "\n";

            List <STransEntry> transEntryList = ParseParentMemberNameList(transfield);

            //生成
            string parentListName = null;
            string strMember      = "v_" + transEntryList[0].name;
            int    nListBraces    = 0;
            for (int i = 1; i < transEntryList.Count; ++i)
            {
                STransEntry entry = transEntryList[i];

                if (!entry.isList)
                {
                    strMember += string.Format(".{0}", entry.name);

                    if (parentListName != null)
                    {
                        if (i + 1 == transEntryList.Count)
                        {
                            //get string desc
                            //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "." + transfield.propName + "\";";
                            strText += GetFieldDesc(transEntryList, transfield.propName);

                            strText += string.Format(@"
        string v = {0}.{1}.{2};", parentListName, entry.name, transfield.propName);

                            strText += "\nstring field = \"" + field + "\";\n";

                            //添加
                            strText += @"
        if (!string.IsNullOrEmpty(v))
            _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});";
                        }
                        else
                        {
                            parentListName = string.Format("{0}.{1}", parentListName, entry.name);
                        }
                    }
                }
                else
                {
                    strMember += string.Format(".{0}", entry.name);
                    if (parentListName != null)
                    {
                        parentListName = string.Format("{0}.{1}", parentListName, entry.name);
                    }

                    string strList = (parentListName != null ? parentListName : strMember);
                    string strVar  = string.Format("v_{0}", entry.name);

                    strText += string.Format(@"
    for(int i{0} = 0; i{1} < {2}.Count; ++i{3})", nListBraces, nListBraces, strList, nListBraces);
                    //try
                    strText += @"
    {try {
";
                    strText += string.Format(@"
        var {0} = {1}[i{2}];
", strVar, strList, nListBraces);

                    if (i + 1 == transEntryList.Count)
                    {
                        //get string desc
                        //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "[\" + i + \"]" + "." + transfield.propName + "\";";
                        strText += GetFieldDesc(transEntryList, transfield.propName);

                        strText += string.Format(@"
        string v = {0}.{1};", strVar, transfield.propName);

                        strText += "\nstring field = \"" + field + "\";\n";

                        //添加
                        strText += @"
        if (!string.IsNullOrEmpty(v))
            _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});";
                    }

                    ++nListBraces;
                    parentListName = strVar;
                }
            }

            if (nListBraces == 0)       //没有List字段
            {
                //try
                strText += @"
    {try {
";
                //get string desc
                //strText += "\t\tstring desc = \"(\" + tid + \")\" + \"" + strMember + "." + transfield.propName + "\";";
                strText += GetFieldDesc(transEntryList, transfield.propName);

                strText += string.Format(@"
        string v = {0}.{1};", strMember, transfield.propName);

                strText += "\nstring field = \"" + field + "\";\n";

                //添加
                strText += @"
        if (!string.IsNullOrEmpty(v))
            _ListTranslateValue.Add(new STranslateValue() {_field = field, _desc = desc, _val = v});";

                //catch
                strText += @"
    } catch(NullReferenceException) {}}";
            }
            else
            {
                for (int i = 0; i < nListBraces; ++i)
                {
                    //catch
                    strText += @"
    } catch(NullReferenceException) {}}";
                }
            }
        }

        strText += @"
}
";

        strText += @"
}
";

        return(strText);
    }
Exemplo n.º 5
0
    private static void GetFieldInfo(List <STranslateField> transFields, string fieldName, TemplateFieldTranslator.CStringFieldInfo info, bool ignoreTranslateTxt)
    {
        string typeName;

        if (fieldName[fieldName.Length - 1] == '>')
        {
            typeName = fieldName;
        }
        else
        {
            typeName = '[' + fieldName + ']';
        }

        //结构中的string字段
        foreach (var prop in info.Fields)
        {
            //Console.WriteLine("{0}   {1}", typeName, prop.Name);
            STranslateField field = new STranslateField()
            {
                parentMemberName = STranslateField.fixParentMemberName(typeName), propName = prop.Name
            };

            if (USE_FORBID)
            {
                if (!field.IsForbid(_ForbidFieldList))
                {
                    transFields.Add(field);
                }
            }
            else
            {
                if (ignoreTranslateTxt || field.IsAllow(_AllowFieldList))
                {
                    transFields.Add(field);
                }
            }
        }

        //结构中的list字段item中的string字段
        foreach (var listkv in info.ListFields)
        {
            /*
             * string listFieldName = listkv.Key;
             * List<PropertyInfo> props = listkv.Value;
             * foreach (var prop in props)
             * {
             *  //string parentMemberName = string.Format("{0}{1}", typeName, listFieldName);
             *  //Console.WriteLine("{0}  {1}", parentMemberName, prop.Name);
             *  STranslateField field = new STranslateField() { parentMemberName = STranslateField.fixParentMemberName(typeName), listName = listFieldName, propName = prop.Name };
             *  if (!field.IsForbid(_ForbidFieldList))
             *      transFields.Add(field);
             * }
             * */
            string memberFieldName = '<' + listkv.Key + '>';
            TemplateFieldTranslator.CStringFieldInfo fieldInfo = listkv.Value;
            GetFieldInfo(transFields, typeName + memberFieldName, fieldInfo, ignoreTranslateTxt);
        }

        //结构中的子结构中的string字段
        foreach (var mkv in info.MemberFields)
        {
            string memberFieldName = '[' + mkv.Key + ']';
            TemplateFieldTranslator.CStringFieldInfo fieldInfo = mkv.Value;
            GetFieldInfo(transFields, typeName + memberFieldName, fieldInfo, ignoreTranslateTxt);
        }
    }
Exemplo n.º 6
0
    //入口,输出列表,供填充csv
    public static void GenerateTranlateStringCS(string filename, bool ignoreTranslateTxt)
    {
        const string classDefBegin = @"
using System;
using System.Collections.Generic;

namespace Template
{
    public static class TemplateTranslateUtility
    {
        private static List<STranslateValue> _ListTranslateValue = new List<STranslateValue>();

        public static List<STranslateValue> GetListTranslateValue() { return _ListTranslateValue; }
";

        const string classMethodBegin = @"
        private static void GenerateTranlateValues()
        {
            _ListTranslateValue.Clear();
        ";

        const string classMethodEnd = @"
        }  
";

        const string classDefEnd = @"
    }
}
";
        StreamWriter writer      = File.CreateText(filename);

        if (writer != null)
        {
            //类开始
            writer.WriteLine(classDefBegin);

            //方法开始
            writer.WriteLine(classMethodBegin);

            //生成方法内容
            string strMethod = Get_GenerateTranlateValues_CS();
            writer.WriteLine(strMethod);

            //方法结束
            writer.WriteLine(classMethodEnd);

            //生成每个Template的方法
            {
                SortedDictionary <string, TemplateFieldTranslator.CStringFieldInfo> dicTempFields = TemplateFieldTranslator.GetOutputFields();

                foreach (var kv in dicTempFields)
                {
                    //每个template
                    string template_Name = kv.Key;
                    TemplateFieldTranslator.CStringFieldInfo info = kv.Value;

                    string strSubMethod = Get_GenerateTranslateValues_Template_CS(template_Name, info, ignoreTranslateTxt);
                    writer.WriteLine(strSubMethod);
                }
            }

            //类结束
            writer.WriteLine(classDefEnd);
        }
        writer.Close();
    }