Beispiel #1
0
        internal void LoadHeading(int idx,
                                  string headingText)
        {
            switch (definition.HeadingConstraint)
            {
            case FtHeadingConstraint.None:
                headings[idx] = headingText;
                break;

            case FtHeadingConstraint.AllConstant:
                if (headingText != headings[idx])
                {
                    throw new FtSerializationException(FtSerializationError.FieldConstNameHeadingMismatch, this, string.Format(Properties.Resources.FtField_LoadHeading_AllConstantViolation, idx));
                }
                break;

            case FtHeadingConstraint.MainConstant:
                if (idx != definition.MainHeadingIndex)
                {
                    headings[idx] = headingText;
                }
                else
                {
                    if (headingText != headings[idx])
                    {
                        throw new FtSerializationException(FtSerializationError.FieldConstNameHeadingMismatch, this, Properties.Resources.FtField_LoadHeading_MainConstantViolation);
                    }
                }
                break;

            case FtHeadingConstraint.NameConstant:
                if (idx != definition.MainHeadingIndex)
                {
                    headings[idx] = headingText;
                }
                else
                {
                    if (string.Equals(headingText, definition.MetaName, StringComparison.OrdinalIgnoreCase))
                    {
                        headings[idx] = headingText;
                    }
                    else
                    {
                        throw new FtSerializationException(FtSerializationError.FieldConstNameHeadingMismatch, this, Properties.Resources.FtField_LoadHeading_NameConstantViolation);
                    }
                }
                break;

            case FtHeadingConstraint.NameIsMain:
                headings[idx] = headingText;
                if (idx == definition.MainHeadingIndex)
                {
                    name = headingText;
                }
                break;

            default:
                throw FtInternalException.Create(InternalError.FtField_ParseHeadingText_UnsupportedHeadingConstraint, definition.HeadingConstraint.ToString());
            }
        }
Beispiel #2
0
 internal static void StaticTest()
 {
     for (int i = 0; i < typeRecArray.Length; i++)
     {
         if (typeRecArray[i].Type != i)
         {
             throw FtInternalException.Create(InternalError.FtStandardDataType_StaticTest_TypeRecOutOfOrder, typeRecArray[i].ToString());
         }
     }
 }
Beispiel #3
0
 internal static void StaticTest()
 {
     for (int i = 0; i < typeRecArray.Length; i++)
     {
         if (typeRecArray[i].Type != i)
         {
             throw FtInternalException.Create(InternalError.FtStandardSequenceRedirectType_StaticTest_TypeRecOutOfOrder);
         }
     }
 }
Beispiel #4
0
        internal void LoadDelimitedValue(string valueText, bool quoted)
        {
            loadedValueText = valueText;

            try
            {
                if (quoted)
                {
                    LoadNonNullValue(valueText);
                }
                else
                {
                    if (valueTextNullTrimmable)
                    {
                        valueText = valueText.Trim();
                        if (valueText.Length == 0)
                        {
                            LoadNullValue();
                        }
                        else
                        {
                            LoadNonNullValue(valueText);
                        }
                    }
                    else
                    {
                        if (valueText.Length != 0)
                        {
                            LoadNonNullValue(valueText);
                        }
                        else
                        {
                            switch (ValueQuotedType)
                            {
                            case FtQuotedType.Never:
                            case FtQuotedType.Optional:
                                LoadNonNullValue(valueText);
                                break;

                            case FtQuotedType.Always:
                                LoadNullValue();
                                break;

                            default:
                                throw FtInternalException.Create(InternalError.FtField_LoadDelimitedValue_UnsupportedValueQuotedType, ValueQuotedType.ToString());
                            }
                        }
                    }
                }
            }
            catch (FtSerializationException E)
            {
                throw new FtSerializationException(E.Error, this, string.Format(Properties.Resources.FtField_LoadDelimitedValue_Prefix, E.Message), E);
            }
        }
