From 30e3cb1d168556c608e6404310d994af1c4a6d80 Mon Sep 17 00:00:00 2001 From: Peter Villadsen Date: Sat, 8 Aug 2020 17:21:58 -0700 Subject: [PATCH] Removed old sample queries file that was no longer used, fixed issue where graph explorer did not show an empty graph if there were no matches, some cleanup --- tools/Explorer/SampleQueries.cs | 53 ------------------- .../GraphExplorer/Models/Model.cs | 23 +++++--- .../ViewModels/EditorViewModel.cs | 1 - .../Views/FormInformationControl.xaml.cs | 2 +- .../Views/TableInformationControl.xaml.cs | 2 +- 5 files changed, 17 insertions(+), 64 deletions(-) delete mode 100644 tools/Explorer/SampleQueries.cs diff --git a/tools/Explorer/SampleQueries.cs b/tools/Explorer/SampleQueries.cs deleted file mode 100644 index d155a7b..0000000 --- a/tools/Explorer/SampleQueries.cs +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Reflection; - -namespace XppReasoningWpf -{ - class SampleQueries - { - public static List AddQueries(string rootDirectory) - { - var result = new List(); - var assembly = Assembly.GetExecutingAssembly(); - - // Get all the xq streams?? - var names = assembly.GetManifestResourceNames().Where(n => n.StartsWith("XppReasoningWpf.Queries", StringComparison.OrdinalIgnoreCase)); - - foreach (var queryName in names) - { - using (Stream s = assembly.GetManifestResourceStream(queryName)) - { - var r = new StreamReader(s); - { - var c = r.ReadToEnd(); - - var parts = queryName.Split('.').ToList(); - parts.RemoveAt(0); // Skip namespace - - var extension = parts.Last(); - parts.RemoveAt(parts.Count() - 1); - - var name = parts.Last(); - parts.RemoveAt(parts.Count() - 1); - - string directoryPart = Path.Combine(parts.ToArray()); - var directoryName = Path.Combine(rootDirectory, directoryPart); - Directory.CreateDirectory(directoryName); - - var fullName = Path.Combine(directoryName, name + '.' + extension); - result.Add(fullName); - File.WriteAllText(fullName, c); - } - } - } - - return result; - } - } -} diff --git a/tools/Graph Explorer/GraphExplorer/Models/Model.cs b/tools/Graph Explorer/GraphExplorer/Models/Model.cs index 4cf5449..09c0352 100644 --- a/tools/Graph Explorer/GraphExplorer/Models/Model.cs +++ b/tools/Graph Explorer/GraphExplorer/Models/Model.cs @@ -192,9 +192,10 @@ namespace SocratexGraphExplorer.Models public string QueryFont => Properties.Settings.Default.QueryFont; - public void CreateNeo4jDriver(string password) + public IDriver CreateNeo4jDriver(string password) { this.Driver = GraphDatabase.Driver(string.Format("bolt://{0}:{1}", this.Server, this.Port), AuthTokens.Basic(this.Username, password)); + return this.Driver; } public Model() @@ -249,10 +250,15 @@ namespace SocratexGraphExplorer.Models if (driver == null) return false; - var session = driver.AsyncSession(); - var cursor = await session.RunAsync("match(c) return count(c)"); - var list = await cursor.ToListAsync(); - return list != null && list.Any(); + try + { + await driver.VerifyConnectivityAsync(); + return true; + } + catch + { + return false; + } } } catch (Exception ) @@ -469,10 +475,11 @@ namespace SocratexGraphExplorer.Models public static HashSet HarvestNodeIdsFromGraph(List records) { - if (!records.Any()) - return null; - var result = new HashSet(); + + if (!records.Any()) + return result; + App.Current.Dispatcher.Invoke(() => { foreach (var record in records) diff --git a/tools/Graph Explorer/GraphExplorer/ViewModels/EditorViewModel.cs b/tools/Graph Explorer/GraphExplorer/ViewModels/EditorViewModel.cs index 8b80290..f1b5d4c 100644 --- a/tools/Graph Explorer/GraphExplorer/ViewModels/EditorViewModel.cs +++ b/tools/Graph Explorer/GraphExplorer/ViewModels/EditorViewModel.cs @@ -335,7 +335,6 @@ namespace SocratexGraphExplorer.ViewModels this.model = model; NodeSelected += UpdateNodeInfoPage; - EdgeSelected += UpdateEdgeInfoPage; this.PropertyChanged += async (object sender, PropertyChangedEventArgs e) => diff --git a/tools/Graph Explorer/GraphExplorer/Views/FormInformationControl.xaml.cs b/tools/Graph Explorer/GraphExplorer/Views/FormInformationControl.xaml.cs index d0b7bda..e3eeab6 100644 --- a/tools/Graph Explorer/GraphExplorer/Views/FormInformationControl.xaml.cs +++ b/tools/Graph Explorer/GraphExplorer/Views/FormInformationControl.xaml.cs @@ -55,7 +55,7 @@ namespace SocratexGraphExplorer.Views this.SourceEditorBox.Content = this.ClassEditor; } - private async void UserControl_Loaded(object sender, RoutedEventArgs e) + private void UserControl_Loaded(object sender, RoutedEventArgs e) { this.Header.Text = string.Format("{0} {1}", node.Labels[0], node.Properties["Name"] as string); properties.Add(new PropertyItem() { Key = "Id", Value = node.Id.ToString() }); diff --git a/tools/Graph Explorer/GraphExplorer/Views/TableInformationControl.xaml.cs b/tools/Graph Explorer/GraphExplorer/Views/TableInformationControl.xaml.cs index ba5f4b5..24c2ff8 100644 --- a/tools/Graph Explorer/GraphExplorer/Views/TableInformationControl.xaml.cs +++ b/tools/Graph Explorer/GraphExplorer/Views/TableInformationControl.xaml.cs @@ -55,7 +55,7 @@ namespace SocratexGraphExplorer.Views this.SourceEditorBox.Content = this.ClassEditor; } - private async void UserControl_Loaded(object sender, RoutedEventArgs e) + private void UserControl_Loaded(object sender, RoutedEventArgs e) { this.Header.Text = string.Format("{0} {1}", node.Labels[0], node.Properties["Name"] as string); properties.Add(new PropertyItem() { Key = "Id", Value = node.Id.ToString() });