Exemplo n.º 1
0
 static async Task Main(string[] args)
 {
     await LambdaRunner.Create()
     .UsePort(5001)
     .Receives <string>()
     .UsesAsyncFunctionWithNoResult <Function>((function, input, context) => function.FunctionHandlerAsync(input, context))
     .Build()
     .RunAsync();
 }
Exemplo n.º 2
0
 static async Task Main(string[] args)
 {
     var port = 5003;
     await LambdaRunner.Create()
     .UsePort(port)
     .Receives <string>()
     .UsesAsyncFunctionWithNoResult <Function>((function, args, context) => function.FunctionHandler(context))
     .Build()
     .RunAsync();
 }
Exemplo n.º 3
0
        private static IRunner BuildRunner(Type lambdaType, MethodInfo method, int?port)
        {
            var returnType = method.ReturnType;
            var paramTypes = method.GetParameters();
            var inputType  = GetInputType(paramTypes);
            var isAsync    = false;

            if (returnType == typeof(void) || returnType == typeof(Task))
            {
                Console.WriteLine("Target lambda must return a value");
                throw new InvalidOperationException();
            }

            var builder = LambdaRunner.Create();

            if (port.HasValue)
            {
                builder = builder.UsePort(port.Value);
            }

            if (returnType.IsGenericType &&
                returnType.GetGenericTypeDefinition() == typeof(Task <>))
            {
                returnType = returnType.GetGenericArguments()[0];
                isAsync    = true;
            }

            object receivingBuilder = inputType == null
                ? builder.Receives <object>()
                : BuildReceivingBuilder(builder, inputType);

            var returningBuilder = receivingBuilder
                                   .GetType()
                                   .GetMethod("Returns")
                                   .MakeGenericMethod(returnType)
                                   .Invoke(receivingBuilder, null);

            var lambdaDelegate = BuildHandler(lambdaType, method, inputType);

            var usesFunctionMethodName = isAsync
                ? "UsesAsyncFunction"
                : "UsesFunction";
            var runnerBuilder = returningBuilder
                                .GetType()
                                .GetMethod(usesFunctionMethodName)
                                .MakeGenericMethod(lambdaType)
                                .Invoke(returningBuilder, new[] { lambdaDelegate.Compile() });

            var runner = runnerBuilder
                         .GetType()
                         .GetMethod("Build")
                         .Invoke(runnerBuilder, null);

            return((IRunner)runner);
        }
 public void Create_returns_a_builder()
 {
     Assert.That(LambdaRunner.Create(), Is.InstanceOf <IRunnerBuilder>());
 }