using Universal; namespace ProximaAnalizer.Helpers; public class DBProcessData(char spilter, int skip) where T_Hierarchy : IDictionary, new() { public bool ToDictionary(IDictionary input, out T_Hierarchy? output) { output = default; if (input is null) return false; T_Hierarchy cache = []; foreach (KeyValuePair rawData in input) { Span source = rawData.Key.Split(spilter).AsSpan()[skip..]; ColumAnalizer(cache, source, rawData.Key); } output = cache; return true; } private static void ColumAnalizer(/*ref*/ T_Hierarchy cache, Span seprated, object value) { if (seprated.Length <= 1) { cache[seprated[0]] = value; return; } if (!cache.TryGetValue(seprated[0], out object? output) || output is not T_Hierarchy hierarchy) { hierarchy = []; cache[seprated[0]] = hierarchy; } cache = hierarchy; ColumAnalizer(cache, seprated[1..], value); } } public class GeneralProcessData(int skip = 0) : DBProcessData>('.', skip) { public static bool CreateTablePM(IDictionary data, IDictionary cache) { Dictionary ValueSensor = []; Dictionary StatusSensor = []; Dictionary leakCheck = []; Dictionary recipe = []; Dictionary aoValue = []; Dictionary ffu = []; Dictionary mfc = []; Dictionary gaslineHeater = []; Dictionary bufferFoup = []; Dictionary avValue = []; foreach (var item in data) { if (item.Value is not IDictionary values) { switch (item.Key) { case string s when s.EndsWith("Enable"): continue; case string s when s.StartsWith("LeakCheck"): leakCheck.Add(item.Key, item.Value); continue; default: recipe.Add(item.Key, item.Value); continue; } } switch (item.Key) { case "APC": case "APCVATGV": case "BoatElevatorServo": case "BoatRotationServo": case "BufferServo": case "Shutter": CreateTable(cache, item.Key, values); continue; case string s when s.StartsWith("Trig"): if (item.Value is IDictionary value) aoValue.Add(item.Key, value["AOValue"]); continue; case string s when s.StartsWith("FS"): case string s1 when s1.StartsWith("PG"): case string s2 when s2.StartsWith("PS"): case string s3 when s3.StartsWith("VG"): if (item.Value is IDictionary vss) ValueSensor.Add(item.Key, vss["Value"]); continue; case string s when s.StartsWith("Sensor"): if (item.Value is IDictionary status) StatusSensor.Add(item.Key, status["Value"]); continue; case string s when s.StartsWith("MFC"): if (item.Value is IDictionary mfcs) mfcs.Foreach(t => mfc.Add($"{item.Key}_{t.Key}", t.Value)); continue; case string s when s.StartsWith("FFU"): if (item.Value is IDictionary ffus) ffus.Foreach(t => ffu.Add($"{item.Key}_{t.Key}", t.Value)); continue; case string s when s.StartsWith("GaselineHeater"): if (item.Value is IDictionary gaslines) gaslines.Foreach(t => gaslineHeater.Add($"{item.Key}_{t.Key}", t.Value)); continue; case string s when s.StartsWith("Valve"): if (item.Value is IDictionary valves) valves.Foreach(t => avValue.Add($"{item.Key}_{t.Key}", t.Value)); continue; default: continue; } } CreateTable(cache, "MFC", mfc); CreateTable(cache, "FFU", ffu); CreateTable(cache, "Valve", avValue); CreateTable(cache, "GaselineHeater", gaslineHeater); CreateTable(cache, "ValueSensor", ValueSensor); CreateTable(cache, "StatusSensor", StatusSensor); CreateTable(cache, "LeakCheck", leakCheck); CreateTable(cache, "AoValue", aoValue); CreateTable(cache, "Recipe", recipe); return true; } public static void CreateTableSystem(IDictionary data, IDictionary cache) { Dictionary systemCollection = []; Dictionary alarmCollection = []; Dictionary Heater = []; Dictionary Stocker = []; Dictionary LoadPort = []; //Dictionary FIMS = []; foreach (var item in data) { if (item.Value is not IDictionary values) continue; switch (item.Key) { case "Boat": case "CarrierRobot": case "Scheduler": case "WaferRobot": CreateTable(cache, item.Key, values); continue; case string s when s.StartsWith("Stocker"): Stocker.Add(item.Key, values); continue; case string s when s.StartsWith("LP"): LoadPort.Add(item.Key, values); continue; //case string s when s.StartsWith("FIMS"): // FIMS.Add(item.Key, values); // continue; case "System": if (values is not IDictionary systems) continue; foreach (var system in systems) { switch (system.Key) { case string s when s.StartsWith("Heater"): Heater.Add(system.Key, system.Value); continue; case string s when s.StartsWith("AlarmSignalHeater"): alarmCollection.Add(system.Key, ((IDictionary)system.Value)["Value"] ??= false); continue; default: systemCollection.Add(system.Key, system.Value); break; } } continue; default: break; } //CreateTable(cache, "FIMS", FIMS); CreateTable(cache, "Heater", Heater); CreateTable(cache, "LoadPort", LoadPort); CreateTable(cache, "Stocker", Stocker); CreateTable(cache, "System", systemCollection); CreateTable(cache, "AlarmSignalHeater", alarmCollection); } } private static bool CreateTable(IDictionary cache, string key, object value) { return cache.TryAdd(key, value); } }