Beispiel #5
0
        internal void LoadMeta(FtMetaSequenceItem metaSequenceItem, FtMetaFieldList metaFieldList, FtFieldDefinitionList fieldDefinitionList)
        {
            int fieldIdx = metaFieldList.IndexOf(metaSequenceItem.Field);

            if (fieldIdx < 0)
            {
                throw FtInternalException.Create(InternalError.FtSequenceItem_LoadMeta_MetaSequenceItemFieldNotFoundInMetaFieldList, metaSequenceItem.Field.Name); // should never happen
            }
            else
            {
                fieldDefinition = fieldDefinitionList[fieldIdx]; // fieldDefinitions are in same order as Meta Fields
            }
        }
Beispiel #6
0
        internal protected virtual void LoadMeta(FtMetaSequenceRedirect metaSequenceRedirect, FtMetaSequenceList metaSequenceList, FtSequenceList sequenceList)
        {
            type            = metaSequenceRedirect.Type;
            invokationDelay = metaSequenceRedirect.InvokationDelay;

            int sequenceIdx = metaSequenceList.IndexOf(metaSequenceRedirect.Sequence);

            if (sequenceIdx < 0)
            {
                throw FtInternalException.Create(InternalError.FtSequenceRedirect_LoadMeta_MetaSequenceRedirectSequenceNotFoundInMetaSequenceList, metaSequenceRedirect.Sequence.Name); // should never happen
            }
            else
            {
                sequence = sequenceList[sequenceIdx]; // sequenceList are in same order as Meta Sequence List
            }
        }
Beispiel #7
0
        protected internal void AssignExcludingRedirects(FtMetaSequenceItem source, FtMetaFieldList fieldList, FtMetaFieldList sourceFieldList)
        {
            int fieldIndex = sourceFieldList.IndexOf(source.Field);

            if (fieldIndex < 0)
            {
                throw FtInternalException.Create(InternalError.FtMetaSequenceItem_AssignExcludingRedirects_SourceFieldNotFound); // should never happen
            }
            else
            {
                if (fieldIndex >= fieldList.Count)
                {
                    throw FtInternalException.Create(InternalError.FtMetaSequenceItem_AssignExcludingRedirects_FieldIndexOutOfRange, fieldIndex.ToString()); // should never happen
                }
                else
                {
                    Field = fieldList[fieldIndex];
                }
            }
        }
Beispiel #8
0
        protected internal virtual void Assign(FtMetaSequenceRedirect source, FtMetaSequenceList sequenceList, FtMetaSequenceList sourceSequenceList)
        {
            InvokationDelay = source.InvokationDelay;

            int sequenceIndex = sourceSequenceList.IndexOf(source.Sequence);

            if (sequenceIndex < 0)
            {
                throw FtInternalException.Create(InternalError.FtMetaSequenceItem_Assign_SourceFieldNotFound); // should never happen
            }
            else
            {
                if (sequenceIndex >= sequenceList.Count)
                {
                    throw FtInternalException.Create(InternalError.FtMetaSequenceItem_Assign_FieldIndexOutOfRange, sequenceIndex.ToString()); // should never happen
                }
                else
                {
                    Sequence = sequenceList[sequenceIndex];
                }
            }
        }
Beispiel #9
0
        public void LoadMeta(FtMetaSubstitution metaSubstitution, FtEndOfLineAutoWriteType autoWriteType)
        {
            type  = metaSubstitution.Type;
            token = metaSubstitution.Token;
            switch (type)
            {
            case FtSubstitutionType.String:
                value = metaSubstitution.Value;
                break;

            case FtSubstitutionType.AutoEndOfLine:
                switch (autoWriteType)
                {
                case FtEndOfLineAutoWriteType.CrLf:
                    value = SerializationCore.CarriageReturnLineFeedString;
                    break;

                case FtEndOfLineAutoWriteType.Cr:
                    value = SerializationCore.CarriageReturnChar.ToString();
                    break;

                case FtEndOfLineAutoWriteType.Lf:
                    value = SerializationCore.LineFeedChar.ToString();
                    break;

                case FtEndOfLineAutoWriteType.Local:
                    value = System.Environment.NewLine;
                    break;

                default:
                    throw FtInternalException.Create(InternalError.FtSubstitution_LoadMeta_UnsupportedAutoWriteType, autoWriteType.ToString());
                }
                value = metaSubstitution.Value;
                break;
            }
        }
