private void Lexcial_Click(object sender, RoutedEventArgs e) { Progress.Visibility = Visibility.Visible; message msg = new message { type = "get_code" }; coreWebView.PostWebMessageAsString(JsonConvert.SerializeObject(msg)); }
private async void LoadedWebview() { await Storage.ensureAsserts(); sourceFolder = Storage.getStoragePath("Source"); engine = await Task.Run(() => { return(Python.CreateEngine()); }); ICollection <string> Paths = engine.GetSearchPaths(); Paths.Add(sourceFolder); Paths.Add(getSourcePath("Lib")); engine.SetSearchPaths(Paths); await MainWebView.EnsureCoreWebView2Async(); coreWebView = MainWebView.CoreWebView2; coreWebView.Settings.IsZoomControlEnabled = false; coreWebView.Settings.AreDevToolsEnabled = true; coreWebView.Navigate(Storage.getEditorPath()); coreWebView.WebMessageReceived += async(s, e) => { message msg = JsonConvert.DeserializeObject <message>(e.TryGetWebMessageAsString()); if (msg.type == "init_code") { string pyFileSource = await File.ReadAllTextAsync(getSourcePath("test.c")); msg.value = pyFileSource; coreWebView.PostWebMessageAsString(JsonConvert.SerializeObject(msg)); Lexcial.IsEnabled = true; } else if (msg.type == "return_code") { FileStream fs = new FileStream(getSourcePath("test.c--"), FileMode.Create); byte[] data = Encoding.Default.GetBytes(msg.value); fs.Write(data, 0, data.Length); fs.Close(); var result = await Task.Run(() => { return(LexcialAnalyzer()); }); List <token> tokens = new List <token>(); foreach (var item in result) { var temp = item as PythonDictionary; token Token = new token(); Token.type = temp["type"].ToString(); Token.value = temp["name"].ToString(); Token.row = temp["row"].ToString(); Token.colum = temp["colum"].ToString(); tokens.Add(Token); } DataGrid.ItemsSource = tokens; DataGrid.Visibility = Visibility.Visible; Progress.Visibility = Visibility.Collapsed; Syntactic.IsEnabled = true; } }; }