using Adaptation.FileHandlers.TIBCO.Transport; using System; using System.Globalization; using System.IO; using System.Text.Json; using System.Threading.Tasks; namespace Adaptation.FileHandlers.MoveAllFiles.ApiController; public class BarcodeHelper { #nullable enable private static string? GetJson(System.Net.Http.HttpContent? httpContent) { string? result; if (httpContent is null) result = null; else { Task task = httpContent.ReadAsStringAsync(); task.Wait(); result = task.Result; } return result; } private static void Write(string barcodeHostFileShare, string cellInstanceConnectionName, Notification notification) { DateTime dateTime = DateTime.Now; Calendar calendar = new CultureInfo("en-US").Calendar; string weekOfYear = $"{dateTime:yyyy}_Week_{calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday):00}"; string directory = Path.Combine(barcodeHostFileShare, weekOfYear, dateTime.ToString("yyyy-MM-dd_HH")); if (!Directory.Exists(directory)) _ = Directory.CreateDirectory(directory); File.WriteAllText(Path.Combine(directory, $"{cellInstanceConnectionName}.csv"), notification.LastScanServiceResultValue); } private static Job GetJob(string lsl2SQLConnectionString, string metrologyFileShare, string barcodeHostFileShare, string id, Notification notification) { Job result; string lastScan = notification.LastScanServiceResultValue.Length < 3 || notification.LastScanServiceResultValue[1] is not 't' and not 'T' || notification.LastScanServiceResultValue[0] != '1' ? notification.LastScanServiceResultValue : notification.LastScanServiceResultValue.Substring(2); string json = string.Concat("{\"Area\": \"Si\", \"EquipmentType\": \"MET08THFTIRQS408M\", \"MesEntity\": \"", id, "\", \"Sequence\": \"", notification.KeyPressEvent.DateTime.Ticks, "\", \"MID\": \"-", lastScan, "-\", \"Recipe\": \"Recipe\"}"); result = new(lsl2SQLConnectionString, metrologyFileShare, barcodeHostFileShare, json); return result; } internal static PostReplay? Post(string id, System.Net.Http.HttpContent? httpContent) { PostReplay? result; string? json = GetJson(httpContent); if (json is null) result = null; else { Notification? notification = JsonSerializer.Deserialize(json); if (notification is null) result = null; else { const string hyphen = "-"; Write(TIBCO.FileRead.BarcodeHostFileShare, id, notification.Value); Job job = GetJob(TIBCO.FileRead.LSL2SQLConnectionString, TIBCO.FileRead.MetrologyFileShare, TIBCO.FileRead.BarcodeHostFileShare, id, notification.Value); string mid = job.SpecName == hyphen || job.ProcessSpecName == hyphen ? $"{job.ProcessType}" : $"{job.ProcessType}.{job.SpecName}.{job.ProcessSpecName}"; try { // https://oi-prod-ec-api.mes.infineon.com/api/oiWizard/materials/rds/ } catch (Exception) { } result = new(job, mid, job.RecipeName); } } return result; } }