Exemplo n.º 1
0
 protected DataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent) :
     base(dataHolder, accessor, parent)
 {
     m_mappedMember = mappedMember;
     m_name         = name;
     //m_fullName = parent;
 }
Exemplo n.º 2
0
 protected ArrayDataField(DataHolderDefinition dataHolder, string name,
                          IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent, int length, IProducer arrProducer)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_length      = length;
     m_arrProducer = arrProducer;
 }
 public LightDBDefinitionSet(DataHolderDefinition[] dataHolderDefinitions)
 {
     DataHolderDefinitions = dataHolderDefinitions;
     foreach (var def in dataHolderDefinitions)
     {
         DataHolderDefinitionMap.Add(def.Type, def);
     }
 }
Exemplo n.º 4
0
 public FlatArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
                           MemberInfo mappedMember, int length, IProducer arrProducer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent, length, arrProducer)
 {
     this.m_ArrayAccessors = (IDataFieldAccessor[])new FlatArrayAccessor[this.m_length];
     for (int index = 0; index < this.m_length; ++index)
     {
         this.m_ArrayAccessors[index] = (IDataFieldAccessor) new FlatArrayAccessor(this, index);
     }
 }
Exemplo n.º 5
0
 public FlatArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
                           MemberInfo mappedMember, int length, IProducer arrProducer, INestedDataField parent) :
     base(dataHolder, name, accessor, mappedMember, parent, length, arrProducer)
 {
     m_ArrayAccessors = new FlatArrayAccessor[m_length];
     for (var i = 0; i < m_length; i++)
     {
         m_ArrayAccessors[i] = new FlatArrayAccessor(this, i);
     }
 }
Exemplo n.º 6
0
 public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
                             MemberInfo mappedMember, IProducer producer, IProducer arrayProducer, int length, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer)
 {
     m_Producer       = producer;
     m_ArrayAccessors = new NestedArrayAccessor[m_length];
     for (int index = 0; index < m_length; ++index)
     {
         m_ArrayAccessors[index] = new NestedArrayAccessor(this, index);
     }
 }
Exemplo n.º 7
0
 public static void CreateAndStoreDataHolderDefinitions(Assembly asm)
 {
     foreach (Type type in asm.GetTypes())
     {
         if (type.GetCustomAttributes <DataHolderAttribute>()
             .Count() > 0)
         {
             DataHolderDefinition holderDefinition = CreateDataHolderDefinition(type);
             DataHolderDefinitions.Add(holderDefinition.Name, holderDefinition);
         }
     }
 }
Exemplo n.º 8
0
        public static Dictionary <string, DataHolderDefinition> CreateDataHolderDefinitionMap(Assembly asm)
        {
            Dictionary <string, DataHolderDefinition> dictionary = new Dictionary <string, DataHolderDefinition>();

            foreach (Type type in asm.GetTypes())
            {
                if (type.GetCustomAttributes <DataHolderAttribute>()
                    .Count() > 0)
                {
                    DataHolderDefinition holderDefinition = CreateDataHolderDefinition(type);
                    dictionary.Add(holderDefinition.Name, holderDefinition);
                }
            }

            return(dictionary);
        }
Exemplo n.º 9
0
        public static List <DataHolderDefinition> CreateDataHolderDefinitionList(Assembly asm)
        {
            List <DataHolderDefinition> holderDefinitionList = new List <DataHolderDefinition>();

            foreach (Type type in asm.GetTypes())
            {
                if (type.Name == "PetLevelStatInfo")
                {
                    type.ToString();
                }
                if (type.GetCustomAttributes <DataHolderAttribute>()
                    .Count() > 0)
                {
                    DataHolderDefinition holderDefinition = CreateDataHolderDefinition(type);
                    holderDefinitionList.Add(holderDefinition);
                }
            }

            return(holderDefinitionList);
        }
Exemplo n.º 10
0
 protected ArrayDataField(DataHolderDefinition dataHolder, string name,
     IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent, int length, IProducer arrProducer)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_length = length;
     m_arrProducer = arrProducer;
 }
Exemplo n.º 11
0
 public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
                              MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, producer, parent)
 {
 }
Exemplo n.º 12
0
 protected NestedDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_Producer = producer;
 }
Exemplo n.º 13
0
 public NestedArrayDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
     MemberInfo mappedMember,
     IProducer producer, IProducer arrayProducer, int length, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent, length, arrayProducer)
 {
     m_Producer = producer;
     m_ArrayAccessors = new NestedArrayAccessor[m_length];
     for (var i = 0; i < m_length; i++)
     {
         m_ArrayAccessors[i] = new NestedArrayAccessor(this, i);
     }
 }
