Example #1
0
        /// <summary>
        /// Helper method to retrieve and validate configuration.
        /// </summary>
        /// <param name="configurationProvider">The configuration provider</param>
        /// <param name="configurationIdentifier">The configuration identifier</param>
        private static Dictionary <string, string> RetrieveAndValidateConfiguration(IQueueConfigurationProvider configurationProvider, string configurationIdentifier)
        {
            #region Initialization
            Dictionary <string, string> configuration = null;
            #endregion

            #region Configuration Retrieval
            configuration = configurationProvider.GetConfiguration(configurationIdentifier);
            #endregion

            #region Validation
            configuration = configuration ?? new Dictionary <string, string>();

            // Implementation
            if (!configuration.ContainsKey(CommonConfigurationKeys.Implementation) ||
                string.IsNullOrEmpty(configuration[CommonConfigurationKeys.Implementation]))
            {
                throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                         string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                       CommonConfigurationKeys.Implementation));
            }
            #endregion

            #region Return
            return(configuration);

            #endregion
        }
Example #2
0
        /// <summary>
        /// Creates IOutboundFaFMq implementation with the configuration provided by provider.
        /// </summary>
        /// <param name="configurationProvider">The configuration provider</param>
        /// <param name="logger">The queue logger</param>
        /// <param name="configurationIdentifier">The configuration identifier</param>
        public static IOutboundFaFMq <TMessage> CreateOutboundFaF <TMessage>(IQueueConfigurationProvider configurationProvider, string configurationIdentifier, IQueueLogger logger = null)
        {
            #region Initialization
            logger = logger ?? new NoLog();
            Dictionary <string, string> configuration = null;
            #endregion

            try
            {
                #region Configuration Retrieval
                configuration = RetrieveAndValidateConfiguration(configurationProvider, configurationIdentifier);
                #endregion

                #region Creating Implementation
                // Getting type details.
                var messageQueueTypeInfo = Type.GetType(configuration[CommonConfigurationKeys.Implementation], true, true);

                // Substituting generic parameters.
                var typeParams      = new[] { typeof(TMessage) };
                var genericTypeInfo = messageQueueTypeInfo.MakeGenericType(typeParams);

                // Creating instance.
                var messagingQueue =
                    Activator.CreateInstance(genericTypeInfo, configuration, logger) as IOutboundFaFMq <TMessage>;
                #endregion

                #region Return
                return(messagingQueue);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw;
            }
            catch (Exception ex)
            {
                var queueException = new QueueException(QueueErrorCode.FailedToInstantiateOutboundFaFMq,
                                                        ErrorMessages.FailedToInstantiateOutboundFaF, ex);

                queueException.Data["Implementation"] = configuration?[CommonConfigurationKeys.Implementation];

                #region Logging - Error
                logger.Error(queueException, queueException.Message);
                #endregion

                throw queueException;
            }
        }