handefeng 5 months ago
parent dff2948d39
commit 67e9ec64c0
  1. 68
      Model/Services/AlgorithmServer.cs

@ -25,12 +25,6 @@ namespace SparkClient.Model.Services
_algorithmConfigVM = new AlgorithmConfigVM(); _algorithmConfigVM = new AlgorithmConfigVM();
} }
private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer)); private static readonly ILog Logger = LogManager.GetLogger(typeof(AlgorithmServer));
// 导入 C++ DLL 中的 DetectDiamond 函数
[DllImport("diamond_cut_inspector.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr DetectDiamond(string jsonData);
// 导入 C++ DLL 中的 FreeMemory 函数
[DllImport("diamond_cut_inspector.dll", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
private static extern void FreeString(IntPtr ptr);
// 添加公共方法 // 添加公共方法
public AlgorithmResultEntity CallParseJsonAndReturnActions(string shape, string shape_mode, string image_files) public AlgorithmResultEntity CallParseJsonAndReturnActions(string shape, string shape_mode, string image_files)
@ -307,68 +301,6 @@ namespace SparkClient.Model.Services
Logger.Error($"Stack Trace: {ex.StackTrace}"); Logger.Error($"Stack Trace: {ex.StackTrace}");
} }
} }
/// <summary>
/// 处理 C++ DLL 的日志文件,将其复制到 log4net 日志目录下的 logs 文件夹,并记录其内容到日志中
/// </summary>
private void ProcessDllLog()
{
try
{
// 获取系统临时目录路径(TMP 或 TEMP 环境变量)
string? tempDirectory = Environment.GetEnvironmentVariable("TMP") ?? Environment.GetEnvironmentVariable("TEMP");
if (tempDirectory != null)
{
// 构建搜索模式
string searchPattern = "*diamond_cut_inspector*";
// 获取所有匹配的文件
string[] logFiles = Directory.GetFiles(tempDirectory, searchPattern, SearchOption.TopDirectoryOnly);
if (logFiles.Length > 0)
{
// 找到最新的日志文件
string latestLogFile = logFiles.OrderByDescending(file => new FileInfo(file).LastWriteTime).First();
// 获取 log4net 日志文件所在的目录
string log4netLogDirectory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
if (log4netLogDirectory != null)
{
// 构建 logs 目录路径
string logsDirectory = Path.Combine(log4netLogDirectory, "logs");
// 确保 logs 目录存在
Directory.CreateDirectory(logsDirectory);
// 构建目标文件路径
string targetFilePath = Path.Combine(logsDirectory, Path.GetFileName(latestLogFile));
// 复制最新日志文件到 logs 目录
File.Copy(latestLogFile, targetFilePath, true);
// 读取复制后的日志文件的内容
string dllLogContent = File.ReadAllText(targetFilePath);
// 记录 C++ DLL 日志文件的内容到日志中
Logger.Error("C++ DLL Log Content:");
Logger.Error(dllLogContent);
}
else
{
Logger.Error("Unable to determine the log4net log directory.");
}
}
else
{
// 如果没有找到匹配的日志文件,记录错误信息
Logger.Error("No C++ DLL log files found matching the pattern '*diamond_cut_inspector*.log'.");
}
}
else
{
// 如果无法获取临时目录路径,记录错误信息
Logger.Error("Unable to determine the temporary directory path.");
}
}
catch (Exception ex)
{
// 记录读取或复制日志文件时的异常
Logger.Error($"Error processing C++ DLL log file: {ex.Message}");
Logger.Error($"Stack Trace: {ex.StackTrace}");
}
}
} }
} }

Loading…
Cancel
Save