Exemplo n.º 1
0
        static async Task MainAsync(CancellationToken cancellationToken)
        {
            var function = new Function();

            function.PrepareFunctionContext();

            System.Diagnostics.Debug.WriteLine("C# AfterBurn running.");

            var httpFormatter = new HttpFormatter();
            var stdin         = Console.OpenStandardInput();

            using (TextReader reader = new StreamReader(stdin))
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    HeaderParser parser = new HeaderParser();
                    var          header = parser.Parse(reader);

                    foreach (string v in header.HttpHeaders)
                    {
                        System.Diagnostics.Debug.WriteLine(v + "=" + header.HttpHeaders[v]);
                    }

                    System.Diagnostics.Debug.WriteLine("Content-Length: " + header.ContentLength);

                    BodyParser bodyParser = new BodyParser();
                    string     body       = String.Empty;
                    if (header.ContentLength > 0)
                    {
                        body = bodyParser.Parse(reader, header.ContentLength);

                        System.Diagnostics.Debug.WriteLine(body);
                    }

                    await function.Invoke(body, cancellationToken);

                    var httpAdded = httpFormatter.Format("");
                    Console.WriteLine(httpAdded);
                }
            }
        }
        static void Main(string[] args)
        {
            var function = new Function.Handler();

            System.Diagnostics.Debug.WriteLine("C# AfterBurn running.");

            var httpFormatter = new HttpFormatter();
            var stdin         = Console.OpenStandardInput();

            using (TextReader reader = new StreamReader(stdin)) {
                while (true)
                {
                    HeaderParser parser = new HeaderParser();
                    var          header = parser.Parse(reader);

                    foreach (string v in header.HttpHeaders)
                    {
                        System.Diagnostics.Debug.WriteLine(v + "=" + header.HttpHeaders[v]);
                    }

                    System.Diagnostics.Debug.WriteLine("Content-Length: " + header.ContentLength);

                    BodyParser bodyParser = new BodyParser();
                    char[]     body       = new char[0] {
                    };
                    if (header.ContentLength > 0)
                    {
                        body = bodyParser.Parse(reader, header.ContentLength);

                        System.Diagnostics.Debug.WriteLine(body);
                    }

                    var httpAdded = httpFormatter.Format(function.Invoke(body));
                    Console.WriteLine(httpAdded);
                }
            }
        }