internal void InternalWriteWhitespace(string ws) { if (ws != null) { if (!StringUtils.IsWhiteSpace(ws)) { throw EdiWriterException.Create(this, "Only white space characters should be used.", null); } } }
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 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); } }
public void WriteServiceStringAdvice() { if (_currentState != State.Start) { throw EdiWriterException.Create(this, "Service string advice can only be applied at the begining of the iterchange. Current state is: {0}".FormatWith(Culture, _currentState), null); } if (null != Grammar.ServiceStringAdviceTag) { WriteRaw(string.Format("{0}{1}{2}{3}{4}{5}{6}", Grammar.ServiceStringAdviceTag, Grammar.ComponentDataElementSeparator, Grammar.DataElementSeparator, Grammar.DecimalMark, Grammar.ReleaseCharacter, new string(Grammar.Reserved), Grammar.SegmentTerminator)); if (Formatting == Formatting.LinePerSegment) { WriteNewLine(); } } }
internal void AutoComplete(EdiToken tokenBeingWritten) { // gets new state based on the current state and what is being written State newState = StateArray[(int)tokenBeingWritten][(int)_currentState]; if (newState == State.Error) { throw EdiWriterException.Create(this, "Token {0} in state {1} would result in an invalid Edi object.".FormatWith(CultureInfo.InvariantCulture, tokenBeingWritten.ToString(), _currentState.ToString()), null); } if ((_currentState == State.Element || _currentState == State.Component || _currentState == State.Value || _currentState == State.SegmentName) && tokenBeingWritten == EdiToken.SegmentName) { AutoCompleteClose(EdiContainerType.Segment); } else if (_currentState == State.SegmentName && tokenBeingWritten.IsPrimitiveToken()) { Push(EdiContainerType.Element); Push(EdiContainerType.Component); } else if (_currentState == State.Element && tokenBeingWritten.IsPrimitiveToken()) { Push(EdiContainerType.Component); } else if (_currentState == State.Value && tokenBeingWritten.IsPrimitiveToken()) { AutoCompleteClose(EdiContainerType.Component); WriteComponentDelimiter(); Push(EdiContainerType.Component); } else if ((_currentState == State.Component || _currentState == State.Value) && tokenBeingWritten == EdiToken.ElementStart) { AutoCompleteClose(EdiContainerType.Element); } else if ((_currentState == State.Component || _currentState == State.Value) && tokenBeingWritten == EdiToken.ComponentStart) { AutoCompleteClose(EdiContainerType.Component); } _currentState = newState; }
private static EdiWriterException CreateUnsupportedTypeException(EdiWriter writer, object value) { return(EdiWriterException.Create(writer, "Unsupported type: {0}. Use the EdiSerializer class to get the object's EDI representation.".FormatWith(CultureInfo.InvariantCulture, value.GetType()), null)); }