Exemple #1
0
        public static void CreateNewFile(ConstructFile construct)
        {
            //ContentFile contentFile = new ContentFile(construct);
            //contentFile.Name = construct.Name;
            //contentFile.Path = construct.Path;

            ////ContentRow row = new ContentRow(contentFile);
            ////foreach (ConstructItem constructItem in construct.ConstructItems)
            ////{
            ////    for (int i = 0; i < constructItem.ItemRepeat; ++i)
            ////    {
            ////        ContentItem contentItem = new ContentItem(row, constructItem, i + 1);
            ////        if (constructItem.ItemCode == ConstructConfig.NEW_FILE_DEFAULT_ID_CODE)
            ////        {
            ////            contentItem.Value = ContentConfig.CONTENT_INIT_DEFAULT_ID;
            ////        }
            ////        else
            ////        {
            ////            contentItem.Value = "";
            ////        }
            ////        row.AddContentItem(contentItem);
            ////    }
            ////}

            ////contentFile.AddContentRow(row);

            //TableContentManager.Instance.AddContentFile(contentFile);
        }
Exemple #2
0
        public static void CreateNewFile(ConstructFile construct)
        {
            ContentFile contentFile = new ContentFile(construct);

            contentFile.Name = construct.Name;

            ContentRow row = new ContentRow(contentFile);

            foreach (ConstructItem constructItem in construct.ConstructItems)
            {
                for (int i = 0; i < constructItem.ItemRepeat; ++i)
                {
                    ContentItem contentItem = new ContentItem(row, constructItem, i + 1);
                    if (constructItem.ItemCode == ConstructConfig.NEW_FILE_DEFAULT_ID_CODE)
                    {
                        contentItem.Value = ContentConfig.CONTENT_INIT_DEFAULT_ID;
                    }
                    else
                    {
                        contentItem.Value = "";
                    }
                    row.AddContentItem(contentItem);
                }
            }

            contentFile.AddContentRow(row);

            TableContentManager.Instance.AddContentFile(contentFile);
        }
Exemple #3
0
        public static ContentRow ReadRow(ConstructFile construct, DataRecord data, ContentFile contentFile)
        {
            ContentRow row = new ContentRow(contentFile);

            try
            {
                row.IsInit = true;
                foreach (ConstructItem constructItem in construct.ConstructItems)
                {
                    ReadItem(constructItem, data, ref row);
                }
                row.IsInit = false;
                //if (row.ContentItems.Count != 0)
                //{
                //    row.Name = row.ContentItems[0].Value.ToString();
                //}
            }
            catch (Exception e)
            {
                throw new Exception("read exception:" + e);
            }
            row.WriteFlag = false;
            row._ContentItems.WriteFlag = false;
            return(row);
        }
Exemple #4
0
        public static void ReadContentFile(ConstructFile construct)
        {
            ContentFile contentFile = new ContentFile(construct);

            contentFile.Name   = construct.Name;
            contentFile.IsInit = true;

            ReadContentFile(construct, ref contentFile);
        }
        private void MenuItem_Remove(object sender, RoutedEventArgs e)
        {
            ConstructFile fileInfo = LinkList.SelectedItem as ConstructFile;

            if (fileInfo == null)
            {
                return;
            }

            ConstructFold.Instance.RemoveFile(fileInfo.Name);
        }
        private void MenuItem_Rename(object sender, RoutedEventArgs e)
        {
            ConstructFile fileInfo = LinkList.SelectedItem as ConstructFile;

            if (fileInfo == null)
            {
                return;
            }

            string newName = DialogMessage.DialogString();

            if (!string.IsNullOrEmpty(newName))
            {
                ConstructFold.Instance.RenameFile(fileInfo.Name, newName);
            }
        }
