public static bool LoadData(string path)
        {
            FileStream file = new FileStream(path, FileMode.Open);

            excel_table table = new excel_table();

            if (file.Length <= 0)
            {
                Console.WriteLine("ConfigManager:LoadData:文件" + path + "为空");
                return(false);
            }
            var data = new byte[file.Length];

            file.Read(data, 0, data.Length);
            table.MergeFrom(data);

            //var configType = CONFIG_TYPE.Parse(table.ProtoMsgName.ToStringUtf8().ToUpper());
            var tablePath = table.Path;

            foreach (var lineData in table.Table)
            {
                int index = lineData.Key;
                foreach (var cell in lineData.Value.CellData)
                {
                }
            }
            return(true);
        }
Example #2
0
        public static void test3()
        {
            FileStream file = new FileStream("all.proto.dat", FileMode.Open);

            Console.WriteLine(file.Length);
            excel_proto proto = new excel_proto();

            proto.MergeFrom(file);
            Console.WriteLine(proto.ToString());
            foreach (var it in proto.AllProto)
            {
                Console.WriteLine(it.Key);
                Console.WriteLine(it.Value.ToStringUtf8());
            }

            var         dataFile = new FileStream("test.dat", FileMode.Open);
            excel_table table    = new excel_table();

            table.MergeFrom(dataFile);
            Console.WriteLine(table.ProtoMsgName);
            foreach (var it in table.Table)
            {
                foreach (var cell in it.Value.CellData)
                {
                    Console.WriteLine("int=" + cell.Int32Value + ",float=" + cell.FloatValue);
                }
            }
            Console.ReadKey();
        }
