/// <summary> /// Initializes a new instance of the <see cref="ConfigurablePacketHandler"/> class. /// </summary> /// <param name="handlerConfiguration">The handler configuration.</param> /// <param name="container">The container.</param> public ConfigurablePacketHandler(PacketHandlerConfiguration handlerConfiguration, IUnityContainer container) { foreach (var config in handlerConfiguration.SubPacketHandlers) { this.CreateHandler(container, config); } }
/// <summary> /// Creates the a new handler, based on the configuration. /// </summary> /// <param name="container">The container.</param> /// <param name="handlerConfiguration">The handler configuration.</param> protected void CreateHandler(IUnityContainer container, PacketHandlerConfiguration handlerConfiguration) { IPacketHandler handler = null; this.encryptionChecks[handlerConfiguration.PacketIdentifier] = handlerConfiguration.NeedsToBeEncrypted; if (handlerConfiguration.SubPacketHandlers != null && handlerConfiguration.SubPacketHandlers.Count > 0) { handler = new ConfigurablePacketHandler(handlerConfiguration, container); } else { var handlerType = Type.GetType(handlerConfiguration.PacketHandlerClassName); if (handlerType == null) { this.log.Warn($"Handler type {handlerConfiguration.PacketHandlerClassName} not found."); } else { var obj = container.Resolve(handlerType, string.Empty); handler = obj as IPacketHandler; } } this.packetHandler[handlerConfiguration.PacketIdentifier] = handler; }