Esempio n. 1
0
 public static Execution FromOperationCompleted(OperationCompletedEventArgs e)
 {
     var execution= new Execution();
     execution.Expection = e.Exception;
     execution.Timestamp = DateTimeOffset.Now;
     execution.QueryText = CypherExtension.GetFormattedCypher(e.QueryText);
     execution.FormattedDebugText = CypherExtension.GetFormattedCypher(e.QueryText); // need to update the neo4jclient to get the debug text
     return execution;
 }
        public void OperationCompletedLog(object sender, OperationCompletedEventArgs eventArgs)
        {
            var message = new OperationCompletedEventMessage()
            {
                Query = eventArgs.QueryText,
                ResultCount = eventArgs.ResourcesReturned,
                Time = eventArgs.TimeTaken
            };

            Publish(message);
        }
Esempio n. 3
0
            public void Complete(string queryText, int resultsCount = -1, Exception exception = null, NameValueCollection customHeaders = null, int?maxExecutionTime = null)
            {
                var args = new OperationCompletedEventArgs
                {
                    QueryText         = queryText,
                    ResourcesReturned = resultsCount,
                    TimeTaken         = stopwatch.Elapsed,
                    Exception         = exception,
                    CustomHeaders     = customHeaders,
                    MaxExecutionTime  = maxExecutionTime
                };

                owner.OnOperationCompleted(args);
            }
Esempio n. 4
0
            public void Complete(string queryText, string lastBookmark, int resultsCount = -1, Exception exception = null, NameValueCollection customHeaders = null, int?maxExecutionTime = null, string identifier = null, IEnumerable <string> bookmarks = null)
            {
                var args = new OperationCompletedEventArgs
                {
                    LastBookmark      = lastBookmark,
                    QueryText         = queryText,
                    ResourcesReturned = resultsCount,
                    TimeTaken         = stopwatch.Elapsed,
                    Exception         = exception,
                    CustomHeaders     = customHeaders,
                    MaxExecutionTime  = maxExecutionTime,
                    Identifier        = identifier,
                    BookmarksUsed     = bookmarks
                };

                owner.OnOperationCompleted(args);
            }
Esempio n. 5
0
 /// <summary>Raises the <see cref="OperationCompleted"/> event.</summary>
 /// <param name="args">The instance of <see cref="OperationCompletedEventArgs"/> to send to listeners.</param>
 protected void OnOperationCompleted(OperationCompletedEventArgs args)
 {
     OperationCompleted?.Invoke(this, args);
 }
Esempio n. 6
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText         = "Connect",
                ResourcesReturned = 0
            };

            Action stopTimerAndNotifyCompleted = () =>
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            };

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration.Realm,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    //  transactionManager = new TransactionManager(this);
                }

                rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
                    ? null
                    : new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);

                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                if (RootApiResponse.Version < new Version(2, 0))
                {
                    cypherCapabilities = CypherCapabilities.Cypher19;
                }

                if (RootApiResponse.Version >= new Version(2, 2))
                {
                    cypherCapabilities = CypherCapabilities.Cypher22;
                }

                if (RootApiResponse.Version >= new Version(2, 2, 6))
                {
                    cypherCapabilities = CypherCapabilities.Cypher226;
                }

                if (RootApiResponse.Version >= new Version(2, 3))
                {
                    cypherCapabilities = CypherCapabilities.Cypher23;
                }

                if (RootApiResponse.Version >= new Version(3, 0))
                {
                    cypherCapabilities = CypherCapabilities.Cypher30;
                }
            }
            catch (AggregateException ex)
            {
                Exception unwrappedException;
                var       wasUnwrapped = ex.TryUnwrap(out unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                stopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                {
                    throw unwrappedException;
                }

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                stopTimerAndNotifyCompleted();
                throw;
            }

            stopTimerAndNotifyCompleted();
        }
