예제 #1
0
        public void RegisterDataObject(Type DataObjectType)
        {
            bool primary = false;

            string TableName = DataObject.GetTableName(DataObjectType);

            DataSet ds = new DataSet();

            DataTable table = new DataTable(TableName);

            table.Columns.Add(TableName + "_ID", typeof(uint));
            MemberValue[] columns      = MemberValue.GetMemberValues(DataObjectType, typeof(Common.Attributes.DataElement), true, true);
            MemberValue[] relations    = MemberValue.GetMemberValues(DataObjectType, typeof(Common.Attributes.Relation), false, false);
            MemberValue   primaryvalue = null;

            foreach (MemberValue column in columns)
            {
                Type valueType = column.GetValueType();
                if (!primary && column.Attribute is Common.Attributes.PrimaryKey)
                {
                    primaryvalue = column;
                    primary      = true;
                    DataColumn[] index = new DataColumn[1];
                    index[0]         = table.Columns.Add(column.GetName(), valueType);
                    table.PrimaryKey = index;
                }
                else
                {
                    table.Columns.Add(column.GetName(), valueType);
                }
            }

            if (primary == false)
            {
                primaryvalue = new PropertyMemberValue(DataObjectType.GetProperty("ObjectId"));
                DataColumn[] index = new DataColumn[1];
                index[0]         = table.Columns[TableName + "_ID"];
                table.PrimaryKey = index;
            }

            ds.DataSetName        = TableName;
            ds.EnforceConstraints = true;
            ds.CaseSensitive      = false;
            ds.Tables.Add(table);

            DataTableHandler dth = new DataTableHandler(ds, DataObjectType, primaryvalue, columns, relations);

            dth.HasRelations = relations.Length != 0;
            tableDatasets.Add(TableName, dth);
            IdGenerator.setIDStart(DataObjectType, 1);
        }
예제 #2
0
 public static SerializeValue[] GetSerializeValues(Type type)
 {
     lock (serializeValues.SyncRoot)
     {
         SerializeValue[] values = (SerializeValue[])serializeValues[type];
         if (values != null)
         {
             return(values);
         }
         MemberValue[] memberValues = MemberValue.GetMemberValues(type, new Type[2] {
             typeof(ServerSerialize), typeof(DataElement)
         }, true, true);
         values = SerializeValue.GetSerializeValues(memberValues);
         serializeValues[type] = values;
         return(values);
     }
 }
예제 #3
0
 static void GetSubClassUpdateValues(Hashtable tbl, MemberValue parentValue, int baseField, Type type, Type updateObjectType)
 {
     foreach (MemberValue tmp in MemberValue.GetMemberValues(type, typeof(UpdateValueAttribute), true, false))
     {
         MemberValue          value  = new SubClassMemberValue(parentValue, tmp);
         UpdateValueAttribute attrib = (UpdateValueAttribute)value.Attribute;
         if (!checkType(attrib, updateObjectType))
         {
             continue;
         }
         Type valueType = value.GetValueType();
         if (valueType.IsArray == false)
         {
             if (!IsSubClass(valueType))
             {
                 if (attrib.Field == -1)
                 {
                     throw new ObjectUpdateManagerException("Field was not set on " + updateObjectType.Name + value.GetName());
                 }
                 if (tmp is IndexMemberValue)
                 {
                     IndexMemberValue indexValue = tmp as IndexMemberValue;
                     if (valueType == typeof(ulong) || valueType == typeof(long))
                     {
                         AddUpdateValue(tbl, value, baseField + attrib.Field + indexValue.Index * 2);
                     }
                     else
                     {
                         AddUpdateValue(tbl, value, baseField + attrib.Field + indexValue.Index);
                     }
                 }
                 else
                 {
                     AddUpdateValue(tbl, value, baseField + attrib.Field);
                 }
             }
             else
             {
                 GetSubClassUpdateValues(tbl, value, attrib.Field == -1 ? baseField : (baseField + attrib.Field), valueType, type);
             }
         }
         else
         {
             if (attrib.ArraySize == -1)
             {
                 throw new ObjectUpdateManagerException("ArraySize was not set on " + updateObjectType.Name + "." + value.GetName());
             }
             if (attrib.Field == -1)
             {
                 throw new ObjectUpdateManagerException("Field was not set on the array " + updateObjectType.Name + "." + value.GetName());
             }
             if (attrib.NumSubFields == -1)
             {
                 throw new ObjectUpdateManagerException("NumFields was not set on the subclass array " + updateObjectType.Name + "." + value.GetName());
             }
             valueType = valueType.GetElementType();
             for (int i = 0; i < attrib.ArraySize; i++)
             {
                 IndexMemberValue indexValue = new IndexMemberValue(value, i);
                 GetSubClassUpdateValues(tbl, indexValue, baseField + attrib.Field + i * attrib.NumSubFields, valueType, updateObjectType);
             }
         }
     }
 }
