コード例 #1
0
ファイル: GenPrefab_TS.cs プロジェクト: neshlabs/nesh
        private static string GenEntityTables(XMLEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(GenUtils.str_tab).Append("export namespace Tables").AppendLine();
            sb.Append(GenUtils.str_tab).Append("{").AppendLine();

            foreach (TablePrefab table in entity.tables.Values)
            {
                string className = FormatSplit(table.name);
                sb.Append(GenUtils.str_tab2).Append("export namespace ").Append(className.ToString()).AppendLine();
                sb.Append(GenUtils.str_tab2 + "{").AppendLine();

                sb.Append(GenUtils.str_tab3).Append($"export const TABLE_NAME = \"{table.name}\";").AppendLine();

                foreach (TablePrefab.ColumnPrefab column in table.columns.Values)
                {
                    sb.AppendLine();
                    sb.Append(GenUtils.str_tab3).Append($"export const COL_{column.name.ToUpper()}: number = {column.index};").AppendLine();
                }

                sb.AppendLine();
                sb.Append(GenUtils.str_tab2 + "}").AppendLine();
                sb.AppendLine();
            }

            sb.Append(GenUtils.str_tab + "}") /*.AppendLine()*/;

            return(sb.ToString());
        }
コード例 #2
0
ファイル: GenPrefab_CS.cs プロジェクト: neshlabs/nesh
        private static string GenEntityTables(XMLEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            string parent_name = entity.GetEntityParentFormat();

            if (!string.IsNullOrEmpty(parent_name) && entity.Parent != null && entity.Parent.tables.Count >= 0)
            {
                sb.Append(GenUtils.str_tab2 + "public new class Tables").Append(" : ").Append(parent_name).Append(".Tables");
            }
            else
            {
                sb.Append(GenUtils.str_tab2 + "public class Tables");
            }

            sb.AppendLine();
            sb.Append(GenUtils.str_tab2 + "{");
            sb.AppendLine();

            foreach (TablePrefab table in entity.SelfTables)
            {
                string className = FormatSplit(table.name);
                sb.Append(GenUtils.str_tab3).Append("public class ").Append(className.ToString());
                sb.AppendLine();
                sb.Append(GenUtils.str_tab3 + "{");

                sb.AppendLine();
                sb.Append(GenUtils.str_tab4).Append("/// <summary>").AppendLine();
                sb.Append(GenUtils.str_tab4).AppendFormat("/// {0} Save={1} Sync={2}", table.desc, table.save, table.sync).AppendLine();
                sb.Append(GenUtils.str_tab4).Append("/// </summary>");

                sb.AppendLine().Append(GenUtils.str_tab4);
                sb.Append("public const string TABLE_NAME = \"").Append(table.name).Append("\";");

                sb.AppendLine();

                foreach (TablePrefab.ColumnPrefab column in table.columns.Values)
                {
                    sb.AppendLine();
                    sb.Append(GenUtils.str_tab4).Append("/// <summary>").AppendLine();
                    sb.Append(GenUtils.str_tab4).AppendFormat("/// {0} {1}", column.desc, column.type).AppendLine();
                    sb.Append(GenUtils.str_tab4).Append("/// </summary>");

                    sb.AppendLine().Append(GenUtils.str_tab4);
                    sb.Append("public const int COL_").Append(column.name.ToUpper()).Append(" = ").Append(column.index).Append(";");
                }

                sb.AppendLine();
                sb.Append(GenUtils.str_tab3 + "}");
                sb.AppendLine();
            }
            sb.AppendLine();
            sb.Append(GenUtils.str_tab2 + "}") /*.AppendLine()*/;

            return(sb.ToString());
        }
コード例 #3
0
ファイル: GenPrefab_CS.cs プロジェクト: neshlabs/nesh
        private static void GenEntityCode(XMLEntity entity, string basepath)
        {
            string entity_path = basepath + GenUtils.RESOURCE_ENTITY_FOLDER;
            string entity_type = GenUtils.FormatName(entity.type);
            string filePath    = entity_path + entity_type + ".cs";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            FileInfo fi = new FileInfo(filePath);
            var      di = fi.Directory;

            if (!di.Exists)
            {
                di.Create();
            }

            FileStream    fs = new FileStream(filePath, FileMode.CreateNew);
            StreamWriter  sw = new StreamWriter(fs, Encoding.UTF8);
            StringBuilder sb = new StringBuilder(GenUtils.RESOURCE_ENTITY_NAMESPACE);

            sb.AppendLine();
            sb.Append("{");
            sb.AppendLine();

            sb.Append(GenUtils.str_tab);

            string namespce_object = GenEntityNamespace(entity);

            Console.WriteLine(namespce_object);

            string Fields = GenEntityFields(entity);

            Console.WriteLine(Fields);

            string Tables = GenEntityTables(entity);

            Console.WriteLine(Tables);

            sb.AppendLine(namespce_object);
            sb.AppendLine(Fields);
            sb.AppendLine(Tables);

            //sb.AppendLine();
            sb.Append(GenUtils.str_tab + "}");

            sb.AppendLine();
            sb.Append("}");
            sw.Write(sb.ToString());
            sw.Close();
            fs.Close();
        }
