Exemplo n.º 1
0
        private void RegisterConventions()
        {
            var pack = new ConventionPack {
                new IgnoreIfNullConvention(true), /*new MongoRefConvention(),*/ new IgnoreExtraElementsConvention(true)
            };

            ConventionRegistry.Register("Custom Conventions", pack, t => true);


            try
            {
                BsonSerializer.RegisterGenericSerializerDefinition(typeof(MongoRef <>), typeof(MongoRefSerializer <>));
            }
            catch (BsonSerializationException bsex) when(bsex.Message == "There is already a serializer mapping registered for type MongoRef<T>.")
            {
            }

            try
            {
                BsonSerializer.RegisterDiscriminatorConvention(typeof(FileAction), new ContentTypeDiscriminatorConvention());
            }
            catch (Exception e) { }

            if (!BsonClassMap.IsClassMapRegistered(typeof(MongoEntity)))
            {
                BsonClassMap.RegisterClassMap <MongoEntity>(delegate(BsonClassMap <MongoEntity> map)
                {
                    map.AutoMap();

                    //map.MapProperty(f => f.ParentId).SetSerializer(new StringSerializer().WithRepresentation(BsonType.ObjectId));

                    map.IdMemberMap.SetSerializer(new StringSerializer().WithRepresentation(BsonType.ObjectId)).SetIdGenerator(StringObjectIdGenerator.Instance);;
                });
            }
        }
Exemplo n.º 2
0
        public static void AddMyStorage(this IServiceCollection services, IConfiguration config)
        {
            config.ConfigureByOption("storage:type", new Alternatives
            {
                ["MongoDB"] = () =>
                {
                    BsonSerializer.RegisterGenericSerializerDefinition(
                        typeof(ReadonlyList <>),
                        typeof(ReadonlyListSerializer <>));

                    BsonSerializer.RegisterGenericSerializerDefinition(
                        typeof(ReadonlyDictionary <,>),
                        typeof(ReadonlyDictionarySerializer <,>));

                    SoftEnumSerializer <ConfirmMode> .Register();

                    services.AddMyMongoApps();
                    services.AddMyMongoDb(config);
                    services.AddMyMongoDbIdentity();
                    services.AddMyMongoDbKeyValueStore();
                    services.AddMyMongoDbScheduler();
                    services.AddMyMongoEvents();
                    services.AddMyMongoLog();
                    services.AddMyMongoMedia();
                    services.AddMyMongoSubscriptions();
                    services.AddMyMongoTemplates();
                    services.AddMyMongoTopics();
                    services.AddMyMongoUserNotifications();
                    services.AddMyMongoUsers();
                }
            });
        }
        public static void RegisterClassMaps()
        {
            BsonSerializer.RegisterGenericSerializerDefinition(typeof(ISet <>), typeof(SetSerializer <>));
            BsonSerializer.RegisterSerializer(new JobDataMapSerializer());

            BsonClassMap.RegisterClassMap <Key <JobKey> >(map =>
            {
                map.AutoMap();
                map.MapProperty(key => key.Group);
                map.MapProperty(key => key.Name);
                map.AddKnownType(typeof(JobKey));
            });
            BsonClassMap.RegisterClassMap <Key <TriggerKey> >(map =>
            {
                map.AutoMap();
                map.MapProperty(key => key.Group);
                map.MapProperty(key => key.Name);
                map.AddKnownType(typeof(TriggerKey));
            });
            BsonClassMap.RegisterClassMap <JobKey>(map =>
            {
                map.MapCreator(jobKey => new JobKey(jobKey.Name));
                map.MapCreator(jobKey => new JobKey(jobKey.Name, jobKey.Group));
            });

            BsonClassMap.RegisterClassMap <TriggerKey>(map =>
            {
                map.MapCreator(triggerKey => new TriggerKey(triggerKey.Name));
                map.MapCreator(triggerKey => new TriggerKey(triggerKey.Name, triggerKey.Group));
            });
            BsonClassMap.RegisterClassMap <TimeOfDay>(map =>
            {
                map.AutoMap();
                map.MapProperty(day => day.Hour);
                map.MapProperty(day => day.Minute);
                map.MapProperty(day => day.Second);
                map.MapCreator(day => new TimeOfDay(day.Hour, day.Minute, day.Second));
                map.MapCreator(day => new TimeOfDay(day.Hour, day.Minute));
            });

            BsonClassMap.RegisterClassMap <JobDetail>(map =>
            {
                map.AutoMap();
                map.MapProperty(detail => detail.JobType).SetSerializer(new TypeSerializer());
            });

            BsonClassMap.RegisterClassMap <DailyTimeIntervalTrigger>(map =>
            {
                map.AutoMap();
                var serializer =
                    new EnumerableInterfaceImplementerSerializer
                    <System.Collections.Generic.HashSet <DayOfWeek>, DayOfWeek>(
                        new EnumSerializer <DayOfWeek>(BsonType.String));
                map.MapProperty(trigger => trigger.DaysOfWeek).SetSerializer(serializer);
            });
        }
 private static void RegisterModel()
 {
     BsonSerializer.RegisterSerializer(typeof (DateTime), new DateTimeTicksSerializer());
     BsonSerializer.RegisterGenericSerializerDefinition(typeof (IKaVESet<>), typeof (KaVECollectionSerializer<>));
     BsonSerializer.RegisterGenericSerializerDefinition(
         typeof (IKaVEList<>),
         typeof (KaVECollectionSerializer<>));
     BsonSerializer.RegisterSerializer(typeof (IProposalCollection), new KaVECollectionSerializer());
     BsonClassMap.RegisterClassMap<IDEEvent>(
         cm =>
         {
             cm.AutoMap();
             cm.SetIdMember(cm.GetMemberMap(c => c.Id));
             cm.IdMemberMap.SetIdGenerator(StringObjectIdGenerator.Instance);
         });
     RegisterModelTypesFrom(typeof (IDEEvent).Assembly);
     RegisterModelTypesFrom(typeof (MongoDbFeedbackDatabase).Assembly);
     BsonClassMap.LookupClassMap(typeof (ConcurrentEvent));
 }
