internal void Format3(object arg) { foreach (var property in Context.SelectEntity.Properties) { property.JsonName = CoderBase.ToLinkWordName(property.Name, "_", false); } }
private static void FindEnumOld(TypedefItem type, EnumConfig enumConfig) { foreach (var item in type.Items.Values) { var oi = enumConfig.Items.FirstOrDefault(p => p.Option.ReferenceKey == item.Key); if (oi != null) { continue; } enumConfig.Add(oi = new EnumItem { Name = CoderBase.ToWordName(item.Name), Value = item.Value }); oi.Option.ReferenceKey = item.Key; } enumConfig.Option.ReferenceKey = type.Key; if (enumConfig.Items.All(p => !string.Equals(p.Name, "None", StringComparison.OrdinalIgnoreCase))) { enumConfig.Add(new EnumItem { Name = "None", Caption = "未知", Value = "0" }); } var items = enumConfig.Items.OrderBy(p => p.Value).ToArray(); enumConfig.Items.Clear(); foreach (var item in items) { enumConfig.Add(item); } }
public List <NotifyItem> CheckNotify(string txt) { var result = new List <NotifyItem>(); var lines = txt.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); List <NameValue> des = new List <NameValue>(); List <string> api_line = new List <string>(); foreach (var line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } api_line.Add(line); var l = line.Trim(); if (l.IndexOf("//", StringComparison.Ordinal) == 0)//注释 { l = l.Trim(CoderBase.NoneLanguageChar); if (string.IsNullOrWhiteSpace(l)) { continue; } var str = l.Split(CoderBase.EmptyChar, 2); if (str.Length >= 2) { des.Add(new NameValue(str[0], str[1])); } else if (des.Count > 0) { des.Last().value += l; } continue; } l = l.Trim(CoderBase.NoneNameChar); if (string.IsNullOrWhiteSpace(l)) { continue; } var item = CheckNotifyItem(l); if (des.Count > 1) { var dess = des.FirstOrDefault(p => p.name == "brief"); item.Caption = dess?.value.Split(CoderBase.NoneNameChar, 2)[0]; item.Description = dess?.value; } item.Org = api_line.LinkToString("\n"); result.Add(item); api_line.Clear(); des.Clear(); } foreach (var it in result) { CoderBase.RepairConfigName(it, true); } return(result); }
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); }
private void DoImport() { _trace.Message1 = "连接数据库"; _trace.Track = _connectionString; using (MySqlConnection connection = new MySqlConnection(_connectionString)) { _trace.Track = "正在连接..."; connection.Open(); _trace.Track = "连接成功"; var tables = new List <string>(); _trace.Message1 = "分析数据表"; using (var cmd = connection.CreateCommand()) { _trace.Message2 = "读取表名"; _trace.Track = "正在读取表名..."; cmd.CommandText = $@"select Table_Name from information_schema.tables where table_schema='{_database}' and table_type='base table';"; using (var reader = cmd.ExecuteReader()) { if (!reader.HasRows) { _trace.Message1 = "没有任何表"; return; } while (reader.Read()) { tables.Add(reader.GetString(0)); } } _trace.Track = $@"读取成功({tables.Count})"; } _trace.Message1 = "分析表结构"; foreach (var t in tables) { string table = t; bool isnew = false; _trace.Message2 = table; var entity = _solution.Entities.FirstOrDefault(p => string.Equals(p.SaveTable, table, StringComparison.OrdinalIgnoreCase)); if (entity == null) { isnew = true; entity = new EntityConfig { ReadTableName = table, Name = CoderBase.ToWordName(table), Project = _database }; _trace.Track = @"新增的表"; entity.Caption = BaiduFanYi.FanYi(entity.Name); _dispatcher.Invoke(() => { _project.Entities.Add(entity); _solution.Entities.Add(entity); }); } _trace.Message3 = "列分析"; using (var cmd = connection.CreateCommand()) { LoadColumn(_database, cmd, table, entity, isnew); } } } _trace.Message1 = "完成"; }
/* * `TABLE_CATALOG` AS `TABLE_CATALOG`, * `TABLE_SCHEMA` AS `TABLE_SCHEMA`, * `TABLE_NAME` AS `TABLE_NAME`, * `COLUMN_NAME` AS `COLUMN_NAME`, * `ORDINAL_POSITION` AS `ORDINAL_POSITION`, * `COLUMN_DEFAULT` AS `COLUMN_DEFAULT`, * `IS_NULLABLE` AS `IS_NULLABLE`, * `DATA_TYPE` AS `DATA_TYPE`, * `CHARACTER_MAXIMUM_LENGTH` AS `CHARACTER_MAXIMUM_LENGTH`, * `CHARACTER_OCTET_LENGTH` AS `CHARACTER_OCTET_LENGTH`, * `NUMERIC_PRECISION` AS `NUMERIC_PRECISION`, * `NUMERIC_SCALE` AS `NUMERIC_SCALE`, * `DATETIME_PRECISION` AS `DATETIME_PRECISION`, * `CHARACTER_SET_NAME` AS `CHARACTER_SET_NAME`, * `COLLATION_NAME` AS `COLLATION_NAME`, * `COLUMN_TYPE` AS `COLUMN_TYPE`, * `COLUMN_KEY` AS `COLUMN_KEY`, * `EXTRA` AS `EXTRA`, * `PRIVILEGES` AS `PRIVILEGES`, * `COLUMN_COMMENT` AS `COLUMN_COMMENT`, * `GENERATION_EXPRESSION` AS `GENERATION_EXPRESSION` */ private void LoadColumn(string db, MySqlCommand cmd, string table, EntityConfig entity, bool isNewEntity) { cmd.CommandText = $@"select COLUMN_NAME,IS_Nullable,DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,COLUMN_KEY,COLUMN_COMMENT,EXTRA from information_schema.columns where table_schema='{ db}' and table_name='{table}'"; using (var reader = cmd.ExecuteReader()) { if (!reader.HasRows) { return; } while (reader.Read()) { var field = reader.GetString(0); _trace.Message4 = field; if (field == null) { continue; } var dbType = reader.GetString(2); var column = entity.Properties.FirstOrDefault(p => string.Equals(p.ColumnName, field, StringComparison.OrdinalIgnoreCase)); bool isNew = isNewEntity; if (column == null) { _trace.Track = @"新字段"; isNew = true; column = new PropertyConfig { ColumnName = field, DbType = dbType, CsType = ToCstringType(dbType), Parent = entity }; InvokeInUiThread(() => entity.Properties.Add(column)); if (!reader.IsDBNull(5)) { column.Caption = reader.GetString(5); } column.Description = column.Caption; } else if (column.DbType != dbType) { _trace.Track = $@"字段类型变更:{column.DbType }->{dbType}"; column.DbType = dbType; column.CsType = ToCstringType(column.DbType); } column.DbNullable = reader.GetString(1) == "YES"; column.IsPrimaryKey = reader.GetString(4) == "PRI"; if (!reader.IsDBNull(3)) { column.Datalen = (int)reader.GetInt64(3); } if (!reader.IsDBNull(6)) { var ext = reader.GetString(6); column.IsIdentity = ext.Contains("auto_increment"); if (column.IsIdentity) { _trace.Track = @"自增列"; } } if (!isNew) { continue; } _trace.Track = @"分析属性名称"; switch (column.DbType.ToLower()) { case "varchar": case "longtext": column.Name = FirstBy(column.ColumnName, "m_str", "M_str", "m_", "M_"); break; case "int": case "tinyint": column.Name = FirstBy(column.ColumnName, "m_b", "m_n", "m_", "M_"); break; case "double": column.Name = FirstBy(column.ColumnName, "m_d", "m_", "M_"); break; default: column.Name = FirstBy(column.ColumnName, "m_", "M_"); break; } column.Name = CoderBase.ToWordName(column.Name ?? column.ColumnName); _trace.Track = $@"属性名称:{column.Name}"; if (string.IsNullOrWhiteSpace(column.Caption)) { column.Caption = BaiduFanYi.FanYi(column.Name); _trace.Track = $@"通过百度翻译得到中文名称:{column.Caption}"; } else { CheckEnum(column); if (column.EnumConfig != null) { column.EnumConfig.Name = column.Name + "Type"; column.EnumConfig.Caption = column.Caption + "自定义类型"; column.CustomType = column.EnumConfig.Name; _trace.Track = $@"解析得到枚举类型:{column.EnumConfig.Name},参考内容{column.EnumConfig.Description}"; } } if (string.IsNullOrWhiteSpace(column.Description)) { column.Description = column.Caption; } column.Caption = column.Caption.Split(CoderBase.NoneLanguageChar, 2)[0]; } } }
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); }