Ejemplo n.º 1
0
        /// Program entry point
        static void Main(string[] args)
        {
            // Add all /var/lang/bin/shared/*/* directories to the search path
            foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2)))
            {
                assemblyDirs.Add(di.FullName);
            }
            AssemblyLoadContext.Default.Resolving += OnAssemblyResolving;

            try
            {
                var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs);

                var handler = GetFunctionHandler(positionalArgs);
                var body    = GetEventBody(positionalArgs);

                if (shouldWaitForDebugger)
                {
                    Console.Error.WriteLine("Waiting for the debugger to attach...");

                    if (!DebuggerExtensions.TryWaitForAttaching(
                            _debuggerStatusQueryInterval,
                            _debuggerStatusQueryTimeout))
                    {
                        Console.Error.WriteLine("Timeout. Proceeding without debugger.");
                    }
                }

                var             lambdaRuntime   = new MockRuntime(handler, body);
                LambdaBootstrap lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER);
                UnhandledExceptionLogger.Register();
                lambdaBootstrap.Initialize();
                lambdaBootstrap.Invoke();
            }

            // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging
            catch (Exception ex)
            {
                Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}");
            }
        }
Ejemplo n.º 2
0
        /// Program entry point
        static void Main(string[] args)
        {
            // Add all /var/lang/bin/shared/*/* directories to the search path
            foreach (var di in new DirectoryInfo("/var/lang/bin/shared").EnumerateDirectories().SelectMany(di => di.EnumerateDirectories().Select(di2 => di2)))
            {
                assemblyDirs.Add(di.FullName);
            }
            AssemblyLoadContext.Default.Resolving += OnAssemblyResolving;

            //Console.CancelKeyPress += delegate {
            //    // call methods to clean up
            //};

            Process mockServer = null;

            try
            {
                var shouldWaitForDebugger = GetShouldWaitForDebuggerFlag(args, out var positionalArgs);

                var handler = GetFunctionHandler(positionalArgs);
                var body    = GetEventBody(positionalArgs);

                var lambdaRuntime = new MockRuntime(handler, body);

                mockServer = new Process();
                mockServer.StartInfo.FileName              = "/var/runtime/mockserver";
                mockServer.StartInfo.CreateNoWindow        = true;
                mockServer.StartInfo.RedirectStandardInput = true;
                mockServer.StartInfo.Environment["DOCKER_LAMBDA_NO_BOOTSTRAP"] = "1";
                mockServer.StartInfo.Environment["DOCKER_LAMBDA_USE_STDIN"]    = "1";
                mockServer.Start();
                mockServer.StandardInput.Write(body);
                mockServer.StandardInput.Close();

                if (shouldWaitForDebugger)
                {
                    Console.Error.WriteLine("Waiting for the debugger to attach...");

                    if (!DebuggerExtensions.TryWaitForAttaching(
                            _debuggerStatusQueryInterval,
                            _debuggerStatusQueryTimeout))
                    {
                        Console.Error.WriteLine("Timeout. Proceeding without debugger.");
                    }
                }

                var lambdaBootstrap = new LambdaBootstrap(lambdaRuntime, InternalLogger.NO_OP_LOGGER);
                UnhandledExceptionLogger.Register();
                lambdaBootstrap.Initialize();
                lambdaBootstrap.Invoke();
            }

            // Catch all unhandled exceptions from runtime, to prevent user from hanging on them while debugging
            catch (Exception ex)
            {
                Console.Error.WriteLine($"\nUnhandled exception occured in runner:\n{ex}");
            }
            finally
            {
                if (mockServer != null)
                {
                    mockServer.Dispose();
                }
            }
        }