예제 #1
0
        static void Main(string[] args)
        {
            if (!Config.Load())
            {
                Console.WriteLine("请添加配置文件!");
                return;
            }
            // TODO Dll path 改成xbuff_config的
            // 验证反射对没对
            Assembly asm = Assembly.LoadFrom("xbuffer_config.dll");

            if (asm == null)
            {
                Console.WriteLine("dll不存在!");
                return;
            }
            configAssembly = asm;

            var csvPath     = Config.Get("csv_path");
            var csvFileList = Directory.GetFiles(csvPath);

            Type t = asm.GetType("xbuffer." + Config.Get("mgr_class_name"));
            //ConfigManager obj = new ConfigManager();
            //Type t = obj.GetType();
            object obj = asm.CreateInstance(t.FullName);

            for (int i = 0; i < csvFileList.Length; ++i)
            {
                var csvFile = csvFileList[i];
                if (csvFile.EndsWith(".csv"))
                {
                    Console.WriteLine("--- Insert Bytes Data ---" + i + "---" + Path.GetFileName(csvFile));

                    CsvReader reader    = CsvReader.ReadFile(csvFile);
                    var       classInfo = CsvParser.Parse(reader.name, reader.table);

                    FillFieldData(t, obj, classInfo, reader.table);
                }
            }

            xbuffer.XSteam stream  = new xbuffer.XSteam(1, 1024 * 1024 * 100);
            Type           bufferT = asm.GetType("xbuffer." + Config.Get("mgr_class_name") + "Buffer");

            object[] arg = new object[2] {
                obj, stream
            };
            var serializeMethod = bufferT.GetMethod("serialize", BindingFlags.Static | BindingFlags.Public);

            if (serializeMethod != null)
            {
                serializeMethod.Invoke(null, arg);
                var buffer = stream.getBytes();
                buffer = CompressTool.CompressBytes(buffer);        //压缩一下
                File.WriteAllBytes(Config.Get("data_out_path") + "/" + "ConfigData.bytes", buffer);
            }
            else
            {
                throw new Exception("找不到方法 ===> xbuffer." + Config.Get("mgr_class_name") + "Buffer.serialize");
            }

            Console.WriteLine("Finish!!!");
        }