public ActionType(XE actionType)
        {
            if (actionType == null)
            {
                throw new ArgumentNullException(nameof(actionType));
            }

            var tidAttribute      = actionType.Attribute(C.tid);
            var tidAttributeValue = int.Parse(tidAttribute.Value);

            if (!Enum.IsDefined(typeof(TransactionId), tidAttributeValue))
            {
                throw new ArgumentException($"Unknown {nameof(C.tid)} '{tidAttributeValue}'");
            }
            Id = (TransactionId)int.Parse(tidAttribute.Value);

            var success = TidToString.TryGetValue(Id, out var value);

            if (!success)
            {
                throw new ArgumentException($"{nameof(TidToString)} mapping doesn't contain {nameof(TransactionId)} with value {tidAttribute.Value}");
            }
            if (value != actionType.Value)
            {
                throw new ArgumentException($"Expected Action Type element to have value '{value}'. Was '{actionType.Value}'");
            }

            // UNDOCUMENTED: type or length of Action/Type content. We can only
            // assume an Ax of sufficient length to represent every
            // TransactionId in textual form.
            FieldTypes.AssertA25(actionType.Value);
        }
Example #2
0
        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);
        }