Ejemplo n.º 1
0
        public static void RegisterTypes()
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(Wax3Data)))
            {
                return;
            }

            BsonClassMap.RegisterClassMap <Wax3Data>();
            BsonClassMap.RegisterClassMap <Wax3State>();
            BsonClassMap.RegisterClassMap <Wax9Data>();
            BsonClassMap.RegisterClassMap <RfidData>();
            BsonClassMap.RegisterClassMap <RfidState>();
            BsonClassMap.RegisterClassMap <ScalesData>();
            BsonClassMap.RegisterClassMap <WaterFlow>();
            BsonClassMap.RegisterClassMap <Media>();
            BsonClassMap.RegisterClassMap <Camera>(cm =>
            {
                cm.AutoMap();
                var guidFrameSerial = new DictionaryInterfaceImplementerSerializer <Dictionary <Guid, Rect> >(DictionaryRepresentation.ArrayOfArrays);
                cm.GetMemberMap(c => c.DetailShots).SetSerializer(guidFrameSerial);
                cm.GetMemberMap(c => c.FaceUpShots).SetSerializer(guidFrameSerial);
            });
            BsonClassMap.RegisterClassMap <Production>(cm =>
            {
                cm.AutoMap();
                var stringStringSerial = new DictionaryInterfaceImplementerSerializer <Dictionary <string, string> >(DictionaryRepresentation.ArrayOfArrays);
                var intStringSerial    = new DictionaryInterfaceImplementerSerializer <Dictionary <int, string> >(DictionaryRepresentation.ArrayOfArrays);

                cm.GetMemberMap(c => c.RfidConfig).SetSerializer(stringStringSerial);
                cm.GetMemberMap(c => c.Wax3Config).SetSerializer(intStringSerial);
            });
        }
        public static void ConfigureMongoForJarvisFramework(params String[] protectedAssemblies)
        {
            var guidConversion = new ConventionPack();

            guidConversion.Add(new GuidAsStringRepresentationConvention(protectedAssemblies.ToList()));
            ConventionRegistry.Register("guidstring", guidConversion, _ => true);

            //Register everything inside the NStore that need to have custom persistence rule.
            if (!BsonClassMap.IsClassMapRegistered(typeof(Changeset)))
            {
                BsonClassMap.RegisterClassMap <Changeset>(map =>
                {
                    map.AutoMap();
                    var dictionarySerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <String, Object> >(DictionaryRepresentation.ArrayOfArrays);
                    map.MapProperty(c => c.Headers).SetSerializer(dictionarySerializer);
                });
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(SnapshotInfo)))
            {
                BsonClassMap.RegisterClassMap <SnapshotInfo>(map => map.AutoMap());
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(MessageReaction)))
            {
                BsonClassMap.RegisterClassMap <MessageReaction>(map => map.AutoMap());
            }
        }
Ejemplo n.º 3
0
        public void InsertRecord()
        {
            BsonClassMap.RegisterClassMap <DeviceRecord>(cm =>
            {
                cm.AutoMap();
                var customDictionarySerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <string, string> >(
                    dictionaryRepresentation: DictionaryRepresentation.Document,
                    keySerializer: new StringSerializer(BsonType.String),
                    valueSerializer: BsonSerializer.SerializerRegistry.GetSerializer <string>());
                cm.GetMemberMap(c => c.models).SetSerializer(customDictionarySerializer);
            });

            var collection = MongoClient.GetDatabase(dbName).GetCollection <BsonDocument>(collectionName);
            var document   = new DeviceRecord
            {
                Id     = new ObjectId(),
                device = "injector",
                models =
                    new Dictionary <string, string> {
                    { "stellant", "https://www.radiologysolutions.bayer.com/static/media/images/content/medrad.jpg" },
                    { "mrxp", "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcRzonl3K7icIGwBLaWdG0X4KOJQweCgRafemz29v-SKG8Bb_3I-1g" },
                    { "centargo", "https://i.gyazo.com/0138e1bfd26d7598f23881243eedd4f8.png" }
                }
            };

            collection.InsertOne(document.ToBsonDocument());
        }
