给版本号增加Build Version;实现系统信息的实时获取

This commit is contained in:
tian 2026-03-09 12:41:44 +08:00
parent 6e6932394a
commit 0fbff5f114
6 changed files with 303 additions and 293 deletions

View File

@ -29,8 +29,6 @@ using System.Runtime.InteropServices;
// 生成号 // 生成号
// 修订号 // 修订号
// //
//可以指定所有这些值,也可以使用"生成号"和"修订号"的默认值 // 主版本和次版本手动维护Build和Revision在编译时自动更新
//通过使用 "*",如下所示: [assembly: AssemblyVersion("1.0.0.0")]
// [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]

View File

@ -325,6 +325,7 @@
<Compile Include="src\Utils\NavisworksSelectionHelper.cs" /> <Compile Include="src\Utils\NavisworksSelectionHelper.cs" />
<Compile Include="src\Utils\NavisworksToDMesh3Converter.cs" /> <Compile Include="src\Utils\NavisworksToDMesh3Converter.cs" />
<Compile Include="src\Utils\UnitsConverter.cs" /> <Compile Include="src\Utils\UnitsConverter.cs" />
<Compile Include="src\Utils\VersionInfo.cs" />
<!-- Coordinate System --> <!-- Coordinate System -->
<Compile Include="src\Utils\CoordinateSystem\CoordinateSystemType.cs" /> <Compile Include="src\Utils\CoordinateSystem\CoordinateSystemType.cs" />
<Compile Include="src\Utils\CoordinateSystem\ICoordinateSystem.cs" /> <Compile Include="src\Utils\CoordinateSystem\ICoordinateSystem.cs" />

View File

@ -736,7 +736,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
public ICommand BrowseOutputDirectoryCommand { get; private set; } public ICommand BrowseOutputDirectoryCommand { get; private set; }
public ICommand SaveSelectedItemsCommand { get; private set; } public ICommand SaveSelectedItemsCommand { get; private set; }
public ICommand CancelOperationCommand { get; private set; } public ICommand CancelOperationCommand { get; private set; }
public ICommand DiagnosticCommand { get; private set; }
public ICommand TestExportToNwdCommand { get; private set; } public ICommand TestExportToNwdCommand { get; private set; }
// 楼层属性相关命令 // 楼层属性相关命令
@ -897,10 +896,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
CancelOperationCommand = new RelayCommand(CancelOperation, () => IsProcessing); CancelOperationCommand = new RelayCommand(CancelOperation, () => IsProcessing);
DiagnosticCommand = new RelayCommand(
async () => await RunDiagnosticAsync(),
() => IsNotProcessing);
TestExportToNwdCommand = new RelayCommand( TestExportToNwdCommand = new RelayCommand(
async () => await TestExportToNwdAsync(), async () => await TestExportToNwdAsync(),
() => IsNotProcessing); () => IsNotProcessing);
@ -2041,214 +2036,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
/// <summary>
/// 运行环境诊断 - 检查Navisworks API环境
/// </summary>
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;
});
}
}
/// <summary>
/// 创建环境诊断报告
/// </summary>
/// <returns>诊断报告</returns>
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();
}
}
/// <summary>
/// 显示环境诊断结果对话框
/// </summary>
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}");
}
}
/// <summary> /// <summary>
/// 测试ExportToNwd API - 专门的导出API /// 测试ExportToNwd API - 专门的导出API
/// </summary> /// </summary>

View File

