fix collision report save timing
This commit is contained in:
parent
da5f8a1ae1
commit
1a9c9ecd21
@ -24,5 +24,15 @@ namespace NavisworksTransport.UnitTests.Core
|
||||
|
||||
Assert.AreEqual("副本_我的路径", duplicatedName);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GenerateCollisionReportFileName_ShouldUseUnifiedChinesePrefixAndTimestamp()
|
||||
{
|
||||
var now = new DateTime(2026, 4, 9, 23, 55, 1);
|
||||
|
||||
var fileName = PathHelper.GenerateCollisionReportFileName("人工_0409_235000", "html", now);
|
||||
|
||||
Assert.AreEqual("碰撞检测报告_人工_0409_235000_20260409_235501.html", fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -602,19 +602,21 @@ namespace NavisworksTransport.Commands
|
||||
ShowReport(result);
|
||||
}
|
||||
|
||||
// 🔥 自动导出HTML报告
|
||||
try
|
||||
if (!_parameters.ShowDialog)
|
||||
{
|
||||
string htmlPath = Utils.CollisionReportHtmlGenerator.AutoSaveHtmlReport(result);
|
||||
if (!string.IsNullOrEmpty(htmlPath))
|
||||
try
|
||||
{
|
||||
LogManager.Info($"HTML报告已自动导出: {htmlPath}");
|
||||
string htmlPath = Utils.CollisionReportHtmlGenerator.AutoSaveHtmlReport(result);
|
||||
if (!string.IsNullOrEmpty(htmlPath))
|
||||
{
|
||||
LogManager.Info($"HTML报告已自动导出: {htmlPath}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"自动导出HTML报告失败: {ex.Message}");
|
||||
// HTML导出失败不影响报告生成
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"自动导出HTML报告失败: {ex.Message}");
|
||||
// HTML导出失败不影响报告生成
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
|
||||
@ -917,7 +917,7 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
Title = "导出碰撞报告",
|
||||
Filter = "HTML报告 (*.html)|*.html|碰撞报告 (*.txt)|*.txt|所有文件 (*.*)|*.*",
|
||||
DefaultExt = "html",
|
||||
FileName = $"NavisworksTransport_CollisionReport_{DateTime.Now:yyyyMMdd_HHmmss}"
|
||||
FileName = PathHelper.GenerateCollisionReportFileName(CurrentReport?.PathName ?? PathName, "html")
|
||||
};
|
||||
|
||||
if (saveFileDialog.ShowDialog() == true)
|
||||
@ -946,11 +946,10 @@ namespace NavisworksTransport.UI.WPF.ViewModels
|
||||
{
|
||||
try
|
||||
{
|
||||
if (CurrentReport == null || !HasCollisions) return;
|
||||
if (CurrentReport == null) return;
|
||||
|
||||
// 生成默认文件名和路径
|
||||
var sanitizedName = PathHelper.SanitizeFileName(CurrentReport.PathName ?? "未知路径");
|
||||
var fileName = $"NavisworksTransport_CollisionReport_{sanitizedName}_{DateTime.Now:yyyyMMdd_HHmmss}.html";
|
||||
var fileName = PathHelper.GenerateCollisionReportFileName(CurrentReport.PathName, "html");
|
||||
var reportDir = PathHelper.GetReportDirectory();
|
||||
var filePath = Path.Combine(reportDir, fileName);
|
||||
|
||||
|
||||
@ -94,11 +94,8 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
LogManager.Info("用户关闭碰撞报告对话框,正在自动导出报告...");
|
||||
|
||||
// 关闭前自动导出报告
|
||||
LogManager.Info("用户关闭碰撞报告对话框,正在自动导出最终报告...");
|
||||
await AutoExportReportAsync();
|
||||
|
||||
this.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -107,24 +104,6 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自动导出报告
|
||||
/// </summary>
|
||||
private async System.Threading.Tasks.Task AutoExportReportAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_viewModel != null)
|
||||
{
|
||||
await _viewModel.AutoExportReportAsync();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogManager.Error($"自动导出报告失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口关闭事件
|
||||
/// </summary>
|
||||
@ -169,6 +148,14 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
}
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task AutoExportReportAsync()
|
||||
{
|
||||
if (_viewModel != null)
|
||||
{
|
||||
await _viewModel.AutoExportReportAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口加载事件
|
||||
/// </summary>
|
||||
@ -470,4 +457,4 @@ namespace NavisworksTransport.UI.WPF.Views
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,8 +422,7 @@ namespace NavisworksTransport.Utils
|
||||
try
|
||||
{
|
||||
// 生成文件名
|
||||
string sanitizedName = PathHelper.SanitizeFileName(report.PathName ?? "未知路径");
|
||||
string fileName = PathHelper.GenerateTimestampedFileName($"collision_{sanitizedName}", "html");
|
||||
string fileName = PathHelper.GenerateCollisionReportFileName(report.PathName, "html");
|
||||
|
||||
// 获取报告目录
|
||||
string reportDir = PathHelper.GetReportDirectory();
|
||||
|
||||
@ -84,6 +84,20 @@ namespace NavisworksTransport.Utils
|
||||
return $"{prefix}_{timestamp}.{extension}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成碰撞检测报告文件名。
|
||||
/// 格式:碰撞检测报告_{路径名}_{时间戳}.{extension}
|
||||
/// </summary>
|
||||
public static string GenerateCollisionReportFileName(string pathName, string extension, DateTime? now = null)
|
||||
{
|
||||
string sanitizedName = SanitizeFileName(pathName ?? "未知路径");
|
||||
string normalizedExtension = string.IsNullOrWhiteSpace(extension)
|
||||
? "html"
|
||||
: extension.Trim().TrimStart('.');
|
||||
string timestamp = (now ?? DateTime.Now).ToString("yyyyMMdd_HHmmss");
|
||||
return $"碰撞检测报告_{sanitizedName}_{timestamp}.{normalizedExtension}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成复制路径名称。
|
||||
/// 如果原名称以 MMdd_HHmmss 结尾,则重建时间戳;否则仅添加“副本_”前缀。
|
||||
|
||||
Loading…
Reference in New Issue
Block a user