Ejemplo n.º 4
0
        private void RegisterMappings()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(OpticalForm)))
            {
                var intFloatDictSerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <int, float> >(
                    DictionaryRepresentation.Document,
                    new Int32Serializer(BsonType.String),
                    BsonSerializer.SerializerRegistry.GetSerializer <float>());
                var intIntDictSerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <int, int> >(
                    DictionaryRepresentation.Document,
                    new Int32Serializer(BsonType.String),
                    BsonSerializer.SerializerRegistry.GetSerializer <int>());

                BsonClassMap.RegisterClassMap <OpticalForm>(cm =>
                {
                    cm.AutoMap();
                    cm.SetIsRootClass(true);
                    cm.MapIdMember(c => c.Id)
                    .SetIdGenerator(StringObjectIdGenerator.Instance)
                    .SetSerializer(new StringSerializer(BsonType.ObjectId));
                });
                BsonClassMap.RegisterClassMap <ReportRequest>(cm => { cm.AutoMap(); });
                BsonClassMap.RegisterClassMap <StudentOpticalForm>(cm => { cm.AutoMap(); });
                BsonClassMap.RegisterClassMap <AnswerKeyOpticalForm>(cm => { cm.AutoMap(); });
                BsonClassMap.RegisterClassMap <SchoolResult>(cm => { cm.AutoMap(); });
                BsonClassMap.RegisterClassMap <ExamStatistics>(cm =>
                {
                    cm.AutoMap();
                    cm.GetMemberMap(c => c.CityAttendanceCounts).SetSerializer(intIntDictSerializer);
                    cm.GetMemberMap(c => c.DistrictAttendanceCounts).SetSerializer(intIntDictSerializer);
                    cm.GetMemberMap(c => c.SchoolAttendanceCounts).SetSerializer(intIntDictSerializer);
                    cm.GetMemberMap(c => c.ClassroomAttendanceCounts).SetSerializer(intIntDictSerializer);
                    cm.GetMemberMap(c => c.CityAverageScores).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.DistrictAverageScores).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.SchoolAverageScores).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.ClassroomAverageScores).SetSerializer(intFloatDictSerializer);
                });

                BsonClassMap.RegisterClassMap <SectionAverage>(cm =>
                {
                    cm.AutoMap();
                    cm.UnmapProperty(x => x.SchoolCorrectCounts);
                    cm.UnmapProperty(x => x.SchoolWrongCounts);
                    cm.UnmapProperty(x => x.SchoolEmptyCounts);
                    cm.GetMemberMap(c => c.CityNets).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.CitySuccessPercents).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.DistrictNets).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.DistrictSuccessPercents).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.SchoolNets).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.SchoolSuccessPercents).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.ClassroomNets).SetSerializer(intFloatDictSerializer);
                    cm.GetMemberMap(c => c.ClassroomSuccessPercents).SetSerializer(intFloatDictSerializer);
                });
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DictionaryBsonSerializer{TDictionary,TKey,TValue}"/> class.
        /// </summary>
        /// <param name="dictionaryRepresentation">The dictionary representation.</param>
        /// <param name="keySerializer">The key serializer.</param>
        /// <param name="valueSerializer">The value serializer.</param>
        public DictionaryBsonSerializer(
            DictionaryRepresentation dictionaryRepresentation,
            IBsonSerializer keySerializer,
            IBsonSerializer valueSerializer)
        {
            if (!typeof(TDictionary).IsClosedSystemDictionaryType())
            {
                throw new ArgumentException("'typeof(TDictionary).IsSystemDictionaryType()' is false");
            }

            this.underlyingSerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <TKey, TValue> >(dictionaryRepresentation, keySerializer, valueSerializer);
        }
