public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                var vector2 = Parse(value);

                binaryWriter.Write(vector2.x);
                binaryWriter.Write(vector2.y);
            }
コード例 #2
0
        public static void GenerateDataFile(DataTableProcessor dataTableProcessor, string dataTableName)
        {
            var binaryDataFileName =
                Utility.Path.GetRegularPath(Path.Combine(DataTableConfig.DataTablePath, dataTableName + ".bytes"));

            if (!dataTableProcessor.GenerateDataFile(binaryDataFileName) && File.Exists(binaryDataFileName))
            {
                File.Delete(binaryDataFileName);
            }
        }
            public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                var quaternion = Parse(value);

                binaryWriter.Write(quaternion.x);
                binaryWriter.Write(quaternion.y);
                binaryWriter.Write(quaternion.z);
                binaryWriter.Write(quaternion.w);
            }
            public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                var color32 = Parse(value);

                binaryWriter.Write(color32.r);
                binaryWriter.Write(color32.g);
                binaryWriter.Write(color32.b);
                binaryWriter.Write(color32.a);
            }
            public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                var rect = Parse(value);

                binaryWriter.Write(rect.x);
                binaryWriter.Write(rect.y);
                binaryWriter.Write(rect.width);
                binaryWriter.Write(rect.height);
            }
コード例 #6
0
        public static void GenerateCodeFile(DataTableProcessor dataTableProcessor, string dataTableName)
        {
            dataTableProcessor.SetCodeTemplate(DataTableConfig.CSharpCodeTemplateFileName, Encoding.UTF8);
            dataTableProcessor.SetCodeGenerator(DataTableCodeGenerator);

            var csharpCodeFileName =
                Utility.Path.GetRegularPath(Path.Combine(DataTableConfig.CSharpCodePath, "DR" + dataTableName + ".cs"));

            if (!dataTableProcessor.GenerateCodeFile(csharpCodeFileName, Encoding.UTF8, dataTableName) &&
                File.Exists(csharpCodeFileName))
            {
                File.Delete(csharpCodeFileName);
            }
        }
コード例 #7
0
            public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                if (string.IsNullOrEmpty(value) || value.ToLowerInvariant().Equals("null"))
                {
                    binaryWriter.Write7BitEncodedInt32(0);
                    return;
                }

                DataProcessor dataProcessor = new T();

                string[] splitValues;
                splitValues = value.Split(dataProcessor.IsSystem || dataProcessor.IsEnum ? ',' : '|');
                binaryWriter.Write7BitEncodedInt32(splitValues.Length);
                foreach (var itemValue in splitValues)
                {
                    dataProcessor.WriteToStream(dataTableProcessor, binaryWriter, itemValue);
                }
            }
コード例 #8
0
        private static string GenerateDataTableProperties(DataTableProcessor dataTableProcessor)
        {
            var stringBuilder = new StringBuilder();
            var firstProperty = true;

            for (var i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    continue;
                }

                if (dataTableProcessor.IsIdColumn(i))
                {
                    // 编号列
                    continue;
                }

                if (firstProperty)
                {
                    firstProperty = false;
                }
                else
                {
                    stringBuilder.AppendLine().AppendLine();
                }

                stringBuilder
                .AppendLine("        /// <summary>")
                .AppendFormat("        /// 获取{0}。", dataTableProcessor.GetComment(i)).AppendLine()
                .AppendLine("        /// </summary>")
                .AppendFormat("        public {0} {1}", dataTableProcessor.GetLanguageKeyword(i),
                              dataTableProcessor.GetName(i)).AppendLine()
                .AppendLine("        {")
                .AppendLine("            get;")
                .AppendLine("            private set;")
                .Append("        }");
            }

            return(stringBuilder.ToString());
        }
コード例 #9
0
        public static bool CheckRawData(DataTableProcessor dataTableProcessor, string dataTableName)
        {
            for (var i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                var name = dataTableProcessor.GetName(i);
                if (string.IsNullOrEmpty(name) || name == "#")
                {
                    continue;
                }

                if (!NameRegex.IsMatch(name))
                {
                    Debug.LogWarning(Utility.Text.Format("Check raw data failure. DataTableName='{0}' Name='{1}'",
                                                         dataTableName, name));
                    return(false);
                }
            }

            return(true);
        }