Exemplo n.º 14
0
 static bool AddTables(ICollection<DataHolderDefinition> allDefs,
     DataHolderDefinition def,
     Dictionary<DataHolderDefinition, List<TableDefinition>> dataHolderToTable,
     HashSet<DataHolderDefinition> dataHolders,
     HashSet<TableDefinition> tables)
 {
     if (allDefs.Contains(def))
     {
         allDefs.Remove(def);
         dataHolders.Add(def);
         foreach (var table in dataHolderToTable[def])
         {
             tables.Add(table);
             foreach (var dataHolder in table.DataHolderDefinitions)
             {
                 dataHolders.Add(dataHolder);
                 AddTables(allDefs, dataHolder, dataHolderToTable, dataHolders, tables);
             }
         }
         return true;
     }
     return false;
 }
Exemplo n.º 15
0
 public TableDefinition[] EnsureTables(string tableName, DataHolderDefinition def)
 {
     return EnsureTables(tableName, GetDefaultTables(def));
 }
Exemplo n.º 16
0
        private void GetDataFields(Type type, IDictionary <string, IDataField> fields, INestedDataField parent)
        {
            MemberInfo[] members = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.SetField |
                                                   BindingFlags.SetProperty);
            int length = members.Length;
            Dictionary <MemberInfo, IGetterSetter> dictionary1 = length >= 80 || !type.IsClass
                ? (Dictionary <MemberInfo, IGetterSetter>)null
                : AccessorMgr.GetOrCreateAccessors(type);

            foreach (MemberInfo index1 in members)
            {
                if (!index1.IsReadonly() && index1.GetCustomAttributes <NotPersistentAttribute>().Length <= 0)
                {
                    PersistentAttribute attr =
                        ((IEnumerable <DBAttribute>)index1.GetCustomAttributes <DBAttribute>())
                        .Where <DBAttribute>((Func <DBAttribute, bool>)(attribute => attribute is PersistentAttribute))
                        .FirstOrDefault <DBAttribute>() as PersistentAttribute;
                    if (attr != null || !this.m_Attribute.RequirePersistantAttr)
                    {
                        Type          variableType = index1.GetVariableType();
                        bool          isArray      = variableType.IsArray;
                        Type          type1;
                        string        name;
                        IGetterSetter accessor;
                        IFieldReader  reader;
                        if (attr != null)
                        {
                            Type actualType = attr.ActualType;
                            if ((object)actualType == null)
                            {
                                actualType = index1.GetActualType();
                            }
                            type1 = actualType;
                            name  = attr.Name ?? index1.Name;
                            if (attr.AccessorType != (Type)null)
                            {
                                object instance = Activator.CreateInstance(attr.AccessorType);
                                if (!(instance is IGetterSetter))
                                {
                                    throw new DataHolderException(
                                              "Accessor for Persistent members must be of type IGetterSetter - Found accessor of type {0} for member {1}",
                                              new object[2]
                                    {
                                        (object)instance.GetType(),
                                        (object)index1.GetFullMemberName()
                                    });
                                }
                                accessor = (IGetterSetter)instance;
                            }
                            else
                            {
                                accessor = dictionary1 != null
                                    ? dictionary1[index1]
                                    : (IGetterSetter) new DefaultVariableAccessor(index1);
                            }

                            Type type2 = attr.ReadType;
                            if ((object)type2 == null)
                            {
                                type2 = type1;
                            }
                            reader = Converters.GetReader(type2);
                        }
                        else
                        {
                            type1    = index1.GetActualType();
                            name     = index1.Name;
                            accessor = dictionary1 != null
                                ? dictionary1[index1]
                                : (IGetterSetter) new DefaultVariableAccessor(index1);
                            reader = Converters.GetReader(type1);
                        }

                        if (isArray && (variableType.GetArrayRank() > 1 || type1.IsArray))
                        {
                            throw new DataHolderException(
                                      "Cannot define Type {0} of {1} because its a multi-dimensional Array.", new object[2]
                            {
                                (object)variableType,
                                (object)index1.GetFullMemberName()
                            });
                        }
                        IDataField dataField1;
                        if (reader == null)
                        {
                            if (type.IsAbstract)
                            {
                                throw new DataHolderException(
                                          "Cannot define member \"{0}\" of DataHolder \"{1}\" because it's Type ({2}) is abstract.",
                                          new object[3]
                                {
                                    (object)index1.GetFullMemberName(),
                                    (object)this,
                                    (object)type1.FullName
                                });
                            }
                            IProducer producer = !type1.IsClass
                                ? (IProducer)null
                                : DataHolderDefinition.CreateProducer(type1);
                            if (isArray)
                            {
                                int arrayLengthByAttr = DataHolderDefinition.GetArrayLengthByAttr(attr, index1);
                                NestedArrayDataField nestedArrayDataField = new NestedArrayDataField(this, name,
                                                                                                     accessor, index1, producer,
                                                                                                     DataHolderDefinition.CreateArrayProducer(type1, arrayLengthByAttr),
                                                                                                     arrayLengthByAttr, parent);
                                Dictionary <string, IDataField> dictionary2 =
                                    new Dictionary <string, IDataField>(
                                        (IEqualityComparer <string>)StringComparer.InvariantCultureIgnoreCase);
                                this.GetDataFields(type1, (IDictionary <string, IDataField>)dictionary2,
                                                   (INestedDataField)nestedArrayDataField);
                                foreach (IDataField dataField2 in dictionary2.Values)
                                {
                                    for (int index2 = 0; index2 < nestedArrayDataField.ArrayAccessors.Length; ++index2)
                                    {
                                        NestedArrayAccessor arrayAccessor =
                                            (NestedArrayAccessor)nestedArrayDataField.ArrayAccessors[index2];
                                        IDataField dataField3 =
                                            ((DataFieldBase)dataField2).Copy((INestedDataField)arrayAccessor);
                                        arrayAccessor.InnerFields.Add(dataField3.Name, dataField3);
                                    }
                                }

                                dataField1 = (IDataField)nestedArrayDataField;
                            }
                            else
                            {
                                NestedSimpleDataField nestedSimpleDataField =
                                    new NestedSimpleDataField(this, name, accessor, index1, producer, parent);
                                this.GetDataFields(type1,
                                                   (IDictionary <string, IDataField>)nestedSimpleDataField.InnerFields,
                                                   (INestedDataField)nestedSimpleDataField);
                                if (nestedSimpleDataField.InnerFields.Count == 0)
                                {
                                    throw new DataHolderException(
                                              "Cannot define " + index1.GetFullMemberName() +
                                              " as Nested because it does not have any inner fields.", new object[0]);
                                }
                                dataField1 = (IDataField)nestedSimpleDataField;
                            }
                        }
                        else if (isArray)
                        {
                            int arrayLengthByAttr = DataHolderDefinition.GetArrayLengthByAttr(attr, index1);
                            dataField1 = (IDataField) new FlatArrayDataField(this, name, accessor, index1,
                                                                             arrayLengthByAttr, DataHolderDefinition.CreateArrayProducer(type1, arrayLengthByAttr),
                                                                             parent);
                        }
                        else
                        {
                            dataField1 = (IDataField) new FlatSimpleDataField(this, name, accessor, index1, parent);
                            if (name == this.m_DependingFieldName)
                            {
                                this.m_DependingField = (FlatSimpleDataField)dataField1;
                            }
                        }

                        fields.Add(dataField1.Name, dataField1);
                    }
                }
            }

            if (fields.Count <KeyValuePair <string, IDataField> >() - length == 0)
            {
                throw new ArgumentException("Invalid data Type has no persistent members: " + type.FullName);
            }
        }
