public static void AddRange(this FluentMappingsContainer container, IEnumerable <Type> types)
 {
     foreach (var type in types ?? Enumerable.Empty <Type>())
     {
         container?.Add(type);
     }
 }
Exemple #2
0
 private void AddFilters(FluentMappingsContainer fluentMappingsContainer)
 {
     foreach (var filter in FluentSessionMappingConfig.Instance.Filters)
     {
         var type = typeof(FluentFilterDefinition <>).MakeGenericType(filter.Type);
         fluentMappingsContainer.Add(type);
     }
 }
Exemple #3
0
        public static FluentMappingsContainer AddAuditModels(this FluentMappingsContainer mappings)
        {
            var auditType = Type.GetType("WebsiteTemplate.Mappings.AuditEventMapping, WebsiteTemplate");

            mappings.Add(auditType);

            return(mappings);
        }
Exemple #4
0
        private void ApplyMapping(FluentMappingsContainer fluentMappings)
        {
            var mappings = this.Container.ResolveAll <IMapping>();

            foreach (var mapping in mappings)
            {
                fluentMappings.Add(mapping.GetType());
            }
        }
Exemple #5
0
        public void MapTypes(FluentMappingsContainer mappingsContainer) {
            var rootDir = AppDomain.CurrentDomain.BaseDirectory;
            var assemblies = AppDomain.CurrentDomain.GetAssemblies()
                .Where(m => !m.IsDynamic && Path.GetDirectoryName(m.CodeBase.Substring(8)).StartsWith(rootDir))
                .Where(m => Constant.ExcludeFlag.All(it => !m.FullName.StartsWith(it, true, CultureInfo.CurrentCulture)));

            var allDataMapping = assemblies.SelectMany(s => s.GetTypes())
                .Where(p => typeof(IMappingProvider).IsAssignableFrom(p))
                .Where(p => p.BaseType.GetGenericArguments().Any(m => IsAssignableToGenericType(m, typeof(IEntityBase<>))));

            foreach (var dataMapping in allDataMapping) {
                mappingsContainer.Add(dataMapping);
            }
        }
        public static FluentMappingsContainer AddFromNamespaceOf <T>(this FluentMappingsContainer fmc)
        {
            var ns    = typeof(T).Namespace;
            var types = typeof(T).Assembly.GetExportedTypes()
                        .Where(t => t.Namespace == ns)
                        .Where(x => IsMappingOf <IMappingProvider>(x) ||
                               IsMappingOf <IIndeterminateSubclassMappingProvider>(x) ||
                               IsMappingOf <IExternalComponentMappingProvider>(x) ||
                               IsMappingOf <IFilterDefinition>(x));

            foreach (var t in types)
            {
                fmc.Add(t);
            }

            return(fmc);
        }
Exemple #7
0
        public static FluentMappingsContainer AddFromAssemblyOf <T>(this FluentMappingsContainer mappings, Predicate <Type> where)
        {
            if (where == null)
            {
                return(mappings.AddFromAssemblyOf <T>());
            }

            var mappingClasses = typeof(T).Assembly.GetExportedTypes()
                                 .Where(x => (typeof(IMappingProvider).IsAssignableFrom(x) || typeof(IIndeterminateSubclassMappingProvider).IsAssignableFrom(x)))
                                 .Where(x => where (x));

            foreach (var type in mappingClasses)
            {
                mappings.Add(type);
            }

            return(mappings);
        }
Exemple #8
0
        // http://stackoverflow.com/q/6204511/206297
        public static FluentMappingsContainer AddFromAssemblyOf <T>(this FluentMappingsContainer mappings, Predicate <Type> where)
        {
            if (where == null)
            {
                return(mappings.AddFromAssemblyOf <T>());
            }

            var mappingClasses = typeof(T).Assembly.GetExportedTypes()
                                 .Where(x => IsMappingOf <IMappingProvider>(x) ||
                                        IsMappingOf <IIndeterminateSubclassMappingProvider>(x) ||
                                        IsMappingOf <IExternalComponentMappingProvider>(x) ||
                                        IsMappingOf <IFilterDefinition>(x))
                                 .Where(x => where (x));

            foreach (var type in mappingClasses)
            {
                mappings.Add(type);
            }

            return(mappings);
        }