Exemplo n.º 5
0
        static TestUtils()
        {
            DefaultOptions.Converters.Add(new JsonReadonlyListConverterFactory());
            DefaultOptions.Converters.Add(new JsonReadonlyDictionaryConverterFactory());
            DefaultOptions.Converters.Add(new JsonActivityContextConverter());
            DefaultOptions.Converters.Add(new JsonActivitySpanIdConverter());
            DefaultOptions.Converters.Add(new JsonActivityTraceIdConverter());

            ActivityContextSerializer.Register();
            ActivitySpanIdSerializer.Register();
            ActivityTraceIdSerializer.Register();

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(ReadonlyList <>),
                typeof(ReadonlyListSerializer <>));

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(ReadonlyDictionary <,>),
                typeof(ReadonlyDictionarySerializer <,>));
        }
Exemplo n.º 6
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            #region MongoDB

            var conventionPack = new ConventionPack
            {
                new CamelCaseElementNameConvention()
            };

            ConventionRegistry.Register(
                "camelCase",
                conventionPack,
                t => true
                );

            //BsonClassMap.RegisterClassMap<SRecipe>(
            //    x => new RecipeMapper().SetupBsonMapping(x)
            //);

            BsonClassMap.RegisterClassMap <JsonLdObject>(
                x => new JsonLdObjectMapper().SetupBsonMapping(x)
                );

            BsonClassMap.RegisterClassMap <Thing>(
                x => new ThingMapper().SetupBsonMapping(x)
                );

            BsonSerializer.RegisterSerializationProvider(
                new ValuesSerializerProvider()
                );

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(OneOrMany <>),
                typeof(OneOrManySerializer <>)
                );

            MongoDbHelper.Default
            .MapInterfaceToDefaultImplementation <IAggregateRating>()
            .MapInterfaceToDefaultImplementation <IClaimReview>()
            .MapInterfaceToDefaultImplementation <IClip>()
            .MapInterfaceToDefaultImplementation <ICreativeWork>()
            .MapInterfaceToDefaultImplementation <IDemand>()
            .MapInterfaceToDefaultImplementation <IHowTo>()
            .MapInterfaceToDefaultImplementation <IHowToSection>()
            .MapInterfaceToDefaultImplementation <IHowToDirection>()
            .MapInterfaceToDefaultImplementation <IHowToItem>()
            .MapInterfaceToDefaultImplementation <IHowToStep>()
            .MapInterfaceToDefaultImplementation <IHowToSupply>()
            .MapInterfaceToDefaultImplementation <IHowToTip>()
            .MapInterfaceToDefaultImplementation <IHowToTool>()
            .MapInterfaceToDefaultImplementation <IIntangible>()
            .MapInterfaceToDefaultImplementation <IImageGallery>()
            .MapInterfaceToDefaultImplementation <IImageObject>()
            .MapInterfaceToDefaultImplementation <IItemList>()
            .MapInterfaceToDefaultImplementation <IMonetaryAmount>()
            .MapInterfaceToDefaultImplementation <INutritionInformation>()
            .MapInterfaceToDefaultImplementation <IOrganization>()
            .MapInterfaceToDefaultImplementation <IPerson>()
            .MapInterfaceToDefaultImplementation <IPublicationEvent>()
            .MapInterfaceToDefaultImplementation <IQuantitativeValue>()
            .MapInterfaceToDefaultImplementation <IRating>()
            .MapInterfaceToDefaultImplementation <IRecipe>()
            .MapInterfaceToDefaultImplementation <IReview>()
            .MapInterfaceToDefaultImplementation <IReviewAction>()
            .MapInterfaceToDefaultImplementation <IStructuredValue>()
            .MapInterfaceToDefaultImplementation <IThing, Thing>(x => x.Name)
            .MapInterfaceToDefaultImplementation <IVideoObject>();

            //BsonSerializer.RegisterSerializer(
            //    typeof(IThing),
            //    new ThingSerializer()
            //);

            BsonSerializer.RegisterSerializer(
                typeof(TimeSpan),
                new TimeSpanSerializer()
                );

            BsonSerializer.RegisterSerializer(
                typeof(JsonLdContext),
                new JsonLdContextSerializer()
                );

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(Values <,>),
                typeof(ValuesSerializer <,>)
                );

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(Values <, ,>),
                typeof(ValuesSerializer <, ,>)
                );

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(Values <, , ,>),
                typeof(ValuesSerializer <, , ,>)
                );

            BsonSerializer.RegisterGenericSerializerDefinition(
                typeof(Values <, , , , , ,>),
                typeof(ValuesSerializer <, , , , , ,>)
                );

            //BsonSerializer.RegisterDiscriminatorConvention(
            //    typeof(Values<,>),
            //    new SchemaValuesConvention()
            //);

            //BsonSerializer.RegisterDiscriminatorConvention(
            //    typeof(Values<,,>),
            //    new SchemaValuesConvention()
            //);

            //BsonSerializer.RegisterDiscriminatorConvention(
            //    typeof(Values<,,,>),
            //    new SchemaValuesConvention()
            //);

            //BsonSerializer.RegisterDiscriminatorConvention(
            //    typeof(Values<,,,,,,>),
            //    new SchemaValuesConvention()
            //);

            services
            .AddMongoDb(
                Configuration.GetConnectionString("RecipeDb"),
                Configuration.GetValue <string>("DatabaseName")
                );

            #endregion

            //services.AddGraphQL(
            //    sp =>
            //    {
            //        var schema = SchemaBuilder.New()
            //            //.EnableRelaySupport()
            //            .AddType<ThingTypeDescriptor>()
            //            .AddServices(sp)
            //            //.AddObjectType<OneOrManyTypeDescriptor>()
            //            //.Use(next => context =>
            //            //{
            //            //    return Task.CompletedTask;
            //            //})
            //            //.AddObjectType<ThingTypeDescriptor>()
            //            .AddObjectType<SchemaOrgTypeDescriptor<SRecipe>>()
            //            //.AddObjectType<RecipeTypeDescriptor>()
            //            .AddQueryType(d => d.Name(QueryConstants.QueryTypeName))
            //            //.AddType<RecipeQueryType>()
            //            .AddType<HelloWorldQueryType>()
            //            .Create();

            //        return schema;
            //    }
            //);
        }
Exemplo n.º 7
0
 public static void RegisterGenericDictionarySerializer()
 {
     //Trace.WriteLine("**** BsonSerializer.RegisterGenericSerializerDefinition(typeof(Dictionary<,>), typeof(PBDictionarySerializer<,>))");
     BsonSerializer.RegisterGenericSerializerDefinition(typeof(Dictionary <,>), typeof(PBDictionarySerializer <,>));
 }