Beispiel #1
0
 /// <summary>
 /// Converts array element into a boolean or returns default value if conversion is not possible.
 /// </summary>
 /// <param name="index">an index of element to get.</param>
 /// <param name="defaultValue">the default value</param>
 /// <returns>boolean of the element or default value if conversion is not supported.</returns>
 /// See <see cref="BooleanConverter.ToBooleanWithDefault(object, bool)"/>
 public bool GetAsBooleanWithDefault(int index, bool defaultValue)
 {
     return(BooleanConverter.ToBooleanWithDefault(this[index], defaultValue));
 }
Beispiel #2
0
        /// <summary>
        /// Converts map element into a boolean or returns default value if conversion is not possible.
        /// </summary>
        /// <param name="key">a key of element to get.</param>
        /// <param name="defaultValue">the default value</param>
        /// <returns>boolean value of the element or default value if conversion is not supported.</returns>
        /// See <see cref="BooleanConverter.ToBooleanWithDefault(object, bool)"/>
        public bool GetAsBooleanWithDefault(string key, bool defaultValue)
        {
            var value = Get(key);

            return(BooleanConverter.ToBooleanWithDefault(value, defaultValue));
        }
Beispiel #3
0
 /// <summary>
 /// Creates a new instance and sets its values.
 /// </summary>
 /// <param name="skip">the number of items to skip.</param>
 /// <param name="take">the number of items to return.</param>
 /// <param name="total">true to return the total number of items.</param>
 public PagingParams(object skip, object take, object total = null)
 {
     Skip  = LongConverter.ToNullableLong(skip);
     Take  = LongConverter.ToNullableLong(take);
     Total = BooleanConverter.ToBooleanWithDefault(total, false);
 }
Beispiel #4
0
 public bool GetAsBooleanWithDefault(bool defaultValue)
 {
     return(BooleanConverter.ToBooleanWithDefault(Value, defaultValue));
 }
Beispiel #5
0
        public async override Task OpenAsync(string correlationId, ConnectionParams connection, CredentialParams credential)
        {
            var awsConnection = new AwsConnectionParams(connection, credential);

            // Assign service name
            awsConnection.Service = "sqs";

            // Assign queue name
            var queueName = awsConnection.Resource ?? awsConnection.Get("queue") ?? Name;

            awsConnection.Resource = queueName;
            var deadQueueName = awsConnection.Get("dead_queue");

            // Determine if a fifo queue is being used
            _fifoQueue = queueName.EndsWith(".fifo", StringComparison.OrdinalIgnoreCase) ? true : false;

            // Validate connection params
            var err = awsConnection.Validate(correlationId);

            if (err != null)
            {
                throw err;
            }

            _logger.Info(null, "Connecting queue {0} to {1}", Name, awsConnection.Arn);

            var region = RegionEndpoint.GetBySystemName(awsConnection.Region);
            var config = new AmazonSQSConfig()
            {
                RegionEndpoint = region,
                UseHttp        = true
            };

            _client = new AmazonSQSClient(awsConnection.AccessId, awsConnection.AccessKey, config);

            try
            {
                try
                {
                    // Create queue if it doesn't exist
                    var queueRequest = new CreateQueueRequest(queueName);

                    if (_fifoQueue)
                    {
                        queueRequest.Attributes.Add("FifoQueue", "true");
                    }

                    await _client.CreateQueueAsync(queueRequest);
                }
                catch (QueueNameExistsException)
                {
                    // Ignore exception.
                }

                try
                {
                    // Create dead queue if it doesn't exist
                    if (!string.IsNullOrEmpty(deadQueueName))
                    {
                        var deadQueueRequest = new CreateQueueRequest(deadQueueName);

                        if (_fifoQueue)
                        {
                            deadQueueRequest.Attributes.Add("FifoQueue", "true");
                        }

                        await _client.CreateQueueAsync(deadQueueRequest);
                    }
                }
                catch (QueueNameExistsException)
                {
                    // Ignore exception.
                }

                var response = await _client.GetQueueUrlAsync(queueName);

                _queue = response.QueueUrl;

                if (_fifoQueue)
                {
                    var temp = await GetQueueAttributesAsync(correlationId, new List <string>() { "ContentBasedDeduplication" }, _queue);

                    _contentBasedDupication = BooleanConverter.ToBooleanWithDefault(temp["ContentBasedDeduplication"], _contentBasedDupication);
                }

                if (!string.IsNullOrEmpty(deadQueueName))
                {
                    response = await _client.GetQueueUrlAsync(deadQueueName);

                    _deadQueue = response.QueueUrl;

                    if (_fifoQueue)
                    {
                        var temp = await GetQueueAttributesAsync(correlationId, new List <string>() { "ContentBasedDeduplication" }, _deadQueue);

                        _contentBasedDupicationDlq = BooleanConverter.ToBooleanWithDefault(temp["ContentBasedDeduplication"], _contentBasedDupicationDlq);
                    }
                }
                else
                {
                    _deadQueue = null;
                }
            }
            catch (Exception ex)
            {
                throw new ConnectionException(correlationId, "CANNOT_ACCESS_QUEUE", "Failed to access SQS queue", ex)
                      .WithDetails("queue", _queue);
            }
        }