public override string Respond()
 {
     if (Success)
     {
         return(new ProtocolResponse("RetryableDone", new { }).Encode());
     }
     else
     {
         return(ExceptionManager.GenerateExceptionResponse(new ClientException("Error from client in retryable tx")).Encode());
     }
 }
Пример #2
0
        public override string Respond()
        {
            var sessionContainer = (NewSession)ObjManager.GetObject(data.sessionId);

            if (sessionContainer.RetryState == NewSession.SessionState.RetryAbleNothing)
            {
                throw new ArgumentException("Should never hit this code with a RetryAbleNothing");
            }

            else if (sessionContainer.RetryState == NewSession.SessionState.RetryAbleNegative)
            {
                if (string.IsNullOrEmpty(sessionContainer.RetryableErrorId))
                {
                    return(ExceptionManager.GenerateExceptionResponse(new ClientException("Error from client in retryable tx")).Encode());
                }
                else
                {
                    var exception = ((ProtocolException)(ObjManager.GetObject(sessionContainer.RetryableErrorId))).ExceptionObj;
                    return(ExceptionManager.GenerateExceptionResponse(exception).Encode());
                }
            }

            return(new ProtocolResponse("RetryableDone", new { }).Encode());
        }
Пример #3
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();
            }
        }
Пример #4
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();
            }
        }
        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();
            }
        }