示例#1
0
        /// <summary>
        /// 注册实体类型
        /// </summary>
        private static void RegisterTypes()
        {
            //加载实体所在程序集
            Assembly entityAssembly = Assembly.Load(GlobalSetting.EntityAssembly);

            Type[] types = entityAssembly.GetTypes();

            //查询所有实体抽象基类
            Func <Type, bool> baseTypeQuery =
                type =>
                type.IsAbstract &&
                type.BaseType == typeof(AggregateRootEntity);

            IEnumerable <Type> baseTypes = types.Where(baseTypeQuery);

            //注册实体类
            foreach (Type baseType in baseTypes)
            {
                BsonClassMap baseMap = new BsonClassMap(baseType);
                baseMap.AutoMap();
                baseMap.SetIsRootClass(true);
                BsonClassMap.RegisterClassMap(baseMap);

                IEnumerable <Type> subTypes = types.Where(x => x.IsSubclassOf(baseType));
                foreach (Type subType in subTypes)
                {
                    BsonClassMap subMap = new BsonClassMap(subType);
                    subMap.AutoMap();
                    subMap.SetIsRootClass(false);
                    BsonClassMap.RegisterClassMap(subMap);
                }
            }
        }
示例#2
0
 public static void Register(BsonClassMap <Update> cm)
 {
     cm.AutoMap();
     //   cm.GetMemberMap(c => c.Value).SetSerializer(new ObjectSerializer());
     cm.SetIsRootClass(true);
     cm.SetIgnoreExtraElements(true);
 }
示例#3
0
        public static void RegisterV3ClassMap()
        {
            var rootTypes = AppDomain.CurrentDomain
                            .GetAssemblies()
                            .SelectMany(assembly => assembly
                                        .GetTypes())
                            .Where(type =>
                                   type.GetCustomAttributes(typeof(AddBsonKnowTypesAttribute), false).Any() &&
                                   type.IsClass &&
                                   type.IsAbstract)
                            .ToList();

            foreach (var rootType in rootTypes)
            {
                var subTypes = AppDomain.CurrentDomain
                               .GetAssemblies()
                               .SelectMany(assembly => assembly.GetTypes())
                               .Where(type =>
                                      rootType.IsAssignableFrom(type) &&
                                      type.IsClass &&
                                      !type.IsAbstract)
                               .ToList();

                var bsonClassMap = new BsonClassMap(rootType);
                bsonClassMap.AutoMap();
                bsonClassMap.SetIsRootClass(true);
                subTypes.ForEach(type => bsonClassMap.AddKnownType(type));

                BsonClassMap.RegisterClassMap(bsonClassMap);
            }
        }
示例#4
0
 public virtual void Apply([NotNull] BsonClassMap classMap)
 {
     if (classMap == null)
     {
         throw new ArgumentNullException(nameof(classMap));
     }
     classMap.SetIsRootClass(true);
 }
示例#5
0
 protected override void Map(BsonClassMap <Entity <long> > map)
 {
     map.MapIdMember(x => x.Id)
     .SetIdGenerator(new Int64IdGenerator())
     .SetElementName("_id")
     ;
     map.SetIsRootClass(true);
 }
示例#6
0
 // public methods
 /// <summary>
 /// Applies a modification to the class map.
 /// </summary>
 /// <param name="classMap">The class map.</param>
 public void Apply(BsonClassMap classMap)
 {
     if (_discriminator != null)
     {
         classMap.SetDiscriminator(_discriminator);
     }
     classMap.SetDiscriminatorIsRequired(_required);
     classMap.SetIsRootClass(_rootClass);
 }
示例#7
0
 public static void Register(BsonClassMap <BaseState> cm)
 {
     cm.AutoMap();
     cm.SetIsRootClass(true);
     cm.SetIgnoreExtraElements(true);
     cm.MapMember(s => s.Nodes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, NodeInformation> >(DictionaryRepresentation.ArrayOfArrays));
     cm.MapMember(s => s.Indexes).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Index> >(DictionaryRepresentation.ArrayOfArrays));
     cm.MapMember(s => s.ClusterTasks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <Guid, BaseTask> >(DictionaryRepresentation.ArrayOfArrays));
     cm.MapMember(s => s.Locks).SetSerializer(new DictionaryInterfaceImplementerSerializer <ConcurrentDictionary <string, Lock> >(DictionaryRepresentation.ArrayOfArrays));
 }
 public void ApplyMapping(Type entityType, BsonClassMap classMap)
 {
     if (entityType != typeof(object) && entityType.BaseType != typeof(object))
     {
         new EntityMapper(entityType.BaseType);
     }
     else
     {
         classMap.SetIsRootClass(true);
     }
 }
