public TraceId(DateTime timestamp, TransmissionKind transmissionKind, SequenceNumber sequence, CheckNumber checkNumber) { Timestamp = timestamp; Kind = transmissionKind; Sequence = sequence; CheckNumber = checkNumber; }
public TraceId(string value) { // UNDOCUMENTED: while POS API spec, Page 23 designates TraceID as // A25, examples show it as A19. Possibly for Oracle to change // TraceID in the future without updating the schema. FieldTypes.AssertA25(value); // Date part of TraceID doesn't follow the pattern used with // LocalDate and BusinessDate. For TraceID, year is two characters // only. Since TraceID is an element on its own and not a field type // (Ax, Nx, ...), its regular expression is defined inline and not // with FieldTypes. const string pattern = @"^(?<year>\d{2})(?<month>\d{2})(?<day>\d{2})(?<hour>\d{2})(?<minute>\d{2})(?<second>\d{2})(?<retransmit>.{1})(?<sequence>\d{2})(?<checkNumber>\d{4})$"; var re = new Regex(pattern); var m = re.Match(value); if (!m.Success) { throw new ArgumentException($"{nameof(value)} must match pattern: {pattern}. Was '{value}'"); } var date = FieldTypes.AssertDate($"20{m.Groups["year"].Value}{m.Groups["month"].Value}{m.Groups["day"].Value}"); var time = FieldTypes.AssertTime($"{m.Groups["hour"].Value}{m.Groups["minute"].Value}{m.Groups["second"].Value}"); Timestamp = date.Add(time); var retransmit = m.Groups["retransmit"].Value; if (!(retransmit == "N" || retransmit == "R")) { throw new ArgumentException($"Retransmit must be either 'N' or 'R'. Was '{retransmit}'"); } Kind = retransmit == "N" ? TransmissionKind.Normal : TransmissionKind.Retransmit; var sequence = int.Parse(m.Groups["sequence"].Value); Sequence = new SequenceNumber(sequence); var checkNumber = int.Parse(m.Groups["checkNumber"].Value); CheckNumber = new CheckNumber(checkNumber); }