TellmePdmsPluging/Class1.cs
root 3082148d7e 实现PDMS模型状态API并移除硬编码数据
## 主要改进
- 实现 /api/status/model 接口,返回真实PDMS模型状态信息
- 使用MDB.CurrentMDB、Project.CurrentProject等AVEVA API获取真实数据
- 移除硬编码的CurrentSession、PositionInfo、PdmsSpecific等复杂结构
- 简化数据模型,只保留核心的真实数据字段

## 技术实现
- 通过DbSession获取真实的用户名、会话开始时间和持续时间
- 通过WorldMembers()获取真实的模型元素统计
- 修复DateTime类型的null合并运算符编译错误
- 清理不使用的方法和类定义

## API返回数据
现在返回的数据主要包含真实的PDMS信息:
- ModelLoaded: MDB连接状态检查
- ProjectName: 真实的设计数据库名称
- MdsName: 真实的MDB名称
- UserName: 真实的数据库会话用户
- StartTime: 真实的会话创建时间
- TotalElements: 真实的模型元素数量统计

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-01 10:36:02 +08:00

101 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Aveva.ApplicationFramework;
using System;
using System.Windows.Forms;
using TellmePdmsPluging.Network;
namespace TellmePdmsPluging
{
public class TellmePdmsAddin : IAddin
{
private HttpServer _httpServer;
public string Name
{
get
{
return "TellmePdmsAddin";
}
}
public string Description
{
get
{
return "PDMS远程控制插件";
}
}
/// <summary>
/// 程序打开时,会调用这个方法
/// </summary>
/// <param name="serviceManager"></param>
public void Start(ServiceManager serviceManager)
{
try
{
// 记录启动日志
LogMessage("开始启动TellmePdms插件...");
// 启动HTTP服务器
_httpServer = new HttpServer(9001);
_httpServer.Start();
// 弹出成功提示
MessageBox.Show(
"TellmePdms插件已成功加载\n" +
"HTTP服务器已启动监听端口: 9001\n\n" +
"测试地址:\n" +
"- 健康检查: http://localhost:9001/health\n" +
"- 测试接口: http://localhost:9001/test",
"插件加载成功",
MessageBoxButtons.OK,
MessageBoxIcon.Information);
LogMessage("TellmePdms插件启动成功");
}
catch (Exception ex)
{
string errorMsg = $"插件启动失败: {ex.Message}";
LogMessage($"ERROR: {errorMsg}\n{ex.StackTrace}");
MessageBox.Show(errorMsg, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 程序关闭时,会调用这个方法
/// </summary>
public void Stop()
{
try
{
LogMessage("开始停止TellmePdms插件...");
// 停止HTTP服务器
if (_httpServer != null)
{
_httpServer.Stop();
_httpServer.Dispose();
_httpServer = null;
}
LogMessage("TellmePdms插件已停止");
}
catch (Exception ex)
{
LogMessage($"插件停止时出错: {ex.Message}");
}
}
private void LogMessage(string message)
{
try
{
string logPath = @"C:\temp\pdms_plugin_log.txt";
string logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} - {message}\r\n";
System.IO.File.AppendAllText(logPath, logEntry);
}
catch { }
}
}
}