private async Task InitializeAsync() { // Make sure everything is set up before doing anything with the browser await this.Browser.EnsureCoreWebView2Async(null); await this.TextBrowser.EnsureCoreWebView2Async(null); this.CypherEditor.SyntaxHighlighting = AvalonSourceEditor.LoadHighlightDefinition("SocratexGraphExplorer.Resources.Cypher-mode.xshd", typeof(MainWindow).Assembly); // Set up a function to call when the user clicks on something in the graph browser. Browser.WebMessageReceived += async(object sender, CoreWebView2WebMessageReceivedEventArgs args) => { string message = args.WebMessageAsJson; // The payload will be empty if the user clicked in the empty space // it will be {edge: id} if an edge is selected // it will be {node: id) if a node is selected //var item = System.Text.Json.JsonSerializer.Deserialize<ClickedItem>(message); var e = Newtonsoft.Json.Linq.JObject.Parse(message); if (e.ContainsKey("nodeId")) { var id = e["nodeId"].ToObject <long>(); var cypher = "MATCH (c) where id(c) = $id return c limit 1"; this.ViewModel.SelectedNode = id; var nodeResult = await this.model.ExecuteCypherAsync(cypher, new Dictionary <string, object>() { { "id", id } }); this.ViewModel.UpdatePropertyListView(nodeResult); } else if (e.ContainsKey("edgeId")) { var id = e["edgeId"].ToObject <long>(); var cypher = "MATCH (c) -[r]- (d) where id(r) = $id return r limit 1"; this.ViewModel.SelectedEdge = id; var edgeResult = await this.model.ExecuteCypherAsync(cypher, new Dictionary <string, object>() { { "id", id } }); this.ViewModel.UpdatePropertyListView(edgeResult); } else { // blank space selected } }; this.Browser.SizeChanged += async(object sender, SizeChangedEventArgs e) => { var browser = sender as WebView2; //await browser.EnsureCoreWebView2Async(); await this.ViewModel.SetGraphSizeAsync(browser); }; this.Browser.NavigationCompleted += Browser_NavigationCompleted; // The debugger does not work in Edge if the source does not come from a file. // Load the script into a temporary file, and use that file in the URI that // the debugger loads. this.Browser.Source = this.model.ScriptUri; this.TextBrowser.NavigateToString(@"<html> <head> <style> html, body, .container { height: 100%; } .container { font-size: 24; color: lightgray; display: flex; align-items: center; justify-content: center; } </style> </head> <body class='container'> Welcome to the Graph Explorer </body> </html>"); this.ViewModel.GraphModeSelected = false; this.ViewModel.TextModeSelected = true; }
/// <summary> /// No cypher queries can be done here, since the driver has not been set up yet /// </summary> /// <returns></returns> private async Task InitializeAsync() { // Make sure everything is set up before doing anything with the browser await this.Browser.EnsureCoreWebView2Async(null); await this.TextBrowser.EnsureCoreWebView2Async(null); this.CypherEditor.SyntaxHighlighting = AvalonSourceEditor.LoadHighlightDefinition("GraphExplorer.Resources.Cypher-mode.xshd", typeof(MainWindow).Assembly); // Set up a function to call when the user clicks on something in the graph browser. Browser.WebMessageReceived += async(object sender, CoreWebView2WebMessageReceivedEventArgs args) => { string message = args.WebMessageAsJson; // The payload will be empty if the user clicked in the empty space // it will be {edge: id} if an edge is selected // it will be {node: id) if a node is selected //var item = System.Text.Json.JsonSerializer.Deserialize<ClickedItem>(message); var e = Newtonsoft.Json.Linq.JObject.Parse(message); if (e.ContainsKey("selectedNodeId")) { // TODO get rid of this. var id = e["selectedNodeId"].ToObject <long>(); this.ViewModel.SelectedNode = id; var node = this.ViewModel.Graph.Node(id); //var nodeResult = await this.model.ExecuteCypherAsync(cypher, new Dictionary<string, object>() { { "id", id } }); this.ViewModel.UpdatePropertyListView(node); } else if (e.ContainsKey("selectedEdgeId")) { // TODO get rid of this. var id = e["selectedEdgeId"].ToObject <long>(); this.ViewModel.SelectedEdge = id; var edge = this.ViewModel.Graph.Edge(id); this.ViewModel.UpdatePropertyListView(edge); } else if (e.ContainsKey("contextOverNode")) { var menu = this.ViewModel.ContextNodeClicked(e["contextOverNode"].ToObject <long>()); } else if (e.ContainsKey("contextOverEdge")) { var menu = this.ViewModel.ContextEdgeClicked(e["contextOverEdge"].ToObject <long>()); } else if (e.ContainsKey("contextOverSurface")) { this.ViewModel.ContextSurfaceClicked(); } else if (e.ContainsKey("showOutgoingEdges")) { var id = e["showOutgoingEdges"].ToObject <long>(); await this.ViewModel.ShowOutgoingEdgesAsync(id); } else if (e.ContainsKey("showIncomingEdges")) { var id = e["showIncomingEdges"].ToObject <long>(); await this.ViewModel.ShowIncomingEdgesAsync(id); } else if (e.ContainsKey("showAllEdges")) { var id = e["showAllEdges"].ToObject <long>(); await this.ViewModel.ShowAllEdgesAsync(id); } else if (e.ContainsKey("showIncomingEdge")) { var edgeName = e["showIncomingEdge"].ToObject <string>(); var toNode = e["toNode"].ToObject <long>(); await this.ViewModel.ShowIncomingEdgeAsync(edgeName, toNode); } else if (e.ContainsKey("showOutgoingEdge")) { var edgeName = e["showOutgoingEdge"].ToObject <string>(); var fromNode = e["fromNode"].ToObject <long>(); await this.ViewModel.ShowOutgoingEdgeAsync(edgeName, fromNode); } else if (e.ContainsKey("showOnly")) { var id = e["showOnly"].ToObject <long>(); await this.ViewModel.ShowOnlyNodeAsync(id); } else if (e.ContainsKey("hideNode")) { var id = e["hideNode"].ToObject <long>(); this.ViewModel.HideNode(id); } else if (e.ContainsKey("hideNamedNodes")) { var name = e["hideNamedNodes"].ToObject <string>(); this.ViewModel.HideNamedNodes(name); } else if (e.ContainsKey("hideEdge")) { var id = e["hideEdge"].ToObject <long>(); this.ViewModel.HideEdge(id); } else if (e.ContainsKey("hideNamedEdges")) { var id = e["hideNamedEdges"].ToObject <string>(); this.ViewModel.HideNamedEdges(id); } }; this.Browser.SizeChanged += async(object sender, SizeChangedEventArgs e) => { var browser = sender as WebView2; //await browser.EnsureCoreWebView2Async(); await this.ViewModel.SetGraphSizeAsync(browser); }; this.Browser.NavigationCompleted += this.Browser_NavigationCompleted; this.ViewModel.GraphModeSelected = false; this.ViewModel.TextModeSelected = true; }