Exemplo n.º 17
0
 internal void SetMainDataHolder(DataHolderDefinition dataDef, bool isDefaultTable)
 {
     if (MainDataHolder != null)
     {
         return;
         //throw new DataHolderException("Table was set as DefaultTable for more than one DataHolder: \"" + dataDef + "\" and \"" + MainDataHolder + "\"");
     }
     m_mainDataHolder = dataDef;
     m_isDefaultTable = isDefaultTable;
 }
Exemplo n.º 18
0
 public NestedSimpleDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor,
     MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, producer, parent)
 {
 }
Exemplo n.º 19
0
 protected NestedDataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, IProducer producer, INestedDataField parent)
     : base(dataHolder, name, accessor, mappedMember, parent)
 {
     m_Producer = producer;
 }
Exemplo n.º 20
0
		public BinaryContentStream(DataHolderDefinition def)
		{
			m_Def = def;
			InitPersistors();
		}
Exemplo n.º 21
0
		public static void SaveDefinitionStub(string file, DataHolderDefinition dataHolderDef)
		{
			var def = new XmlDataHolderDefinition {
				Name = dataHolderDef.Name,
				DefaultTables = new[] { " " },
				Fields = new DataFieldDefinition[dataHolderDef.Fields.Count]
			};

			int i = 0;
			foreach (var field in dataHolderDef.Fields.Values)
			{
				def.Fields[i++] = DataFieldCreators[(int)field.DataFieldType](field);
			}

			var cfg = new LightRecordXmlConfig {
				FileName = file,
				DataHolders = new[] { def }
			};
			cfg.Save();
		}
