diff --git a/PLCSharp.Mcp/Program.cs b/PLCSharp.Mcp/Program.cs index 6e207b3..56e76f3 100644 --- a/PLCSharp.Mcp/Program.cs +++ b/PLCSharp.Mcp/Program.cs @@ -3,15 +3,17 @@ using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using PLCSharp.Mcp; -if (args.Length != 2 || args[0] != "--project" || !File.Exists(Path.Combine(args[1], "project.json"))) +bool allowWrite = args.Length == 3 && args[2] == "--allow-write"; +if ((args.Length != 2 && !allowWrite) || args[0] != "--project" || !File.Exists(Path.Combine(args[1], "project.json"))) { - Console.Error.WriteLine("Usage: PLCSharp.Mcp --project "); + Console.Error.WriteLine("Usage: PLCSharp.Mcp --project [--allow-write]"); return 2; } var builder = Host.CreateApplicationBuilder(); builder.Logging.ClearProviders(); builder.Logging.AddConsole(options => options.LogToStandardErrorThreshold = LogLevel.Trace); -builder.Services.AddSingleton(new ProjectGateway(Path.GetFullPath(args[1]))); +builder.Services.AddSingleton(new ProjectGateway(Path.GetFullPath(args[1]), allowWrite)); +builder.Logging.SetMinimumLevel(LogLevel.Warning); builder.Services.AddMcpServer().WithStdioServerTransport().WithTools(); await builder.Build().RunAsync(); return 0; diff --git a/PLCSharp.Mcp/ProjectGateway.cs b/PLCSharp.Mcp/ProjectGateway.cs index 6ab5edd..e7e4b50 100644 --- a/PLCSharp.Mcp/ProjectGateway.cs +++ b/PLCSharp.Mcp/ProjectGateway.cs @@ -3,11 +3,30 @@ using System.Text.Json.Nodes; namespace PLCSharp.Mcp; -internal sealed class ProjectGateway(string root) +internal sealed class ProjectGateway(string root, bool allowWrite) { + private readonly ProjectChanges changes = new(); + private readonly object gate = new(); + public string Call(string operation, JsonObject arguments) { - using var project = ProjectDirectory.Open(root); - return ProjectInspection.Query(project, operation, arguments).ToJsonString(); + try { lock (gate) return Dispatch(operation, arguments); } + catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or InvalidOperationException + or ArgumentException or FormatException or TimeoutException or System.Text.Json.JsonException) + { + throw new ModelContextProtocol.McpException(ex.Message, ex); + } + } + + private string Dispatch(string operation, JsonObject arguments) + { + if (operation == "apply" && !allowWrite) throw new InvalidOperationException("Start MCP with --allow-write to save."); + return ProjectPipe.Call(root, new() { ["operation"] = operation, ["arguments"] = arguments }, () => + { + using var project = ProjectDirectory.Open(root); + if (operation is "preview" or "apply" or "status") + return changes.Execute(project, operation, arguments, allowWrite); + return ProjectInspection.Query(project, operation, arguments); + }).ToJsonString(); } } diff --git a/PLCSharp.Mcp/ProjectTools.cs b/PLCSharp.Mcp/ProjectTools.cs index 407cb22..aac1e90 100644 --- a/PLCSharp.Mcp/ProjectTools.cs +++ b/PLCSharp.Mcp/ProjectTools.cs @@ -7,6 +7,16 @@ namespace PLCSharp.Mcp; [McpServerToolType] internal sealed class ProjectTools(ProjectGateway gateway) { + [McpServerTool(Name = "preview_changes"), Description("Preview a comment change to one recipe, variable or workflow. Returns a draft ID and before/after values. No file is written.")] + public string PreviewChanges(string kind, string id, string comment) => + gateway.Call("preview", new() { ["kind"] = kind, ["id"] = id, ["comment"] = comment }); + + [McpServerTool(Name = "apply_changes"), Description("Save an existing preview using its draft ID. Requires write-enabled launch. An open editor requests user confirmation.")] + public string ApplyChanges(string draftId) => gateway.Call("apply", new() { ["draftId"] = draftId }); + + [McpServerTool(Name = "get_change_status", ReadOnly = true), Description("Inspect a pending, rejected or saved draft.")] + public string GetChangeStatus(string draftId) => gateway.Call("status", new() { ["draftId"] = draftId }); + [McpServerTool(Name = "find_references", ReadOnly = true), Description("Find C# references to a Variables, SystemVariables or Workflows ID within its recipe. Dynamic hits require human review.")] public string FindReferences(string kind, string id) => gateway.Call("references", new() { ["kind"] = kind, ["id"] = id }); diff --git a/PLCSharpWpf/App.xaml.cs b/PLCSharpWpf/App.xaml.cs index 4b6a659..20892ae 100644 --- a/PLCSharpWpf/App.xaml.cs +++ b/PLCSharpWpf/App.xaml.cs @@ -24,6 +24,19 @@ namespace PLCSharp { internal bool SwitchingProject { get; set; } private Mutex mutex; + private ProjectPipe projectPipe; + + internal void AttachProjectPipe(string root) + { + projectPipe ??= new ProjectPipe(root, request => + Dispatcher.Invoke(() => Container.Resolve().HandleAiRequest(request))); + } + + protected override void OnExit(ExitEventArgs e) + { + projectPipe?.Dispose(); + base.OnExit(e); + } //第1执行 /// @@ -51,11 +64,17 @@ namespace PLCSharp ProjectDirectory project; try { - project = args.Length == 2 && (switching || args[0] == "--project") - ? ProjectDirectory.Open(args[1]) : ProjectDirectory.New(); + if (args.Length == 2 && (switching || args[0] == "--project")) + { + AttachProjectPipe(args[1]); + project = ProjectDirectory.Open(args[1]); + } + else project = ProjectDirectory.New(); } catch (Exception ex) { + projectPipe?.Dispose(); + projectPipe = null; MessageBox.Show($"无法打开工程:{ex.Message}", "PLCSharp"); project = ProjectDirectory.New(); } diff --git a/PLCSharpWpf/Models/GlobalModel.Project.cs b/PLCSharpWpf/Models/GlobalModel.Project.cs index eb2ead0..dfcfa91 100644 --- a/PLCSharpWpf/Models/GlobalModel.Project.cs +++ b/PLCSharpWpf/Models/GlobalModel.Project.cs @@ -8,6 +8,46 @@ public partial class GlobalModel { internal ProjectDirectory Project { get; } public string ProjectLocation => Project.Root ?? "未保存工程"; + public bool AllowAiAccess { get; set; } + private DelegateCommand copyMcpConfig; + public DelegateCommand CopyMcpConfig => copyMcpConfig ??= new DelegateCommand(() => + { + if (Project.Root == null) { SendInfoDialog("请先保存工程。"); return; } + var exe = System.IO.Path.Combine(AppContext.BaseDirectory, "PLCSharp.Mcp.exe"); + if (!System.IO.File.Exists(exe)) + { + var picker = new OpenFileDialog { Title = "选择 MCP 服务程序", Filter = "PLCSharp.Mcp.exe|PLCSharp.Mcp.exe" }; + if (picker.ShowDialog() != true) return; + exe = picker.FileName; + } + var config = new { mcpServers = new { plcsharp = new { command = exe, + args = new[] { "--project", Project.Root, "--allow-write" } } } }; + Clipboard.SetText(System.Text.Json.JsonSerializer.Serialize(config, new System.Text.Json.JsonSerializerOptions { WriteIndented = true })); + SendInfoDialog("已复制当前工程的 MCP 配置。仅需读取时可移除 --allow-write。"); + }); + private readonly ProjectChanges aiChanges = new(); + + internal System.Text.Json.Nodes.JsonNode HandleAiRequest(System.Text.Json.Nodes.JsonObject request) + { + if (!AllowAiAccess) throw new InvalidOperationException("请在机种配方页面启用 AI 访问。"); + string operation = (string)request["operation"]; + var args = request["arguments"].AsObject(); + if (operation is "preview" or "apply" or "status") + { + if (operation == "apply" && (ModeState.State.Execute || WorkflowsModel.IsBusy)) + throw new InvalidOperationException("运行或切换配方期间无法保存 AI 修改。"); + return aiChanges.Execute(Project, operation, args, true, change => + MessageBox.Show($"{change.Path}\n{change.Kind} / {change.Name}\n\n原备注:{change.Before}\n新备注:{change.After}", + "应用 AI 修改", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes); + } + var result = ProjectInspection.Query(Project, operation, args); + if (operation == "summary") + { + result["source"] = "editor"; + result["currentRecipeId"] = CurrentRecipe.ID.ToString(); + } + return result; + } private AsyncDelegateCommand projectManage; public AsyncDelegateCommand ProjectManage => projectManage ??= new AsyncDelegateCommand(ManageProjectAsync); @@ -24,6 +64,7 @@ public partial class GlobalModel var root = Project.Root ?? ChooseFolder("选择空文件夹以保存工程"); if (root == null) return false; Project.Save(root); + ((App)Application.Current).AttachProjectPipe(root); RaisePropertyChanged(nameof(ProjectLocation)); foreach (var recipe in Recipes) { diff --git a/PLCSharpWpf/Models/ProjectChanges.cs b/PLCSharpWpf/Models/ProjectChanges.cs new file mode 100644 index 0000000..650d8f0 --- /dev/null +++ b/PLCSharpWpf/Models/ProjectChanges.cs @@ -0,0 +1,117 @@ +using Microsoft.EntityFrameworkCore; +using System.Security.Cryptography; +using System.Text; +using System.Text.Json; +using System.Text.Json.Nodes; + +namespace PLCSharp.Models; + +public sealed record ProjectChange(Guid DraftId, Guid ProjectId, string Kind, Guid ObjectId, Guid RecipeId, + string Name, string Path, string Before, string After, string Revision, string Status); + +public sealed class ProjectChanges +{ + private readonly Dictionary drafts = new(); + + public JsonNode Execute(ProjectDirectory project, string operation, JsonObject args, bool allowWrite, + Func confirm = null) + { + if (operation == "preview") + { + string kind = (string)args["kind"], after = (string)args["comment"]; + if (after == null || after.Length > 8192) throw new ArgumentException("Expected a comment of at most 8192 characters."); + if (kind is not ("Recipes" or "Variables" or "SystemVariables" or "Workflows")) + throw new ArgumentException("Unsupported comment target."); + var id = Guid.Parse((string)args["id"]); + lock (project.Data.Sync) + { + var target = ProjectInspection.Query(project, "get", args); + var recipeId = kind == "Recipes" ? id : Guid.Parse((string)target["RecipeID"]); + string path = kind is "Variables" or "SystemVariables" ? "configuration/variables.json" : $"recipes/{recipeId:D}/recipe.json"; + string before = (string)target["Comment"]; + var change = new ProjectChange(Guid.NewGuid(), project.Id, kind, id, recipeId, (string)target["Name"], + path, before, after, project.Revision(path), "pending"); + if (drafts.Count >= 256) drafts.Remove(drafts.Keys.First()); + drafts.Add(change.DraftId, change); + return JsonSerializer.SerializeToNode(change); + } + } + if (!drafts.TryGetValue(Guid.Parse((string)args["draftId"]), out var draft) || draft.ProjectId != project.Id) + throw new ArgumentException("Unknown or expired draft."); + if (operation == "apply" && draft.Status == "pending") + { + if (!allowWrite) throw new InvalidOperationException("Start the MCP server with --allow-write to apply a preview."); + if (confirm != null && !confirm(draft)) draft = draft with { Status = "rejected" }; + else + { + try { project.ApplyComment(draft); } + catch (ProjectConflictException) + { + drafts[draft.DraftId] = draft with { Status = "conflict" }; + throw; + } + draft = draft with { Status = "saved" }; + } + drafts[draft.DraftId] = draft; + } + return JsonSerializer.SerializeToNode(draft); + } +} + +internal sealed class ProjectConflictException(string message) : System.IO.IOException(message); + +public sealed partial class ProjectDirectory +{ + internal string Revision(string path) => Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(baseline[path]))); + + internal void ApplyComment(ProjectChange change) + { + lock (Data.Sync) + { + var id = change.ObjectId; + var current = ProjectInspection.Query(this, "get", new() { ["kind"] = change.Kind, ["id"] = id.ToString() }); + if (Revision(change.Path) != change.Revision || (string)current["Comment"] != change.Before) + throw new ProjectConflictException("The target changed after preview. Create a new preview."); + var document = JsonNode.Parse(baseline[change.Path]); + var isVariable = change.Kind is "Variables" or "SystemVariables"; + JsonNode target = change.Kind switch + { + "Recipes" => document, + "Workflows" => document["workflows"].AsArray().Single(w => Guid.Parse((string)w["id"]) == id), + _ => document[change.Kind].AsArray().Single(v => Guid.Parse((string)v["ID"]) == id) + }; + var field = isVariable ? "Comment" : "comment"; + if ((string)target[field] != change.Before) + throw new ProjectConflictException("Save the pending editor change to this comment first."); + target[field] = change.After; + var json = Serialize(document); + var files = new Dictionary(baseline) { [change.Path] = json }; + // Change only the approved column in the private working database. Other tracked drafts stay pending. + using var transaction = isVariable ? Data.Database.BeginTransaction() : null; + if (change.Kind == "Variables") + Data.Variables.Where(v => v.ID == id).ExecuteUpdate(s => s.SetProperty(v => v.Comment, change.After)); + if (change.Kind == "SystemVariables") + Data.SystemVariables.Where(v => v.ID == id).ExecuteUpdate(s => s.SetProperty(v => v.Comment, change.After)); + try { WriteFiles(Root, files, [change.Path]); } + catch (System.IO.IOException) when (!System.IO.File.Exists(ProjectFile(Root, change.Path)) || + System.IO.File.ReadAllText(ProjectFile(Root, change.Path)) != baseline[change.Path]) + { + throw new ProjectConflictException("The file changed outside the editor. Reopen the project and preview again."); + } + transaction?.Commit(); + if (isVariable) + { + configuration[change.Path] = json; + object entity = change.Kind == "Variables" ? Data.Variables.Local.First(v => v.ID == id) + : Data.SystemVariables.Local.First(v => v.ID == id); + var property = Data.Entry(entity).Property(field); + if (entity is PLCSharp.VVMs.GlobalVariables.Variable variable) variable.Comment = change.After; + else ((PLCSharp.VVMs.GlobalVariables.SystemVariable)entity).Comment = change.After; + property.OriginalValue = change.After; + } + else if (change.Kind == "Recipes") Recipes.Single(r => r.ID == id).Comment = change.After; + else Flows(change.RecipeId).Single(w => w.ID == id).Comment = change.After; + } + } +} + diff --git a/PLCSharpWpf/Models/ProjectConfiguration.cs b/PLCSharpWpf/Models/ProjectConfiguration.cs index a883853..69dd302 100644 --- a/PLCSharpWpf/Models/ProjectConfiguration.cs +++ b/PLCSharpWpf/Models/ProjectConfiguration.cs @@ -26,7 +26,7 @@ internal static class ProjectConfiguration private static string Quote(string identifier) => "\"" + identifier.Replace("\"", "\"\"") + "\""; - internal static JsonObject Capture(DatasContext db, string[] tables) + internal static JsonObject Capture(DatasContext db, string[] tables, bool embedInputs = true) { var document = new JsonObject(); foreach (var table in tables) @@ -49,7 +49,7 @@ internal static class ProjectConfiguration { var raw = reader.GetValue(i); value = IsJson(p) ? (JsonNode.Parse((string)raw) ?? JsonValue.Create("null")) : JsonSerializer.SerializeToNode(raw); - if (table == "VisionFunctions" && p.GetColumnName() == "VisionFlows") + if (embedInputs && table == "VisionFunctions" && p.GetColumnName() == "VisionFlows") EmbedImageInputs(value); } row.Add(p.GetColumnName(), value); diff --git a/PLCSharpWpf/Models/ProjectDirectory.cs b/PLCSharpWpf/Models/ProjectDirectory.cs index dfc1c33..212e098 100644 --- a/PLCSharpWpf/Models/ProjectDirectory.cs +++ b/PLCSharpWpf/Models/ProjectDirectory.cs @@ -7,7 +7,7 @@ using System.Text.Json; namespace PLCSharp.Models; -public sealed class ProjectDirectory : IDisposable +public sealed partial class ProjectDirectory : IDisposable { private sealed record Manifest(int FormatVersion, Guid ProjectId, Guid DefaultRecipeId, Guid[] Recipes); private sealed record RecipeFile(Guid Id, string Name, string Comment, FlowFile[] Workflows); @@ -95,11 +95,26 @@ public sealed class ProjectDirectory : IDisposable } } + private static string ProjectFile(string root, string relative) + { + var path = root; + foreach (var part in relative.Split('/')) + { + path = Path.Combine(path, part); + if (File.Exists(path) || Directory.Exists(path)) + { + if ((File.GetAttributes(path) & FileAttributes.ReparsePoint) != 0) + throw new InvalidDataException($"Project files must be inside the directory: {relative}"); + } + } + return path; + } + private void ReadDirectory() { string Read(string path) { - string value = File.ReadAllText(Path.Combine(Root, path)); + string value = File.ReadAllText(ProjectFile(Root, path)); baseline.Add(path, value); return value; } @@ -207,7 +222,7 @@ public sealed class ProjectDirectory : IDisposable var paths = scope ?? files.Keys.Union(previous.Keys).ToArray(); foreach (var path in paths) { - var full = Path.Combine(root, path); + var full = ProjectFile(root, path); var disk = File.Exists(full) ? File.ReadAllText(full) : null; previous.TryGetValue(path, out var original); if (disk != original) @@ -233,7 +248,7 @@ public sealed class ProjectDirectory : IDisposable { var temp = Path.Combine(stage, path); if (files.ContainsKey(path) && !File.Exists(temp)) continue; - var target = Path.Combine(root, path); + var target = ProjectFile(root, path); if (previous.ContainsKey(path)) { var backup = Path.Combine(stage, Guid.NewGuid().ToString()); diff --git a/PLCSharpWpf/Models/ProjectInspection.cs b/PLCSharpWpf/Models/ProjectInspection.cs index 3333b69..8204cef 100644 --- a/PLCSharpWpf/Models/ProjectInspection.cs +++ b/PLCSharpWpf/Models/ProjectInspection.cs @@ -11,7 +11,7 @@ public static class ProjectInspection { if (operation == "references") return WorkflowReferences.Find(project, (string)args["kind"], (string)args["id"]); if (operation == "summary") - return JsonSerializer.SerializeToNode(new { project.Id, project.DefaultRecipeId, project.Root, + return JsonSerializer.SerializeToNode(new { project.Id, project.DefaultRecipeId, project.Root, source = "directory", kinds = Kinds, recipes = project.Recipes.Select(r => new { r.ID, r.Name }) }); string kind = (string)args["kind"]; if (!Kinds.Contains(kind)) throw new ArgumentException("Unknown object kind."); @@ -47,7 +47,13 @@ public static class ProjectInspection if (kind == "SystemVariables") return p.Data.SystemVariables.ToList().Select(v => JsonSerializer.SerializeToNode(new { v.ID, v.RecipeID, v.Name, v.Comment, v.Type, v.DefaultValueStr, v.ValueStr, v.RetainPersistent }).AsObject()); - var table = ProjectConfiguration.Capture(p.Data, [kind])[kind].AsArray(); + var table = ProjectConfiguration.Capture(p.Data, [kind], embedInputs: false)[kind].AsArray(); + if (kind == "LocalImageDatas") + { + var owners = p.Data.VisionFunctions.Select(f => new { f.ID, f.RecipeID }).ToDictionary(f => f.ID, f => f.RecipeID); + foreach (var row in table) + if (owners.TryGetValue(Guid.Parse((string)row["FuncID"]), out var owner)) row["RecipeID"] = owner.ToString(); + } return table.Select(n => n.AsObject()); } } diff --git a/PLCSharpWpf/Models/ProjectPipe.cs b/PLCSharpWpf/Models/ProjectPipe.cs new file mode 100644 index 0000000..1b81057 --- /dev/null +++ b/PLCSharpWpf/Models/ProjectPipe.cs @@ -0,0 +1,111 @@ +using System.IO; +using System.IO.Pipes; +using System.Security.Cryptography; +using System.Security.Principal; +using System.Text; +using System.Text.Json.Nodes; +using System.Threading; + +namespace PLCSharp.Models; + +public sealed class ProjectPipe : IDisposable +{ + private readonly CancellationTokenSource stopping = new(); + private readonly Mutex marker; + private readonly string name; + private readonly Func handle; + private static readonly UTF8Encoding Utf8 = new(false); + + private static string Name(string root) + { + var path = Path.TrimEndingDirectorySeparator(Path.GetFullPath(root)).ToUpperInvariant(); + using var user = WindowsIdentity.GetCurrent(); + var identity = user.User.Value; + return "PLCSharp-" + Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(identity + "|" + path))); + } + + internal static T Synchronized(string root, Func action) + { + using var mutex = new Mutex(false, Name(root) + "-access"); + bool acquired; + try { acquired = mutex.WaitOne(TimeSpan.FromSeconds(15)); } + catch (AbandonedMutexException) { acquired = true; } + if (!acquired) throw new IOException("Project is busy. Retry the request."); + try { return action(); } + finally { mutex.ReleaseMutex(); } + } + + public static JsonNode Call(string root, JsonObject request, Func offline) + { + var result = Synchronized(root, () => + { + if (!Mutex.TryOpenExisting(Name(root) + "-editor", out var active)) return offline(); + active.Dispose(); + return null; + }); + return result ?? TryCall(root, request) ?? throw new IOException("Editor closed. Retry the request."); + } + + public ProjectPipe(string root, Func handle) + { + name = Name(root); + this.handle = handle; + marker = Synchronized(root, () => + { + var registration = new Mutex(false, name + "-editor", out var created); + if (created) return registration; + registration.Dispose(); + throw new IOException("工程已在另一个编辑器中打开。"); + }); + _ = ServeAsync(stopping.Token); + } + + private async Task ServeAsync(CancellationToken token) + { + while (!token.IsCancellationRequested) + { + try + { + using var pipe = new NamedPipeServerStream(name, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, + PipeOptions.Asynchronous | PipeOptions.CurrentUserOnly); + await pipe.WaitForConnectionAsync(token).ConfigureAwait(false); + using var input = new StreamReader(pipe, Utf8, leaveOpen: true); + using var output = new StreamWriter(pipe, Utf8, leaveOpen: true) { AutoFlush = true }; + JsonObject response; + try + { + var line = await input.ReadLineAsync(token).ConfigureAwait(false); + response = new() { ["result"] = handle(JsonNode.Parse(line).AsObject()) }; + } + catch (Exception ex) { response = new() { ["error"] = ex.GetBaseException().Message }; } + await output.WriteLineAsync(response.ToJsonString()).ConfigureAwait(false); + } + catch (OperationCanceledException) when (token.IsCancellationRequested) { return; } + catch (IOException) { if (!token.IsCancellationRequested) await Task.Delay(50).ConfigureAwait(false); } + } + } + + public static JsonNode TryCall(string root, JsonObject request) + { + string name = Name(root); + if (!Mutex.TryOpenExisting(name + "-editor", out var active)) return null; + using (active) + using (var pipe = new NamedPipeClientStream(".", name, PipeDirection.InOut, PipeOptions.CurrentUserOnly)) + { + pipe.Connect(5000); + using var input = new StreamReader(pipe, Utf8, leaveOpen: true); + using var output = new StreamWriter(pipe, Utf8, leaveOpen: true) { AutoFlush = true }; + output.WriteLine(request.ToJsonString()); + var response = JsonNode.Parse(input.ReadLine() ?? throw new IOException("Editor disconnected.")); + if (response["error"] != null) throw new InvalidOperationException((string)response["error"]); + return response["result"]; + } + } + + public void Dispose() + { + stopping.Cancel(); + marker.Dispose(); + } +} + diff --git a/PLCSharpWpf/VVMs/GlobalVariables/Variable.cs b/PLCSharpWpf/VVMs/GlobalVariables/Variable.cs index 53d2fd8..910af23 100644 --- a/PLCSharpWpf/VVMs/GlobalVariables/Variable.cs +++ b/PLCSharpWpf/VVMs/GlobalVariables/Variable.cs @@ -35,7 +35,8 @@ namespace PLCSharp.VVMs.GlobalVariables /// /// 备注 /// - public string Comment { get; set; } + public string Comment { get => _comment; set => SetProperty(ref _comment, value); } + private string _comment; private dynamic _Value; @@ -212,7 +213,8 @@ namespace PLCSharp.VVMs.GlobalVariables /// /// 备注 /// - public string Comment { get; set; } + public string Comment { get => _comment; set => SetProperty(ref _comment, value); } + private string _comment; private dynamic _Value; diff --git a/PLCSharpWpf/VVMs/Recipe/RecipeEdit.xaml b/PLCSharpWpf/VVMs/Recipe/RecipeEdit.xaml index dcc9cfa..57529b7 100644 --- a/PLCSharpWpf/VVMs/Recipe/RecipeEdit.xaml +++ b/PLCSharpWpf/VVMs/Recipe/RecipeEdit.xaml @@ -70,7 +70,9 @@