public override async Task Process(Controller controller) { var sessionContainer = (NewSession)ObjManager.GetObject(data.sessionId); await sessionContainer.Session.ReadTransactionAsync(async tx => { sessionContainer.SetupRetryAbleState(NewSession.SessionState.RetryAbleNothing); TransactionId = controller.TransactionManager.AddTransaction(new TransactionWrapper(tx, async cursor => { var result = ProtocolObjectFactory.CreateObject <Result>(); await result.PopulateRecords(cursor).ConfigureAwait(false); return(result.uniqueId); })); sessionContainer.SessionTransactions.Add(TransactionId); await controller.SendResponse(new ProtocolResponse("RetryableTry", TransactionId).Encode()).ConfigureAwait(false); Exception storedException = new TestKitClientException("Error from client"); await controller.Process(false, e => { switch (sessionContainer.RetryState) { case NewSession.SessionState.RetryAbleNothing: return(true); case NewSession.SessionState.RetryAblePositive: return(false); case NewSession.SessionState.RetryAbleNegative: throw e; default: return(true); } }); }, TransactionConfig); }
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(); } }