Esempio n. 7
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText = "Connect",
                ResourcesReturned = 0
            };

            Action stopTimerAndNotifyCompleted = () =>
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            };

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    //  transactionManager = new TransactionManager(this);
                }

                rootNode = string.IsNullOrEmpty(RootApiResponse.ReferenceNode)
                    ? null
                    : new RootNode(long.Parse(GetLastPathSegment(RootApiResponse.ReferenceNode)), this);

                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                if (RootApiResponse.Version < new Version(2, 0))
                    cypherCapabilities = CypherCapabilities.Cypher19;

                if (RootApiResponse.Version >= new Version(2, 2))
                    cypherCapabilities = CypherCapabilities.Cypher22;

                if (RootApiResponse.Version >= new Version(2, 2, 6))
                    cypherCapabilities = CypherCapabilities.Cypher226;

                if (RootApiResponse.Version >= new Version(2, 3))
                    cypherCapabilities = CypherCapabilities.Cypher23;

                if (RootApiResponse.Version >= new Version(3, 0))
                    cypherCapabilities = CypherCapabilities.Cypher30;
            }
            catch (AggregateException ex)
            {
                Exception unwrappedException;
                var wasUnwrapped = ex.TryUnwrap(out unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                stopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                    throw unwrappedException;

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                stopTimerAndNotifyCompleted();
                throw;
            }

            stopTimerAndNotifyCompleted();
        }
Esempio n. 8
0
        public virtual async Task ConnectAsync(NeoServerConfiguration configuration = null)
        {
            if (IsConnected)
            {
                return;
            }

            var stopwatch = Stopwatch.StartNew();
            var operationCompletedArgs = new OperationCompletedEventArgs
            {
                QueryText         = "Connect",
                ResourcesReturned = 0
            };

            void StopTimerAndNotifyCompleted()
            {
                stopwatch.Stop();
                operationCompletedArgs.TimeTaken = stopwatch.Elapsed;
                OnOperationCompleted(operationCompletedArgs);
            }

            try
            {
                configuration = configuration ?? await NeoServerConfiguration.GetConfigurationAsync(
                    RootUri,
                    ExecutionConfiguration.Username,
                    ExecutionConfiguration.Password,
                    ExecutionConfiguration.Realm,
                    ExecutionConfiguration.EncryptionLevel,
                    ExecutionConfiguration).ConfigureAwait(false);

                RootApiResponse = configuration.ApiConfig;

                if (!string.IsNullOrWhiteSpace(RootApiResponse.Transaction))
                {
                    transactionManager = new TransactionManager(this);
                }


                // http://blog.neo4j.org/2012/04/streaming-rest-api-interview-with.html
                ExecutionConfiguration.UseJsonStreaming = ExecutionConfiguration.UseJsonStreaming &&
                                                          RootApiResponse.Version >= new Version(1, 8);

                var version = RootApiResponse.Version;
                if (version < new Version(2, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher19;
                }

                if (version >= new Version(2, 2))
                {
                    CypherCapabilities = CypherCapabilities.Cypher22;
                }

                if (version >= new Version(2, 2, 6))
                {
                    CypherCapabilities = CypherCapabilities.Cypher226;
                }

                if (version >= new Version(2, 3))
                {
                    CypherCapabilities = CypherCapabilities.Cypher23;
                }

                if (version >= new Version(3, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher30;
                }

                if (version >= new Version(4, 0))
                {
                    CypherCapabilities = CypherCapabilities.Cypher40;
                }
                if (ServerVersion >= new Version(4, 4))
                {
                    CypherCapabilities = CypherCapabilities.Cypher44;
                }
            }
            catch (AggregateException ex)
            {
                var wasUnwrapped = ex.TryUnwrap(out var unwrappedException);
                operationCompletedArgs.Exception = wasUnwrapped ? unwrappedException : ex;

                StopTimerAndNotifyCompleted();

                if (wasUnwrapped)
                {
                    throw unwrappedException;
                }

                throw;
            }
            catch (Exception e)
            {
                operationCompletedArgs.Exception = e;
                StopTimerAndNotifyCompleted();
                throw;
            }

            StopTimerAndNotifyCompleted();
        }