示例#9
0
        public static void Register(BsonClassMap <NodeStorage <CindiClusterState> > cm)
        {
            cm.AutoMap();
            cm.SetIsRootClass(true);
            cm.MapMember(s => s.Logs).SetSerializer(new DictionaryInterfaceImplementerSerializer <SortedList <int, LogEntry> >(DictionaryRepresentation.ArrayOfArrays));

            /*AppDomain.CurrentDomain.GetAssemblies().SelectMany(assem => assem.GetTypes()).Where(type => type.IsSubclassOf(typeof(NodeStorage))).ToList()
             *  .ForEach(type => cm.AddKnownType(type));*/
            cm.UnmapMember(c => c.CommandsQueue);
            cm.SetIgnoreExtraElements(true);
        }
示例#10
0
        public static void Register(BsonClassMap <Condition> cm)
        {
            cm.AutoMap();
            cm.SetIsRootClass(true);
            cm.SetIgnoreExtraElements(true);
            var featureType = typeof(Condition);

            featureType.Assembly.GetTypes()
            .Where(type => featureType.IsAssignableFrom(type)).ToList()
            .ForEach(type => cm.AddKnownType(type));
        }
        public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap)
        {
            var entityType = definition.EntityType;

            if (EntityMapping.IsValidTypeToMap(entityType.BaseType))
            {
                EntityMapping.TryRegisterType(entityType.BaseType, out _);
            }
            else
            {
                classMap.SetIsRootClass(true);
            }
        }
        public void ApplyMapping(IEntityDefinition definition, BsonClassMap classMap)
        {
            var entityType = definition.EntityType;

            if (entityType != typeof(object) && entityType.BaseType != typeof(object) && !EntityMapping.IsRegistered(entityType.BaseType))
            {
                EntityMapping.RegisterType(entityType.BaseType);
            }
            else
            {
                classMap.SetIsRootClass(true);
            }
        }
示例#13
0
        private void RegisterClass <T>() where T : IUnifiedIMObject
        {
            Type inheritType = typeof(UnifiedIMObject <>).MakeGenericType(typeof(T));

            if (typeof(T).IsSubclassOf(inheritType))
            {
                BsonClassMap basecm = new BsonClassMap(inheritType);
                basecm.MapIdMember(inheritType.GetProperty("ObjectID"))
                .SetSerializer(new IdSerializer())
                .SetIdGenerator(StringObjectIdGenerator.Instance)
                .SetElementName("_id");
                basecm.SetIsRootClass(true);
                BsonClassMap.RegisterClassMap(basecm);
                BsonClassMap.RegisterClassMap <T>();
            }
        }
示例#14
0
        private static void Map()
        {
            if (BsonClassMap.GetRegisteredClassMaps().Any())
            {
                return;
            }

            foreach (var type in TyperConfigurarion.Typers)
            {
                var map = new BsonClassMap(type);
                map.AutoMap();
                map.SetIsRootClass(true);

                //map.
                //map.IdMemberMap.SetIdGenerator(BsonObjectIdGenerator.Instance);
                //map.IdMemberMap.SetIdGenerator()
                BsonClassMap.RegisterClassMap(map);

                //type.Assembly.GetTypes()
                //    .Where(type => featureType.IsAssignableFrom(type)).ToList()
                //    .ForEach(type => cm.AddKnownType(type));
            }
        }
 // public methods
 /// <summary>
 /// Applies a modification to the class map.
 /// </summary>
 /// <param name="classMap">The class map.</param>
 public void Apply(BsonClassMap classMap)
 {
     if (_discriminator != null)
     {
         classMap.SetDiscriminator(_discriminator);
     }
     classMap.SetDiscriminatorIsRequired(_required);
     classMap.SetIsRootClass(_rootClass);
 }
示例#16
0
 public static void Register(BsonClassMap <MetricTick> cm)
 {
     cm.AutoMap();
     cm.SetIsRootClass(true);
     cm.SetIgnoreExtraElements(true);
 }