Beispiel #10
0
        public bool Validate(out string errorMessage)
        {
            // check various - including multiple sequence roots and duplicate sequence names
            errorMessage = "";

            foreach (ValidateTest test in Enum.GetValues(typeof(ValidateTest)))
            {
                switch (test)
                {
                case ValidateTest.FieldList:
                    if (FieldList.Count == 0)
                    {
                        errorMessage = Properties.Resources.FtMeta_Validate_MustHaveAtLeastOneField;
                    }
                    break;

                case ValidateTest.QuoteCharSameAsDelimiterChar:
                    if (QuoteChar == DelimiterChar)
                    {
                        errorMessage = Properties.Resources.FtMeta_Validate_QuoteCharAndDelimiterCharMustBeDifferent;
                    }
                    break;

                case ValidateTest.QuoteCharSameAsLineCommentChar:
                    if (QuoteChar == LineCommentChar)
                    {
                        errorMessage = Properties.Resources.FtMeta_Validate_QuoteCharAndLineCommentCharMustBeDifferent;
                    }
                    break;

                case ValidateTest.LineCommentCharSameAsDelimiterChar:
                    if (LineCommentChar == DelimiterChar)
                    {
                        errorMessage = Properties.Resources.FtMeta_Validate_LineCommentCharAndDelimiterCharMustBeDifferent;
                    }
                    break;

                case ValidateTest.SubstitutionChar:
                    if (SubstitutionsEnabled)
                    {
                        if (QuoteChar == SubstitutionChar)
                        {
                            errorMessage = Properties.Resources.FtMeta_Validate_QuoteCharAndSubstitutionCharMustBeDifferent;
                        }
                        else
                        {
                            if (DelimiterChar == SubstitutionChar)
                            {
                                errorMessage = Properties.Resources.FtMeta_Validate_DelimiterCharAndSubstitutionCharMustBeDifferent;
                            }
                            else
                            {
                                if (LineCommentChar == SubstitutionChar)
                                {
                                    errorMessage = Properties.Resources.FtMeta_Validate_LineCommentCharAndSubstitutionCharMustBeDifferent;
                                }
                                else
                                {
                                }
                            }
                        }
                    }
                    break;

                case ValidateTest.EndOfLineType:
                    switch (EndOfLineType)
                    {
                    case FtEndOfLineType.CrLf:
                    case FtEndOfLineType.Auto:
                        if (ValidateEndOfLineTypeChar(Serialization.SerializationCore.CarriageReturnChar, out errorMessage))
                        {
                            ValidateEndOfLineTypeChar(Serialization.SerializationCore.LineFeedChar, out errorMessage);
                        }
                        break;

                    case FtEndOfLineType.Char:
                        ValidateEndOfLineTypeChar(EndOfLineChar, out errorMessage);
                        break;

                    default: throw FtInternalException.Create(InternalError.FtMeta_Validate_UnsupportedEndOfLineType);
                    }
                    break;

                case ValidateTest.SequenceRoot:
                    string firstRootSequenceName;
                    string secondRootSequenceName;
                    if (SequenceList.IsMoreThanOneRoot(out firstRootSequenceName, out secondRootSequenceName))
                    {
                        errorMessage = string.Format(Properties.Resources.FtMeta_Validate_MoreThanOneRootSequence, firstRootSequenceName, secondRootSequenceName);
                    }
                    break;

                case ValidateTest.DuplicateSequenceName:
                    string duplicateSequenceName;
                    if (SequenceList.HasDuplicateName(out duplicateSequenceName))
                    {
                        errorMessage = string.Format(Properties.Resources.FtMeta_Validate_DuplicateSequenceName, duplicateSequenceName);
                    }
                    break;

                case ValidateTest.SequenceItemHasNullField:
                    for (int i = 0; i < SequenceList.Count; i++)
                    {
                        int itemIdx;
                        if (SequenceList[i].AnyItemWithNullField(out itemIdx))
                        {
                            errorMessage = string.Format(Properties.Resources.FtMeta_Validate_SequenceItemWithNullField, SequenceList[i].Name, itemIdx);
                        }
                    }
                    break;

                case ValidateTest.SequenceItemWithConstantFieldHasRedirects:
                    for (int i = 0; i < SequenceList.Count; i++)
                    {
                        int itemIdx;
                        if (SequenceList[i].AnyItemWithConstantFieldHasRedirects(out itemIdx))
                        {
                            errorMessage = string.Format(Properties.Resources.FtMeta_Validate_SequenceItemWithConstantFieldHasRedirects, SequenceList[i].Name, itemIdx);
                        }
                    }
                    break;

                default: throw FtInternalException.Create(InternalError.FtMeta_Validate_UnsupportedValidateTest);
                }

                if (errorMessage.Length != 0)
                {
                    break;
                }
            }

            return(errorMessage == "");
        }
