public EdiPosition(EdiContainerType type) { Type = type; HasIndex = TypeHasIndex(type); Position = -1; SegmentName = null; }
public EdiPosition(EdiContainerType type) { Type = type; HasIndex = TypeHasIndex(type); Position = -1; FunctionalGroupCount = 0; MessageCount = 0; SegmentCount = 0; SegmentName = null; }
public EdiPosition(EdiContainerType type, EdiPosition?parent = null) { Type = type; HasIndex = TypeHasIndex(type); Position = -1; GroupCount = parent?.GroupCount ?? 0; MessageCount = parent?.MessageCount ?? 0; SegmentCount = parent?.SegmentCount ?? 0; SegmentName = parent?.SegmentName; SegmentCountCache = parent?.SegmentCount ?? 0; }
private void WriteEnd(EdiContainerType type) { switch (type) { case EdiContainerType.Segment: case EdiContainerType.Element: case EdiContainerType.Component: InternalWriteEnd(type); break; default: throw EdiWriterException.Create(this, "Unexpected type when writing end: " + type, null); } }
private void AutoCompleteClose(EdiContainerType type) { // write closing symbol and calculate new state while (Peek() >= type && Top > 0) { EdiToken token; bool forcebreak = false; if (Peek() == type && _currentPosition.HasIndex) { token = GetCloseTokenForType(type); forcebreak = true; } else { token = GetCloseTokenForType(Pop()); } WriteEnd(token); EdiContainerType currentLevelType = Peek(); switch (currentLevelType) { case EdiContainerType.Segment: _currentState = State.Segment; break; case EdiContainerType.Element: _currentState = State.Element; break; case EdiContainerType.Component: _currentState = State.Component; break; case EdiContainerType.None: _currentState = State.Start; break; default: throw EdiWriterException.Create(this, "Unknown EdiContainerType: " + currentLevelType, null); } if (forcebreak) { break; } } }
private void Push(EdiContainerType value) { if (_currentPosition.Type == EdiContainerType.None) { _currentPosition = new EdiPosition(value); } else { _stack.Add(_currentPosition); _currentPosition = new EdiPosition(value); // this is a little hacky because Depth increases when first property/value is written but only testing here is faster/simpler if (_maxDepth != null && Depth + 1 > _maxDepth && !_hasExceededMaxDepth) { _hasExceededMaxDepth = true; throw EdiReaderException.Create(this, "The reader's MaxDepth of {0} has been exceeded.".FormatWith(CultureInfo.InvariantCulture, _maxDepth)); } } }
private EdiToken GetCloseTokenForType(EdiContainerType type) { switch (type) { case EdiContainerType.Segment: return(EdiToken.SegmentStart); case EdiContainerType.Element: return(EdiToken.None); case EdiContainerType.Component: return(EdiToken.None); case EdiContainerType.None: return(EdiToken.None); default: throw EdiWriterException.Create(this, "No close token for type: " + type, null); } }
private void Push(EdiContainerType value) { if (_currentPosition.Type != EdiContainerType.None) { if (_stack == null) { _stack = new List <EdiPosition>(); } if (_currentPosition.Type == value && _currentPosition.HasIndex) { _currentPosition.Position++; return; } else { _stack.Add(_currentPosition); } } _currentPosition = new EdiPosition(value); if (_currentPosition.HasIndex) { _currentPosition.Position = 0; } }
internal void InternalWriteEnd(EdiContainerType container) { AutoCompleteClose(container); }
private void AutoCompleteClose(EdiContainerType type) { // write closing symbol and calculate new state while (Peek() >= type && Top > 0) { EdiToken token; bool forcebreak = false; if (Peek() == type && _currentPosition.HasIndex) { token = GetCloseTokenForType(type); forcebreak = true; } else { token = GetCloseTokenForType(Pop()); } WriteEnd(token); EdiContainerType currentLevelType = Peek(); switch (currentLevelType) { case EdiContainerType.Segment: _currentState = State.Segment; break; case EdiContainerType.Element: _currentState = State.Element; break; case EdiContainerType.Component: _currentState = State.Component; break; case EdiContainerType.None: _currentState = State.Start; break; default: throw EdiWriterException.Create(this, "Unknown EdiContainerType: " + currentLevelType, null); } if (forcebreak) break; } }
private EdiToken GetCloseTokenForType(EdiContainerType type) { switch (type) { case EdiContainerType.Segment: return EdiToken.SegmentStart; case EdiContainerType.Element: return EdiToken.None; case EdiContainerType.Component: return EdiToken.None; case EdiContainerType.None: return EdiToken.None; default: throw EdiWriterException.Create(this, "No close token for type: " + type, null); } }
private void Push(EdiContainerType value) { if (_currentPosition.Type != EdiContainerType.None) { if (_stack == null) { _stack = new List<EdiPosition>(); } if (_currentPosition.Type == value && _currentPosition.HasIndex) { _currentPosition.Position++; return; } else { _stack.Add(_currentPosition); } } _currentPosition = new EdiPosition(value); if (_currentPosition.HasIndex) _currentPosition.Position = 0; }
internal void InternalWriteStart(EdiToken token, EdiContainerType container) { AutoComplete(token); Push(container); }
internal static bool TypeHasIndex(EdiContainerType type) { return (type == EdiContainerType.Segment || type == EdiContainerType.Element || type == EdiContainerType.Component); }
internal static bool TypeHasIndex(EdiContainerType type) { return(type == EdiContainerType.Segment || type == EdiContainerType.Element || type == EdiContainerType.Component); }