Beispiel #1
0
    private void ListenerCallback(IAsyncResult future)
    {
        HttpListenerContext context;

        try
        {
            context = listener.EndGetContext(future);
        }
        catch (HttpListenerException)
        {
            // raised by listener.Stop
            return;
        }

        if (stop.WaitOne(0, false))
        {
            return;
        }

        try
        {
            string text = ReadPostData(context.Request);
            // maybe check errors in process and write
            // maybe errors in thread in general
            var result = Pullenti_.Process(text);
            WriteResult(result, context.Response);
        }
        catch (ServerException error)
        {
            Log.Error("Bad request: {0}", error.Message);
            WriteError(error, context.Response);
        }
    }
Beispiel #2
0
    private static void WriteResult(AnalysisResult result, HttpListenerResponse response)
    {
        response.StatusCode = 200;
        Stream output = response.OutputStream;

        using (XmlWriter xml = WriteXml(output))
        {
            Pullenti_.XmlResult(result, xml);
        }
        output.Close();
    }
Beispiel #3
0
    static void Main()
    {
        Conf conf = new Conf();

        try
        {
            conf.Load();
        }
        catch (ConfException error)
        {
            Log.Error("Bad conf: {0}", error.Message);
            return;
        }

        Pullenti_.Init(conf.langs, conf.analyzers);
        using (Server server = new Server())
        {
            server.Start(conf.host, conf.port);
            // maybe better to handle ctrl-c
            Thread.Sleep(Timeout.Infinite);
        }
    }