public DocumentAlteration(ITypeSource typeSource)
        {
            var types = typeSource.GetTypes().ToArray();

            _hasDocumentIndexes  = types.Where(x => typeof(IHasDocumentIndex).IsAssignableFrom(x));
            _hasDocumentsIndexes = types.Where(x => typeof(IHasDocumentsIndex).IsAssignableFrom(x));
        }
Beispiel #2
0
        /// <summary>
        /// Adds local text translations defined implicitly by Description attributes in
        /// enumeration classes. Only enum values that has Description attribute are added as
        /// local text. By default, enums are registered in format:
        /// "Enums.{EnumerationTypeFullName}.{EnumValueName}". EnumerationTypeFullName, is
        /// fullname of the enumeration type. This can be overridden by attaching a EnumKey
        /// attribute.
        /// </summary>
        /// <param name="typeSource">Type source to search for enumeration classes in</param>
        /// <param name="languageID">Language ID texts will be added (default is invariant language)</param>
        /// <param name="registry">Registry</param>
        public static void AddEnumTexts(this ILocalTextRegistry registry, ITypeSource typeSource,
                                        string languageID = LocalText.InvariantLanguageID)
        {
            if (typeSource == null)
            {
                throw new ArgumentNullException("assemblies");
            }

            var provider = registry ?? throw new ArgumentNullException(nameof(registry));

            foreach (var type in typeSource.GetTypes())
            {
                if (type.IsEnum)
                {
                    var enumKey = EnumMapper.GetEnumTypeKey(type);

                    foreach (var name in Enum.GetNames(type))
                    {
                        var member = type.GetMember(name);
                        if (member.Length == 0)
                        {
                            continue;
                        }

                        var descAttr = member[0].GetCustomAttribute <DescriptionAttribute>();
                        if (descAttr != null)
                        {
                            provider.Add(languageID, "Enums." + enumKey + "." + name, descAttr.Description);
                        }
                    }
                }
            }
        }
        public void AddMappingsFromSource(ITypeSource source)
        {
            source.GetTypes()
            .Where(IsMappingOf <IMappingProvider>)
            .Each(Add);

            Log.LoadedFluentMappingsFromSource(source);
        }
Beispiel #4
0
        /// <summary>
        /// Maps the <see cref="IBusinessObject"/> classes in the <see cref="ITypeSource"/>.
        /// </summary>
        /// <returns></returns>
        ///
        public ClassDefCol Map()
        {
            var typesToBeMapped = Source.GetTypes().Where(type => type.MustBeMapped());
            var classDefsMapped = typesToBeMapped.Select(MapAndStoreClassDefFor).ToList();

            MapAllReverseRelationships(classDefsMapped);
            return(ClassDefCol);
        }
 public void AddMappingsFromSource(ITypeSource source)
 {
     source.GetTypes()
     .Where(x => IsMappingOf <IMappingProvider>(x) ||
            IsMappingOf <IIndeterminateSubclassMappingProvider>(x) ||
            IsMappingOf <IExternalComponentMappingProvider>(x) ||
            IsMappingOf <IFilterDefinition>(x))
     .Each(Add);
 }
