From 9b1f479425d386d8755fc5f3e1877ee1ef6bbbfc Mon Sep 17 00:00:00 2001 From: PeterZhong Date: Mon, 23 Jun 2025 21:52:33 +0800 Subject: [PATCH] =?UTF-8?q?[tmp]MCP=E6=9C=8D=E5=8A=A1=E5=99=A8=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E9=85=8D=E7=BD=AE=E7=AA=97=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/mcp/McpConfigWindow.xaml | 27 +++++++++++++ ui/mcp/McpConfigWindow.xaml.cs | 71 ++++++++++++++++++++++++++++++++++ ui/mcp/ShowMcpConfigWindow.cs | 42 ++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 ui/mcp/McpConfigWindow.xaml create mode 100644 ui/mcp/McpConfigWindow.xaml.cs create mode 100644 ui/mcp/ShowMcpConfigWindow.cs 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(); + } + + } +}