internal IAdminPacketService Create()
        {
            IEnumerable <Type> packetTransformerTypes = new AssemblyTypeFinder(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.PacketTransformers")
                                                        .WithTypeMatcher(new ClassTypeMatcher())
                                                        .WithTypeMatcher(ImplementsTypeMatcher.Create <IPacketTransformer>())
                                                        .Find();

            IEnumerable <Type> messageTransformerTypes = new AssemblyTypeFinder(Assembly.GetExecutingAssembly(), $"{GetType().Namespace}.MessageTransformers")
                                                         .WithTypeMatcher(new ClassTypeMatcher())
                                                         .WithTypeMatcher(ImplementsTypeMatcher.Create <IMessageTransformer>())
                                                         .Find();

            IPacketTransformer[]  packetTransformers  = new IPacketTransformer[packetTransformerTypes.Count()];
            IMessageTransformer[] messageTransformers = new IMessageTransformer[messageTransformerTypes.Count()];

            for (int i = 0; i < packetTransformers.Length; ++i)
            {
                packetTransformers[i] = (IPacketTransformer)Activator.CreateInstance(packetTransformerTypes.ElementAt(i));
            }

            for (int i = 0; i < messageTransformers.Length; ++i)
            {
                messageTransformers[i] = (IMessageTransformer)Activator.CreateInstance(messageTransformerTypes.ElementAt(i));
            }

            return(new AdminPacketService(packetTransformers, messageTransformers));
        }
예제 #2
0
        public AdminEventFactory()
        {
            var creatorTypes = new AssemblyTypeFinder(Assembly.GetExecutingAssembly(), GetType().Namespace + ".Creators")
                               .WithTypeMatcher(new ClassTypeMatcher())
                               .WithTypeMatcher(new ImplementsTypeMatcher(typeof(IEventCreator)))
                               .Find();

            var creators = new IEventCreator[creatorTypes.Count()];

            for (int i = 0; i < creators.Length; ++i)
            {
                creators[i] = (IEventCreator)Activator.CreateInstance(creatorTypes.ElementAt(i));
            }

            this.creators = creators.ToDictionary(x => x.SupportedMessageType);
        }