Beispiel #1
0
 public ConnectionDialog(DBInformation dbInformation) : this()
 {
     this.dbInformation       = dbInformation;
     databaseNameTextBox.Text = dbInformation.Db;
     databaseUrlTextBox.Text  = dbInformation.Url;
     usernameTextBox.Text     = dbInformation.Username;
     passwordTextBox.Text     = dbInformation.Password;
 }
Beispiel #2
0
        /// <summary>
        /// Opens the database connection.
        /// </summary>
        /// <param name="dbInformation"></param>
        private static void StartSession(DBInformation dbInformation)
        {
            var authToken = AuthTokens.Basic(dbInformation.Username, dbInformation.Password);
            var driver    = GraphDatabase.Driver(dbInformation.Url, authToken);

            Session =
                dbInformation.Db == "default"
          ? driver.AsyncSession(builder => builder.WithDefaultAccessMode(AccessMode.Read))
          : driver.AsyncSession(builder => builder.WithDefaultAccessMode(AccessMode.Read).WithDatabase(dbInformation.Db));
        }
Beispiel #3
0
        /// <summary>
        /// Executes a query and populates the graph with the result.
        /// </summary>
        /// <param name="query">The query to execute.</param>
        /// <param name="dbInformation">The connection information.</param>
        /// <param name="clearGraph">A value indicating whether to replace the graph with the result of the query.</param>
        /// <param name="desiredLocation">An optional location where newly-created nodes should appear.</param>
        private async Task LoadGraphAsync(string query, DBInformation dbInformation, bool clearGraph = false, PointD desiredLocation = default(PointD))
        {
            try {
                ShowLoadingIndicator();
                var(nodes, edges) = await LoadDataFromDatabaseAsync(query, dbInformation);

                // Finally, with the new data, build the graph
                await BuildGraphAsync(nodes, edges, clearGraph, desiredLocation);
            } finally {
                HideLoadingIndicator();
            }
        }
Beispiel #4
0
        /// <summary>
        /// Executes a query and populates the graph with the result.
        /// </summary>
        /// <param name="query">The query to execute.</param>
        /// <param name="dbInformation">The connection information.</param>
        /// <param name="clearGraph">A value indicating whether to replace the graph with the result of the query.</param>
        /// <param name="desiredLocation">An optional location where newly-created nodes should appear.</param>
        private async Task LoadGraphAsync(string query, DBInformation dbInformation, bool clearGraph = false, PointD desiredLocation = default)
        {
            try {
                loadingIndicator.Visibility = Visibility.Visible;
                var(nodes, edges)           = await LoadDataFromDatabaseAsync(query, dbInformation);

                // Finally, with the new data, build the graph
                await BuildGraphAsync(nodes, edges, clearGraph, desiredLocation);
            } finally {
                loadingIndicator.Visibility = Visibility.Collapsed;
            }
        }
Beispiel #5
0
        /// <summary>
        /// Fetches nodes and edges from the database
        /// </summary>
        /// <param name="query">The query to execute.</param>
        /// <param name="dbInformation">The connection information.</param>
        /// <returns>A tuple of nodes and edges returned from the database.</returns>
        public static async Task <(List <INeo4jNode>, List <IRelationship>)> LoadDataFromDatabaseAsync(string query, DBInformation dbInformation)
        {
            //Connect to database
            if (Session == null)
            {
                StartSession(dbInformation);
            }

            //Ask for the result
            var result = await Session.RunAsync(query);

            // Collect nodes and edges from the result
            // Items may appear multiple times, so we need to remove duplicates based on their ID
            var nodes = new HashSet <INeo4jNode>(IdEqualityComparer <INeo4jNode> .Instance);
            var edges = new HashSet <IRelationship>(IdEqualityComparer <IRelationship> .Instance);

            foreach (var record in await result.ToListAsync())
            {
                foreach (var kv in record.Values)
                {
                    // This may be in a variety of formats (lists, paths, nodes, edges, ...)
                    // so it's a bit more complicated to get at the actual elements
                    Unpack(kv.Value, nodes, edges);
                }
            }

            return(nodes.ToList(), edges.ToList());
        }