Beispiel #11
0
        internal protected virtual void LoadMeta(FtMetaField metaField, CultureInfo myCulture, int myMainHeadingIndex)
        {
            dataType         = metaField.DataType;
            id               = metaField.Id;
            metaName         = metaField.Name;
            metaHeadings     = metaField.Headings;
            mainHeadingIndex = myMainHeadingIndex;
            culture          = myCulture;
            fixedWidth       = metaField.FixedWidth;
            width            = metaField.Width;
            constant         = metaField.Constant;
            _null            = metaField.Null;
            valueQuotedType  = metaField.ValueQuotedType;
            valueAlwaysWriteOptionalQuote = metaField.ValueAlwaysWriteOptionalQuote;
            valueWritePrefixSpace         = metaField.ValueWritePrefixSpace;
            valuePadAlignment             = metaField.ValuePadAlignment;
            valuePadCharType                = metaField.ValuePadCharType;
            valuePadChar                    = metaField.ValuePadChar;
            valueTruncateType               = metaField.ValueTruncateType;
            valueTruncateChar               = metaField.ValueTruncateChar;
            valueEndOfValueChar             = metaField.ValueEndOfValueChar;
            valueNullChar                   = metaField.ValueNullChar;
            headingConstraint               = metaField.HeadingConstraint;
            headingQuotedType               = metaField.HeadingQuotedType;
            headingAlwaysWriteOptionalQuote = metaField.HeadingAlwaysWriteOptionalQuote;
            headingWritePrefixSpace         = metaField.HeadingWritePrefixSpace;
            headingPadAlignment             = metaField.HeadingPadAlignment;
            headingPadCharType              = metaField.HeadingPadCharType;
            headingPadChar                  = metaField.HeadingPadChar;
            headingTruncateType             = metaField.HeadingTruncateType;
            headingTruncateChar             = metaField.HeadingTruncateChar;
            headingEndOfValueChar           = metaField.HeadingEndOfValueChar;

            formatter.Culture = culture;

            if (
                ((headingConstraint == FtHeadingConstraint.NameIsMain) || (headingConstraint == FtHeadingConstraint.NameConstant))
                &&
                (mainHeadingIndex >= 0)
                &&
                (mainHeadingIndex < MetaHeadingCount)
                )
            {
                metaHeadings[mainHeadingIndex] = metaName;
            }

            switch (headingPadAlignment)
            {
            case FtPadAlignment.Left:
                headingLeftPad = true;
                break;

            case FtPadAlignment.Right:
                headingLeftPad = false;
                break;

            case FtPadAlignment.Auto:
                headingLeftPad = autoLeftPad;
                break;

            default: throw FtInternalException.Create(InternalError.FtFieldFieldDefinition_LoadMeta_UnsupportedHeadingPadAlignment, headingPadAlignment.ToString());
            }

            switch (valuePadAlignment)
            {
            case FtPadAlignment.Left:
                valueLeftPad = true;
                break;

            case FtPadAlignment.Right:
                valueLeftPad = false;
                break;

            case FtPadAlignment.Auto:
                valueLeftPad = autoLeftPad;
                break;

            default: throw FtInternalException.Create(InternalError.FtFieldFieldDefinition_LoadMeta_UnsupportedValuePadAlignment, headingPadAlignment.ToString());
            }

            if (fixedWidth)
            {
                fixedWidthNullValueText = new string(ValueNullChar, Width);
            }
        }