Example #3
0
        public bool BeginMessage(string inputMsgName, string path, List <string> descList, List <string> nameList, List <string> typeList)
        {
            filePath = path;
            msgName  = inputMsgName.ToLower();
            dataStructMap.Clear();
            structMap.Clear();
            indexPathAll.Clear();
            index2Type.Clear();
            table_data = new excel_table();

            if (nameList.Count <= 0 || nameList.Count != typeList.Count || nameList.Count != descList.Count)
            {
                ConsoleError(inputMsgName, -1, "类型解析内容为空");
                return(false);
            }

            for (int j = 0; j < nameList.Count; ++j)
            {
                var indexPath = new List <DataTypeKey>();
                indexPathAll.Add(indexPath);
                var sectionDesc = descList[j];
                var section     = nameList[j];
                var sectionType = typeList[j];
                if (sectionDesc.Length <= 0)
                {
                    ConsoleError(inputMsgName, j, "注释为空");
                    return(false);
                }
                if (section.Length <= 0)
                {
                    ConsoleError(inputMsgName, j, "字段名称为空");
                    return(false);
                }
                if (sectionType.Length <= 0)
                {
                    ConsoleError(inputMsgName, j, "字段类型为空");
                    return(false);
                }

                var curMap         = structMap;
                var pDataStructMap = dataStructMap;

                var sectionTypeSplit = Utils.Split(sectionType, "$");
                var indexVec         = new List <int>();
                if (sectionTypeSplit.Length == 2)
                {
                    int index = int.Parse(sectionTypeSplit[1]);
                    while (index > 0)
                    {
                        int tempIndex = index % 100;
                        if (tempIndex <= 0)
                        {
                            ConsoleError(inputMsgName, j, "索引错误");
                            return(false);
                        }
                        indexVec.Insert(0, tempIndex);
                        index = index / 100;
                    }
                    if (indexVec.Count <= 0)
                    {
                        //索引是空的
                        ConsoleError(inputMsgName, j, "索引是空的");
                        return(false);
                    }

                    sectionTypeSplit = Utils.Split(sectionTypeSplit[0], "#");
                }
                else if (sectionTypeSplit.Length != 1)
                {
                    ConsoleError(inputMsgName, j, "字段类型分隔符$数量不正确");
                    return(false);
                }
                else
                {
                    sectionTypeSplit = Utils.Split(sectionTypeSplit[0], "#");
                }

                var sectionSplit = Utils.Split(section, "#");
                if (sectionTypeSplit.Length <= 0 || sectionSplit.Length != sectionTypeSplit.Length)
                {
                    //类型同字段数量不匹配
                    ConsoleError(inputMsgName, j, "字段类型与字段名字个数不符");
                    return(false);
                }

                int usedIndexNum = 0;
                for (int k = 0; k < sectionTypeSplit.Length; ++k)
                {
                    var tempSection = sectionSplit[k].ToLower();

                    var tempSectionType      = sectionTypeSplit[k];
                    var tempSectionTypeSplit = Utils.Split(tempSectionType, "_ARRAY");
                    if (tempSectionTypeSplit.Length != 1)
                    {
                        //类型错误
                        ConsoleError(inputMsgName, j, "字段类型可能包含不正确的ARRAY");
                        return(false);
                    }
                    bool isArray = (tempSectionTypeSplit[0].Length != tempSectionType.Length);
                    tempSectionType = tempSectionTypeSplit[0];
                    int tempIndex = 0;
                    if (isArray)
                    {
                        if (usedIndexNum >= indexVec.Count)
                        {
                            //索引数量不正确
                            ConsoleError(inputMsgName, j, "字段类型索引错误,不匹配");
                            return(false);
                        }
                        tempIndex = indexVec[usedIndexNum++];
                    }

                    //记下类型
                    var dataType = GetDataType(tempSectionType);
                    if (dataType == DATA_TYPE.INVALID)
                    {
                        //错误的数据类型
                        ConsoleError(inputMsgName, j, "错误的数据类型" + tempSectionType);
                        return(false);
                    }
                    if (!pDataStructMap.TryGetValue(tempSection, out DataStruct tempStru))
                    {
                        tempStru = new DataStruct(dataType, isArray);
                        if (k >= sectionTypeSplit.Length - 1)
                        {
                            tempStru.desc = Utils.RemoveNumber(sectionDesc);
                        }
                        tempStru.excelLine          = j;
                        tempStru.section            = tempSection;
                        pDataStructMap[tempSection] = tempStru;
                        pDataStructMap = tempStru.subStructMap;
                    }
                    else
                    {
                        pDataStructMap = tempStru.subStructMap;
                    }

                    //记下索引
                    var tempDataMap = curMap;
                    var tempKey     = new DataTypeKey(tempSection, tempIndex, isArray, dataType);
                    foreach (var tempCheck in tempDataMap)
                    {
                        if (tempCheck.Key.typeName != tempSection)
                        {
                            continue;
                        }
                        if (tempCheck.Key.isArray != isArray)
                        {
                            ConsoleError(inputMsgName, j, "字段相同,但一个是数组另一个不是数组");
                            return(false);
                        }
                    }
                    if (tempDataMap.TryGetValue(tempKey, out DataTypeDesc tempDataDesc))
                    {
                        if (k >= sectionTypeSplit.Length - 1)
                        {
                            //已经有重复类型了
                            ConsoleError(inputMsgName, j, "字段类型索引错误,有重复的");
                            return(false);
                        }
                    }
                    else
                    {
                        tempDataDesc          = new DataTypeDesc();
                        tempDataDesc.dataType = dataType;
                        tempDataDesc.isArray  = isArray;
                        tempDataMap.Add(tempKey, tempDataDesc);
                    }
                    curMap = tempDataDesc.dataMap;

                    if (k == sectionTypeSplit.Length - 1)
                    {
                        //最后一个元素
                        if (dataType == DATA_TYPE.STRUCT)
                        {
                            ConsoleError(inputMsgName, j, "没有指定数据类型");
                            return(false);
                        }
                        index2Type[j] = dataType;
                    }
                    //记下路径
                    indexPath.Add(tempKey);
                }
            }

            StringBuilder ss = new StringBuilder();

            if (!ParseDataStruct(ss, msgName, dataStructMap, 0))
            {
                return(false);
            }
            //写proto文件
            if (!WriteProto(ss.ToString()))
            {
                return(false);
            }

            //设置msgName
            table_data.Path = new excel_path_full();
            if (!ParsePath(table_data.Path))
            {
                return(false);
            }
            allPaths.Add(msgName, table_data.Path);
            return(true);
        }