Exemple #1
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            StartContentModerationResponse response = new StartContentModerationResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("JobId", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.JobId = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemple #2
0
        private async Task <bool> ProcessVideoMessages(ILambdaContext context, StartContentModerationResponse response)
        {
            bool validLength;

            do
            {
                ReceiveMessageResponse messageResponse = await sqsClient.ReceiveMessageAsync(new ReceiveMessageRequest
                {
                    QueueUrl            = QUrl,
                    MaxNumberOfMessages = 10,
                    WaitTimeSeconds     = 15
                }).ConfigureAwait(false);

                if (!messageResponse.Messages.Any())
                {
                    continue;
                }

                Message message = messageResponse.Messages.SingleOrDefault(x => x.Body.Contains(response.JobId));

                if (message == null)
                {
                    context.Logger.LogLine("job received is not of interest");

                    messageResponse.Messages.ForEach(async msg => await sqsClient.DeleteMessageAsync(new DeleteMessageRequest
                    {
                        QueueUrl      = QUrl,
                        ReceiptHandle = msg.ReceiptHandle
                    }));
                }
                else
                {
                    validLength = await ProcessInterestedMessage(context, response, message).ConfigureAwait(false);

                    break;
                }
            } while (true);

            return(validLength);
        }
Exemple #3
0
        public async Task <bool> FunctionHandler(FileInfo fileInfo, ILambdaContext context)
        {
            StartContentModerationRequest request = new StartContentModerationRequest
            {
                Video = new Video
                {
                    S3Object = new S3Object
                    {
                        Bucket = fileInfo.Bucket,
                        Name   = fileInfo.Key
                    }
                },
                MinConfidence       = 40.0f,
                NotificationChannel = new NotificationChannel {
                    RoleArn = "arn:aws:iam::518495728486:role/hackathon-rek-role", SNSTopicArn = "arn:aws:sns:us-east-1:518495728486:AmazonRekognition-hackathon-2018"
                }
            };

            StartContentModerationResponse response = await rekClient.StartContentModerationAsync(request).ConfigureAwait(false);

            bool validLength = await ProcessVideoMessages(context, response);

            return(validLength);
        }
Exemple #4
0
        private async Task <bool> ProcessInterestedMessage(ILambdaContext context, StartContentModerationResponse response,
                                                           Message message)
        {
            bool validLength = false;

            if (message.Body.Contains("SUCCEEDED"))
            {
                context.Logger.LogLine(
                    $"job with jobId {response.JobId} found and succeeded, continuing to process remaining messages");
                validLength = await this.ProcessLabels(context, response.JobId).ConfigureAwait(false);
            }
            else
            {
                context.Logger.LogLine($"job with jobId {response.JobId} found and failed, please check cloud watch logs for more details");
            }

            await sqsClient.DeleteMessageAsync(new DeleteMessageRequest
            {
                QueueUrl      = QUrl,
                ReceiptHandle = message.ReceiptHandle
            }).ConfigureAwait(false);

            return(validLength);
        }