static FieldDescriptorCache()
        {
            TimestampLongFactory = new SyncValueFactory(typeof(SyncLongTimestamp));
            TimestampIntFactory  = new SyncValueFactory(typeof(SyncIntTimestamp));

            AttributeHelper.ForAllTypesWithAttribute <EnumerateSyncValueAttribute>(
                (type, attribute) => { RegisterFieldType(type, attribute.FieldType, attribute.Flags); }
                );
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="modelBuilder"></param>
        /// <param name="modelsProject">Like var modelsProject = System.Reflection.Assembly.GetExecutingAssembly();</param>
        public void Extend(DbModelBuilder modelBuilder, System.Reflection.Assembly modelsProject)
        {
            var applyTablePerConcreteMethod = new Action <DbModelBuilder>(applyTablePerConcrete <object>).Method.GetGenericMethodDefinition();
            var applyForcePKIdMethod        = new Action <DbModelBuilder>(applyForcePKId <IId>).Method.GetGenericMethodDefinition();

            AttributeHelper.ForAllTypesWithAttribute <TablePerConcreteAttribute>(clas =>
            {
                var applyTPC = applyTablePerConcreteMethod.MakeGenericMethod(clas);
                applyTPC.Invoke(this, new object[] { modelBuilder });

                var applyPKId = applyForcePKIdMethod.MakeGenericMethod(clas);
                applyPKId.Invoke(this, new object[] { modelBuilder });
            }, null, modelsProject);
        }
Пример #3
0
        public void LoadEntityTypes(string[] tags)
        {
            // Create a list of Types for each tag.
            List <Type>[] entityTypesByTag = new List <Type> [tags.Length];
            for (int i = 0; i < tags.Length; i++)
            {
                entityTypesByTag[i] = new List <Type>();
            }

            AttributeHelper.ForAllTypesWithAttribute <EnumerateSyncEntityAttribute>(
                (type, attribute) => {
                for (int i = 0; i < tags.Length; i++)
                {
                    if (attribute.Tag == tags[i])
                    {
                        entityTypesByTag[i].Add(type);
                        break;
                    }
                }
            });

            // Flatten the types into one list.
            List <Type> entityTypes = new List <Type>();

            // The types are loaded in order of their tags for future compatibility reasons.
            foreach (List <Type> types in entityTypesByTag)
            {
                // We sort the types in alphabetical order in case the order which they are returned from assembly.GetTypes() is not consistant.
                types.Sort((a, b) => { return(a.Name.CompareTo(b.Name)); });
                entityTypes.AddRange(types);
            }

            // We snapshot this, because we need to loop over all recent additions.
            int lastEntityIndex = EntityFactories.Count;

            // Create all the descriptors and give them ID's
            foreach (Type type in entityTypes)
            {
                SyncEntityFactory factory = new SyncEntityFactory(new EntityDescriptor(GetNewTypeID()));
                EntityFactories.Add(factory);
                EntityFactoriesByType[type.TypeHandle] = factory;
            }

            // For all the newly added descriptors, we set them up.
            foreach (Type type in entityTypes)
            {
                // We must do this AFTER all types are given EntityID's, to resolve nested entities.
                EntityFactories[lastEntityIndex++].Descriptor.GenerateFieldDescriptors(type, FieldCache);
            }
        }
Пример #4
0
        static PayloadGenerator()
        {
            List <Type> PayloadTypes = new List <Type>();

            AttributeHelper.ForAllTypesWithAttribute <EnumeratePayloadAttribute>(
                (type, attribute) => { PayloadTypes.Add(type); }
                );

            PayloadTypes.Sort((a, b) => (a.Name.CompareTo(b.Name)));

            for (int i = 0; i < PayloadTypes.Count; i++)
            {
                Type type = PayloadTypes[i];
                PayloadConstructors.Add(DelegateGenerator.GenerateConstructor <Payload>(type));
                PayloadTypeIDs[type.TypeHandle] = (byte)i;
            }
        }