private string FinishText() { string text; switch (quotedState) { case QuotedState.MustOpen: text = ""; // is null break; case QuotedState.Opened: if (fieldQuotedType == FtQuotedType.Always) { FtSerializationError error = headings ? FtSerializationError.HeadingQuotedFieldMissingEndQuoteChar : FtSerializationError.ValueQuotedFieldMissingEndQuoteChar; throw new FtSerializationException(error, field, ""); } else { text = fieldQuoteChar.ToString(); rawOffset--; rawLength++; } break; case QuotedState.Open: if (fieldQuotedType == FtQuotedType.Always) { FtSerializationError error = headings ? FtSerializationError.HeadingQuotedFieldMissingEndQuoteChar : FtSerializationError.ValueQuotedFieldMissingEndQuoteChar; throw new FtSerializationException(error, field, ""); } else { text = fieldQuoteChar.ToString() + textBuilder.ToString(); rawOffset--; rawLength++; } break; default: text = textBuilder.ToString(); break; } return(text); }
public FtSerializationException(FtSerializationError error, FtField field, string message, Exception innerException) : base(Enum.GetName(typeof(FtSerializationError), error) + ((message == "")? "": (": " + message)), innerException) { state.Error = error; if (field == null) { state.FieldName = null; state.FieldIndex = -1; state.SequenceName = null; state.SequenceItemIndex = -1; } else { state.FieldName = field.Name; state.FieldIndex = field.Index; FtSequence sequence = field.Sequence; if (sequence == null) { state.SequenceName = null; } else { state.SequenceName = sequence.Name; } FtSequenceItem sequenceItem = field.SequenceItem; if (sequenceItem == null) { state.SequenceItemIndex = -1; } else { state.SequenceItemIndex = sequenceItem.Index; } } SerializeObjectState += delegate(object exception, SafeSerializationEventArgs eventArgs) { eventArgs.AddSerializedState(state); }; }
private string FinishText() { rawLength = textBuilder.Length; if (fieldLength < fieldWidth) { FtSerializationError error = headings? FtSerializationError.HeadingWidthNotReached : FtSerializationError.ValueWidthNotReached; string formatString = headings ? Properties.Resources.FixedWidthFieldParser_FinishText_HeadingWidthNotReached : Properties.Resources.FixedWidthFieldParser_FinishText_ValueWidthNotReached; throw new FtSerializationException(error, field, string.Format(formatString, fieldWidth, fieldLength)); } else { if (fieldLength > fieldWidth) { FtSerializationError error = headings ? FtSerializationError.HeadingWidthExceeded : FtSerializationError.ValueWidthExceeded; string formatString = headings ? Properties.Resources.FixedWidthFieldParser_FinishText_HeadingWidthExceeded : Properties.Resources.FixedWidthFieldParser_FinishText_ValueWidthExceeded; throw new FtSerializationException(error, field, string.Format(formatString, fieldWidth, fieldLength)); } else { return(textBuilder.ToString()); } } }
public FtSerializationException(FtSerializationError code, FtField field, string message) : this(code, field, message, null) { }
public FtSerializationException(FtSerializationError code, string message, Exception innerException) : this(code, null, message, innerException) { }
public FtSerializationException(FtSerializationError code, string message) : this(code, null, message, null) { }
public FtSerializationException(FtSerializationError code, FtField field, Exception innerException) : this(code, field, innerException.Message, innerException) { }
internal void ParseChar(char aChar) { switch (state) { case State.Out: throw FtInternalException.Create(InternalError.HeadingLineRecordParser_ParseChar_OutState); case State.InOutField: if (fieldCount < core.FieldList.Count) { EnterField(core.FieldList[fieldCount]); } else { FtSerializationError error = headingLines ? FtSerializationError.HeadingLineTooManyFields : FtSerializationError.RecordTooManyFields; string formatString = headingLines ? Properties.Resources.HeadingLineRecordParser_ParseChar_HeadingLineTooManyFields : Properties.Resources.HeadingLineRecordParser_ParseChar_RecordTooManyFields; throw new FtSerializationException(error, string.Format(formatString, core.FieldList.Count)); } ParseChar(aChar); break; case State.InFixedWidthField: bool previousFieldFinished; fixedWidthFieldParser.ParseChar(aChar, out previousFieldFinished); if (previousFieldFinished) { if (!core.Seeking) { LoadFixedWidthHeadingValue(); } ExitActiveField(); if (fieldCount < core.FieldList.Count || !core.IgnoreExtraChars) { state = State.InOutField; } else { state = State.OutIgnoreChars; ignoreExtraCharsStartPosition = charReader.Position; } ParseChar(aChar); } break; case State.InDelimitedField: bool fieldFinished; delimitedFieldParser.ParseChar(aChar, out fieldFinished); if (fieldFinished) { // aChar was delimiter if (!core.Seeking) { LoadDelimitedHeadingValue(); } ExitActiveField(); if (fieldCount < core.FieldList.Count || !core.IgnoreExtraChars) { state = State.InOutField; } else { state = State.OutIgnoreChars; ignoreExtraCharsStartPosition = charReader.Position; } } break; case State.OutIgnoreChars: // nothing to do break; default: throw FtInternalException.Create(InternalError.HeadingLineRecordParser_ParseChar_UnsupportedState, state.ToString()); } }
internal void Finish() { switch (state) { case State.Out: // nothing to do break; case State.InOutField: state = State.Out; break; case State.InFixedWidthField: if (!core.Seeking) { LoadFixedWidthHeadingValue(); } ExitActiveField(); state = State.Out; break; case State.InDelimitedField: if (!core.Seeking) { LoadDelimitedHeadingValue(); } ExitActiveField(); state = State.Out; break; case State.OutIgnoreChars: state = State.Out; break; default: throw FtInternalException.Create(InternalError.HeadingLineRecordParser_Finish_UnsupportedState, state.ToString()); } if (fieldCount < core.FieldList.Count) { if (!core.AllowIncompleteRecords) { FtSerializationError error = headingLines ? FtSerializationError.HeadingLineNotEnoughFields : FtSerializationError.RecordNotEnoughFields; string formatString = headingLines ? Properties.Resources.HeadingLineRecordParser_Finish_HeadingLineNotEnoughFields : Properties.Resources.HeadingLineRecordParser_Finish_RecordNotEnoughFields; throw new FtSerializationException(error, string.Format(formatString, fieldCount, core.FieldList.Count)); } else { for (int i = fieldCount; i < core.FieldList.Count; i++) { activeField.LoadPosition(-1, -1, -1, -1); if (headingLines) { activeField.LoadHeading(index, ""); } else { activeField.LoadNullValue(); } } } } }
internal void ParseChar(char aChar, out bool finished) { if (substitutionActive) { AppendSubstitution(aChar); substitutionActive = false; rawLength++; finished = false; } else { if (fieldSubstitutionsEnabled && aChar == fieldSubstitutionChar) { substitutionActive = true; rawLength++; finished = false; } else { switch (quotedState) { case QuotedState.NeverOpen: if (aChar == fieldDelimiterChar) { finished = true; } else { finished = false; AppendValueChar(aChar); } break; case QuotedState.CanOpen: if (aChar == fieldQuoteChar) { finished = false; quotedState = QuotedState.Opened; } else { if (char.IsWhiteSpace(aChar)) { finished = false; rawLength++; textBuilder.Append(aChar); } else { quotedState = QuotedState.NeverOpen; ParseChar(aChar, out finished); } } break; case QuotedState.MustOpen: if (char.IsWhiteSpace(aChar)) { finished = false; // ignore white space before quote is opened } else { if (aChar == fieldDelimiterChar) { finished = true; // null } else { if (aChar == fieldQuoteChar) { finished = false; quotedState = QuotedState.Opened; } else { FtSerializationError error = headings ? FtSerializationError.HeadingNonWhiteSpaceCharBeforeQuotesOpened : FtSerializationError.ValueNonWhiteSpaceCharBeforeQuotesOpened; string message = headings ? Properties.Resources.DelimitedFieldParser_ParseChar_HeadingNonWhiteSpaceCharBeforeQuotesOpened : Properties.Resources.DelimitedFieldParser_ParseChar_ValueNonWhiteSpaceCharBeforeQuotesOpened; throw new FtSerializationException(error, field, message); } } } break; case QuotedState.Opened: rawOffset = (int)(charReader.Position - position); rawLength = 0; quotedState = QuotedState.Open; ParseChar(aChar, out finished); break; case QuotedState.Open: finished = false; if (aChar != fieldQuoteChar) { AppendValueChar(aChar); } else { if (charReader.Peek() == fieldQuoteChar) { rawLength++; quotedState = QuotedState.Stuffed; } else { rawLength = (int)(charReader.Position - position) + rawOffset; quotedState = QuotedState.Closed; } } break; case QuotedState.Stuffed: AppendValueChar(fieldQuoteChar); quotedState = QuotedState.Open; finished = false; break; case QuotedState.Closed: if (aChar == fieldDelimiterChar) { finished = true; } else { if (char.IsWhiteSpace(aChar)) { finished = false; } else { FtSerializationError error = headings ? FtSerializationError.HeadingNonWhiteSpaceCharAfterQuotesClosed : FtSerializationError.ValueNonWhiteSpaceCharAfterQuotesClosed; string message = headings ? Properties.Resources.DelimitedFieldParser_ParseChar_HeadingNonWhiteSpaceCharAfterQuotesClosed : Properties.Resources.DelimitedFieldParser_ParseChar_ValueNonWhiteSpaceCharAfterQuotesClosed; throw new FtSerializationException(error, field, message); } } break; default: throw FtInternalException.Create(InternalError.DelimitedFieldParser_ParseChar_UnsupportedQuotedState, quotedState.ToString()); } } } }