Esempio n. 1
0
        public async System.Threading.Tasks.Task <int> Random(int maxValue, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            // Create a scope for every request,
            // this allows creating scoped dependencies without creating a scope manually.
            using var scope = serviceProvider.CreateScope();
            var simpleCalculator = scope.ServiceProvider.GetRequiredService <SimpleCalculator>();

            return(await simpleCalculator.Random(maxValue, __context__));
        }
        public System.Collections.Generic.IList <int> Randoms(TestServerlessApp.SimpleCalculator.RandomsInput input, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            // Create a scope for every request,
            // this allows creating scoped dependencies without creating a scope manually.
            using var scope = serviceProvider.CreateScope();
            var simpleCalculator = scope.ServiceProvider.GetRequiredService <SimpleCalculator>();

            return(simpleCalculator.Randoms(input, __context__));
        }
        public Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse Multiply(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            // Create a scope for every request,
            // this allows creating scoped dependencies without creating a scope manually.
            using var scope = serviceProvider.CreateScope();
            var simpleCalculator = scope.ServiceProvider.GetRequiredService <SimpleCalculator>();

            var validationErrors = new List <string>();

            var x = default(int);

            if (__request__.PathParameters?.ContainsKey("x") == true)
            {
                try
                {
                    x = (int)Convert.ChangeType(__request__.PathParameters["x"], typeof(int));
                }
                catch (Exception e) when(e is InvalidCastException || e is FormatException || e is OverflowException || e is ArgumentException)
                {
                    validationErrors.Add($"Value {__request__.PathParameters["x"]} at 'x' failed to satisfy constraint: {e.Message}");
                }
            }

            var y = default(int);

            if (__request__.PathParameters?.ContainsKey("y") == true)
            {
                try
                {
                    y = (int)Convert.ChangeType(__request__.PathParameters["y"], typeof(int));
                }
                catch (Exception e) when(e is InvalidCastException || e is FormatException || e is OverflowException || e is ArgumentException)
                {
                    validationErrors.Add($"Value {__request__.PathParameters["y"]} at 'y' failed to satisfy constraint: {e.Message}");
                }
            }

            // return 400 Bad Request if there exists a validation error
            if (validationErrors.Any())
            {
                return(new Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse
                {
                    Body = @$ "{{" "message" ": " "{validationErrors.Count} validation error(s) detected: {string.Join(", ", validationErrors)}" "}}",
                    Headers = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/json" },
                        { "x-amzn-ErrorType", "ValidationException" }
                    },
                    StatusCode = 400
                });
        public Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse Add(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            var complexNumbers = __request__.Body;

            var response = complexCalculator.Add(complexNumbers, __context__, __request__);

            var body = System.Text.Json.JsonSerializer.Serialize(response);

            return(new Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse
            {
                Body = body,
                Headers = new Dictionary <string, string>
                {
                    { "Content-Type", "application/json" }
                },
                StatusCode = 200
            });
        }
Esempio n. 5
0
        public async System.Threading.Tasks.Task <Amazon.Lambda.APIGatewayEvents.APIGatewayProxyResponse> SayHelloAsync(Amazon.Lambda.APIGatewayEvents.APIGatewayProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            var validationErrors = new List <string>();

            var firstNames = default(System.Collections.Generic.IEnumerable <string>);

            if (__request__.MultiValueHeaders?.ContainsKey("names") == true)
            {
                firstNames = __request__.MultiValueHeaders["names"]
                             .Select(q =>
                {
                    try
                    {
                        return((string)Convert.ChangeType(q, typeof(string)));
                    }
                    catch (Exception e) when(e is InvalidCastException || e is FormatException || e is OverflowException || e is ArgumentException)
                    {
                        validationErrors.Add($"Value {q} at 'names' failed to satisfy constraint: {e.Message}");
                        return(default);
 public void VoidReturn(string text, Amazon.Lambda.Core.ILambdaContext __context__)
 {
     voidExample.VoidReturn(text, __context__);
 }
        public Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse Subtract(Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyRequest __request__, Amazon.Lambda.Core.ILambdaContext __context__)
        {
            var validationErrors = new List <string>();

            var complexNumbers = default(System.Collections.Generic.IList <System.Collections.Generic.IList <int> >);

            try
            {
                complexNumbers = System.Text.Json.JsonSerializer.Deserialize <System.Collections.Generic.IList <System.Collections.Generic.IList <int> > >(__request__.Body);
            }
            catch (Exception e)
            {
                validationErrors.Add($"Value {__request__.Body} at 'body' failed to satisfy constraint: {e.Message}");
            }

            // return 400 Bad Request if there exists a validation error
            if (validationErrors.Any())
            {
                return(new Amazon.Lambda.APIGatewayEvents.APIGatewayHttpApiV2ProxyResponse
                {
                    Body = @$ "{{" "message" ": " "{validationErrors.Count} validation error(s) detected: {string.Join(", ", validationErrors)}" "}}",
                    Headers = new Dictionary <string, string>
                    {
                        { "Content-Type", "application/json" },
                        { "x-amzn-ErrorType", "ValidationException" }
                    },
                    StatusCode = 400
                });