Ejemplo n.º 1
0
        private void SerializeCSObj(CSObjectData obj, Type type, MemoryStream stream, Assembly assembly, CSObject data, int row)
        {
            object instance = Activator.CreateInstance(type);

            PropertyInfo[] pis = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            int key   = 0;
            int count = pis.Length;

            for (int i = 0; i < count; i++)
            {
                PropertyInfo  pi            = pis[i];
                string        value         = obj.datas[i];
                TypeDecorator typeDecorator = data.type.datas[i];
                try
                {
                    typeDecorator.runtimeType = pi.PropertyType;
                    object objvalue = ValueAdapter.Adapter(value, typeDecorator);
                    pi.SetValue(instance, objvalue, null);

                    if (i == 0 && pi.PropertyType == typeof(int))
                    {
                        key = (int)objvalue;
                    }
                }
                catch (Exception e)
                {
                    throw new Exception(string.Format("[{0}] complier data is error, the fild is:{1}, value is:{2}, row:{3}, column:{4},  {5}{6} ",
                                                      data.name,
                                                      data.property.datas[i].name,
                                                      value,
                                                      row + Define.UserDefine.global.excel.startIndex,
                                                      typeDecorator.index,
                                                      "\r\n",
                                                      e.ToString()));
                }
            }

            byte[] data_byte = Serialize(instance);

            int length      = sizeof(int);
            int data_length = data_byte.Length;
            int all_length  = length + length + data_length;

            byte[] write       = new byte[all_length];
            byte[] length_byte = BitConverter.GetBytes(data_length);
            byte[] key_byte    = BitConverter.GetBytes(key);

            Buffer.BlockCopy(key_byte, 0, write, 0, length);
            Buffer.BlockCopy(length_byte, 0, write, length, length);
            Buffer.BlockCopy(data_byte, 0, write, length + length, data_length);

            stream.Write(write, 0, all_length);
        }
Ejemplo n.º 2
0
        private void CheckObjectKey(CSObjectData objectData, int index)
        {
            string key = objectData.key;

            if (string.IsNullOrEmpty(key))
            {
                throw new Exception(string.Format("[{0}] data had null key, row index is {1}.", name, index));
            }

            foreach (var item in objectDatas)
            {
                if (item.key == key)
                {
                    throw new Exception(string.Format("[{0}] data had repeated key : {1}, row index is {2} and {3}.", name, key, item.index, index));
                }
            }
        }
Ejemplo n.º 3
0
        private void SerializeCSData(Assembly assembly, CSObject data)
        {
            Common.Utility.Logger.Log(string.Format("complier {0}.cs", data.name));
            Type type = assembly.GetType(data.fullName, true);

            byte[] serialized = null;
            using (MemoryStream ms = new MemoryStream())
            {
                int count = data.dataCount;
                for (int i = 0; i < count; i++)
                {
                    CSObjectData obj = data.objectDatas[i];
                    SerializeCSObj(obj, type, ms, assembly, data, i);
                }
                serialized = ms.ToArray();
            }

            string filename = Define.UserDefine.global.path.tempBinPath + "/" + data.name + "." + Define.ConstDefine.BIN_FILE_SUFFIX;

            Common.Utility.File.WriteBytes2File(filename, serialized);
            Common.Utility.Logger.Log("write " + data.name + "." + Define.ConstDefine.BIN_FILE_SUFFIX);
        }
Ejemplo n.º 4
0
        private void InternalConstruction(Excel.ExcelData excelData)
        {
            System.Data.DataTable data = excelData.data;
            CheckSourceData(data);

            DataRowCollection rows = data.Rows;

            int dataStartIndex = Define.UserDefine.global.excel.startIndex;

            if (rows.Count <= dataStartIndex)
            {
                throw new Exception(string.Format("Excel Data rows count:{0} can not less than excel start index:{1}", rows.Count, Define.UserDefine.global.excel.startIndex));
            }

            int columnCount = data.Columns.Count;

            type = new CSObjectTypeGroup(rows[Define.UserDefine.global.excel.typeIndex], columnCount, name);

            List <int> ignoreIndexs = type.ignoreIndexs;

            int           propertyIndex    = Define.UserDefine.global.excel.propertyIndex;
            List <string> propertyOriginal = FiterRowData(rows[propertyIndex], columnCount, ignoreIndexs, string.Format("propertyIndex:{0}", propertyIndex));

            int           summaryIndex    = Define.UserDefine.global.excel.summaryIndex;
            List <string> summaryOriginal = FiterRowData(rows[summaryIndex], columnCount, ignoreIndexs, string.Format("summaryIndex:{0}", summaryIndex));

            property = new CSObjectPropertyGroup(summaryOriginal, propertyOriginal);

            objectDatas = new List <CSObjectData>();
            for (int i = dataStartIndex; i < rows.Count; i++)
            {
                List <string> originalData = FiterRowData(rows[i], columnCount, ignoreIndexs, string.Format("Data Row:{0}", i));
                CSObjectData  objectData   = new CSObjectData(originalData, i);
                CheckObjectKey(objectData, i);
                objectDatas.Add(objectData);
            }
        }