コード例 #1
0
        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 (DriverExceptionWrapper ex)
                {
                    storedException = ex;
                    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.
                    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();
            }
        }