Exemplo n.º 1
0
        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 }));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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;
        }
Exemplo n.º 4
0
        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));
            }));
        }
Exemplo n.º 5
0
        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 }));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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.
        }
Exemplo n.º 8
0
        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);
 }
Exemplo n.º 10
0
 public RequestReader(Reader reader, ProtocolObjectFactory factory)
 {
     InputReader     = reader;
     ProtocolFactory = factory;
 }
Exemplo n.º 11
0
 public IProtocolObject CreateObjectFromData()
 {
     return(ProtocolObjectFactory.CreateObject(GetObjectType(), CurrentObjectData));
 }
Exemplo n.º 12
0
 public Type GetObjectType()
 {
     return(ProtocolObjectFactory.GetObjectType(CurrentObjectData));
 }