Пример #1
0
        /// <summary>
        /// Shows a separate window that allows to visualize the shortest path between any two nodes.
        /// </summary>
        private async void ShowPathViewer(INode n)
        {
            // Create a small window to choose the target for the shortest path search
            using (var dialog = new ShortestPathDialog(n, Graph.Nodes.ToList())) {
                var result = dialog.ShowDialog(this);
                if (result == DialogResult.OK)
                {
                    try {
                        var(nodes, edges) = await LoadDataFromDatabaseAsync(
                            $"MATCH (n1),(n2), path = shortestPath((n1)-[*..100]-(n2)) WHERE id(n1) = {dialog.FromItem.Id} AND id(n2) = {dialog.ToItem.Id} RETURN path",
                            ConnectionInfo);

                        if (nodes.Count == 0)
                        {
                            MessageBox.Show("No path found!");
                            return;
                        }

                        using (var pathViewer = new PathViewerDialog(nodes, edges)) {
                            pathViewer.ShowDialog(this);
                        }
                    } catch (Exception e) {
                        MessageBox.Show("Could not load the graph. Please check the database or the query.\n\n" + e.Message);
                        connectionInfoPanel.ShowDialog(this);
                        Connect_OnClick(null, null);
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Shows a separate window that allows to visualize the shortest path between any two nodes.
        /// </summary>
        private async void ShowPathViewer(INode n)
        {
            // Create a small window to choose the target for the shortest path search
            var dialog = new ShortestPathDialog(n, Graph.Nodes.ToList());

            if (dialog.ShowDialog() == true)
            {
                try {
                    var(nodes, edges) = await LoadDataFromDatabaseAsync(
                        $"MATCH (n1),(n2), path = shortestPath((n1)-[*..100]-(n2)) WHERE id(n1) = {dialog.FromItem.Id} AND id(n2) = {dialog.ToItem.Id} RETURN path",
                        ConnectionInfo);

                    if (nodes.Count == 0)
                    {
                        MessageBox.Show("No path found!");
                        return;
                    }

                    var pathViewer = new PathViewer(nodes, edges);
                    pathViewer.Show();
                } catch (Exception e) {
                    MessageBox.Show("Could not load the graph. Please check the database or the query.\n\n" + e.Message);
                    ConnectionInfoPanel.Visibility = Visibility.Visible;
                }
            }
        }