[tmp]MCP服务器自定义配置窗口
This commit is contained in:
parent
0a4ed9ee6b
commit
9b1f479425
27
ui/mcp/McpConfigWindow.xaml
Normal file
27
ui/mcp/McpConfigWindow.xaml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<controls:ProWindow x:Class="LinkToolAddin.ui.mcp.McpConfigWindow"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:controls="clr-namespace:ArcGIS.Desktop.Framework.Controls;assembly=ArcGIS.Desktop.Framework"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:extensions="clr-namespace:ArcGIS.Desktop.Extensions;assembly=ArcGIS.Desktop.Extensions"
|
||||||
|
mc:Ignorable="d"
|
||||||
|
Title="MCP服务器配置" Height="450" Width="500"
|
||||||
|
WindowStartupLocation="CenterOwner"
|
||||||
|
>
|
||||||
|
<controls:ProWindow.Resources>
|
||||||
|
<ResourceDictionary>
|
||||||
|
<ResourceDictionary.MergedDictionaries>
|
||||||
|
<extensions:DesignOnlyResourceDictionary Source="pack://application:,,,/ArcGIS.Desktop.Framework;component\Themes\Default.xaml"/>
|
||||||
|
</ResourceDictionary.MergedDictionaries>
|
||||||
|
</ResourceDictionary>
|
||||||
|
</controls:ProWindow.Resources>
|
||||||
|
<Grid>
|
||||||
|
<Grid.RowDefinitions>
|
||||||
|
<RowDefinition Height="*"></RowDefinition>
|
||||||
|
<RowDefinition Height="Auto"></RowDefinition>
|
||||||
|
</Grid.RowDefinitions>
|
||||||
|
<TextBox Grid.Row="0" Name="McpJsonTextBox" AcceptsReturn="True"></TextBox>
|
||||||
|
<Button Grid.Row="1" Name="McpJsonButton">保存</Button>
|
||||||
|
</Grid>
|
||||||
|
</controls:ProWindow>
|
||||||
71
ui/mcp/McpConfigWindow.xaml.cs
Normal file
71
ui/mcp/McpConfigWindow.xaml.cs
Normal file
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for McpConfigWindow.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class McpConfigWindow : ArcGIS.Desktop.Framework.Controls.ProWindow
|
||||||
|
{
|
||||||
|
private static Dictionary<string,McpServer> servers = new Dictionary<string, McpServer>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
ui/mcp/ShowMcpConfigWindow.cs
Normal file
42
ui/mcp/ShowMcpConfigWindow.cs
Normal file
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user