Ejemplo n.º 1
0
        /// <summary>
        /// Find the reflection objects for the code that will be executed for the Lambda function based on the
        /// Lambda function handler.
        /// </summary>
        /// <param name="functionInfo"></param>
        /// <returns></returns>
        public LambdaFunction LoadLambdaFunction(LambdaFunctionInfo functionInfo)
        {
            var function      = new LambdaFunction(functionInfo);
            var handlerTokens = functionInfo.Handler.Split("::");

            if (handlerTokens.Length != 3)
            {
                function.ErrorMessage = $"Invalid format for function handler string {functionInfo.Handler}. Format is <assembly>::<type-name>::<method>.";
                return(function);
            }

            // Using our custom Assembly resolver load the target Assembly.
            function.LambdaAssembly = this.Resolver.LoadAssembly(handlerTokens[0]);
            if (function.LambdaAssembly == null)
            {
                function.ErrorMessage = $"Failed to find assembly {handlerTokens[0]}";
                return(function);
            }

            function.LambdaType = function.LambdaAssembly.GetType(handlerTokens[1]);
            if (function.LambdaType == null)
            {
                function.ErrorMessage = $"Failed to find type {handlerTokens[1]}";
                return(function);
            }

            var methodInfos = function.LambdaType.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static)
                              .Where(x => string.Equals(x.Name, handlerTokens[2])).ToArray();

            if (methodInfos.Length == 1)
            {
                function.LambdaMethod = methodInfos[0];
            }
            else
            {
                // TODO: Handle method overloads
                if (methodInfos.Length > 1)
                {
                    function.ErrorMessage = $"More then one method called {handlerTokens[2]} was found. This tool does not currently support method overloading.";
                }
                else
                {
                    function.ErrorMessage = $"Failed to find method {handlerTokens[2]}";
                }
                return(function);
            }

            // Search to see if a Lambda serializer is registered.
            var attribute = function.LambdaMethod.GetCustomAttribute(typeof(LambdaSerializerAttribute)) as LambdaSerializerAttribute ??
                            function.LambdaAssembly.GetCustomAttribute(typeof(LambdaSerializerAttribute)) as LambdaSerializerAttribute;


            if (attribute != null)
            {
                function.Serializer = Activator.CreateInstance(attribute.SerializerType) as ILambdaSerializer;
            }


            return(function);
        }
Ejemplo n.º 2
0
 public DlqMonitor(ILocalLambdaRuntime runtime, LambdaFunction function, string profile, string region, string queueUrl)
 {
     this._runtime  = runtime;
     this._function = function;
     this._profile  = profile;
     this._region   = region;
     this._queueUrl = queueUrl;
 }