コード例 #1
0
 public ReportRegistry(ITypeSource typeSource, IPermissionService permissions, ITextLocalizer localizer)
 {
     types = (typeSource ?? throw new ArgumentNullException(nameof(types)))
             .GetTypesWithAttribute(typeof(ReportAttribute));
     this.permissions = permissions ?? throw new ArgumentNullException(nameof(permissions));
     this.localizer   = localizer ?? throw new ArgumentNullException(nameof(localizer));
 }
コード例 #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);
                        }
                    }
                }
            }
        }
コード例 #3
0
        public static void RegisterFormScripts(IDynamicScriptManager scriptManager,
                                               ITypeSource typeSource, IPropertyItemProvider propertyProvider, 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 scripts = new List <Func <string> >();

            foreach (var type in typeSource.GetTypesWithAttribute(typeof(FormScriptAttribute)))
            {
                var attr   = type.GetCustomAttribute <FormScriptAttribute>();
                var key    = attr.Key ?? type.FullName;
                var script = new FormScript(key, type, propertyProvider, serviceProvider);
                scriptManager.Register(script);
                scripts.Add(script.GetScript);
            }

            scriptManager.Register("FormBundle", new ConcatenatedScript(scripts));
        }
コード例 #4
0
        public ImplementationTypesCollection(ITypeSource typeSource, ITypesHelper typesHelper)
        {
            this.typeSource  = typeSource;
            this.typesHelper = typesHelper;

            getImplementationTypes = GetImplementationTypes;
        }
コード例 #5
0
 public TranslationController(IWebHostEnvironment hostEnvironment,
                              ILocalTextRegistry localTextRegistry, ITypeSource typeSource)
 {
     HostEnvironment   = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
     LocalTextRegistry = localTextRegistry ?? throw new ArgumentNullException(nameof(localTextRegistry));
     TypeSource        = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
 }
コード例 #6
0
        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));
        }
コード例 #7
0
        private static ILookup <string, NavigationItemAttribute> GetNavigationItemAttributes(
            ITypeSource typeSource, IServiceProvider serviceProvider,
            Func <NavigationItemAttribute, bool> filter)
        {
            var list = new List <NavigationItemAttribute>();

            foreach (NavigationItemAttribute attr in typeSource
                     .GetAssemblyAttributes <NavigationItemAttribute>())
            {
                if (filter == null || filter(attr))
                {
                    list.Add(attr);
                }
            }

            foreach (var navItemType in typeSource.GetTypesWithInterface(typeof(INavigationItemSource))
                     .Where(x => !x.IsAbstract && !x.IsInterface))
            {
                var navItem = (INavigationItemSource)ActivatorUtilities.CreateInstance(
                    serviceProvider, navItemType);
                foreach (var item in navItem.GetItems())
                {
                    if (filter == null || filter(item))
                    {
                        list.Add(item);
                    }
                }
            }

            return(ByCategory(list));
        }
コード例 #8
0
 ///<summary>
 /// constructor that takes a <see cref="ITypeSource"/> that wil be used to build the
 /// ClassDefinitions.
 ///</summary>
 ///<param name="source"></param>
 ///<exception cref="ArgumentNullException"></exception>
 public ReflectionClassDefLoader(ITypeSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     Source = source;
 }
コード例 #9
0
        public FilteredTypeSource(Func<Type, bool> filter, ITypeSource inner)
        {
            Guard.IsNotNull(filter, "filter");
            Guard.IsNotNull(inner, "inner");

            _filter = filter;
            _inner = inner;
        }
