in tools/Graph Explorer/GraphExplorer/MainWindow.xaml.cs [101:179]
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;
}