Exemple #1
0
        public GuidTypeResolver(params Type[] types)
        {
            if (types == null || types.Length == 0)
            {
                throw new AzosException(StringConsts.ARGUMENT_ERROR + "GuidTypeResolver.ctor(types==null|Empty)");
            }

            var mappings = types.ToDictionary(t => GuidTypeAttribute.GetGuidTypeAttribute <T, A>(t).TypeGuid, t => t);

            ctor(mappings);
        }
Exemple #2
0
        public GuidTypeResolver(IConfigSectionNode conf)
        {
            m_Cache = new Dictionary <Guid, Type>();

            if (conf == null || !conf.Exists)
            {
                return;
            }

            foreach (var nasm in conf.Children.Where(n => n.IsSameName(CONFIG_ASSEMBLY_SECTION)))
            {
                var asmName = nasm.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
                var asmNS   = nasm.AttrByName(CONFIG_NS_ATTR).Value;
                if (asmName.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var asm = Assembly.LoadFrom(asmName);

                foreach (var type in asm.GetTypes().Where(t => t.IsPublic && t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(T))))
                {
                    if (asmNS.IsNotNullOrWhiteSpace() && !Azos.Text.Utils.MatchPattern(type.FullName, asmNS))
                    {
                        continue;
                    }
                    var atr = GuidTypeAttribute.GetGuidTypeAttribute <T, A>(type);

                    Type existing;
                    if (m_Cache.TryGetValue(atr.TypeGuid, out existing))
                    {
                        throw new AzosException(StringConsts.GUID_TYPE_RESOLVER_DUPLICATE_ATTRIBUTE_ERROR.Args(type.FullName, atr.TypeGuid, existing.FullName));
                    }

                    m_Cache.Add(atr.TypeGuid, type);
                }
            }

            if (m_Cache.Count == 0)
            {
                App.Log.Write(new Azos.Log.Message
                {
                    Type  = Azos.Log.MessageType.Warning,
                    Topic = CoreConsts.APPLICATION_TOPIC,
                    From  = "{0}.ctor()".Args(GetType().Name),
                    Text  = "No assemblies/types have been registered"
                });
            }
        }
Exemple #3
0
        public GuidTypeResolver(IConfigSectionNode conf)
        {
            m_Cache = new Dictionary <Guid, Type>();

            if (conf == null || !conf.Exists)
            {
                return;
            }

            foreach (var nasm in conf.Children.Where(n => n.IsSameName(CONFIG_ASSEMBLY_SECTION)))
            {
                var asmName = nasm.AttrByName(Configuration.CONFIG_NAME_ATTR).Value;
                var asmNS   = nasm.AttrByName(CONFIG_NS_ATTR).Value;
                if (asmName.IsNullOrWhiteSpace())
                {
                    continue;
                }

                var asm = Assembly.LoadFrom(asmName);

                foreach (var type in asm.GetTypes().Where(t => t.IsPublic && t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(T))))
                {
                    if (asmNS.IsNotNullOrWhiteSpace() && !Azos.Text.Utils.MatchPattern(type.FullName, asmNS))
                    {
                        continue;
                    }
                    var atr = GuidTypeAttribute.GetGuidTypeAttribute <T, A>(type);

                    Type existing;
                    if (m_Cache.TryGetValue(atr.TypeGuid, out existing))
                    {
                        throw new AzosException(StringConsts.GUID_TYPE_RESOLVER_DUPLICATE_ATTRIBUTE_ERROR.Args(type.FullName, atr.TypeGuid, existing.FullName));
                    }

                    m_Cache.Add(atr.TypeGuid, type);
                }
            }

            if (m_Cache.Count == 0)
            {
                throw new AzosException(StringConsts.GUID_TYPE_RESOLVER_NO_TYPES_ERROR.Args(this.GetType().DisplayNameWithExpandedGenericArgs()));
            }
        }