Exemple #9
0
        /// <summary>
        ///     Adds mappings from the assembly and namespace specified by <typeparamref name="T" />.
        /// </summary>
        /// <remarks>
        ///     This method is useful when multiple databases are mapped from the same assembly
        ///     as it allows to separate mappings by namespace.
        /// </remarks>
        /// <typeparam name="T">Type to use as assembly and namespace filter.</typeparam>
        /// <param name="mappingsContainer">Mappings container</param>
        /// <returns>Container <paramref name="mappingsContainer" /></returns>
        /// <exception cref="T:System.ArgumentNullException"><paramref name="mappingsContainer" /> is <c>null</c>.</exception>
        public static FluentMappingsContainer AddFromNamespaceOf <T>(this FluentMappingsContainer mappingsContainer)
        {
            if (mappingsContainer == null)
            {
                throw new ArgumentNullException(nameof(mappingsContainer));
            }
            string ns    = typeof(T).Namespace !;
            var    types = typeof(T).Assembly.GetTypes()
                           .Where(t => !t.IsAbstract && t.Namespace == ns)
                           .Where(x => IsMappingOf <IMappingProvider>(x) ||
                                  IsMappingOf <IIndeterminateSubclassMappingProvider>(x) ||
                                  IsMappingOf <IExternalComponentMappingProvider>(x) ||
                                  IsMappingOf <IFilterDefinition>(x));

            foreach (var t in types)
            {
                mappingsContainer.Add(t);
            }

            return(mappingsContainer);
        }
 private static void GetMappings(this FluentMappingsContainer map)
 {
     map.Add <UserMap>();
 }
Exemple #11
0
        public static FluentMappingsContainer AddFromRunningAssemblies(this FluentMappingsContainer mappings)
        {
            var types         = new List <Type>();
            var allAssemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (var assembly in allAssemblies)
            {
                var assemblyTypes = assembly.GetTypes();
                var tmpBaseTypes  = assemblyTypes
                                    .Where(myType => myType.IsClass /*&& !myType.IsAbstract */ && myType.IsSubclassOf(typeof(DynamicClass)))
                                    .ToList();
                types.AddRange(tmpBaseTypes);

                var refreshTokenMapper = assemblyTypes.Where(t => t.Name.EndsWith("RefreshTokenMap")).FirstOrDefault();
                if (refreshTokenMapper != null)
                {
                    mappings.Add(refreshTokenMapper);
                }

                var baseMappingTypes = assemblyTypes.Where(t => t.BaseType != null &&
                                                           t.BaseType.Name.Contains("BaseClassMap") &&
                                                           !t.Name.Contains("AuditEventMapping"))      // Don't map audit table to main data store.
                                       .ToList();
                if (baseMappingTypes.Count > 0)
                {
                    baseMappingTypes.ForEach(b =>
                    {
                        mappings.Add(b);
                    });
                }
            }

            var list = new List <string>();

            foreach (var type in types)
            {
                var typeString = type.ToString();
                if (list.Contains(typeString))
                {
                    continue;
                }

                list.Add(typeString);
                if (type.BaseType == typeof(DynamicClass))
                {
                    var    d1       = typeof(DynamicMap <>);
                    Type[] typeArgs = { type };
                    var    makeme   = d1.MakeGenericType(typeArgs);
                    mappings.Add(makeme);
                }
                else
                {
                    var    d1       = typeof(ChildDynamicMap <>);
                    Type[] typeArgs = { type };
                    var    makeme   = d1.MakeGenericType(typeArgs);
                    mappings.Add(makeme);
                }
            }

            return(mappings);
        }
 private static void GetMappings(this FluentMappingsContainer map)
 {
     map.Add <RecordMap>();
     map.Add <EmployeeMap>();
 }