Exemple #7
0
        private static bool IsHeaderMatch(ConstructFile constructFile, HeaderRecord fileHeader)
        {
            var titles = constructFile.GetColumnTitles();

            for (int i = 0; i < fileHeader.Count; ++i)
            {
                if (i < titles.Length)
                {
                    if (titles[i] != fileHeader[i])
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Exemple #8
0
        public static void ReadContentFile(ConstructFile construct, ref ContentFile contentFile)
        {
            string path = TableGlobalConfig.Instance.ResTablePath + "\\" + construct.Path + construct.Name + ".csv";

            if (!string.IsNullOrEmpty(construct.OldName))
            {
                path = TableGlobalConfig.Instance.ResTablePath + "\\" + construct.Path + construct.OldName + ".csv";
            }

            if (!File.Exists(path))
            {
                //CreateNewFile(construct);
                TableContentManager.Instance.AddContentFile(contentFile);
                return;
            }

            string[] lines = File.ReadAllLines(path, Encoding.Default);
            if (lines.Length == 0)
            {
                return;
            }

            contentFile.ContentRow.Clear();
            lines[0] = lines[0].Replace("\r\n", "\n");
            StringReader rdr = new StringReader(string.Join("\n", lines));

            using (var reader = new CsvReader(rdr))
            {
                HeaderRecord header = reader.ReadHeaderRecord();
                //string curGourpName = "";
                //string curClassName = "";



                var columnTitles = construct.GetColumnTitles();
                while (reader.HasMoreRecords)
                {
                    DataRecord data = reader.ReadDataRecord();
                    //if (data[0].StartsWith("###"))
                    //{
                    //    curGourpName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    //if (data[0].StartsWith("##"))
                    //{
                    //    curClassName = data[0].TrimStart('#');
                    //    continue;
                    //}

                    ContentRow clumn = ReadRow(construct, data, contentFile);
                    contentFile.AddContentRow(clumn);
                }

                if (IsHeaderMatch(construct, header))
                {
                    contentFile.WriteFlag = false;
                }
                else
                {
                    contentFile.WriteFlag = true;
                }
                contentFile.IsInit = false;
                TableContentManager.Instance.AddContentFile(contentFile);
            }
        }
Exemple #9
0
 public ContentFile(ConstructFile construct)
 {
     _ConstuctFile = construct;
 }
Exemple #10
0
        private void CSCreateTableFile(ConstructFile constructFile, string filePath)
        {
            var builder  = new StringBuilder();
            var itemInit = new StringBuilder();

            //record
            builder.Append("using System;\n");
            builder.Append("using System.IO;\n");
            builder.Append("using System.Text;\n");
            builder.Append("using System.Collections.Generic;\n");
            builder.Append("using Kent.Boogaart.KBCsv;\n\n");
            builder.Append("using UnityEngine;\n\n");
            builder.Append("namespace Tables\n");
            builder.Append("{\n");

            builder.Append("    public partial class " + constructFile.Name + "Record  : TableRecordBase\n");
            builder.Append("    {\n");
            builder.Append("        public DataRecord ValueStr;\n\n");
            foreach (ConstructItem constructItem in constructFile.ConstructItems)
            {
                string typeCode = CSTableItemTypeCode(constructItem);
                builder.Append("        public " + typeCode + " " + constructItem.ItemCode + " { get; set; }\n");
                if (typeCode.Contains("List"))
                {
                    itemInit.Append("            " + constructItem.ItemCode +
                                    " = new " + typeCode + "();\n");
                }
            }

            builder.Append("        public " + constructFile.Name + "Record(DataRecord dataRecord)\n");
            builder.Append("        {\n");
            builder.Append("            if (dataRecord != null)\n");
            builder.Append("            {\n");
            builder.Append("                ValueStr = dataRecord;\n");
            builder.Append("                Id = ValueStr[0];\n\n");
            builder.Append("            }\n");
            builder.Append(itemInit);

            builder.Append("        }\n");
            builder.Append("        public string[] GetRecordStr()\n");
            builder.Append("        {\n");
            builder.Append("            List<string> recordStrList = new List<string>();\n");
            for (int i = 0; i < constructFile.ConstructItems.Count; ++i)
            {
                var constructItem = constructFile.ConstructItems[i] as ConstructItem;
                if (constructItem.ItemRepeat > 1)
                {
                    builder.Append("            foreach (var testTableItem in " + constructItem.ItemCode + ")\n");
                    builder.Append("            {\n");
                    if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID &&
                        constructItem.ItemType2.Count == 1)
                    {
                        builder.Append("                if (testTableItem != null)\n");
                        builder.Append("                {\n");
                        builder.Append("                    recordStrList.Add(testTableItem.Id);\n");
                        builder.Append("                }\n");
                        builder.Append("                else\n");
                        builder.Append("                {\n");
                        builder.Append("                    recordStrList.Add(\"\");\n");
                        builder.Append("                }\n");
                    }
                    else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM)
                    {
                        builder.Append("                recordStrList.Add(((int)testTableItem).ToString());\n");
                    }
                    else
                    {
                        builder.Append("                recordStrList.Add(TableWriteBase.GetWriteStr(testTableItem));\n");
                    }
                    builder.Append("            }\n");
                }
                else
                {
                    if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_TABLE_ID &&
                        constructItem.ItemType2.Count == 1)
                    {
                        builder.Append("            if (" + constructItem.ItemCode + " != null)\n");
                        builder.Append("            {\n");
                        builder.Append("                recordStrList.Add(" + constructItem.ItemCode + ".Id);\n");
                        builder.Append("            }\n");
                        builder.Append("            else\n");
                        builder.Append("            {\n");
                        builder.Append("                recordStrList.Add(\"\");\n");
                        builder.Append("            }\n");
                    }
                    else if (constructItem.ItemType1 == ConstructConfig.CONSTRUCT_ITEM_TYPE_ENUM)
                    {
                        builder.Append("            recordStrList.Add(((int)" + constructItem.ItemCode + ").ToString());\n");
                    }
                    else
                    {
                        builder.Append("            recordStrList.Add(TableWriteBase.GetWriteStr(" + constructItem.ItemCode + "));\n");
                    }
                }
            }
            builder.Append("\n            return recordStrList.ToArray();\n");
            builder.Append("        }\n");
            builder.Append("    }\n\n");

            //for info
            builder.Append("    public partial class " + constructFile.Name + " : TableFileBase\n");
            builder.Append("    {\n");
            builder.Append("        public Dictionary<string, " + constructFile.Name + "Record> Records { get; internal set; }\n\n");
            builder.Append("        public bool ContainsKey(string key)\n");
            builder.Append("        {\n");
            builder.Append("             return Records.ContainsKey(key);\n");
            builder.Append("        }\n\n");
            builder.Append("        public " + constructFile.Name + "Record GetRecord(string id)\n");
            builder.Append("        {\n");
            builder.Append("            try\n");
            builder.Append("            {\n");
            builder.Append("                return Records[id];\n");
            builder.Append("            }\n");
            builder.Append("            catch (Exception ex)\n");
            builder.Append("            {\n");
            builder.Append("                throw new Exception(\"" + constructFile.Name + "\" + \": \" + id, ex);\n");
            builder.Append("            }\n");
            builder.Append("        }\n\n");
            builder.Append("        public " + constructFile.Name + "(string pathOrContent,bool isPath = true)\n");
            builder.Append("        {\n");
            builder.Append("            Records = new Dictionary<string, " + constructFile.Name + "Record>();\n");
            builder.Append("            if(isPath)\n");
            builder.Append("            {\n");
            builder.Append("                string[] lines = File.ReadAllLines(pathOrContent, Encoding.Default);\n");
            builder.Append("                lines[0] = lines[0].Replace(\"\\r\\n\", \"\\n\");\n");
            builder.Append("                ParserTableStr(string.Join(\"\\n\", lines));\n");
            builder.Append("            }\n");
            builder.Append("            else\n");
            builder.Append("            {\n");
            builder.Append("                ParserTableStr(pathOrContent.Replace(\"\\r\\n\", \"\\n\"));\n");
            builder.Append("            }\n");
            builder.Append("        }\n\n");
            builder.Append("        private void ParserTableStr(string content)\n");
            builder.Append("        {\n");
            builder.Append("            StringReader rdr = new StringReader(content);\n");
            builder.Append("            using (var reader = new CsvReader(rdr))\n");
            builder.Append("            {\n");
            builder.Append("                HeaderRecord header = reader.ReadHeaderRecord();\n");
            builder.Append("                while (reader.HasMoreRecords)\n");
            builder.Append("                {\n");
            builder.Append("                    DataRecord data = reader.ReadDataRecord();\n");
            builder.Append("                    if (data[0].StartsWith(\"#\"))\n");
            builder.Append("                        continue;\n\n");
            builder.Append("                    " + constructFile.Name + "Record record = new " + constructFile.Name + "Record(data);\n");
            builder.Append("                    Records.Add(record.Id, record);\n");
            builder.Append("                }\n");
            builder.Append("            }\n");
            builder.Append("        }\n\n");
            builder.Append("        public void CoverTableContent()\n");
            builder.Append("        {\n");
            builder.Append("            foreach (var pair in Records)\n");
            builder.Append("            {\n");

            int dataIdx = 0;

            for (int i = 1; i < constructFile.ConstructItems.Count; ++i)
            {
                ++dataIdx;
                var constructItem = constructFile.ConstructItems[i] as ConstructItem;
                if (constructItem.ItemRepeat > 1)
                {
                    for (int j = 0; j < constructItem.ItemRepeat; ++j)
                    {
                        builder.Append(CSTableItemParseCode(constructItem, dataIdx, j));
                        if (j != constructItem.ItemRepeat - 1)
                        {
                            ++dataIdx;
                        }
                    }
                }
                else
                {
                    builder.Append(CSTableItemParseCode(constructItem, dataIdx, -1));
                }
            }

            builder.Append("            }\n");
            builder.Append("        }\n");
            builder.Append("    }\n");

            builder.Append("\n");
            builder.Append("}");

            File.WriteAllText(filePath, builder.ToString(), Encoding.UTF8);
        }