Exemplo n.º 22
0
        public static DataHolderTableMapping[] CreateDataHolderTableMappings(
            Dictionary<TableDefinition, List<DataHolderDefinition>> tableDataHolderMap,
            DataHolderDefinition[] dataHolderDefinitions
            )
        {
            // find exact mappings and split them up into as small parts as possible
            // this way we will only read the data from tables that is actually
            // mapped to DataHolders and we will read every cell only once

            var tablesByHolder = new Dictionary<DataHolderDefinition, List<TableDefinition>>();
            foreach (var pair in tableDataHolderMap)
            {
                if (pair.Value == null)
                {
                    log.Warn("Table-definition \"{0}\" has no used columns (and can possibly be removed from the config).");
                }
                else
                {
                    pair.Key.DataHolderDefinitions = pair.Value.ToArray();
                    foreach (var dataHolder in pair.Key.DataHolderDefinitions)
                    {
                        tablesByHolder.GetOrCreate(dataHolder).Add(pair.Key);
                    }
                }
            }

            var mappings = new List<DataHolderTableMapping>();
            var allDefs = new HashSet<DataHolderDefinition>(tablesByHolder.Keys.ToArray());

            var dataHolders = new HashSet<DataHolderDefinition>();
            var tables = new HashSet<TableDefinition>();
            foreach (var holder in tablesByHolder.Keys)
            {
                if (AddTables(allDefs, holder, tablesByHolder, dataHolders, tables))
                {
                    var mapping = new DataHolderTableMapping(dataHolders.ToArray(), tables.ToArray());
                    mappings.Add(mapping);
                    dataHolders.Clear();
                    tables.Clear();
                }
            }

            foreach (var table in tableDataHolderMap.Keys)
            {
                foreach (var field in table.ColumnDefinitions)
                {
                    if (field is IDataFieldBase)
                    {
                        var holderDef = ((IDataFieldBase)field).DataHolderDefinition;
                        if (!dataHolders.Contains(holderDef))
                        {
                            var mapping = mappings.Find(map => map.TableDefinitions.Contains(table));
                            var tableHolders = mapping.DataHolderDefinitions;
                            mapping.DataHolderDefinitions = new DataHolderDefinition[tableHolders.Length + 1];
                            Array.Copy(tableHolders, mapping.TableDefinitions, tableHolders.Length);
                            mapping.DataHolderDefinitions[tableHolders.Length] = holderDef;
                        }
                    }
                }
            }

            return mappings.ToArray();
        }
Exemplo n.º 23
0
 public TableDefinition[] GetDefaultTables(DataHolderDefinition def)
 {
     TableDefinition[] tables;
     DefaultTables.TryGetValue(def.Name, out tables);
     return tables;
 }
Exemplo n.º 24
0
		public DataFieldProxy(string fieldName, DataHolderDefinition dataHolderDef)
		{
			m_FieldName = fieldName;
			m_DataHolderDef = dataHolderDef;
		}
Exemplo n.º 25
0
 protected DataField(DataHolderDefinition dataHolder, string name, IGetterSetter accessor, MemberInfo mappedMember, INestedDataField parent)
     : base(dataHolder, accessor, parent)
 {
     m_mappedMember = mappedMember;
     m_name = name;
     //m_fullName = parent;
 }
Exemplo n.º 26
0
 protected DataFieldBase(DataHolderDefinition dataHolder, IGetterSetter accessor, INestedDataField parent)
 {
     m_DataHolderDefinition = dataHolder;
     m_parent = parent;
     m_accessor = accessor;
 }
Exemplo n.º 27
0
 public BinaryContentStream(DataHolderDefinition def)
 {
     m_Def = def;
     InitPersistors();
 }
Exemplo n.º 28
0
 protected DataFieldBase(DataHolderDefinition dataHolder, IGetterSetter accessor, INestedDataField parent)
 {
     m_DataHolderDefinition = dataHolder;
     m_parent   = parent;
     m_accessor = accessor;
 }