示例#1
0
        private static void TypedefToCombo(StringBuilder code, TypedefItem typedef)
        {
            code.AppendFormat(@"
        
        /// <summary>
        /// {0}
        /// </summary>
        List<NameValue> {1}Dictionary = new List<NameValue>
        {{", typedef.Description, typedef.Name);

            bool first = true;

            foreach (var con in typedef.Items.Values)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    code.Append(',');
                }
                code.AppendFormat(@"
                new NameValue{{value=""{0}"",name=""{1}""}}", con.Value.Trim('\''), con.Caption);
            }
            code.Append(@"
        };");
        }
        private TypedefItem CheckTypedef(List <TypedefItem> result, ref TypedefItem item, string l)
        {
            var words = l.Split(new[] { '\t', ' ', ';', '=', '\\' }, StringSplitOptions.RemoveEmptyEntries);

            switch (words[0])
            {
            case "typedef":
                if (item == null)
                {
                    item = new TypedefItem
                    {
                        Tag = SystemName
                    };
                }
                var idx = l.IndexOf('[');
                if (idx < 0)
                {
                    item.Name = words[words.Length - 1];
                }
                else
                {
                    var ks = l.Split(new[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                    item.ArrayLen = ks[1];
                    words         = ks[0].Split(new[] { '\t', ' ', ';', '=' }, StringSplitOptions.RemoveEmptyEntries);
                }

                item.Name    = words[words.Length - 1];
                item.KeyWork = string.Empty;
                for (int index = 1; index < words.Length - 1; index++)
                {
                    if (index > 1)
                    {
                        item.KeyWork += " ";
                    }
                    item.KeyWork += words[index];
                }
                result.Add(item);
                item = null;
                break;

            case "const":
                var name = words[1];
                var tp   = result.FirstOrDefault(p => p.Name == name) ?? FindTypedef(name);
                if (tp != null && !tp.Items.ContainsKey(words[2]))
                {
                    tp.Items.Add(words[2], new EnumItem
                    {
                        Tag         = SystemName,
                        Name        = words[2].Trim(CoderBase.NoneLanguageChar),
                        Value       = words[3],
                        Caption     = words.Length > 4 ? words[4].Trim(CoderBase.NoneLanguageChar) : item?.Description.Trim(CoderBase.NoneLanguageChar),
                        Description = words.Length > 4 ? words[4].Trim(CoderBase.NoneLanguageChar) : item?.Description.Trim(CoderBase.NoneLanguageChar)
                    });
                }
                item = null;
                break;
            }

            return(item);
        }
示例#3
0
        private void SaveTypedef(TypedefItem type, string path, bool checkState = true)
        {
            var filename = Path.Combine(path, type.Name + ".typ");

            if (checkState && !CheckCanSave(type, filename))
            {
                return;
            }
            DeleteOldFile(type, filename, false);
            if (type.IsDelete)
            {
                Solution.TypedefItems.Remove(type);
            }
            else
            {
                foreach (var field in type.Items.Where(p => p.Value.IsDelete).ToArray())
                {
                    type.Items.Remove(field.Key);
                }
            }
            if (type.IsDelete)
            {
                Solution.TypedefItems.Remove(type);
            }
            Serializer(filename, type);
        }
示例#4
0
        private void LoadTypedefs(string directory)
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            string path     = Path.Combine(directory, "Typedefs");
            var    typedefs = IOHelper.GetAllFiles(path, "typ");

            foreach (var file in typedefs)
            {
                TypedefItem type = DeSerializer <TypedefItem>(file);
                if (!type.IsDelete)
                {
                    _solution.TypedefItems.Add(type);
                }
            }
        }
示例#5
0
     private static void TypeDefLog(StringBuilder code, PropertyConfig field, TypedefItem typedef)
     {
         code.AppendFormat(@"
 ostr << "",\""{0}({1})\"":"";
 switch(value->{1})
 {{", field.Caption, field.Name);
         foreach (var item in typedef.Items)
         {
             code.Append($@"
 case '{item.Value.Value}':
     ostr << ""{item.Value.Caption}\"""";
     break;");
         }
         code.Append(@"
 }");
     }
示例#6
0
     private static void EnumOut(StringBuilder code, PropertyConfig field, TypedefItem typedef)
     {
         code.AppendFormat(@""";");
         code.AppendFormat(@"
 switch(value->{0})
 {{", field.Name);
         foreach (var kv in typedef.Items.Values)
         {
             code.AppendFormat(@"
 case {0}:
         cout << ""{1}"" << endl;
         break;", kv.Name, kv.Value);
         }
         code.Append(@"
 }");
     }
        public List <TypedefItem> CheckTypedef(string txt)
        {
            var result = new List <TypedefItem>();

            var         lines = txt.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            TypedefItem item  = new TypedefItem();

            foreach (var line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                var l = line.Trim();
                if (l.IndexOf("//", StringComparison.Ordinal) == 0)//注释
                {
                    item = new TypedefItem
                    {
                        Tag         = SystemName,
                        Description = line.Trim(CoderBase.NoneLanguageChar)
                    };
                    item.Caption = item.Description;
                }
                else
                {
                    item = CheckTypedef(result, ref item, l);
                }
            }
            foreach (var it in result)
            {
                CoderBase.RepairConfigName(it, true);
                foreach (var pro in it.Items.Values)
                {
                    CoderBase.RepairConfigName(pro, true);
                }
            }
            return(result);
        }
        public List <EntityConfig> CheckCppFieldes(string text)
        {
            List <EntityConfig> tables = new List <EntityConfig>();

            string[]     lines      = text.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            int          idx        = 0;
            EntityConfig entity     = new EntityConfig();
            bool         isNewTable = true;
            bool         isInStruct = false;

            foreach (string l in lines)
            {
                if (string.IsNullOrEmpty(l))
                {
                    continue;
                }
                var line = l.Trim(' ', '\t', ';');
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }
                switch (line)
                {
                case "{":
                    isInStruct = true;
                    continue;

                case "}":
                    isNewTable = true;
                    isInStruct = false;
                    entity     = new EntityConfig();
                    continue;
                }
                if (line.IndexOf("//", StringComparison.Ordinal) == 0) //注释
                {
                    if (isNewTable || line.Contains("//!"))
                    {
                        entity.Caption = line.Trim(CoderBase.NoneLanguageChar);
                        isNewTable     = false;
                    }
                    else
                    {
                        entity.Description = line.Trim(CoderBase.NoneLanguageChar);
                    }
                    continue;
                }
                string[] words = line.Split(new[] { ' ', ';', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                switch (words[0])
                {
                case "typedef":
                    var item = new TypedefItem
                    {
                        Tag = SystemName
                    };
                    var i = l.IndexOf('[');
                    if (i < 0)
                    {
                        item.Name = words[words.Length - 1];
                    }
                    else
                    {
                        var ks = l.Split(new[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                        item.ArrayLen = ks[1];
                        words         = ks[0].Split(new[] { '\t', ' ', ';', '=' }, StringSplitOptions.RemoveEmptyEntries);
                    }
                    item.Description = entity.Caption;
                    item.Name        = words[words.Length - 1].Trim(CoderBase.NoneLanguageChar);
                    item.KeyWork     = string.Empty;
                    for (int index = 1; index < words.Length - 1; index++)
                    {
                        item.KeyWork += " " + words[index];
                    }
                    InvokeInUiThread(() => TypedefItems.Add(item));
                    continue;

                case "struct":
                    entity.Name = words[1];
                    if (words.Length > 2)
                    {
                        entity.Caption = words[2].Trim(CoderBase.NoneNameChar);
                    }
                    tables.Add(entity);
                    isInStruct = false;
                    idx        = 0;
                    continue;

                case "private":
                case "protected":
                case "public":
                    continue;
                }
                if (!isInStruct)
                {
                    continue;
                }
                PropertyConfig column;
                entity.Properties.Add(column = new PropertyConfig
                {
                    Index  = idx++,
                    DbType = "nvarchar"
                });
                words = line.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                if (words.Length > 1)
                {
                    column.Description = column.Caption = words[1].Trim('/', '\t', ' ');
                }

                words = words[0].Split(new[] { '[', ']' }, StringSplitOptions.RemoveEmptyEntries);
                if (words.Length > 1)
                {
                    column.Datalen = int.Parse(words[1].Trim('/', '\t', ' '));
                }
                words = words[0].Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
                int nameIdx = words.Length - 1;
                column.Name    = column.ColumnName = words[nameIdx].Trim(CoderBase.NoneLanguageChar);
                column.CppType = "";
                for (int index = 0; index < nameIdx; index++)
                {
                    if (index > 0)
                    {
                        column.CppType += " " + words[index];
                    }
                    else
                    {
                        column.CppType = words[index];
                    }
                }
            }
            foreach (var t in tables)
            {
                t.Parent  = Project;
                t.Tag     = SystemName + "," + t.Name;
                t.CppName = t.Name;
                CoderBase.RepairConfigName(t, true);
                foreach (var pro in t.Properties)
                {
                    pro.Parent  = t;
                    pro.CppName = pro.CppName;
                    CoderBase.RepairConfigName(pro, true);
                    pro.CppLastType = CppTypeHelper.CppLastType(pro.CppType);
                    pro.CsType      = CppTypeHelper.CppTypeToCsType(pro);
                }
                t.IsClass = true;

                //EntityBusinessModel business = new EntityBusinessModel
                //{
                //    Entity = t
                //};
                //t.IsReference = true;
                //business.RepairByModel(true);
                //t.IsReference = false;
            }
            return(tables);
        }