From 0fbff5f11412b8e4ab265106bc6a73fdac7df1ba Mon Sep 17 00:00:00 2001 From: tian <11429339@qq.com> Date: Mon, 9 Mar 2026 12:41:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=99=E7=89=88=E6=9C=AC=E5=8F=B7=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0Build=20Version=EF=BC=9B=E5=AE=9E=E7=8E=B0=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E4=BF=A1=E6=81=AF=E7=9A=84=E5=AE=9E=E6=97=B6=E8=8E=B7?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Properties/AssemblyInfo.cs | 8 +- TransportPlugin.csproj | 1 + .../ViewModels/LayerManagementViewModel.cs | 213 ------------------ .../ViewModels/SystemManagementViewModel.cs | 135 +++++++---- src/UI/WPF/Views/SystemManagementView.xaml | 39 ++-- src/Utils/VersionInfo.cs | 200 ++++++++++++++++ 6 files changed, 303 insertions(+), 293 deletions(-) create mode 100644 src/Utils/VersionInfo.cs diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 5e88e62..1020f6e 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -29,8 +29,6 @@ using System.Runtime.InteropServices; // 生成号 // 修订号 // -//可以指定所有这些值,也可以使用"生成号"和"修订号"的默认值 -//通过使用 "*",如下所示: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("2.0.0.0")] -[assembly: AssemblyFileVersion("2.0.0.0")] \ No newline at end of file +// 主版本和次版本手动维护,Build和Revision在编译时自动更新 +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/TransportPlugin.csproj b/TransportPlugin.csproj index 91df4ae..11427cc 100644 --- a/TransportPlugin.csproj +++ b/TransportPlugin.csproj @@ -325,6 +325,7 @@ + diff --git a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs index 0ced78d..e0de785 100644 --- a/src/UI/WPF/ViewModels/LayerManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/LayerManagementViewModel.cs @@ -736,7 +736,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels public ICommand BrowseOutputDirectoryCommand { get; private set; } public ICommand SaveSelectedItemsCommand { get; private set; } public ICommand CancelOperationCommand { get; private set; } - public ICommand DiagnosticCommand { get; private set; } public ICommand TestExportToNwdCommand { get; private set; } // 楼层属性相关命令 @@ -897,10 +896,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels CancelOperationCommand = new RelayCommand(CancelOperation, () => IsProcessing); - DiagnosticCommand = new RelayCommand( - async () => await RunDiagnosticAsync(), - () => IsNotProcessing); - TestExportToNwdCommand = new RelayCommand( async () => await TestExportToNwdAsync(), () => IsNotProcessing); @@ -2041,214 +2036,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels - /// - /// 运行环境诊断 - 检查Navisworks API环境 - /// - private async Task RunDiagnosticAsync() - { - try - { - LogManager.Info("[LayerManagementViewModel] 开始环境诊断"); - - // 1. 初始UI状态更新 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - IsProcessing = true; - CurrentOperationText = "正在进行环境诊断..."; - UpdateMainStatus("检查Navisworks API环境和线程状态"); - }); - - // 2. 纯业务逻辑执行(后台线程) - string diagnosticReport = await Task.Run(() => - { - return CreateDiagnosticReport(); - }); - - // 3. 结果UI更新 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - CurrentOperationText = "环境诊断完成"; - UpdateMainStatus("环境诊断报告已生成"); - }); - - // 显示诊断结果 - ShowDiagnosticResult(diagnosticReport); - - LogManager.Info("[LayerManagementViewModel] 环境诊断完成"); - } - catch (Exception ex) - { - LogManager.Error($"[LayerManagementViewModel] 环境诊断异常: {ex.Message}", ex); - - // 异常UI更新 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - CurrentOperationText = "环境诊断异常"; - UpdateMainStatus($"诊断失败: {ex.Message}"); - }); - - ShowDiagnosticResult($"诊断过程中发生异常: {ex.Message}"); - } - finally - { - // 4. 清理UI状态 - await _uiStateManager.ExecuteUIUpdateAsync(() => - { - IsProcessing = false; - }); - } - } - - /// - /// 创建环境诊断报告 - /// - /// 诊断报告 - private string CreateDiagnosticReport() - { - var report = new System.Text.StringBuilder(); - report.AppendLine("=== Navisworks API环境诊断报告 ==="); - - try - { - // 1. 线程状态 - var apartmentState = System.Threading.Thread.CurrentThread.GetApartmentState(); - report.AppendLine($"线程状态: {apartmentState} {(apartmentState == System.Threading.ApartmentState.STA ? "✓" : "✗")}"); - - // 2. API可用性 - try - { - var app = Autodesk.Navisworks.Api.Application.ActiveDocument; - report.AppendLine("API可用性: 可用 ✓"); - } - catch (Exception apiEx) - { - report.AppendLine($"API可用性: 异常 - {apiEx.Message} ✗"); - } - - // 3. 文档状态 - try - { - var document = Autodesk.Navisworks.Api.Application.ActiveDocument; - if (document != null) - { - report.AppendLine($"活动文档: {document.FileName ?? "未命名"} ✓"); - report.AppendLine($"模型数量: {document.Models?.Count ?? 0}"); - } - else - { - report.AppendLine("活动文档: 无 ✗"); - } - } - catch (Exception docEx) - { - report.AppendLine($"活动文档: 异常 - {docEx.Message} ✗"); - } - - // 4. 内存状态 - long memoryMB = GC.GetTotalMemory(false) / 1024 / 1024; - report.AppendLine($"当前内存: {memoryMB} MB"); - - report.AppendLine("=== 诊断完成 ==="); - - string result = report.ToString(); - LogManager.Info($"[LayerManagement] 环境诊断报告:\n{result}"); - return result; - } - catch (Exception ex) - { - string error = $"诊断过程出错: {ex.Message}"; - report.AppendLine(error); - LogManager.Error($"[LayerManagement] {error}"); - return report.ToString(); - } - } - - /// - /// 显示环境诊断结果对话框 - /// - private void ShowDiagnosticResult(string report) - { - try - { - System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => - { - var diagWindow = new Window - { - Title = "Navisworks API环境诊断", - Width = 600, - Height = 500, - WindowStartupLocation = WindowStartupLocation.CenterScreen, - ResizeMode = ResizeMode.CanResize - }; - - var textBox = new System.Windows.Controls.TextBox - { - Text = report, - IsReadOnly = true, - VerticalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto, - HorizontalScrollBarVisibility = System.Windows.Controls.ScrollBarVisibility.Auto, - FontFamily = new System.Windows.Media.FontFamily("Consolas"), - FontSize = 12, - Margin = new Thickness(10), - TextWrapping = TextWrapping.Wrap - }; - - var panel = new System.Windows.Controls.DockPanel(); - - var buttonPanel = new System.Windows.Controls.StackPanel - { - Orientation = System.Windows.Controls.Orientation.Horizontal, - HorizontalAlignment = HorizontalAlignment.Right, - Margin = new Thickness(10) - }; - System.Windows.Controls.DockPanel.SetDock(buttonPanel, System.Windows.Controls.Dock.Bottom); - - var copyButton = new System.Windows.Controls.Button - { - Content = "复制报告", - Width = 80, - Height = 25, - Margin = new Thickness(0, 0, 10, 0) - }; - copyButton.Click += (s, e) => - { - try - { - System.Windows.Clipboard.SetText(report); - MessageBox.Show("诊断报告已复制到剪贴板", "复制成功", MessageBoxButton.OK, MessageBoxImage.Information); - } - catch (Exception ex) - { - MessageBox.Show($"复制失败: {ex.Message}", "复制错误", MessageBoxButton.OK, MessageBoxImage.Warning); - } - }; - - var closeButton = new System.Windows.Controls.Button - { - Content = "关闭", - Width = 80, - Height = 25, - IsDefault = true - }; - closeButton.Click += (s, e) => diagWindow.Close(); - - buttonPanel.Children.Add(copyButton); - buttonPanel.Children.Add(closeButton); - panel.Children.Add(buttonPanel); - panel.Children.Add(textBox); - - diagWindow.Content = panel; - diagWindow.ShowDialog(); - })); - } - catch (Exception ex) - { - LogManager.Error($"[LayerManagementViewModel] 显示诊断结果失败: {ex.Message}"); - } - } - - - /// /// 测试ExportToNwd API - 专门的导出API /// diff --git a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs index 52bf942..7c88a51 100644 --- a/src/UI/WPF/ViewModels/SystemManagementViewModel.cs +++ b/src/UI/WPF/ViewModels/SystemManagementViewModel.cs @@ -3,6 +3,7 @@ using System.Collections.ObjectModel; using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using System.Windows.Threading; using NavisworksTransport.UI.WPF.Collections; using NavisworksTransport.Core; using NavisworksTransport.Core.Config; @@ -41,6 +42,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 🔧 修复:添加释放状态标志 private bool _disposed = false; + // 系统信息刷新定时器 + private DispatcherTimer _systemInfoTimer; + #endregion #region 公共属性 @@ -156,7 +160,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels public ICommand ViewLogCommand { get; private set; } public ICommand OpenSettingsCommand { get; private set; } - public ICommand CheckUpdateCommand { get; private set; } public ICommand GeneratePerformanceReportCommand { get; private set; } public ICommand DiagnosticCommand { get; private set; } @@ -294,7 +297,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels // 系统管理命令 ViewLogCommand = new RelayCommand(() => ExecuteViewLog()); OpenSettingsCommand = new RelayCommand(() => ExecuteOpenSettings()); - CheckUpdateCommand = new RelayCommand(() => ExecuteCheckUpdate()); GeneratePerformanceReportCommand = new RelayCommand(() => ExecuteGeneratePerformanceReport()); DiagnosticCommand = new RelayCommand(() => ExecuteDiagnostic()); @@ -588,13 +590,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels var currentLevel = LogManager.GetLogLevel(); SelectedLogLevel = currentLevel.ToString(); - // 初始化系统信息 - PluginVersion = "v1.0"; - NavisworksVersion = "2026"; + // 初始化系统信息 - 使用动态获取 + var systemInfo = VersionInfo.GetSystemInfo(); + PluginVersion = systemInfo.PluginVersion; + NavisworksVersion = systemInfo.NavisworksVersion; + MemoryUsage = systemInfo.MemoryUsage; + RunningTime = systemInfo.RunningTime; // 初始化数据库状态(如果数据库已连接) RefreshDatabaseStatus(); + // 启动系统信息定时刷新 + StartSystemInfoTimer(); + UpdateMainStatus("系统管理初始化完成"); }); @@ -680,47 +688,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels }, "打开设置"); } - /// - /// 检查更新 (已优化为Idle事件监听) - /// - private void ExecuteCheckUpdate() - { - SafeExecute(() => - { - UpdateMainStatus("正在检查更新..."); - - // 使用Idle事件监听替代Thread.Sleep(2000) - const string taskId = "SystemManagement_CheckUpdate"; - var startTime = DateTime.Now; - - IdleEventManager.Instance.RegisterOnceTask( - taskId, - () => (DateTime.Now - startTime).TotalMilliseconds >= 2000, // 2秒后条件满足 - () => - { - try - { - // 检查释放状态,避免在释放后更新UI - if (_disposed) - { - LogManager.Info("SystemManagementViewModel已释放,跳过更新检查UI更新"); - return; - } - - UpdateMainStatus("当前版本已是最新版本"); - } - catch (Exception ex) - { - LogManager.Error($"更新检查UI更新失败: {ex.Message}"); - } - }, - 8 // 高优先级 - ); - - LogManager.Info("检查更新 (使用Idle事件监听)"); - }, "检查更新"); - } - /// /// 生成性能报告 (已优化为Idle事件监听) /// @@ -805,7 +772,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels private string DiagnoseEnvironment() { var report = new System.Text.StringBuilder(); - report.AppendLine("=== Navisworks API环境诊断报告 ==="); try { @@ -852,8 +818,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels report.AppendLine($"Navisworks版本: {NavisworksVersion}"); report.AppendLine("系统状态: 正常"); - report.AppendLine("=== 诊断完成 ==="); - string result = report.ToString(); LogManager.Info($"[SystemManagement] 环境诊断报告:\n{result}"); return result; @@ -1850,6 +1814,68 @@ namespace NavisworksTransport.UI.WPF.ViewModels } } + /// + /// 启动系统信息定时刷新 + /// + private void StartSystemInfoTimer() + { + try + { + if (_systemInfoTimer == null) + { + _systemInfoTimer = new DispatcherTimer + { + Interval = TimeSpan.FromSeconds(5) // 每5秒刷新一次 + }; + _systemInfoTimer.Tick += (s, e) => RefreshSystemInfo(); + } + + _systemInfoTimer.Start(); + LogManager.Debug("系统信息定时器已启动 (5秒间隔)"); + } + catch (Exception ex) + { + LogManager.Error($"启动系统信息定时器失败: {ex.Message}"); + } + } + + /// + /// 停止系统信息定时刷新 + /// + private void StopSystemInfoTimer() + { + try + { + if (_systemInfoTimer != null) + { + _systemInfoTimer.Stop(); + _systemInfoTimer.Tick -= (s, e) => { }; + _systemInfoTimer = null; + } + } + catch (Exception ex) + { + LogManager.Warning($"停止系统信息定时器时出现警告: {ex.Message}"); + } + } + + /// + /// 刷新系统信息 (内存、运行时间) + /// + private void RefreshSystemInfo() + { + try + { + // 使用 VersionInfo 获取最新的内存和运行时间 + MemoryUsage = VersionInfo.GetMemoryUsage(); + RunningTime = VersionInfo.GetRunningTime(); + } + catch (Exception ex) + { + LogManager.Debug($"刷新系统信息时出错: {ex.Message}"); + } + } + public void Cleanup() { try @@ -1882,6 +1908,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels LogManager.Debug($"清理一次性Idle任务时出现提示: {ex.Message}"); } + // 停止系统信息定时器 + try + { + StopSystemInfoTimer(); + LogManager.Debug("SystemManagementViewModel系统信息定时器已停止"); + } + catch (Exception ex) + { + LogManager.Debug($"停止系统信息定时器时出现提示: {ex.Message}"); + } + LogManager.Info("SystemManagementViewModel资源清理完成"); } catch (Exception ex) diff --git a/src/UI/WPF/Views/SystemManagementView.xaml b/src/UI/WPF/Views/SystemManagementView.xaml index bd336df..ea8e40b 100644 --- a/src/UI/WPF/Views/SystemManagementView.xaml +++ b/src/UI/WPF/Views/SystemManagementView.xaml @@ -2,10 +2,11 @@ NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Navisworks 2026风格 功能说明: -1. 日志管理:查看、清空、导出日志,设置日志级别 -2. 插件设置:设置选项、重置设置、导入配置、启用选项 -3. 系统信息:插件版本、Navisworks版本、系统状态、内存使用、运行时间 -4. 性能监控:性能信息和性能报告生成 +1. 数据管理:备份、恢复、修复数据库 +2. 日志管理:查看、清空、导出日志,设置日志级别 +3. 插件设置:设置选项、重置设置、导入配置、启用选项 +4. 系统信息:插件版本、Navisworks版本、内存使用、运行时间 +5. 功能测试:测试新功能和实验性特性 设计原则:与Navisworks 2026风格一致,480像素宽度,现代化UI布局,采用Border分组 --> @@ -198,7 +199,7 @@ NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Nav