teigha 오류 수정
This commit is contained in:
@@ -56,15 +56,158 @@ public class FieldMapper
|
||||
/// </summary>
|
||||
public static FieldMapper LoadFromFile(string jsonFilePath)
|
||||
{
|
||||
string jsonContent = File.ReadAllText(jsonFilePath);
|
||||
var options = new JsonSerializerOptions
|
||||
try
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
|
||||
};
|
||||
|
||||
var mappingData = JsonSerializer.Deserialize<MappingTableData>(jsonContent, options);
|
||||
return new FieldMapper(mappingData);
|
||||
string jsonContent = File.ReadAllText(jsonFilePath, System.Text.Encoding.UTF8);
|
||||
Console.WriteLine($"[DEBUG] 매핑 테이블 JSON 파일 크기: {jsonContent.Length} bytes");
|
||||
|
||||
// JSON 내용 정리 (주석 제거 등)
|
||||
jsonContent = CleanJsonContent(jsonContent);
|
||||
|
||||
var options = new JsonSerializerOptions
|
||||
{
|
||||
PropertyNameCaseInsensitive = true,
|
||||
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping,
|
||||
AllowTrailingCommas = true
|
||||
};
|
||||
|
||||
var mappingData = JsonSerializer.Deserialize<MappingTableData>(jsonContent, options);
|
||||
Console.WriteLine($"[DEBUG] 매핑 테이블 로드 성공: {mappingData?.MappingTable?.AilabelToSystems?.Count ?? 0}개 항목");
|
||||
return new FieldMapper(mappingData);
|
||||
}
|
||||
catch (JsonException jsonEx)
|
||||
{
|
||||
Console.WriteLine($"❌ 매핑 테이블 JSON 파싱 오류: {jsonEx.Message}");
|
||||
Console.WriteLine($"❌ 파일: {jsonFilePath}");
|
||||
if (File.Exists(jsonFilePath))
|
||||
{
|
||||
string content = File.ReadAllText(jsonFilePath);
|
||||
Console.WriteLine($"❌ JSON 내용 미리보기 (첫 500자):");
|
||||
Console.WriteLine(content.Length > 500 ? content.Substring(0, 500) + "..." : content);
|
||||
}
|
||||
throw new Exception($"매핑 테이블 JSON 파일 파싱 실패: {jsonEx.Message}\n파일: {jsonFilePath}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"❌ 매핑 테이블 로드 중 오류: {ex.Message}");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// JSON 내용을 정리하여 파싱 가능한 상태로 만듭니다.
|
||||
/// 주석 제거 및 기타 무효한 문자 처리
|
||||
/// </summary>
|
||||
/// <param name="jsonContent">원본 JSON 내용</param>
|
||||
/// <returns>정리된 JSON 내용</returns>
|
||||
private static string CleanJsonContent(string jsonContent)
|
||||
{
|
||||
if (string.IsNullOrEmpty(jsonContent))
|
||||
return jsonContent;
|
||||
|
||||
try
|
||||
{
|
||||
// 줄별로 처리하여 주석 제거
|
||||
var lines = jsonContent.Split('\n');
|
||||
var cleanedLines = new List<string>();
|
||||
|
||||
bool inMultiLineComment = false;
|
||||
|
||||
foreach (string line in lines)
|
||||
{
|
||||
string processedLine = line;
|
||||
|
||||
// 멀티라인 주석 처리 (/* */)
|
||||
if (inMultiLineComment)
|
||||
{
|
||||
int endIndex = processedLine.IndexOf("*/");
|
||||
if (endIndex >= 0)
|
||||
{
|
||||
processedLine = processedLine.Substring(endIndex + 2);
|
||||
inMultiLineComment = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
continue; // 전체 라인이 주석
|
||||
}
|
||||
}
|
||||
|
||||
// 멀티라인 주석 시작 확인
|
||||
int multiLineStart = processedLine.IndexOf("/*");
|
||||
if (multiLineStart >= 0)
|
||||
{
|
||||
int multiLineEnd = processedLine.IndexOf("*/", multiLineStart + 2);
|
||||
if (multiLineEnd >= 0)
|
||||
{
|
||||
// 같은 라인에서 시작하고 끝나는 주석
|
||||
processedLine = processedLine.Substring(0, multiLineStart) +
|
||||
processedLine.Substring(multiLineEnd + 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 멀티라인 주석 시작
|
||||
processedLine = processedLine.Substring(0, multiLineStart);
|
||||
inMultiLineComment = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 싱글라인 주석 제거 (//) - 문자열 내부의 //는 제외
|
||||
bool inString = false;
|
||||
bool escaped = false;
|
||||
int commentIndex = -1;
|
||||
|
||||
for (int i = 0; i < processedLine.Length - 1; i++)
|
||||
{
|
||||
char current = processedLine[i];
|
||||
char next = processedLine[i + 1];
|
||||
|
||||
if (escaped)
|
||||
{
|
||||
escaped = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current == '\\')
|
||||
{
|
||||
escaped = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (current == '"')
|
||||
{
|
||||
inString = !inString;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!inString && current == '/' && next == '/')
|
||||
{
|
||||
commentIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (commentIndex >= 0)
|
||||
{
|
||||
processedLine = processedLine.Substring(0, commentIndex);
|
||||
}
|
||||
|
||||
// 빈 라인이 아니면 추가
|
||||
if (!string.IsNullOrWhiteSpace(processedLine))
|
||||
{
|
||||
cleanedLines.Add(processedLine);
|
||||
}
|
||||
}
|
||||
|
||||
string result = string.Join("\n", cleanedLines);
|
||||
Console.WriteLine($"[DEBUG] 매핑 테이블 JSON 정리 완료: {jsonContent.Length} -> {result.Length} bytes");
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"❌ 매핑 테이블 JSON 정리 중 오류: {ex.Message}");
|
||||
// 정리 실패시 원본 반환
|
||||
return jsonContent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user