示例#1
0
        /// <summary>
        /// Helper method to validate and collect ZeroMq parameters.
        /// </summary>
        public static ZeroMqConfiguration CollectZmqConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Parameters Validation
                var zeroMqSettings = new ZeroMqConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();

                var notSupportedParams =
                    rawConfiguration.Keys.Where(x => !CommonConfigurationKeys.GetAllKeys().Contains(x) &&
                                                !ZeroMqConfigurationKeys.GetAllKeys().Contains(x)).ToList();

                if (notSupportedParams.Any())
                {
                    throw new QueueException(QueueErrorCode.NotSupportedConfigurationParameters,
                                             ErrorMessages.NotSupportedConfigurationParameters, context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.NotSupportedParameters] = string.Join(",", notSupportedParams)
                    });
                }

                // Address
                if (!rawConfiguration.ContainsKey(CommonConfigurationKeys.Address) ||
                    string.IsNullOrWhiteSpace(rawConfiguration[CommonConfigurationKeys.Address]))
                {
                    throw new QueueException(QueueErrorCode.MissingRequiredConfigurationParameter,
                                             string.Format(ErrorMessages.MissingRequiredConfigurationParameter,
                                                           CommonConfigurationKeys.Address),
                                             context: new Dictionary <string, string>
                    {
                        [CommonContextKeys.ParameterName] = CommonConfigurationKeys.Address
                    });
                }

                zeroMqSettings.Address = rawConfiguration[CommonConfigurationKeys.Address];
                #endregion

                #region Return
                return(zeroMqSettings);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, ZeroMqName);
                #endregion

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

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, ZeroMqName, logger: logger);
            }
        }
        /// <summary>
        /// Helper method to validate and collect ZeroMq parameters.
        /// </summary>
        public static ZeroMqConfiguration CollectZmqConfiguration(ref Dictionary <string, string> rawConfiguration, bool isInbound, ref IQueueLogger logger)
        {
            try
            {
                #region Initialization
                var zeroMqConfiguration = new ZeroMqConfiguration();
                rawConfiguration = rawConfiguration ?? new Dictionary <string, string>();
                #endregion

                #region Collecting Common Configuration
                MessageQueueCommonItems.CollectCommonConfiguration(ref rawConfiguration, zeroMqConfiguration, ZeroMqConfigurationKeys.GetAllKeys());
                #endregion

                #region Collecting Other Configuration
                // Nothing to collect.
                #endregion

                #region Return
                return(zeroMqConfiguration);

                #endregion
            }
            catch (QueueException queueException)
            {
                #region Adding Context Data
                queueException.Data.Add(CommonContextKeys.QueueContext, ZeroMqName);
                #endregion

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

                throw;
            }
            catch (Exception ex)
            {
                throw MessageQueueCommonItems.PrepareAndLogQueueException(
                          QueueErrorCode.GeneralConfigurationParsingError
                          , ErrorMessages.GeneralConfigurationParsingError, ex, ZeroMqName, logger: logger);
            }
        }