@ -3,6 +3,7 @@ using System.Collections.ObjectModel;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Threading;
using NavisworksTransport.UI.WPF.Collections; using NavisworksTransport.UI.WPF.Collections;
using NavisworksTransport.Core; using NavisworksTransport.Core;
using NavisworksTransport.Core.Config; using NavisworksTransport.Core.Config;
@ -41,6 +42,9 @@ namespace NavisworksTransport.UI.WPF.ViewModels
// 🔧 修复:添加释放状态标志 // 🔧 修复:添加释放状态标志
private bool _disposed = false; private bool _disposed = false;
// 系统信息刷新定时器
private DispatcherTimer _systemInfoTimer;
#endregion #endregion
#region #region
@ -156,7 +160,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
public ICommand ViewLogCommand { get; private set; } public ICommand ViewLogCommand { get; private set; }
public ICommand OpenSettingsCommand { get; private set; } public ICommand OpenSettingsCommand { get; private set; }
public ICommand CheckUpdateCommand { get; private set; }
public ICommand GeneratePerformanceReportCommand { get; private set; } public ICommand GeneratePerformanceReportCommand { get; private set; }
public ICommand DiagnosticCommand { get; private set; } public ICommand DiagnosticCommand { get; private set; }
@ -294,7 +297,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
// 系统管理命令 // 系统管理命令
ViewLogCommand = new RelayCommand(() => ExecuteViewLog()); ViewLogCommand = new RelayCommand(() => ExecuteViewLog());
OpenSettingsCommand = new RelayCommand(() => ExecuteOpenSettings()); OpenSettingsCommand = new RelayCommand(() => ExecuteOpenSettings());
CheckUpdateCommand = new RelayCommand(() => ExecuteCheckUpdate());
GeneratePerformanceReportCommand = new RelayCommand(() => ExecuteGeneratePerformanceReport()); GeneratePerformanceReportCommand = new RelayCommand(() => ExecuteGeneratePerformanceReport());
DiagnosticCommand = new RelayCommand(() => ExecuteDiagnostic()); DiagnosticCommand = new RelayCommand(() => ExecuteDiagnostic());
@ -588,13 +590,19 @@ namespace NavisworksTransport.UI.WPF.ViewModels
var currentLevel = LogManager.GetLogLevel(); var currentLevel = LogManager.GetLogLevel();
SelectedLogLevel = currentLevel.ToString(); SelectedLogLevel = currentLevel.ToString();
// 初始化系统信息 // 初始化系统信息 - 使用动态获取
PluginVersion = "v1.0"; var systemInfo = VersionInfo.GetSystemInfo();
NavisworksVersion = "2026"; PluginVersion = systemInfo.PluginVersion;
NavisworksVersion = systemInfo.NavisworksVersion;
MemoryUsage = systemInfo.MemoryUsage;
RunningTime = systemInfo.RunningTime;
// 初始化数据库状态(如果数据库已连接) // 初始化数据库状态(如果数据库已连接)
RefreshDatabaseStatus(); RefreshDatabaseStatus();
// 启动系统信息定时刷新
StartSystemInfoTimer();
UpdateMainStatus("系统管理初始化完成"); UpdateMainStatus("系统管理初始化完成");
}); });
@ -680,47 +688,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
}, "打开设置"); }, "打开设置");
} }
/// <summary>
/// 检查更新 (已优化为Idle事件监听)
/// </summary>
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事件监听)");
}, "检查更新");
}
/// <summary> /// <summary>
/// 生成性能报告 (已优化为Idle事件监听) /// 生成性能报告 (已优化为Idle事件监听)
/// </summary> /// </summary>
@ -805,7 +772,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
private string DiagnoseEnvironment() private string DiagnoseEnvironment()
{ {
var report = new System.Text.StringBuilder(); var report = new System.Text.StringBuilder();
report.AppendLine("=== Navisworks API环境诊断报告 ===");
try try
{ {
@ -852,8 +818,6 @@ namespace NavisworksTransport.UI.WPF.ViewModels
report.AppendLine($"Navisworks版本: {NavisworksVersion}"); report.AppendLine($"Navisworks版本: {NavisworksVersion}");
report.AppendLine("系统状态: 正常"); report.AppendLine("系统状态: 正常");
report.AppendLine("=== 诊断完成 ===");
string result = report.ToString(); string result = report.ToString();
LogManager.Info($"[SystemManagement] 环境诊断报告:\n{result}"); LogManager.Info($"[SystemManagement] 环境诊断报告:\n{result}");
return result; return result;
@ -1850,6 +1814,68 @@ namespace NavisworksTransport.UI.WPF.ViewModels
} }
} }
/// <summary>
/// 启动系统信息定时刷新
/// </summary>
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}");
}
}
/// <summary>
/// 停止系统信息定时刷新
/// </summary>
private void StopSystemInfoTimer()
{
try
{
if (_systemInfoTimer != null)
{
_systemInfoTimer.Stop();
_systemInfoTimer.Tick -= (s, e) => { };
_systemInfoTimer = null;
}
}
catch (Exception ex)
{
LogManager.Warning($"停止系统信息定时器时出现警告: {ex.Message}");
}
}
/// <summary>
/// 刷新系统信息 (内存、运行时间)
/// </summary>
private void RefreshSystemInfo()
{
try
{
// 使用 VersionInfo 获取最新的内存和运行时间
MemoryUsage = VersionInfo.GetMemoryUsage();
RunningTime = VersionInfo.GetRunningTime();
}
catch (Exception ex)
{
LogManager.Debug($"刷新系统信息时出错: {ex.Message}");
}
}
public void Cleanup() public void Cleanup()
{ {
try try
@ -1882,6 +1908,17 @@ namespace NavisworksTransport.UI.WPF.ViewModels
LogManager.Debug($"清理一次性Idle任务时出现提示: {ex.Message}"); LogManager.Debug($"清理一次性Idle任务时出现提示: {ex.Message}");
} }
// 停止系统信息定时器
try
{
StopSystemInfoTimer();
LogManager.Debug("SystemManagementViewModel系统信息定时器已停止");
}
catch (Exception ex)
{
LogManager.Debug($"停止系统信息定时器时出现提示: {ex.Message}");
}
LogManager.Info("SystemManagementViewModel资源清理完成"); LogManager.Info("SystemManagementViewModel资源清理完成");
} }
catch (Exception ex) catch (Exception ex)