Beispiel #6
0
        internal IEnumerable <Registration> GetRegistrations()
        {
            var types = _typeSource.GetTypes().ToList();

            return(from c in _conventions.AsParallel().AsOrdered()
                   let ct = c.GetType()
                            from t in types
                            where c.Matches(t)
                            select new Registration(ct, t));
        }
        public void AddSource(ITypeSource source)
        {
            foreach (var type in source.GetTypes())
            {
                if (type.IsAbstract || type.IsGenericType || !typeof(IConvention).IsAssignableFrom(type))
                {
                    continue;
                }

                Add(type, MissingConstructor.Ignore);
            }

            log.LoadedConventionsFromSource(source);
        }
        public static IEnumerable <string> ListPermissionKeys(IMemoryCache memoryCache, ITypeSource typeSource)
        {
            if (typeSource is null)
            {
                throw new ArgumentNullException(nameof(typeSource));
            }

            return(memoryCache.Get("Administration:PermissionKeys", TimeSpan.Zero, () =>
            {
                var result = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

                result.AddRange(NestedPermissionKeyRegistration.AddNestedPermissions(registry: null, typeSource));

                foreach (var attr in typeSource.GetAssemblyAttributes <PermissionAttributeBase>())
                {
                    if (!attr.Permission.IsEmptyOrNull())
                    {
                        result.AddRange(SplitPermissions(attr.Permission));
                    }
                }

                foreach (var type in typeSource.GetTypes())
                {
                    ProcessAttributes <PageAuthorizeAttribute>(result, type, x => x.Permission);
                    ProcessAttributes <PermissionAttributeBase>(result, type, x => x.Permission);
                    ProcessAttributes <ServiceAuthorizeAttribute>(result, type, x => x.Permission);

                    foreach (var member in type.GetMethods(BindingFlags.Instance | BindingFlags.Public))
                    {
                        ProcessAttributes <PageAuthorizeAttribute>(result, member, x => x.Permission);
                        ProcessAttributes <PermissionAttributeBase>(result, member, x => x.Permission);
                        ProcessAttributes <ServiceAuthorizeAttribute>(result, member, x => x.Permission);
                    }

                    foreach (var member in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                    {
                        if (member.GetIndexParameters().Length == 0)
                        {
                            ProcessAttributes <PermissionAttributeBase>(result, member, x => x.Permission);
                        }
                    }
                }

                result.Remove("*");
                result.Remove("?");

                return result;
            }));
        }
        public static void RegisterDataScripts(IDynamicScriptManager scriptManager,
                                               ITypeSource typeSource, IServiceProvider serviceProvider)
        {
            if (scriptManager == null)
            {
                throw new ArgumentNullException(nameof(scriptManager));
            }

            if (typeSource == null)
            {
                throw new ArgumentNullException(nameof(typeSource));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            DataScriptAttribute attr;

            foreach (var type in typeSource.GetTypes())
            {
                if (type.IsAbstract ||
                    type.IsInterface ||
                    type.IsGenericTypeDefinition ||
                    !type.IsPublic)
                {
                    continue;
                }

                attr = type.GetCustomAttribute <DataScriptAttribute>();
                if (attr != null)
                {
                    var script = (INamedDynamicScript)ActivatorUtilities
                                 .CreateInstance(serviceProvider, type);
                    scriptManager.Register(script);
                    continue;
                }
            }
        }
Beispiel #10
0
        public static void RegisterDistinctValueScripts(IDynamicScriptManager scriptManager,
                                                        ITypeSource typeSource, IServiceProvider serviceProvider)
        {
            if (scriptManager == null)
            {
                throw new ArgumentNullException(nameof(scriptManager));
            }

            if (typeSource == null)
            {
                throw new ArgumentNullException(nameof(typeSource));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var list = new List <DistinctValuesEditorAttribute>();

            foreach (var type in typeSource.GetTypes())
            {
                bool isRow = typeof(IRow).IsAssignableFrom(type) &&
                             !type.IsInterface;

                if (!isRow &&
                    type.GetCustomAttribute <FormScriptAttribute>() == null &&
                    type.GetCustomAttribute <ColumnsScriptAttribute>() == null)
                {
                    continue;
                }

                if (isRow &&
                    type.IsAbstract)
                {
                    continue;
                }

                foreach (var property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    var attr = property.GetCustomAttribute <DistinctValuesEditorAttribute>();
                    if (attr == null)
                    {
                        continue;
                    }

                    if (attr.RowType != null)
                    {
                        if (attr.RowType.IsInterface ||
                            attr.RowType.IsAbstract ||
                            !typeof(IRow).IsAssignableFrom(attr.RowType))
                        {
                            throw new Exception("DistinctValuesEditor can't be used with type: " +
                                                attr.RowType.FullName + " as it is not a row type. This attribute is specified " +
                                                "on " + property.Name + " property of " + type.FullName);
                        }

                        attr.PropertyName = attr.PropertyName.IsEmptyOrNull() ? property.Name :
                                            attr.PropertyName;
                    }
                    else
                    {
                        if (!isRow)
                        {
                            var basedOnRowAttr = type.GetCustomAttribute <BasedOnRowAttribute>();
                            if (basedOnRowAttr == null || basedOnRowAttr.RowType == null ||
                                basedOnRowAttr.RowType.IsAbstract ||
                                basedOnRowAttr.RowType.IsInterface ||
                                !typeof(IRow).IsAssignableFrom(basedOnRowAttr.RowType))
                            {
                                throw new Exception("Invalid usage of DistinctValuesEditor attribute on " +
                                                    "property " + property.Name + " of " + type.FullName + ". " +
                                                    "RowType has to be specified!");
                            }

                            attr.RowType = basedOnRowAttr.RowType;
                        }
                        else
                        {
                            attr.RowType = type;
                        }

                        attr.PropertyName = attr.PropertyName.IsEmptyOrNull() ? property.Name :
                                            attr.PropertyName;
                    }

                    list.Add(attr);
                }
            }

            var byRowProperty = list.ToLookup(x => new Tuple <Type, string>(x.RowType, x.PropertyName));

            foreach (var key in byRowProperty)
            {
                var row = (IRow)Activator.CreateInstance(key.Key.Item1);

                var script = (LookupScript)ActivatorUtilities.CreateInstance(serviceProvider,
                                                                             typeof(DistinctValuesScript <>).MakeGenericType(key.Key.Item1),
                                                                             new object[] { key.Key.Item2 });

                script.LookupKey = "Distinct." + row.GetFields().LocalTextPrefix + "." +
                                   key.Key.Item2;

                var withPermission = key.FirstOrDefault(x => !string.IsNullOrEmpty(x.Permission));
                if (withPermission != null)
                {
                    script.Permission = withPermission.Permission;
                }

                var withExpiration = key.FirstOrDefault(x => x.Expiration != 0);
                if (withExpiration != null)
                {
                    script.Expiration = TimeSpan.FromSeconds(withExpiration.Expiration);
                }

                scriptManager.Register(script.ScriptName, script);
            }
        }
 public IEnumerable <Type> GetTypes()
 {
     return(_innerTypeSource.GetTypes().Where(_predicate));
 }
Beispiel #12
0
 public IEnumerable <Type> GetTypes()
 {
     return(_inner.GetTypes().Where(_filter));
 }