示例#1
0
        public IActionResult Transform(PicturesTransformationModel model)
        {
            if (model != null)
            {
                _amazonClient.RequestPictureTransformations(model);
            }

            return(Json("OK"));
        }
示例#2
0
        public void RequestPictureTransformations(PicturesTransformationModel transformations)
        {
            using (var client = new AmazonSQSClient(_accessKeyId, _secretAccessKey, AmazonRegion.USWest2))
            {
                var batchRequest = new SendMessageBatchRequest()
                {
                    QueueUrl = _queueUrl,
                    Entries  = new List <SendMessageBatchRequestEntry>()
                };

                foreach (var file in transformations.FileNames)
                {
                    batchRequest.Entries.Add(new SendMessageBatchRequestEntry()
                    {
                        Id                = Guid.NewGuid().ToString(),
                        MessageBody       = $"File '{file}' transformation [{transformations.Transformation.ToString()}] request",
                        MessageAttributes = new Dictionary <string, MessageAttributeValue>
                        {
                            { "fileName", new MessageAttributeValue()
                              {
                                  StringValue = file, DataType = "String"
                              } },
                            { "transformation", new MessageAttributeValue()
                              {
                                  StringValue = transformations.Transformation.ToString(), DataType = "String"
                              } },
                            { "date", new MessageAttributeValue()
                              {
                                  StringValue = DateTime.Now.ToString("HH:mm:ss dd.MM.yyyy"), DataType = "String"
                              } }
                        }
                    });
                }

                client.SendMessageBatchAsync(batchRequest).Wait();
            }
        }