コード例 #4
0
        private static void LoadTables(ref XMLEntity entity, XmlNode tables_node)
        {
            if (tables_node == null)
            {
                return;
            }

            foreach (XmlNode table_node in tables_node.ChildNodes)
            {
                TablePrefab table_prefab = new TablePrefab();
                table_prefab.name = table_node.Attributes["name"].Value;
                table_prefab.save = bool.Parse(table_node.Attributes["save"].Value);
                table_prefab.sync = bool.Parse(table_node.Attributes["sync"].Value);
                table_prefab.desc = table_node.Attributes["desc"].Value;
                table_prefab.cols = int.Parse(table_node.Attributes["cols"].Value);

                foreach (XmlNode child_node in table_node.ChildNodes)
                {
                    if (child_node.Name == "primary_key")
                    {
                        TablePrefab.PrimaryKeyPrefab primary_key = new TablePrefab.PrimaryKeyPrefab();
                        primary_key.type = Enum.Parse <VarType>(child_node.Attributes["type"].Value);
                        primary_key.name = child_node.Attributes["name"].Value;
                        primary_key.desc = child_node.Attributes["desc"].Value;

                        table_prefab.primary_key = primary_key;
                    }
                    else if (child_node.Name == "column")
                    {
                        TablePrefab.ColumnPrefab column = new TablePrefab.ColumnPrefab();
                        column.index = int.Parse(child_node.Attributes["index"].Value);
                        column.type  = Enum.Parse <VarType>(child_node.Attributes["type"].Value);
                        column.name  = child_node.Attributes["name"].Value;
                        column.desc  = child_node.Attributes["desc"].Value;

                        table_prefab.columns.Add(column.index, column);
                    }
                }


                if (table_prefab.columns.Count != table_prefab.cols ||
                    table_prefab.columns.Keys.ToList()[0] != 0 ||
                    table_prefab.columns.Keys.ToList()[table_prefab.cols - 1] != (table_prefab.cols - 1))
                {
                    throw new Exception($"{entity.type} table {table_prefab.name} columns config failed");
                }

                entity.SelfTables.Add(table_prefab);
            }
        }
コード例 #5
0
ファイル: GenPrefab_TS.cs プロジェクト: neshlabs/nesh
        private static string GenEntityFields(XMLEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(GenUtils.str_tab).Append("export namespace Fields").AppendLine();

            sb.Append(GenUtils.str_tab + "{").AppendLine();

            foreach (FieldPrefab field in entity.fields.Values)
            {
                sb.Append(GenUtils.str_tab2).Append("export const ").Append(field.name.ToUpper()).Append($": string = \"{field.name}\";").AppendLine();
                sb.AppendLine();
            }

            sb.Append(GenUtils.str_tab + "}").AppendLine();

            return(sb.ToString());
        }
コード例 #6
0
        private static void FindAncestor(ref XMLEntity entity, XMLEntity ancestor)
        {
            if (ancestor != null)
            {
                entity.ancestors.Add(ancestor.type);

                foreach (FieldPrefab field in ancestor.SelfFields)
                {
                    entity.fields.Add(field.name, field);
                }

                foreach (TablePrefab table in ancestor.SelfTables)
                {
                    entity.tables.Add(table.name, table);
                }

                FindAncestor(ref entity, ancestor.Parent);
            }
        }
コード例 #7
0
        private static void LoadFields(ref XMLEntity entity, XmlNode fields_node)
        {
            if (fields_node == null)
            {
                return;
            }

            foreach (XmlNode field_node in fields_node.ChildNodes)
            {
                FieldPrefab field_prefab = new FieldPrefab();
                field_prefab.name = field_node.Attributes["name"].Value;
                field_prefab.type = Enum.Parse <VarType>(field_node.Attributes["type"].Value);
                field_prefab.save = bool.Parse(field_node.Attributes["save"].Value);
                field_prefab.sync = bool.Parse(field_node.Attributes["sync"].Value);
                field_prefab.desc = field_node.Attributes["desc"].Value;

                entity.SelfFields.Add(field_prefab);
            }
        }