コード例 #10
0
        private static void DataTableCodeGenerator(DataTableProcessor dataTableProcessor,
                                                   StringBuilder codeContent, object userData)
        {
            var dataTableName = (string)userData;

            codeContent.Replace("__DATA_TABLE_CREATE_TIME__", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
            codeContent.Replace("__DATA_TABLE_NAME_SPACE__", DataTableConfig.NameSpace);
            codeContent.Replace("__DATA_TABLE_CLASS_NAME__", "DR" + dataTableName);
            codeContent.Replace("__DATA_TABLE_COMMENT__", dataTableProcessor.GetValue(0, 1) + "。");
            codeContent.Replace("__DATA_TABLE_ID_COMMENT__", "获取" + dataTableProcessor.GetComment(dataTableProcessor.IdColumn) + "。");
            codeContent.Replace("__DATA_TABLE_PROPERTIES__", GenerateDataTableProperties(dataTableProcessor));
            codeContent.Replace("__DATA_TABLE_PARSER__", GenerateDataTableParser(dataTableProcessor));
            codeContent.Replace("__DATA_TABLE_PROPERTY_ARRAY__", GenerateDataTablePropertyArray(dataTableProcessor));
            _nameSpace = _nameSpace.Distinct().ToList();
            StringBuilder nameSpaceBuilder = new StringBuilder();

            foreach (string nameSpace in _nameSpace)
            {
                nameSpaceBuilder.AppendLine($"using {nameSpace};");
            }
            codeContent.Replace("__DATA_TABLE_PROPERTIES_NAMESPACE__", nameSpaceBuilder.ToString());
        }
            public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                               string value)
            {
                if (string.IsNullOrEmpty(value) || value.ToLowerInvariant().Equals("null"))
                {
                    binaryWriter.Write7BitEncodedInt32(0);
                    return;
                }

                DataProcessor dataProcessor1 = new T1();
                DataProcessor dataProcessor2 = new T2();
                var           splitValues    = value.Split('|');

                binaryWriter.Write7BitEncodedInt32(splitValues.Length);
                foreach (var itemValue in splitValues)
                {
                    var keyValue = itemValue.Split('#');
                    dataProcessor1.WriteToStream(dataTableProcessor, binaryWriter, keyValue[0].Substring(1));
                    dataProcessor2.WriteToStream(dataTableProcessor, binaryWriter,
                                                 keyValue[1].Substring(0, keyValue[1].Length - 1));
                }
            }
コード例 #12
0
 public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                    string value)
 {
     binaryWriter.Write(Parse(value));
 }