예제 #4
0
        public static void RegisterUpdateObject(Type type)
        {
            try {
                object[] tmp = type.GetCustomAttributes(typeof(UpdateObjectAttribute), true);
                if (tmp.Length == 0)
                {
                    throw new ObjectUpdateManagerException(type.ToString() + " has no UpdateObjectAttribute");
                }
                UpdateObjectAttribute updateObjectAttribute = (UpdateObjectAttribute)tmp[0];
                if (updateObjectAttribute.MaxFields == -1)
                {
                    throw new ObjectUpdateManagerException("MaxFields is not set in UpdateObjectAttribute on " + type.ToString());
                }

                Hashtable tbl = new Hashtable();
                foreach (MemberValue value in MemberValue.GetMemberValues(type, typeof(UpdateValueAttribute), true, false))
                {
                    UpdateValueAttribute attrib = (UpdateValueAttribute)value.Attribute;
                    if (!checkType(attrib, type))
                    {
                        continue;
                    }
                    Type valueType = value.GetValueType();
                    if (valueType.IsArray == false)
                    {
                        if (!IsSubClass(valueType))
                        {
                            if (attrib.Field == -1)
                            {
                                throw new ObjectUpdateManagerException("Field was not set on " + type.Name + value.GetName());
                            }
                            if (value is IndexMemberValue)
                            {
                                IndexMemberValue indexValue = value as IndexMemberValue;
                                if (valueType == typeof(ulong) || valueType == typeof(long))
                                {
                                    AddUpdateValue(tbl, value, attrib.Field + indexValue.Index * 2);
                                }
                                else
                                {
                                    AddUpdateValue(tbl, value, attrib.Field + indexValue.Index);
                                }
                            }
                            else
                            {
                                AddUpdateValue(tbl, value, attrib.Field);
                            }
                        }
                        else
                        {
                            GetSubClassUpdateValues(tbl, value, attrib.Field == -1 ? 0 : attrib.Field, valueType, type);
                        }
                    }
                    else
                    {
                        if (attrib.ArraySize == -1)
                        {
                            throw new ObjectUpdateManagerException("ArraySize was not set on " + type.Name + "." + value.GetName());
                        }
                        if (attrib.Field == -1)
                        {
                            throw new ObjectUpdateManagerException("Field was not set on the array " + type.Name + "." + value.GetName());
                        }
                        if (attrib.NumSubFields == -1)
                        {
                            throw new ObjectUpdateManagerException("NumFields was not set on the subclass array " + type.Name + "." + value.GetName());
                        }
                        valueType = valueType.GetElementType();
                        for (int i = 0; i < attrib.ArraySize; i++)
                        {
                            IndexMemberValue indexValue = new IndexMemberValue(value, i);
                            GetSubClassUpdateValues(tbl, indexValue, attrib.Field + i * attrib.NumSubFields, valueType, type);
                        }
                    }
                }

                if (tbl.Count == 0)
                {
                    throw new ObjectUpdateManagerException("No update values in " + type.ToString());
                }
                UpdateObjectInfo uoi = new UpdateObjectInfo(tbl, updateObjectAttribute.MaxFields);
                m_updateObjectInfos[type] = uoi;
            } catch (Exception exp) {
                DebugLogger.Log("", exp);
            }
        }
 static LoginHandlers()
 {
     MemberValue[] values = MemberValue.GetMemberValues(typeof(DBItemTemplate), typeof(Common.Attributes.DataElement), true, true);
     itemTemplateValues = SerializeValue.GetSerializeValues(values);
 }