SetIgnoreExtraElementsConvention() 공개 메소드

Sets the ignore extra elements convention.
public SetIgnoreExtraElementsConvention ( IIgnoreExtraElementsConvention convention ) : ConventionProfile
convention IIgnoreExtraElementsConvention An ignore extra elements convention.
리턴 ConventionProfile
 public static void ConfigureMapping()
 {
     var conventionsProfile = new ConventionProfile();
     conventionsProfile.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
     conventionsProfile.SetIdMemberConvention(new NamedIdMemberConvention("Id"));
     BsonClassMap.RegisterConventions(conventionsProfile, t => typeof(ISagaEntity).IsAssignableFrom(t));
 }
        private IQueryable GetQueryableCollection(string connectionString, Dictionary<string, Type> providerTypes, string collectionName)
        {
            var collectionType = CreateDynamicTypeForCollection(collectionName, providerTypes);

            var conventions = new ConventionProfile();
            conventions.SetIdMemberConvention(new NamedIdMemberConvention(MongoMetadata.MappedObjectIdName));
            conventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
            BsonClassMap.RegisterConventions(conventions, t => t == collectionType);

            return InterceptingProvider.Intercept(
                new MongoQueryableResource(connectionString, collectionName, collectionType),
                new ResultExpressionVisitor());
        }
예제 #3
0
        public static void ConfigureMongoDB(IUnityContainer container)
        {
            var settings = container.Resolve<PrototypeSettings>();
            container.RegisterInstance(new MongoViewDatabase(settings.MongoViewConnectionString).EnsureIndexes());
            container.RegisterInstance(new MongoLogsDatabase(settings.MongoLogsConnectionString).EnsureIndexes());
            container.RegisterInstance(new MongoEventsDatabase(settings.MongoEventsConnectionString));

            // Register bson serializer conventions
            var myConventions = new ConventionProfile();
            myConventions.SetIdMemberConvention(new NoDefaultPropertyIdConvention());
            myConventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
            BsonClassMap.RegisterConventions(myConventions, type => true);
            DateTimeSerializationOptions.Defaults = DateTimeSerializationOptions.UtcInstance;
        }
예제 #4
0
        public void InitTestDatabase()
        {
            var conventions = new ConventionProfile();
            conventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());
            BsonClassMap.RegisterConventions(conventions, t => t.FullName.StartsWith("Bikee."));

            // Compose all maps.
            BsonMapRegistrator.Compose();

            string connectionString = ConfigurationManager.ConnectionStrings[0].ConnectionString;
            this.MongoServer = string.IsNullOrEmpty(connectionString)
                                                ? MongoServer.Create() // connect to local host
                                                : MongoServer.Create(connectionString);

            string databaseName = ConfigurationManager.AppSettings["testDatabaseName"] ?? "bikee_test";
            if (this.MongoServer.DatabaseExists(databaseName))
            {
                this.MongoServer.DropDatabase(databaseName);
            }

            this.MongoDatabase = this.MongoServer.GetDatabase(databaseName);

            DateTimeSerializationOptions.Defaults = DateTimeSerializationOptions.LocalInstance;
        }
        public void AfterPropertiesSet()
        {
            var defaultProfile = ConventionProfile.GetDefault();
            _profile = new ConventionProfile();
            _filter = new ConventionFilterHelper(IncludeFilters, ExcludeFilters);

            _profile.SetDefaultValueConvention(DefaultValueConvention ?? defaultProfile.DefaultValueConvention);
            _profile.SetElementNameConvention(ElementNameConvention ?? defaultProfile.ElementNameConvention);
            _profile.SetExtraElementsMemberConvention(ExtraElementsMemberConvention ?? defaultProfile.ExtraElementsMemberConvention);
            _profile.SetIdGeneratorConvention(IdGeneratorConvention ?? defaultProfile.IdGeneratorConvention);
            _profile.SetIdMemberConvention(IdMemberConvention ?? defaultProfile.IdMemberConvention);
            _profile.SetIgnoreExtraElementsConvention(IgnoreExtraElementsConvention ?? defaultProfile.IgnoreExtraElementsConvention);
            _profile.SetIgnoreIfDefaultConvention(IgnoreIfDefaultConvention ?? defaultProfile.IgnoreIfDefaultConvention);
            _profile.SetIgnoreIfNullConvention(IgnoreIfNullConvention ?? defaultProfile.IgnoreIfNullConvention);
            _profile.SetMemberFinderConvention(MemberFinderConvention ?? defaultProfile.MemberFinderConvention);
            _profile.SetSerializationOptionsConvention(SerializationOptionsConvention ?? defaultProfile.SerializationOptionsConvention);

            BsonClassMap.RegisterConventions(_profile, _filter.Filter);
        }
        /// <summary>
        /// Initializes the driver after it has been instantiated.
        /// </summary>
        /// <param name="cxInfo">the serialized connection properties.</param>
        /// <param name="context">The driver object</param>
        /// <param name="executionManager">The current Query Execution Manager for this query</param>
        public override void InitializeContext(IConnectionInfo cxInfo, object context, QueryExecutionManager executionManager)
        {
            base.InitializeContext(cxInfo, context, executionManager);

            //since the type is generated dynamically we can only access it by reflection
            ConnectionProperties props = propsSerializer.Deserialize(cxInfo.DriverData);

            PropertyInfo pinf = context.GetType().GetProperty("SqlTabWriter", BindingFlags.Instance | BindingFlags.Public);
            pinf.SetValue(context, executionManager.SqlTranslationWriter, null);

            if (props.InitializationQuery != null)
            {

                MethodInfo customInitialize = context.GetType().GetMethod("DoCustomInit", new[] { typeof(ConnectionProperties) });
                customInitialize.Invoke(context, new object[] { props });
            }

            MethodInfo init = context.GetType().GetMethod("InitCollections", BindingFlags.Instance | BindingFlags.Public);
            init.Invoke(context, new object[] { });

            if(!mSerializersAlreadyRegistered && props.CustomSerializers != null)
            {
                List<Assembly> assemblies =
                    props.AssemblyLocations.Select(LoadAssemblySafely).ToList();

                foreach (var pair in props.CustomSerializers)
                {
                    var type = assemblies.Select(a => a.GetType(pair.Key)).FirstOrDefault(x => x != null);
                    var serializer = assemblies.Select(a => a.GetType(pair.Value)).FirstOrDefault(x => x != null);
                    if (type == null || serializer == null)
                        return;
                        //throw new Exception(string.Format("Unable to initialize custom serializer {0} for type {1}", pair.Value, pair.Key));

                    BsonSerializer.RegisterSerializer(type, (IBsonSerializer)Activator.CreateInstance(serializer));
                }

                mSerializersAlreadyRegistered = true;
            }

            if (props.AdditionalOptions.BlanketIgnoreExtraElements)
            {
                var conventions = new ConventionProfile();
                conventions.SetIgnoreExtraElementsConvention(new AlwaysIgnoreExtraElementsConvention());

                BsonClassMap.RegisterConventions(conventions, t => true);
            }

            //set as default
            MongoDB.Bson.IO.JsonWriterSettings.Defaults.Indent = true;
        }