Exemplo n.º 1
0
        internal protected override bool TryCreate(MetaElementType elementType, out ReadElement element)
        {
            switch (elementType)
            {
            case MetaElementType.SequenceItem:
                SequenceItemReadElement itemReadElement = new SequenceItemReadElement();
                itemList.Add(itemReadElement);
                element = itemReadElement;
                return(true);

            default:
                element = null;
                return(false);
            }
        }
Exemplo n.º 2
0
        internal protected virtual bool ResolveItemsTo(FtMetaSequence sequence, FtMetaFieldList fieldList, FtMetaSequenceList sequenceList, out string errorDescription)
        {
            ItemSorter.Rec[]          sorterRecArray = new ItemSorter.Rec[itemList.Count + fieldIndices.Length];
            SequenceItemReadElement[] sortedItemElements;

            for (int i = 0; i < itemList.Count; i++)
            {
                SequenceItemReadElement itemElement = itemList[i];

                sorterRecArray[i].Target   = itemElement;
                sorterRecArray[i].Implicit = i;
                sorterRecArray[i].Explicit = itemElement.ExplicitIndex;
            }

            int elementallyDefinedItemCount = itemList.Count;

            for (int i = 0; i < fieldIndices.Length; i++)
            {
                SequenceItemReadElement itemElement = new SequenceItemReadElement();
                // Add FieldIndex to element as if it were read from an attribute.
                int    fieldIndex     = fieldIndices[i];
                string attributeName  = SequenceItemPropertyIdFormatter.ToAttributeName(FtMetaSequenceItem.PropertyId.FieldIndex);
                string attributeValue = FtStandardText.Get(fieldIndex);
                if (!itemElement.TryAddOrIgnoreAttribute(attributeName, attributeValue, out errorDescription))
                {
                    throw FtInternalException.Create(InternalError.SequenceReadElement_ResolveItemsTo_TryAddOrIgnoreAttribute, errorDescription); // program error
                }
                else
                {
                    int implicitIndex = elementallyDefinedItemCount + i;
                    sorterRecArray[implicitIndex].Target   = itemElement;
                    sorterRecArray[implicitIndex].Implicit = implicitIndex;
                    sorterRecArray[implicitIndex].Explicit = -1;
                }
            }

            int duplicateExplicitIndex;

            if (!ItemSorter.TrySort(sorterRecArray, out sortedItemElements, out duplicateExplicitIndex))
            {
                errorDescription = string.Format(Properties.Resources.SequenceReadElement_ResolveItemsTo_DuplicateExplicitIndex, duplicateExplicitIndex);
                return(false);
            }
            else
            {
                errorDescription = "";
                bool result = true;

                for (int i = 0; i < sortedItemElements.Length; i++)
                {
                    SequenceItemReadElement itemElement = sortedItemElements[i];
                    FtMetaSequenceItem      item        = sequence.ItemList.New();
                    if (!itemElement.ResolveTo(item, fieldList, sequenceList, out errorDescription))
                    {
                        result = false;
                        break;
                    }
                }

                return(result);
            }
        }