Ejemplo n.º 1
0
        private async Task InitialiseCommunicationLayer()
        {
            await Connection.Open();

            var connectionReader = new StreamReader(Connection.ConnectionStream, new UTF8Encoding(false));
            var connectionWriter = new StreamWriter(Connection.ConnectionStream, new UTF8Encoding(false));

            connectionWriter.NewLine = "\n";

            Trace.WriteLine("Connection open");

            RequestReader  = new RequestReader(connectionReader);
            ResponseWriter = new ResponseWriter(connectionWriter);

            Trace.WriteLine("Starting to listen for requests");
        }
Ejemplo n.º 2
0
        public async Task Process()
        {
            bool restartConnection = true;

            try
            {
                Trace.WriteLine("Starting Controller.Process");

                while (true)
                {
                    if (restartConnection)
                    {
                        await InitialiseCommunicationLayer();
                    }

                    try
                    {
                        await ProcessStreamObjects().ConfigureAwait(false);

                        restartConnection = true;
                    }
                    catch (Neo4jException ex)
                    {
                        // Generate "driver" exception something happened within the driver
                        await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                        restartConnection = false;
                    }
                    catch (NotSupportedException ex)
                    {
                        // Get this sometimes during protocol handshake, like when connectiong with bolt:// on server
                        // with TLS. Could be a dirty read in the driver or a write from TLS server that causes strange
                        // version received..
                        await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                        restartConnection = false;
                    }
                    catch (IOException ex)
                    {
                        Trace.WriteLine($"Socket exception detected: {ex.Message}");    //Handled outside of the exception manager because there is no connection to reply on.
                        restartConnection = true;
                    }
                    finally
                    {
                        if (restartConnection)
                        {
                            Trace.WriteLine("Closing Connection");
                            Connection.Close();
                        }
                    }
                    Trace.Flush();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"It looks like the ExceptionExtensions system has failed in an unexpected way. \n{ex}");
            }
            finally
            {
                Connection.StopServer();
            }
        }
Ejemplo n.º 3
0
 public async Task SendResponse(string response)
 {
     await ResponseWriter.WriteResponseAsync(response);
 }
Ejemplo n.º 4
0
 public async Task SendResponse(IProtocolObject protocolObject)
 {
     await ResponseWriter.WriteResponseAsync(protocolObject).ConfigureAwait(false);
 }
Ejemplo n.º 5
0
        public async Task Process()
        {
            bool restartConnection = true;

            try
            {
                Trace.WriteLine("Starting Controller.Process");

                while (true)
                {
                    if (restartConnection)
                    {
                        await InitialiseCommunicationLayer();
                    }

                    try
                    {
                        await ProcessStreamObjects().ConfigureAwait(false);

                        restartConnection = true;
                    }
                    catch (Neo4jException ex)
                    {
                        // Generate "driver" exception something happened within the driver
                        await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                        restartConnection = false;
                    }
                    catch (NotSupportedException ex)
                    {
                        await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                        restartConnection = false;
                    }
                    catch (JsonSerializationException ex)
                    {
                        await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                        restartConnection = false;
                    }
                    catch (TestKitProtocolException ex)
                    {
                        Trace.WriteLine($"TestKit protocol exception detected: {ex.Message}");
                        restartConnection = true;
                    }
                    catch (IOException ex)
                    {
                        Trace.WriteLine($"Socket exception detected: {ex.Message}");    //Handled outside of the exception manager because there is no connection to reply on.
                        restartConnection = true;
                    }
                    finally
                    {
                        if (restartConnection)
                        {
                            Trace.WriteLine("Closing Connection");
                            Connection.Close();
                        }
                    }
                    Trace.Flush();
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine($"It looks like the ExceptionExtensions system has failed in an unexpected way. \n{ex}");
            }
            finally
            {
                Connection.StopServer();
            }
        }
        public async Task Process(bool restartInitialState, Func <Exception, bool> loopConditional)
        {
            bool restartConnection = restartInitialState;

            Trace.WriteLine("Starting Controller.Process");

            Exception storedException = new TestKitClientException("Error from client");

            while (loopConditional(storedException))
            {
                if (restartConnection)
                {
                    await InitialiseCommunicationLayer();
                }

                try
                {
                    await ProcessStreamObjects().ConfigureAwait(false);
                }
                catch (Neo4jException ex)               //TODO: sort this catch list out...reduce it down using where clauses?
                {
                    // Generate "driver" exception something happened within the driver
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = false;
                }
                catch (TestKitClientException ex)
                {
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = false;
                }
                catch (ArgumentException ex)
                {
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = false;
                }
                catch (NotSupportedException ex)
                {
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = false;
                }
                catch (JsonSerializationException ex)
                {
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = false;
                }
                catch (TestKitProtocolException ex)
                {
                    Trace.WriteLine($"TestKit protocol exception detected: {ex.Message}");
                    await ResponseWriter.WriteResponseAsync(ExceptionManager.GenerateExceptionResponse(ex));

                    storedException   = ex;
                    restartConnection = true;
                }
                catch (IOException ex)
                {
                    Trace.WriteLine($"Socket exception detected: {ex.Message}");    //Handled outside of the exception manager because there is no connection to reply on.
                    storedException   = ex;
                    restartConnection = true;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine($"General exception detected, restarting connection: {ex.Message}");
                    storedException   = ex;
                    restartConnection = true;
                }
                finally
                {
                    if (restartConnection)
                    {
                        Trace.WriteLine("Closing Connection");
                        Connection.Close();
                    }
                }
                Trace.Flush();
            }
        }