Ejemplo n.º 6
0
        public static IServiceCollection AddDataAccess(this IServiceCollection services,
                                                       IConfiguration configuration)
        {
            var options = configuration.GetOptions <DataAccessOptions>();

            services.AddHangfire(x => x.UseMongoStorage(options.ConnectionString, options.JobDatabase,
                                                        new MongoStorageOptions
            {
                MigrationOptions = new MongoMigrationOptions
                {
                    Strategy = MongoMigrationStrategy.Migrate
                }
            }));

            DataAccessClassMap.RegisterConventions("SIL.XForge",
                                                   new CamelCaseElementNameConvention(),
                                                   new ObjectRefConvention(),
                                                   new EnumRepresentationConvention(BsonType.String),
                                                   new IgnoreIfNullConvention(true));

            DataAccessClassMap.RegisterClass <Entity>(cm =>
            {
                cm.MapIdProperty(e => e.Id)
                .SetIdGenerator(StringObjectIdGenerator.Instance)
                .SetSerializer(new StringSerializer(BsonType.ObjectId));
            });

            DataAccessClassMap.RegisterClass <ProjectUserEntity>(cm =>
            {
                cm.SetIdMember(null);
                cm.MapProperty(u => u.Id).SetSerializer(new StringSerializer(BsonType.ObjectId));
                cm.UnmapProperty(u => u.ProjectRef);
            });

            services.AddSingleton <IMongoClient>(sp => new MongoClient(options.ConnectionString));
            services.AddSingleton <IMongoDatabase>(
                sp => sp.GetService <IMongoClient>().GetDatabase(options.MongoDatabaseName));

            services.AddMongoRepository <UserEntity>("users",
                                                     mapSetup: cm =>
            {
                var customSitesSerializer =
                    new DictionaryInterfaceImplementerSerializer <Dictionary <string, Site> >(
                        DictionaryRepresentation.Document, new StringSerializer(),
                        BsonSerializer.SerializerRegistry.GetSerializer <Site>());
                cm.GetMemberMap(u => u.Sites).SetSerializer(customSitesSerializer);
            });

            return(services);
        }
 public static Dictionary <Tkey, Tvalue> AsDictionary <Tkey, Tvalue>(this BsonValue bsonValue)
 {
     using (BsonReader reader = new JsonReader(bsonValue.ToJson()))
     {
         var    dictionarySerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <Tkey, Tvalue> >();
         object result = dictionarySerializer.Deserialize(
             BsonDeserializationContext.CreateRoot(reader, b => { }),
             new BsonDeserializationArgs()
         {
             NominalType = typeof(Dictionary <Tkey, Tvalue>)
         }
             );
         return((Dictionary <Tkey, Tvalue>)result);
     }
 }
Ejemplo n.º 8
0
        static MongoDbAuditStore()
        {
            if (BsonClassMap.IsClassMapRegistered(typeof(AuditDocument)))
            {
                return;
            }

            // easiest way to metadata since keys wont become element names, therefore subject to validation
            // will allow keys like $correlationId to be kept
            var headersSerializer = new DictionaryInterfaceImplementerSerializer <AuditHeaders, string, string>(
                DictionaryRepresentation.ArrayOfDocuments
                );

            BsonClassMap.RegisterClassMap <AuditDocument>(x =>
            {
                x.AutoMap();
                x.MapIdMember(doc => doc.AuditId);
                x.MapMember(doc => doc.Headers).SetSerializer(headersSerializer);
                x.MapMember(doc => doc.Custom).SetSerializer(headersSerializer);
            });
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NaosDictionarySerializer{T, TKey,TValue}"/> class.
        /// </summary>
        /// <param name="dictionaryRepresentation">The dictionary representation.</param>
        /// <param name="keySerializer">The key serializer.</param>
        /// <param name="valueSerializer">The value serializer.</param>
        public NaosDictionarySerializer(DictionaryRepresentation dictionaryRepresentation, IBsonSerializer keySerializer, IBsonSerializer valueSerializer)
        {
            DeserializationConverterFuncBySerializedType.ContainsKey(typeof(TDictionary)).Named(Invariant($"{typeof(TDictionary)}-mustBeSupportedDictionaryType")).Must().BeTrue();

            this.underlyingSerializer = new DictionaryInterfaceImplementerSerializer <Dictionary <TKey, TValue> >(dictionaryRepresentation, keySerializer, valueSerializer);
        }