protected override void OnClick() { try { var bpf = new BrowseProjectFilter("esri_browseDialogFilters_json_file") { Name = "Select JSON file containing exported Geometries" }; var openItemDialog = new OpenItemDialog { BrowseFilter = bpf }; var result = openItemDialog.ShowDialog(); if (result.Value == false || openItemDialog.Items.Count() == 0) { return; } var item = openItemDialog.Items.ToArray()[0]; var filePath = item.Path; var json = System.IO.File.ReadAllText(filePath); var geometryBag = GeometryBagBuilderEx.FromJson(json); Module1.Geometries = geometryBag.Geometries.ToList(); Module1.HasImportData = true; MessageBox.Show($@"Geometries loaded: {Module1.Geometries.Count()}"); } catch (Exception ex) { MessageBox.Show($@"Import exception: {ex}"); } }
protected override void OnClick() { try { if (Module1.Geometries == null || Module1.Geometries.Count <= 0) { MessageBox.Show($@"You have to first render a geometry before you can export the Geometry"); return; } var bpf = new BrowseProjectFilter("esri_browseDialogFilters_json_file") { Name = "Specify JSON file to export Geometries to" }; var saveItemDialog = new SaveItemDialog { BrowseFilter = bpf }; var result = saveItemDialog.ShowDialog(); if (result.Value == false) { return; } var jsonPath = $@"{saveItemDialog.FilePath}.json"; var folder = System.IO.Path.GetDirectoryName(jsonPath); if (!System.IO.Directory.Exists(folder)) { System.IO.Directory.CreateDirectory(folder); } var exists = System.IO.File.Exists(jsonPath); if (exists) { var isYes = MessageBox.Show($@"The export will write over the existing file {jsonPath}", "Override File", System.Windows.MessageBoxButton.YesNo); if (isYes != System.Windows.MessageBoxResult.Yes) { return; } System.IO.File.Delete(jsonPath); } GeometryBag bag = GeometryBagBuilderEx.CreateGeometryBag(Module1.Geometries, Module1.Geometries[0].SpatialReference); System.IO.File.WriteAllText(jsonPath, bag.ToJson()); MessageBox.Show($@"Export saved to {jsonPath}"); } catch (Exception ex) { MessageBox.Show($@"Export Exception: {ex}"); } }