Beispiel #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);
        }
Beispiel #2
0
        public GuidTypeResolver(IConfigSectionNode conf)
        {
            m_Cache1 = new Dictionary <Guid, Type>();
            m_Cache2 = new Dictionary <Fguid, 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.IsClass && !t.IsAbstract && typeof(TDecorationTarget).IsAssignableFrom(t))) //.Where(t => t.IsPublic && t.IsClass && !t.IsAbstract && typeof(TDecorationTarget).IsAssignableFrom(t)))
                {
                    if (asmNS.IsNotNullOrWhiteSpace() && !Azos.Text.Utils.MatchPattern(type.FullName, asmNS))
                    {
                        continue;
                    }
                    var atr = GuidTypeAttribute.TryGetGuidTypeAttribute <TDecorationTarget, TAttribute>(type);
                    if (atr == null)
                    {
                        continue;
                    }

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

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

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

            m_Cache1.ForEach(kvp => m_Cache2.Add(kvp.Key, kvp.Value));

            System.Threading.Thread.MemoryBarrier();
        }
Beispiel #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)
            {
                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"
                });
            }
        }