コード例 #10
0
 public TranslationRepository(IRequestContext context, IWebHostEnvironment hostEnvironment,
                              ILocalTextRegistry localTextRegistry, ITypeSource typeSource)
     : base(context)
 {
     HostEnvironment   = hostEnvironment;
     LocalTextRegistry = localTextRegistry;
     TypeSource        = typeSource;
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DefaultPropertyItemProvider"/> class.
 /// </summary>
 /// <param name="provider">The provider.</param>
 /// <param name="typeSource">The type source.</param>
 /// <exception cref="ArgumentNullException">
 /// provider or typeSource is null
 /// </exception>
 public DefaultPropertyItemProvider(IServiceProvider provider, ITypeSource typeSource)
 {
     this.provider      = provider ?? throw new ArgumentNullException(nameof(provider));
     processorFactories = (typeSource ?? throw new ArgumentNullException(nameof(typeSource)))
                          .GetTypesWithInterface(typeof(IPropertyProcessor))
                          .Where(x => !x.IsAbstract && !x.IsInterface)
                          .Select(type => ActivatorUtilities.CreateFactory(type, Type.EmptyTypes));
 }
コード例 #12
0
        public void AddMappingsFromSource(ITypeSource source)
        {
            source.GetTypes()
            .Where(IsMappingOf <IMappingProvider>)
            .Each(Add);

            Log.LoadedFluentMappingsFromSource(source);
        }
コード例 #13
0
 internal static IFilterableTypeSource FromTypeSource(ITypeSource typeSource)
 {
     if (typeSource == null)
     {
         throw new ArgumentNullException("typeSource");
     }
     return(new FilterableTypeSource(typeSource));
 }
コード例 #14
0
 /// <summary>
 /// Constructs the AllClassesAutoMapper with a specified Source.
 /// </summary>
 /// <param name="source"></param>
 public AllClassesAutoMapper(ITypeSource source)
 {
     if (source == null)
     {
         throw new ArgumentNullException("source");
     }
     Source = source;
 }
コード例 #15
0
 public PermissionService(ITwoLevelCache cache, ISqlConnections sqlConnections,
                          ITypeSource typeSource, IUserAccessor userAccessor)
 {
     Cache          = cache ?? throw new ArgumentNullException(nameof(cache));
     SqlConnections = sqlConnections ?? throw new ArgumentNullException(nameof(sqlConnections));
     TypeSource     = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
     UserAccessor   = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor));
 }
コード例 #16
0
 public ListResponse <string> ListPermissionKeys(
     [FromServices] ITypeSource typeSource)
 {
     return(new ListResponse <string>
     {
         Entities = MyRepository.ListPermissionKeys(Cache.Memory, typeSource).ToList()
     });
 }
コード例 #17
0
        public FilteredTypeSource(Func <Type, bool> filter, ITypeSource inner)
        {
            Guard.IsNotNull(filter, "filter");
            Guard.IsNotNull(inner, "inner");

            _filter = filter;
            _inner  = inner;
        }
コード例 #18
0
        public ITypeScanner Scan(ITypeSource typeSource)
        {
            Guard.IsNotNull(typeSource, "typeSource");

            var scanner = new TypeScanner(typeSource);
            _typeScanners.Add(scanner);
            return scanner;
        }
コード例 #19
0
 public void AddMappingsFromSource(ITypeSource source)
 {
     source.GetTypes()
     .Where(x => IsMappingOf <IMappingProvider>(x) ||
            IsMappingOf <IIndeterminateSubclassMappingProvider>(x) ||
            IsMappingOf <IExternalComponentMappingProvider>(x) ||
            IsMappingOf <IFilterDefinition>(x))
     .Each(Add);
 }
コード例 #20
0
 public void LoadedConventionsFromSource(ITypeSource source)
 {
     isDirty = true;
     scannedSources.Add(new ScannedSource
     {
         Identifier = source.GetIdentifier(),
         Phase      = ScanPhase.Conventions
     });
 }
コード例 #21
0
 public IFilterableTypeSource FromTypeSource(ITypeSource typeSource)
 {
     if (typeSource == null)
     {
         throw new ArgumentNullException("typeSource");
     }
     _innerTypeSource = typeSource;
     return(this);
 }
コード例 #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DefaultRowTypeRegistry"/> class.
        /// </summary>
        /// <param name="typeSource">The type source.</param>
        /// <exception cref="ArgumentNullException">typeSource</exception>
        public DefaultRowTypeRegistry(ITypeSource typeSource)
        {
            rowTypes = (typeSource ?? throw new ArgumentNullException(nameof(typeSource)))
                       .GetTypesWithInterface(typeof(IRow))
                       .Where(x => !x.IsAbstract && !x.IsInterface);

            byConnectionKey = rowTypes.Where(x => x.GetCustomAttribute <ConnectionKeyAttribute>() != null)
                              .ToLookup(x => x.GetCustomAttribute <ConnectionKeyAttribute>().Value);
        }
