Ejemplo n.º 1
0
        /// <summary>
        /// Creates the message sink.
        /// </summary>
        /// <param name="pi">The pi.</param>
        /// <returns></returns>
        protected IMessageSink CreateMessageSink(CategoryPropertyItem pi)
        {
            if (string.IsNullOrEmpty(pi.EntryValue))
            {
                throw new InvalidConfigurationException("No message sink class definied in a message sink configuration entry.");
            }

            IMessageSink result = null;

            try
            {
                if (LOGGER.IsInfoEnabled)
                {
                    LOGGER.Info(string.Format("Channel, create message sink from type '{0}'. ChannelId: '{1}'.", pi.EntryValue, this.ChannelId));
                }
                Type type = TypeHelper.GetTypeFromString(pi.EntryValue);
                result = (IMessageSink)type.GetConstructor(new Type[] { }).Invoke(null);
                result.Initialize(pi);
            }
            catch (Exception ex)
            {
                throw new InvalidConfigurationException(String.Format("Unable to instantiate message sink '{0}' specified in configuration.", pi.EntryValue), ex);
            }
            return(result);
        }