diff --git a/ui/mcp/McpConfigWindow.xaml b/ui/mcp/McpConfigWindow.xaml new file mode 100644 index 0000000..7d9b7c3 --- /dev/null +++ b/ui/mcp/McpConfigWindow.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + diff --git a/ui/mcp/McpConfigWindow.xaml.cs b/ui/mcp/McpConfigWindow.xaml.cs new file mode 100644 index 0000000..aa36ce5 --- /dev/null +++ b/ui/mcp/McpConfigWindow.xaml.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using LinkToolAddin.host; +using LinkToolAddin.host.mcp; +using Newtonsoft.Json; +using Path = System.IO.Path; + +namespace LinkToolAddin.ui.mcp +{ + /// + /// Interaction logic for McpConfigWindow.xaml + /// + public partial class McpConfigWindow : ArcGIS.Desktop.Framework.Controls.ProWindow + { + private static Dictionary servers = new Dictionary(); + public McpConfigWindow() + { + InitializeComponent(); + string mcpConfigStr = ReadMcpConfig(); + McpJsonTextBox.Text = mcpConfigStr; + } + + private string ReadMcpConfig() + { + string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + string configDirPath = Path.Combine(appDataPath, "LinkTool"); + string mcpConfigPath = Path.Combine(appDataPath, "LinkTool", "McpConfig.json"); + Directory.CreateDirectory(configDirPath); + if (!File.Exists(mcpConfigPath)) + { + File.Create(mcpConfigPath); + McpServerList mcpServerList = new McpServerList(); + string json = JsonConvert.SerializeObject(mcpServerList.GetAllServers()); + File.WriteAllText(mcpConfigPath, json); + return json; + } + else + { + string mcpConfigStr = File.ReadAllText(mcpConfigPath); + McpServerList mcpServerList = new McpServerList(mcpConfigStr); + return JsonConvert.SerializeObject(mcpServerList.GetAllServers()); + } + } + + private void WriteMcpConfig(string json) + { + string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); + string configDirPath = Path.Combine(appDataPath, "LinkTool"); + string mcpConfigPath = Path.Combine(appDataPath, "LinkTool", "McpConfig.json"); + Directory.CreateDirectory(configDirPath); + if (!File.Exists(mcpConfigPath)) + { + File.Create(mcpConfigPath); + } + File.WriteAllText(mcpConfigPath, json); + } + } +} diff --git a/ui/mcp/ShowMcpConfigWindow.cs b/ui/mcp/ShowMcpConfigWindow.cs new file mode 100644 index 0000000..d561420 --- /dev/null +++ b/ui/mcp/ShowMcpConfigWindow.cs @@ -0,0 +1,42 @@ +using ArcGIS.Core.CIM; +using ArcGIS.Core.Data; +using ArcGIS.Core.Geometry; +using ArcGIS.Desktop.Catalog; +using ArcGIS.Desktop.Core; +using ArcGIS.Desktop.Editing; +using ArcGIS.Desktop.Extensions; +using ArcGIS.Desktop.Framework; +using ArcGIS.Desktop.Framework.Contracts; +using ArcGIS.Desktop.Framework.Dialogs; +using ArcGIS.Desktop.Framework.Threading.Tasks; +using ArcGIS.Desktop.KnowledgeGraph; +using ArcGIS.Desktop.Layouts; +using ArcGIS.Desktop.Mapping; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LinkToolAddin.ui.mcp +{ + internal class ShowMcpConfigWindow : Button + { + + private McpConfigWindow _mcpconfigwindow = null; + + protected override void OnClick() + { + //already open? + if (_mcpconfigwindow != null) + return; + _mcpconfigwindow = new McpConfigWindow(); + _mcpconfigwindow.Owner = FrameworkApplication.Current.MainWindow; + _mcpconfigwindow.Closed += (o, e) => { _mcpconfigwindow = null; }; + _mcpconfigwindow.Show(); + //uncomment for modal + //_mcpconfigwindow.ShowDialog(); + } + + } +}