コード例 #23
0
 public void LoadedFluentMappingsFromSource(ITypeSource source)
 {
     isDirty = true;
     scannedSources.Add(new ScannedSource
     {
         Identifier = source.GetIdentifier(),
         Phase = ScanPhase.FluentMappings
     });
 }
コード例 #24
0
        internal FilterableTypeSource(ITypeSource innerTypeSource, Func <Type, bool> predicate = null) : this(predicate)
        {
            if (innerTypeSource == null)
            {
                throw new ArgumentNullException("innerTypeSource");
            }

            _innerTypeSource = innerTypeSource;
        }
コード例 #25
0
 public void LoadedFluentMappingsFromSource(ITypeSource source)
 {
     isDirty = true;
     scannedSources.Add(new ScannedSource
     {
         Identifier = source.GetIdentifier(),
         Phase      = ScanPhase.FluentMappings
     });
 }
コード例 #26
0
        public static List <NavigationItem> GetNavigationItems(IPermissionService permissions,
                                                               ITypeSource typeSource, IServiceProvider serviceProvider,
                                                               Func <string, string> resolveUrl            = null,
                                                               Func <NavigationItemAttribute, bool> filter = null)
        {
            var menuItems = GetNavigationItemAttributes(typeSource, serviceProvider, filter);

            return(ConvertToNavigationItems(permissions, menuItems, resolveUrl));
        }
コード例 #27
0
 public void LoadedConventionsFromSource(ITypeSource source)
 {
     isDirty = true;
     scannedSources.Add(new ScannedSource
     {
         Identifier = source.GetIdentifier(),
         Phase = ScanPhase.Conventions
     });
 }
コード例 #28
0
        public ITypeScanner Scan(ITypeSource typeSource)
        {
            Guard.IsNotNull(typeSource, "typeSource");

            var scanner = new TypeScanner(typeSource);

            _typeScanners.Add(scanner);
            return(scanner);
        }
コード例 #29
0
ファイル: TypeScanner.cs プロジェクト: bnwasteland/thorn
 public IEnumerable<Export> GetExportsIn(ITypeSource source)
 {
     var result = new List<Export>();
     foreach (var type in _convention.TypesToExport(source.Types))
     {
         result.AddRange(GetExportsIn(type));
     }
     return result;
 }
コード例 #30
0
 public UserDataScript(ITwoLevelCache cache, IPermissionService permissions,
                       ITypeSource typeSource, IUserAccessor userAccessor, IUserRetrieveService userRetrieveService)
 {
     Cache         = cache ?? throw new ArgumentNullException(nameof(cache));
     Permissions   = permissions ?? throw new ArgumentNullException(nameof(permissions));
     TypeSource    = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
     UserAccessor  = userAccessor ?? throw new ArgumentNullException(nameof(userAccessor));
     UserRetriever = userRetrieveService ?? throw new ArgumentNullException(nameof(userRetrieveService));
 }
コード例 #31
0
        internal FilterableTypeSource(ITypeSource innerTypeSource)
        {
            if (innerTypeSource == null)
            {
                throw new ArgumentNullException("innerTypeSource");
            }

            _innerTypeSource = innerTypeSource;
            _predicate       = anyType;
        }
コード例 #32
0
        public TestContainerProvider(string connectionString, ITypeSource typeSource)
        {
            var builder = new ContainerBuilder()
                .RegisterPersistence(connectionString, typeSource)
                .RegisterApplicationServices(Assembly.GetExecutingAssembly());

            RegisterMockedUserContext(builder);

            this.Container = builder.Build();
        }