コード例 #13
0
        private static string GenerateDataTablePropertyArray(DataTableProcessor dataTableProcessor)
        {
            var propertyCollections = new List <PropertyCollection>();

            for (var i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    continue;
                }

                if (dataTableProcessor.IsIdColumn(i))
                {
                    // 编号列
                    continue;
                }

                var name = dataTableProcessor.GetName(i);
                if (!EndWithNumberRegex.IsMatch(name))
                {
                    continue;
                }

                var propertyCollectionName = EndWithNumberRegex.Replace(name, string.Empty);
                var id = int.Parse(EndWithNumberRegex.Match(name).Value);

                PropertyCollection propertyCollection = null;
                foreach (var pc in propertyCollections)
                {
                    if (pc.Name == propertyCollectionName)
                    {
                        propertyCollection = pc;
                        break;
                    }
                }

                if (propertyCollection == null)
                {
                    propertyCollection =
                        new PropertyCollection(propertyCollectionName, dataTableProcessor.GetLanguageKeyword(i));
                    propertyCollections.Add(propertyCollection);
                }

                propertyCollection.AddItem(id, name);
            }

            var stringBuilder = new StringBuilder();
            var firstProperty = true;

            foreach (var propertyCollection in propertyCollections)
            {
                if (firstProperty)
                {
                    firstProperty = false;
                }
                else
                {
                    stringBuilder.AppendLine().AppendLine();
                }

                stringBuilder
                .AppendFormat("        private KeyValuePair<int, {1}>[] m_{0} = null;", propertyCollection.Name,
                              propertyCollection.LanguageKeyword).AppendLine()
                .AppendLine()
                .AppendFormat("        public int {0}Count", propertyCollection.Name).AppendLine()
                .AppendLine("        {")
                .AppendLine("            get")
                .AppendLine("            {")
                .AppendFormat("                return m_{0}.Length;", propertyCollection.Name).AppendLine()
                .AppendLine("            }")
                .AppendLine("        }")
                .AppendLine()
                .AppendFormat("        public {1} Get{0}(int id)", propertyCollection.Name,
                              propertyCollection.LanguageKeyword).AppendLine()
                .AppendLine("        {")
                .AppendFormat("            foreach (KeyValuePair<int, {1}> i in m_{0})", propertyCollection.Name,
                              propertyCollection.LanguageKeyword).AppendLine()
                .AppendLine("            {")
                .AppendLine("                if (i.Key == id)")
                .AppendLine("                {")
                .AppendLine("                    return i.Value;")
                .AppendLine("                }")
                .AppendLine("            }")
                .AppendLine()
                .AppendFormat(
                    "            throw new GameFrameworkException(Utility.Text.Format(\"Get{0} with invalid id '{{0}}'.\", id.ToString()));",
                    propertyCollection.Name).AppendLine()
                .AppendLine("        }")
                .AppendLine()
                .AppendFormat("        public {1} Get{0}At(int index)", propertyCollection.Name,
                              propertyCollection.LanguageKeyword).AppendLine()
                .AppendLine("        {")
                .AppendFormat("            if (index < 0 || index >= m_{0}.Length)", propertyCollection.Name)
                .AppendLine()
                .AppendLine("            {")
                .AppendFormat(
                    "                throw new GameFrameworkException(Utility.Text.Format(\"Get{0}At with invalid index '{{0}}'.\", index.ToString()));",
                    propertyCollection.Name).AppendLine()
                .AppendLine("            }")
                .AppendLine()
                .AppendFormat("            return m_{0}[index].Value;", propertyCollection.Name).AppendLine()
                .Append("        }");
            }

            if (propertyCollections.Count > 0)
            {
                stringBuilder.AppendLine().AppendLine();
            }

            stringBuilder
            .AppendLine("        private void GeneratePropertyArray()")
            .AppendLine("        {");

            firstProperty = true;
            foreach (var propertyCollection in propertyCollections)
            {
                if (firstProperty)
                {
                    firstProperty = false;
                }
                else
                {
                    stringBuilder.AppendLine().AppendLine();
                }

                stringBuilder
                .AppendFormat("            m_{0} = new KeyValuePair<int, {1}>[]", propertyCollection.Name,
                              propertyCollection.LanguageKeyword).AppendLine()
                .AppendLine("            {");

                var itemCount = propertyCollection.ItemCount;
                for (var i = 0; i < itemCount; i++)
                {
                    var item = propertyCollection.GetItem(i);
                    stringBuilder.AppendFormat("                new KeyValuePair<int, {0}>({1}, {2}),",
                                               propertyCollection.LanguageKeyword, item.Key.ToString(), item.Value).AppendLine();
                }

                stringBuilder.Append("            };");
            }

            stringBuilder
            .AppendLine()
            .Append("        }");

            return(stringBuilder.ToString());
        }
