Exemple #1
0
        /// <summary>
        /// A simple function that takes a string and does a ToUpper
        /// </summary>
        /// <param name="input"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public string FunctionHandler(SQSEvent sqsEvent, ILambdaContext context)
        {
            IOrdenesQueueRepository      ordenesQueueRepository = new OrdenesQueueRepository();
            IConfirmarOrdenApiRepository confirmarOrdenApiRepository
                = new ConfirmarOrdenApiRepository("https://hayi88qmck.execute-api.us-east-2.amazonaws.com/Prod");

            int count = 0;

            if (sqsEvent.Records != null)
            {
                foreach (var singleEvent in sqsEvent.Records)
                {
                    ConfirmarOrdenResponse orden;

                    string body = singleEvent.Body;

                    try
                    {
                        orden = JsonConvert.DeserializeObject <ConfirmarOrdenResponse>(body);
                    }
                    catch
                    {
                        orden = new ConfirmarOrdenResponse()
                        {
                            Id = 0
                        };
                    }

                    string response = string.Empty;

                    if (orden.Id > 0)
                    {
                        try
                        {
                            var confirmarResponse =
                                confirmarOrdenApiRepository.ExecuteApi(body).GetAwaiter().GetResult();

                            response = JsonConvert.SerializeObject(confirmarResponse);
                        }
                        catch (Exception ex)
                        {
                            response = ex.ToString();
                        }
                    }

                    if (orden.Id >= 0)
                    {
                        OrdenQueueEvent ordenQueueEvent = new OrdenQueueEvent();
                        ordenQueueEvent.messageid = singleEvent.MessageId;
                        ordenQueueEvent.fecha     = DateTime.Now.ToUniversalTime().AddHours(-5).ToString("s");
                        ordenQueueEvent.request   = body;
                        ordenQueueEvent.response  = response;

                        ordenesQueueRepository.InsertEvent(ordenQueueEvent).GetAwaiter().GetResult();
                    }
                }
            }

            return("ok:" + count.ToString());
        }
        public async Task <bool> InsertEvent(OrdenQueueEvent ordenQueueEvent)
        {
            var tableName = "OrdenesQueue";

            AWSConfigsDynamoDB.Context.TypeMappings[typeof(OrdenQueueEvent)] = new Amazon.Util.TypeMapping(typeof(OrdenQueueEvent), tableName);

            var config = new DynamoDBContextConfig {
                Conversion = DynamoDBEntryConversion.V2
            };

            this.DDBContext = new DynamoDBContext(new AmazonDynamoDBClient(), config);

            await DDBContext.SaveAsync <OrdenQueueEvent>(ordenQueueEvent);

            return(true);
        }