コード例 #33
0
        public static IDictionary<string, HashSet<string>> GetImplicitPermissions(IMemoryCache memoryCache,
            ITypeSource typeSource)
        {
            if (memoryCache is null)
                throw new ArgumentNullException(nameof(memoryCache));

            if (typeSource is null)
                throw new ArgumentNullException(nameof(typeSource));

            return memoryCache.Get<IDictionary<string, HashSet<string>>>("ImplicitPermissions", TimeSpan.Zero, () =>
            {
                var result = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase);

                Action<Type> addFrom = null;
                addFrom = (type) =>
                {
                    foreach (var member in type.GetFields(BindingFlags.Static | BindingFlags.DeclaredOnly |
                        BindingFlags.Public | BindingFlags.NonPublic))
                    {
                        if (member.FieldType != typeof(String))
                            continue;

                        var key = member.GetValue(null) as string;
                        if (key == null)
                            continue;

                        foreach (var attr in member.GetCustomAttributes<ImplicitPermissionAttribute>())
                        {
                            HashSet<string> list;
                            if (!result.TryGetValue(key, out list))
                            {
                                list = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
                                result[key] = list;
                            }

                            list.Add(attr.Value);
                        }
                    }

                    foreach (var nested in type.GetNestedTypes(BindingFlags.Public | BindingFlags.DeclaredOnly))
                        addFrom(nested);
                };

                foreach (var type in typeSource.GetTypesWithAttribute(
                    typeof(NestedPermissionKeysAttribute)))
                {
                    addFrom(type);
                }

                return result;
            });
        }
コード例 #34
0
        public static AutoPersistenceModel Source(ITypeSource source, Func <Type, bool> where)
        {
            var persistenceModel = new AutoPersistenceModel();

            persistenceModel.AddTypeSource(source);

            if (where != null)
            {
                persistenceModel.Where(where);
            }

            return(persistenceModel);
        }
コード例 #35
0
        public TestContainerProvider(ITypeSource typeSource)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            var builder = new ContainerBuilder()
                .RegisterPersistence(connectionString, typeSource)
                .RegisterApplicationServices(Assembly.GetExecutingAssembly());

            var mockedUserContext = CreateMockedUserContext();
            builder.RegisterInstance(mockedUserContext).AsImplementedInterfaces();

            this.Container = builder.Build();
        }
コード例 #36
0
        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);
        }
コード例 #37
0
 ///<summary>
 /// constructor that takes a <see cref="ITypeSource"/> that wil be used to build the
 /// ClassDefinitions.
 ///</summary>
 ///<param name="source"></param>
 ///<exception cref="ArgumentNullException"></exception>
 public ReflectionClassDefLoader(ITypeSource source)
 {
     if (source == null) throw new ArgumentNullException("source");
     Source = source;
 }
コード例 #38
0
ファイル: FilterableTypeSource.cs プロジェクト: drwill/Quarks
		internal FilterableTypeSource(ITypeSource innerTypeSource, Func<Type, bool> predicate = null) : this(predicate)
		{
			if (innerTypeSource == null) throw new ArgumentNullException("innerTypeSource");

			_innerTypeSource = innerTypeSource;
		}
コード例 #39
0
 public static ContainerBuilder RegisterPersistence(this ContainerBuilder builder, string connectionString, ITypeSource persistenceModelsTypeSource)
 {
     var autoPersistenceModel = AutoMap.Source(persistenceModelsTypeSource, new AutomappingConfiguration());
     InternalRegisterPersistence(builder, connectionString, autoPersistenceModel);
     return builder;
 }
コード例 #40
0
 public TypeScanner(ITypeSource typeSource)
 {
     _typeSource = typeSource;
 }
コード例 #41
0
 public void LoadedFluentMappingsFromSource(ITypeSource source)
 {}
コード例 #42
0
 public void LoadedConventionsFromSource(ITypeSource source)
 {}
コード例 #43
0
 /// <summary>
 /// Constructs the AllClassesAutoMapper with a specified Source.
 /// </summary>
 /// <param name="source"></param>
 public AllClassesAutoMapper(ITypeSource source)
 {
     if (source == null) throw new ArgumentNullException("source");
     Source = source;
 }
コード例 #44
0
ファイル: FilterableTypeSource.cs プロジェクト: drwill/Quarks
		public IFilterableTypeSource FromTypeSource(ITypeSource typeSource)
		{
			if (typeSource == null) throw new ArgumentNullException("typeSource");
			_innerTypeSource = typeSource;
			return this;
		}
コード例 #45
0
		public void DeclaredProvider( ITypeSource sut )
		{
			Assert.NotNull( sut );
			Assert.Same( DeclaredAssemblyProvider.Default, sut );
		}
コード例 #46
0
ファイル: FilterableTypeSource.cs プロジェクト: drwill/Quarks
		internal static IFilterableTypeSource FromTypeSource(ITypeSource typeSource)
		{
			if (typeSource == null) throw new ArgumentNullException("typeSource");
			return new FilterableTypeSource(typeSource);
		}