88 lines
2.3 KiB
C#

using System.Text.Json.Serialization;
namespace Adaptation.FileHandlers.txt;
public class Header
{
public Header(string lot,
string session)
{
Lot = lot;
Session = session;
}
public string Lot { get; }
public string Session { get; }
internal static void ScanPast(string text, int[] i, string search)
{
int num = text.IndexOf(search, i[0]);
if (num > -1)
i[0] = num + search.Length;
else
i[0] = text.Length;
}
internal static string GetBefore(string text, int[] i, string search)
{
int num = text.IndexOf(search, i[0]);
if (num > -1)
{
string str = text.Substring(i[0], num - i[0]);
i[0] = num + search.Length;
return str.Trim();
}
string str1 = text.Substring(i[0]);
i[0] = text.Length;
return str1.Trim();
}
internal static string GetBefore(string text, int[] i, string search, bool trim)
{
if (trim)
return GetBefore(text, i, search);
int num = text.IndexOf(search, i[0]);
if (num > -1)
{
string str = text.Substring(i[0], num - i[0]);
i[0] = num + search.Length;
return str;
}
string str1 = text.Substring(i[0]);
i[0] = text.Length;
return str1;
}
internal static string GetToEOL(string text, int[] i) =>
GetBefore(text, i, "\n");
internal static string GetToEOL(string text, int[] i, bool trim)
{
if (trim)
return GetToEOL(text, i);
return GetBefore(text, i, "\n", false);
}
internal static Header Get(Constant constant, int[] i, string text)
{
Header result;
string lot;
string session;
ScanPast(text, i, constant.LongWaferSummary);
_ = GetToEOL(text, i);
ScanPast(text, i, constant.Session);
session = GetToEOL(text, i, true);
ScanPast(text, i, constant.LotId);
lot = GetToEOL(text, i, true);
result = new(lot, session);
return result;
}
}
[JsonSourceGenerationOptions(WriteIndented = true)]
[JsonSerializable(typeof(Header))]
internal partial class HeaderSourceGenerationContext : JsonSerializerContext
{
}