internal static ProtocolResponse GenerateExceptionResponse(Exception ex) { string outerExceptionMessage = ex.Message; string exceptionMessage = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; var type = TypeMap.GetValueOrDefault(ex.GetType()); //if (ex is Neo4jException || ex is NotSupportedException) if (type is not null) { ProtocolException newError = ProtocolObjectFactory.CreateObject <ProtocolException>(); newError.ExceptionObj = ex; string errorCode = (ex is Neo4jException) ? ((Neo4jException)ex).Code : type; return(new ProtocolResponse("DriverError", new { id = newError.uniqueId, errorType = type, msg = exceptionMessage, code = errorCode })); } else if (ex is DriverExceptionWrapper) { ProtocolException newError = ProtocolObjectFactory.CreateObject <ProtocolException>(); return(new ProtocolResponse("DriverError", new { id = newError.uniqueId, errorType = ex.InnerException.GetType().Name, msg = exceptionMessage })); } Trace.WriteLine($"Exception thrown {outerExceptionMessage}\n which contained -- {exceptionMessage}\n{ex.StackTrace}"); return(new ProtocolResponse("BackendError", new { msg = exceptionMessage })); }
public override async Task Process(Controller controller) { Success = true; var sessionContainer = (NewSession)ObjManager.GetObject(data.sessionId); await sessionContainer.Session.ReadTransactionAsync(async tx => { TransactionId = controller.TransactionManagager.AddTransaction(new TransactionWrapper(tx, async cursor => { var result = ProtocolObjectFactory.CreateObject <TransactionResult>(); await result.PopulateRecords(cursor).ConfigureAwait(false); return(result.uniqueId); })); sessionContainer.SessionTransactions.Add(TransactionId); await controller.SendResponse(new ProtocolResponse("RetryableTry", TransactionId).Encode()).ConfigureAwait(false); try { //Start another message processing loop to handle the retry mechanism. await controller.ProcessStreamObjects().ConfigureAwait(false); } catch { Success = false; } controller.TransactionManagager.RemoveTransaction(TransactionId); }, TransactionConfig); }
public override async Task Process() { var newSession = (NewSession)ObjManager.GetObject(data.sessionId); IResultCursor cursor = await newSession.Session.RunAsync(data.cypher, ConvertParameters(data.parameters), TransactionConfig).ConfigureAwait(false); var result = (Result)ProtocolObjectFactory.CreateObject(Protocol.Types.Result); result.Results = cursor; ResultId = result.uniqueId; }
public override async Task Process(Controller controller) { var sessionContainer = (NewSession)ObjManager.GetObject(data.sessionId); var transaction = await sessionContainer.Session.BeginTransactionAsync(TransactionConfig); TransactionId = controller.TransactionManager.AddTransaction(new TransactionWrapper(transaction, async cursor => { var result = ProtocolObjectFactory.CreateObject <Result>(); result.ResultCursor = cursor; return(await Task.FromResult <string>(result.uniqueId)); })); }
internal static ProtocolResponse GenerateExceptionResponse(Exception ex) { string exceptionMessage = (ex.InnerException != null) ? ex.InnerException.Message : ex.Message; if (ex is Neo4jException || ex is NotSupportedException) { ProtocolException newError = ProtocolObjectFactory.CreateObject <ProtocolException>(); newError.ExceptionObj = ex; return(new ProtocolResponse("DriverError", new { id = newError.uniqueId, errorType = TypeMap[ex.GetType()], msg = exceptionMessage })); } Trace.WriteLine($"Exception thrown {exceptionMessage}\n{ex.StackTrace}"); return(new ProtocolResponse("BackendError", new { msg = exceptionMessage })); }
public async Task <IProtocolObject> TryConsumeStreamObjectOfType(Type type) { //Read the next incoming request message await RequestReader.ParseNextRequest().ConfigureAwait(false); //Is it of the correct type if (RequestReader.GetObjectType() != type) { return(null); } //Create and return an object from the request message return(ProtocolObjectFactory.CreateObject(RequestReader.GetObjectType(), RequestReader.CurrentObjectData)); }
public async Task ProcessStreamObjects() { BreakProcessLoop = false; while (!BreakProcessLoop && await RequestReader.ParseNextRequest().ConfigureAwait(false)) { var protocolObject = ProtocolObjectFactory.CreateObject(RequestReader.GetObjectType(), RequestReader.CurrentObjectData); protocolObject.ProtocolEvent += BreakLoopEvent; await protocolObject.Process(this).ConfigureAwait(false); await SendResponse(protocolObject).ConfigureAwait(false); Trace.Flush(); } BreakProcessLoop = false; //Ensure that any process loops that this one is running within still continue. }
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 Controller(IConnection conn) { Trace.WriteLine("Controller initialising"); Connection = conn; ProtocolFactory = new ProtocolObjectFactory(ObjManager); }
public RequestReader(Reader reader, ProtocolObjectFactory factory) { InputReader = reader; ProtocolFactory = factory; }
public IProtocolObject CreateObjectFromData() { return(ProtocolObjectFactory.CreateObject(GetObjectType(), CurrentObjectData)); }
public Type GetObjectType() { return(ProtocolObjectFactory.GetObjectType(CurrentObjectData)); }