コード例 #14
0
        private static string GenerateDataTableParser(DataTableProcessor dataTableProcessor)
        {
            var stringBuilder = new StringBuilder();

            stringBuilder
            .AppendLine("        public override bool ParseDataRow(string dataRowString, object userData)")
            .AppendLine("        {")
            .AppendLine(
                "            string[] columnStrings = dataRowString.Split(DataTableExtension.DataSplitSeparators);")
            .AppendLine("            for (int i = 0; i < columnStrings.Length; i++)")
            .AppendLine("            {")
            .AppendLine(
                "                columnStrings[i] = columnStrings[i].Trim(DataTableExtension.DataTrimSeparators);")
            .AppendLine("            }")
            .AppendLine()
            .AppendLine("            int index = 0;");

            for (var i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    stringBuilder.AppendLine("            index++;");
                    continue;
                }

                if (dataTableProcessor.IsIdColumn(i))
                {
                    // 编号列
                    stringBuilder.AppendLine("            m_Id = int.Parse(columnStrings[index++]);");
                    continue;
                }

                if (dataTableProcessor.IsSystem(i))
                {
                    var languageKeyword = dataTableProcessor.GetLanguageKeyword(i);

                    if (languageKeyword == "string")
                    {
                        stringBuilder
                        .AppendFormat("\t\t\t{0} = columnStrings[index++];", dataTableProcessor.GetName(i))
                        .AppendLine();
                    }
                    else
                    {
                        stringBuilder.AppendFormat("\t\t\t{0} = {1}.Parse(columnStrings[index++]);",
                                                   dataTableProcessor.GetName(i), languageKeyword).AppendLine();
                    }
                }
                else
                {
                    if (dataTableProcessor.IsListColumn(i))
                    {
                        var    t             = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                        var    dataProcessor = Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                        string typeName      = dataProcessor.Type.Name;

                        if (dataProcessor.IsEnum)
                        {
                            typeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessor.LanguageKeyword);
                        }

                        stringBuilder
                        .AppendFormat("\t\t\t{0} = DataTableExtension.Parse{1}List(columnStrings[index++]);",
                                      dataTableProcessor.GetName(i), typeName).AppendLine();
                        continue;
                    }

                    if (dataTableProcessor.IsArrayColumn(i))
                    {
                        var t             = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                        var dataProcessor =
                            Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                        string typeName = dataProcessor.Type.Name;

                        if (dataProcessor.IsEnum)
                        {
                            typeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessor.LanguageKeyword);
                        }
                        stringBuilder
                        .AppendFormat("\t\t\t{0} = DataTableExtension.Parse{1}Array(columnStrings[index++]);",
                                      dataTableProcessor.GetName(i), typeName).AppendLine();
                        continue;
                    }

                    if (dataTableProcessor.IsDictionaryColumn(i))
                    {
                        var t = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                        var dataProcessorT1 =
                            Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                        var dataProcessorT2 =
                            Activator.CreateInstance(t[1]) as DataTableProcessor.DataProcessor;
                        var dataProcessorT1TypeName = dataProcessorT1.Type.Name;
                        if (dataProcessorT1.IsEnum)
                        {
                            dataProcessorT1TypeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessorT1.LanguageKeyword);
                        }

                        var dataProcessorT2TypeName = dataProcessorT2.Type.Name;
                        if (dataProcessorT2.IsEnum)
                        {
                            dataProcessorT2TypeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessorT2.LanguageKeyword);
                        }
                        stringBuilder.AppendFormat(
                            "\t\t\t{0} = DataTableExtension.Parse{1}{2}Dictionary(columnStrings[index++]);",
                            dataTableProcessor.GetName(i), dataProcessorT1TypeName, dataProcessorT2TypeName)
                        .AppendLine();
                        continue;
                    }

                    if (dataTableProcessor.IsEnumrColumn(i))
                    {
                        stringBuilder.AppendFormat("\t\t\t{0} = ({1})int.Parse(columnStrings[index++]);",
                                                   dataTableProcessor.GetName(i), dataTableProcessor.GetLanguageKeyword(i)).AppendLine();
                        continue;
                    }

                    stringBuilder.AppendFormat("\t\t\t{0} = DataTableExtension.Parse{1}(columnStrings[index++]);",
                                               dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
                }
            }

            stringBuilder
            .AppendLine("            GeneratePropertyArray();")
            .AppendLine("            return true;")
            .AppendLine("        }")
            .AppendLine()
            .AppendLine(
                "        public override bool ParseDataRow(byte[] dataRowBytes, int startIndex, int length, object userData)")
            .AppendLine("        {")
            .AppendLine(
                "            using (MemoryStream memoryStream = new MemoryStream(dataRowBytes, startIndex, length, false))")
            .AppendLine("            {")
            .AppendLine(
                "                using (BinaryReader binaryReader = new BinaryReader(memoryStream, Encoding.UTF8))")
            .AppendLine("                {");

            for (var i = 0; i < dataTableProcessor.RawColumnCount; i++)
            {
                if (dataTableProcessor.IsCommentColumn(i))
                {
                    // 注释列
                    continue;
                }

                if (dataTableProcessor.IsIdColumn(i))
                {
                    // 编号列
                    stringBuilder.AppendLine("                    m_Id = binaryReader.Read7BitEncodedInt32();");
                    continue;
                }

                if (dataTableProcessor.IsIdColumn(i))
                {
                    // 编号列
                    stringBuilder.AppendLine("                m_Id = binaryReader.ReadInt32();");
                    continue;
                }

                var languageKeyword = dataTableProcessor.GetLanguageKeyword(i);
                if (dataTableProcessor.IsListColumn(i))
                {
                    var t             = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                    var dataProcessor =
                        Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                    string typeName = dataProcessor.Type.Name;
                    if (dataProcessor.IsEnum)
                    {
                        typeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessor.LanguageKeyword);
                    }
                    stringBuilder.AppendFormat("\t\t\t\t\t{0} = binaryReader.Read{1}List();",
                                               dataTableProcessor.GetName(i), typeName).AppendLine();
                    continue;
                }

                if (dataTableProcessor.IsArrayColumn(i))
                {
                    var    t             = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                    var    dataProcessor = Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                    string typeName      = dataProcessor.Type.Name;

                    if (dataProcessor.IsEnum)
                    {
                        typeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessor.LanguageKeyword);
                    }
                    stringBuilder.AppendFormat("\t\t\t\t\t{0} = binaryReader.Read{1}Array();",
                                               dataTableProcessor.GetName(i), typeName).AppendLine();
                    continue;
                }

                if (dataTableProcessor.IsDictionaryColumn(i))
                {
                    var t = dataTableProcessor.GetDataProcessor(i).GetType().GetGenericArguments();
                    var dataProcessorT1 =
                        Activator.CreateInstance(t[0]) as DataTableProcessor.DataProcessor;
                    var dataProcessorT2 =
                        Activator.CreateInstance(t[1]) as DataTableProcessor.DataProcessor;
                    var dataProcessorT1TypeName = dataProcessorT1.Type.Name;
                    if (dataProcessorT1.IsEnum)
                    {
                        dataProcessorT1TypeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessorT1.LanguageKeyword);
                    }

                    var dataProcessorT2TypeName = dataProcessorT2.Type.Name;
                    if (dataProcessorT2.IsEnum)
                    {
                        dataProcessorT2TypeName = DataTableProcessorExtensions.GetFullNameWithNotDot(dataProcessorT2.LanguageKeyword);
                    }
                    stringBuilder.AppendFormat("\t\t\t\t\t{0} = binaryReader.Read{1}{2}Dictionary();",
                                               dataTableProcessor.GetName(i), dataProcessorT1TypeName, dataProcessorT2TypeName)
                    .AppendLine();
                    continue;
                }

                if (dataTableProcessor.IsEnumrColumn(i))
                {
                    stringBuilder.AppendFormat("\t\t\t\t\t{0} = ({1})binaryReader.Read7BitEncodedInt32();",
                                               dataTableProcessor.GetName(i), dataTableProcessor.GetLanguageKeyword(i)).AppendLine();;
                    continue;
                }


                if (languageKeyword == "int" || languageKeyword == "uint" || languageKeyword == "long" ||
                    languageKeyword == "ulong")
                {
                    stringBuilder.AppendFormat("                    {0} = binaryReader.Read7BitEncoded{1}();",
                                               dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
                }
                else
                {
                    stringBuilder.AppendFormat("                    {0} = binaryReader.Read{1}();",
                                               dataTableProcessor.GetName(i), dataTableProcessor.GetType(i).Name).AppendLine();
                }
            }

            stringBuilder
            .AppendLine("                }")
            .AppendLine("            }")
            .AppendLine()
            .AppendLine("            GeneratePropertyArray();")
            .AppendLine("            return true;")
            .Append("        }");

            return(stringBuilder.ToString());
        }
コード例 #15
0
 public override void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                    string value)
 {
     binaryWriter.Write7BitEncodedInt32(int.Parse(value));
 }
 public abstract void WriteToStream(DataTableProcessor dataTableProcessor, BinaryWriter binaryWriter,
                                    string value);