View File

@ -2,10 +2,11 @@
NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Navisworks 2026风格 NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Navisworks 2026风格
功能说明: 功能说明:
1. 日志管理:查看、清空、导出日志,设置日志级别 1. 数据管理:备份、恢复、修复数据库
2. 插件设置:设置选项、重置设置、导入配置、启用选项 2. 日志管理:查看、清空、导出日志,设置日志级别
3. 系统信息插件版本、Navisworks版本、系统状态、内存使用、运行时间 3. 插件设置:设置选项、重置设置、导入配置、启用选项
4. 性能监控:性能信息和性能报告生成 4. 系统信息插件版本、Navisworks版本、内存使用、运行时间
5. 功能测试:测试新功能和实验性特性
设计原则与Navisworks 2026风格一致480像素宽度现代化UI布局采用Border分组 设计原则与Navisworks 2026风格一致480像素宽度现代化UI布局采用Border分组
--> -->
@ -198,7 +199,7 @@ NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Nav
<Label Content="系统信息" Style="{StaticResource SectionHeaderStyle}"/> <Label Content="系统信息" Style="{StaticResource SectionHeaderStyle}"/>
<!-- 系统信息表格 --> <!-- 系统信息表格 -->
<Grid Margin="0,10,0,15"> <Grid Margin="0,10,0,10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/> <ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/> <ColumnDefinition Width="*"/>
@ -225,11 +226,12 @@ NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Nav
<Label Grid.Row="4" Grid.Column="1" Content="{Binding RunningTime}" Style="{StaticResource InfoTextStyle}"/> <Label Grid.Row="4" Grid.Column="1" Content="{Binding RunningTime}" Style="{StaticResource InfoTextStyle}"/>
</Grid> </Grid>
<!-- 更新检查按钮 --> <!-- 系统操作按钮 -->
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal" Margin="0,5,0,5">
<Button Content="检查更新" <Button Content="环境检查"
Command="{Binding CheckUpdateCommand}" Style="{StaticResource SecondaryButtonStyle}"
Style="{StaticResource SecondaryButtonStyle}"/> Command="{Binding DiagnosticCommand}"
ToolTip="检查运行环境和线程状态"/>
<Button Content="导出剖面盒" <Button Content="导出剖面盒"
Command="{Binding ExportSectionBoxCommand}" Command="{Binding ExportSectionBoxCommand}"
@ -238,23 +240,8 @@ NavisworksTransport 系统管理页签视图 - 采用与其他页签一致的Nav
</StackPanel> </StackPanel>
</StackPanel> </StackPanel>
</Border> </Border>
<!-- 区域4: 性能监控 -->
<Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
<StackPanel>
<Label Content="性能监控" Style="{StaticResource SectionHeaderStyle}"/>
<!-- 环境检查按钮 --> <!-- 区域4: 功能测试 -->
<StackPanel Orientation="Horizontal" Margin="0,5,0,5">
<Button Content="环境检查"
Style="{StaticResource SecondaryButtonStyle}"
Command="{Binding DiagnosticCommand}"
ToolTip="检查运行环境和线程状态"/>
</StackPanel>
</StackPanel>
</Border>
<!-- 区域5: 功能测试 -->
<Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12"> <Border BorderBrush="#FFD4E7FF" BorderThickness="1" CornerRadius="0" Margin="0,0,0,15" Padding="12">
<StackPanel> <StackPanel>
<Label Content="功能测试" Style="{StaticResource SectionHeaderStyle}"/> <Label Content="功能测试" Style="{StaticResource SectionHeaderStyle}"/>

200
src/Utils/VersionInfo.cs Normal file
View File

