public string DataControl( SOCRecord record, IntegrationTemplates templates) { if (string.IsNullOrWhiteSpace(record.Template)) { throw new Exception($"No hardware template specified for '{record.HardwareName}'"); } if (!templates.Templates.ContainsKey(record.Template)) { throw new Exception($"Template '{record.Template}' was not provided"); } var map = new Dictionary <string, string>(); map["NAME"] = record.HardwareName; map["SEG"] = record.Segment.ToString("X2"); map["be_3"] = record.Width > 24 ? "" : "//"; map["be_2"] = record.Width > 16 ? "" : "//"; map["be_1"] = record.Width > 8 ? "" : "//"; map["be_0"] = record.Width > 0 ? "" : "//"; map["WIDTH"] = record.Width.ToString(); map["HIGH"] = (record.Width - 1).ToString(); map["SEG_WIDTH"] = record.SegmentBits.ToString(); map["SEG_END"] = (32 - record.SegmentBits).ToString(); var template = templates.Templates[record.Template]; foreach (var pair in map) { var token = $"{{{pair.Key}}}"; template = template.Replace(token, pair.Value); } return(template); }
public string DataControl( List <SOCRecord> externalData, IntegrationTemplates templates) { return(string.Join("", externalData.Select(d => $"{DataControl(d, templates)}{Environment.NewLine}"))); }