コード例 #8
0
        private static void LoadEntity(XmlNode xml_node, XMLEntity parent = null)
        {
            string type = xml_node.Attributes["type"].Value;
            string path = xml_node.Attributes["path"].Value;

            if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(path))
            {
                Console.WriteLine("{0} Load Fail type or path config error!!", xml_node.Name);
                return;
            }

            string       file_name = Path.Combine(_DevPath, path);
            string       content   = "";
            StreamReader sr        = new StreamReader(file_name, Encoding.UTF8);

            content = sr.ReadToEnd();
            sr.Close();

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(content);
            XmlNode root = xml.FirstChild;

            XMLEntity entity = new XMLEntity();

            entity.Parent = parent;
            entity.type   = type;
            if (xml_node.Attributes["priority"] != null)
            {
                entity.priority = int.Parse(xml_node.Attributes["priority"].Value);
            }

            LoadFields(ref entity, root["fields"]);
            LoadTables(ref entity, root["tables"]);
            LoadIncludes(ref entity, root["includes"]);

            _XMLEntities.Add(entity.type, entity);

            foreach (XmlNode sub_node in xml_node.ChildNodes)
            {
                LoadEntity(sub_node, entity);
            }
        }
コード例 #9
0
        private static void LoadIncludes(ref XMLEntity entity, XmlNode includes_node)
        {
            if (includes_node == null)
            {
                return;
            }

            foreach (XmlNode include_node in includes_node.ChildNodes)
            {
                string       include_path = Path.Combine(_DevPath, include_node.Attributes["path"].Value);
                StreamReader sr           = new StreamReader(include_path, Encoding.UTF8);
                string       content      = sr.ReadToEnd();
                sr.Close();

                XmlDocument xml = new XmlDocument();
                xml.Load(content);

                LoadFields(ref entity, include_node["fields"]);
                LoadTables(ref entity, include_node["tables"]);
                LoadIncludes(ref entity, include_node["includes"]);
            }
        }
コード例 #10
0
ファイル: GenPrefab_CS.cs プロジェクト: neshlabs/nesh
        private static string GenEntityFields(XMLEntity entity)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(GenUtils.str_tab2);

            string parent_name = entity.GetEntityParentFormat();

            if (!string.IsNullOrEmpty(parent_name) && entity.Parent != null && entity.Parent.fields.Count >= 0)
            {
                sb.Append("public new class Fields").Append(" : ").Append(parent_name).Append(".Fields");
            }
            else
            {
                sb.Append("public class Fields");
            }
            sb.AppendLine();
            sb.Append(GenUtils.str_tab2 + "{");

            foreach (FieldPrefab field in entity.SelfFields)
            {
                sb.AppendLine();
                sb.Append(GenUtils.str_tab3).Append("/// <summary>").AppendLine();
                sb.Append(GenUtils.str_tab3).AppendFormat("/// {0} {1} Save={2} Sync={3}", field.desc, field.type, field.save, field.sync).AppendLine();
                sb.Append(GenUtils.str_tab3).Append("/// </summary>").AppendLine();

                sb.Append(GenUtils.str_tab3).Append("public const string ").Append(field.name.ToUpper()).Append(" = \"");
                sb.Append(field.name).Append("\";");

                //sb.AppendLine();
            }

            sb.AppendLine();
            sb.Append(GenUtils.str_tab2 + "}");
            sb.AppendLine();

            return(sb.ToString());
        }
コード例 #11
0
        private static void LoadEntities()
        {
            string       sb      = Path.Combine(_DevPath, "entities.xml");
            string       content = "";
            StreamReader sr      = new StreamReader(sb.ToString(), Encoding.UTF8);

            content = sr.ReadToEnd();
            sr.Close();

            XmlDocument xml = new XmlDocument();

            xml.LoadXml(content);
            XmlNode root = xml.FirstChild;

            foreach (XmlNode xml_node in xml.FirstChild.ChildNodes)
            {
                LoadEntity(xml_node);
            }

            foreach (string type in _XMLEntities.Keys)
            {
                XMLEntity entity = _XMLEntities[type];

                foreach (FieldPrefab field in entity.SelfFields)
                {
                    entity.fields.Add(field.name, field);
                }

                foreach (TablePrefab table in entity.SelfTables)
                {
                    entity.tables.Add(table.name, table);
                }

                FindAncestor(ref entity, entity.Parent);
            }
        }