@ -0,0 +1,200 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Text;
namespace NavisworksTransport.Utils
{
/// <summary>
/// 版本信息管理工具类 - 提供统一的版本信息获取
/// </summary>
public static class VersionInfo
{
private static readonly DateTime _startupTime = DateTime.Now;
private static readonly string _buildTimestamp;
private static readonly string _fullVersion;
private static readonly string _shortVersion;
/// <summary>
/// 静态构造函数 - 初始化版本信息
/// </summary>
static VersionInfo()
{
try
{
var assembly = Assembly.GetExecutingAssembly();
var version = assembly.GetName().Version;
// 短版本号: 2.0.0 (使用 AssemblyVersion 的主.次.构建)
_shortVersion = $"{version.Major}.{version.Minor}.{version.Build}";
// 获取程序集文件的构建时间 (从文件修改时间)
DateTime buildDate = GetBuildDate(assembly);
_buildTimestamp = buildDate.ToString("yyyy-MM-dd-HHmmss");
// 完整版本: 2.0.0 Build-2025-03-09-113300
_fullVersion = $"{_shortVersion} Build-{_buildTimestamp}";
}
catch (Exception ex)
{
LogManager.Error($"初始化版本信息失败: {ex.Message}");
_shortVersion = "0.0.0";
_buildTimestamp = DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
_fullVersion = $"{_shortVersion} Build-{_buildTimestamp}";
}
}
/// <summary>
/// 从程序集文件获取构建日期
/// </summary>
private static DateTime GetBuildDate(Assembly assembly)
{
try
{
// 方法1: 从程序集文件的最后修改时间获取
var assemblyLocation = assembly.Location;
if (!string.IsNullOrEmpty(assemblyLocation) && File.Exists(assemblyLocation))
{
var fileInfo = new FileInfo(assemblyLocation);
return fileInfo.LastWriteTime;
}
}
catch (Exception ex)
{
LogManager.Debug($"从文件获取构建日期失败: {ex.Message}");
}
// 回退: 使用当前时间(开发模式)
return DateTime.Now;
}
/// <summary>
/// 获取插件短版本号 (例如: 2.0.0)
/// </summary>
public static string ShortVersion => _shortVersion;
/// <summary>
/// 获取完整版本号 (包含构建时间戳)
/// 格式: 2.0.0 Build-20250309-113300
/// </summary>
public static string FullVersion => _fullVersion;
/// <summary>
/// 获取构建时间戳
/// 格式: 20250309-113300
/// </summary>
public static string BuildTimestamp => _buildTimestamp;
/// <summary>
/// 获取 Navisworks 版本信息
/// </summary>
public static string GetNavisworksVersion()
{
try
{
var version = Autodesk.Navisworks.Api.Application.Version;
if (version != null)
{
// 计算年份:主版本号 + 2003
// 23 + 2003 = 2026, 22 + 2003 = 2025
int year = version.RuntimeMajor + 2003;
return $"{version.Runtime} {year} ({version.RuntimeLanguage})";
}
return "未运行";
}
catch (Exception ex)
{
LogManager.Error($"获取Navisworks版本失败: {ex.Message}");
return "未知版本";
}
}
/// <summary>
/// 获取当前内存使用情况
/// </summary>
public static string GetMemoryUsage()
{
try
{
long memoryBytes = GC.GetTotalMemory(false);
Process process = Process.GetCurrentProcess();
long workingSetMB = process.WorkingSet64 / 1024 / 1024;
return $"{workingSetMB} MB";
}
catch (Exception ex)
{
LogManager.Error($"获取内存使用失败: {ex.Message}");
return "--";
}
}
/// <summary>
/// 获取插件运行时间
/// </summary>
public static string GetRunningTime()
{
try
{
TimeSpan elapsed = DateTime.Now - _startupTime;
if (elapsed.TotalDays >= 1)
{
return $"{elapsed.Days}天 {elapsed.Hours:D2}:{elapsed.Minutes:D2}:{elapsed.Seconds:D2}";
}
return $"{elapsed.Hours:D2}:{elapsed.Minutes:D2}:{elapsed.Seconds:D2}";
}
catch (Exception ex)
{
LogManager.Error($"获取运行时间失败: {ex.Message}");
return "--";
}
}
/// <summary>
/// 获取系统信息汇总
/// </summary>
public static SystemInfo GetSystemInfo()
{
return new SystemInfo
{
PluginVersion = FullVersion,
NavisworksVersion = GetNavisworksVersion(),
MemoryUsage = GetMemoryUsage(),
RunningTime = GetRunningTime(),
BuildTimestamp = BuildTimestamp
};
}
}
/// <summary>
/// 系统信息数据类
/// </summary>
public class SystemInfo
{
/// <summary>
/// 插件版本
/// </summary>
public string PluginVersion { get; set; }
/// <summary>
/// Navisworks版本
/// </summary>
public string NavisworksVersion { get; set; }
/// <summary>
/// 内存使用
/// </summary>
public string MemoryUsage { get; set; }
/// <summary>
/// 运行时间
/// </summary>
public string RunningTime { get; set; }
/// <summary>
/// 构建时间戳
/// </summary>
public string BuildTimestamp { get; set; }
}
}