Beispiel #12
0
        public static bool TryParse(string value, bool strict, out string[] resultArray, out string errorDescription)
        {
            string[] strArray = null;
            errorDescription = "";
            int      count               = 0;
            InQuotes inQuotes            = InQuotes.NotIn;
            bool     waitingForDelimiter = false;
            int      startPos            = 0;
            int      valueLength         = value.Length;

            for (int i = 0; i < valueLength; i++)
            {
                char valueChar = value[i];
                if (waitingForDelimiter)
                {
                    if (valueChar == DelimiterChar)
                    {
                        waitingForDelimiter = false;
                        startPos            = i + 1;
                    }
                    else
                    {
                        if (strict && (!Char.IsWhiteSpace(valueChar)))
                        {
                            errorDescription = string.Format(Properties.Resources.FtCommaText_TryParse_UnexpectedCharAfterQuotedElement, i);
                            break;
                        }
                    }
                }
                else
                {
                    switch (inQuotes)
                    {
                    case InQuotes.NotIn:
                        switch (valueChar)
                        {
                        case DelimiterChar:
                            AddElement(value, ref strArray, ref count, startPos, i, false);
                            startPos = i + 1;
                            break;

                        case QuoteChar:
                            if (value.Substring(startPos, i - startPos).Trim() == "")
                            {
                                inQuotes = InQuotes.In;
                                startPos = i + 1;
                            }
                            break;
                        }
                        break;

                    case InQuotes.In:
                        if (valueChar == QuoteChar)
                        {
                            inQuotes = InQuotes.CheckingStuffed;
                        }
                        break;

                    case InQuotes.CheckingStuffed:
                        switch (valueChar)
                        {
                        case QuoteChar:
                            inQuotes = InQuotes.In;
                            break;

                        case DelimiterChar:
                            inQuotes = InQuotes.NotIn;
                            AddElement(value, ref strArray, ref count, startPos, i - 1, true);
                            startPos = i + 1;
                            break;

                        default:
                            inQuotes = InQuotes.NotIn;
                            AddElement(value, ref strArray, ref count, startPos, i - 1, true);
                            waitingForDelimiter = true;
                            if (strict && (!(Char.IsWhiteSpace(valueChar))))
                            {
                                errorDescription = string.Format(Properties.Resources.FtCommaText_TryParse_UnexpectedCharAfterQuotedElement, i);
                                break;
                            }
                            break;
                        }
                        break;

                    default:
                        throw FtInternalException.Create(InternalError.FtCommaText_TryParse_UnsupportedInQuotes1, inQuotes.ToString());
                    }
                }
            }

            if ((errorDescription == "") && (!waitingForDelimiter))
            {
                switch (inQuotes)
                {
                case InQuotes.NotIn:
                    if (startPos <= valueLength)
                    {
                        AddElement(value, ref strArray, ref count, startPos, valueLength, false);
                    }
                    break;

                case InQuotes.In:
                    if (strict)
                    {
                        errorDescription = Properties.Resources.FtCommaText_TryParse_QuotesNotClosedInLastElement;
                    }
                    else
                    {
                        AddElement(value, ref strArray, ref count, startPos, valueLength, true);
                    }
                    break;

                case InQuotes.CheckingStuffed:
                    AddElement(value, ref strArray, ref count, startPos, valueLength - 1, true);
                    break;

                default:
                    throw FtInternalException.Create(InternalError.FtCommaText_TryParse_UnsupportedInQuotes2, inQuotes.ToString());
                }
            }

            resultArray = new string[count];
            Array.Copy(strArray, resultArray, count);
            return(errorDescription == "");
        }