Example #1
0
        private EdiPropertyDescriptor FindForCurrentSegment(EdiReader reader, EdiStructure currentStructure, EdiStructureType newContainerType)
        {
            var candidates = currentStructure.GetMatchingProperties(newContainerType);

            if (candidates.Length == 0)
            {
                return(null);
            }
            var property = default(EdiPropertyDescriptor);

            if (reader.TokenType == EdiToken.SegmentName || currentStructure.CachedReads.Count > 0)
            {
                var segmentName = reader.TokenType == EdiToken.SegmentName ? reader.Value : ((EdiPath)currentStructure.CachedReads.Peek().Path).Segment;
                var matches     = candidates.Where(p => segmentName.Equals(p.Segment)).ToArray();
                if (matches.Length == 0)
                {
                    property = null;
                }
                else if (matches.Length == 1 && matches[0].Conditions == null)
                {
                    property = matches[0];
                }
                else
                {
                    property = ConditionalMatch(reader, currentStructure, newContainerType, matches);
                }
            }
            return(property);
        }
Example #2
0
        /// <summary>
        /// Finds for current element.
        /// </summary>
        /// <returns>The for current element.</returns>
        /// <param name="reader">Reader.</param>
        /// <param name="currentStructure">Current structure.</param>
        /// <param name="newContainerType">New container type.</param>
        private EdiPropertyDescriptor FindForCurrentElement(EdiReader reader, EdiStructure currentStructure, EdiStructureType newContainerType)
        {
            var candidates = currentStructure.GetMatchingProperties(newContainerType);

            if (candidates.Length == 0)
            {
                return(null);
            }
            var property = default(EdiPropertyDescriptor);

            if (reader.TokenType == EdiToken.ElementStart)
            {
                var matches = candidates.Where(p => p.PathInfo.PathInternal.ToString("E").Equals(reader.Path)).ToArray();
                if (matches.Length == 0)
                {
                    property = null;
                }
                else if (matches.Length == 1 && matches[0].ConditionInfo == null)
                {
                    property = matches[0];
                }
                else
                {
                    property = ConditionalMatch(reader, currentStructure, newContainerType, matches);
                }
            }
            return(property);
        }
Example #3
0
 private EdiPropertyDescriptor FindForCurrentLogicalStructure(EdiReader reader, EdiStructure currentStructure, EdiStructureType newContainerType) {
     var candidates = currentStructure.GetMatchingProperties(newContainerType);
     var property = default(EdiPropertyDescriptor);
     if (candidates.Length == 0) {
         return null;
     }
     if (candidates.Length == 1 && candidates[0].Conditions == null) {
         property = candidates[0];
     } else {
         property = ConditionalMatch(reader, currentStructure, newContainerType, candidates);
     }
     return property;
 }
Example #4
0
        private EdiPropertyDescriptor FindForCurrentElement(EdiReader reader, EdiStructure currentStructure, EdiStructureType newContainerType, out Queue <EdiEntry> elementReads)
        {
            elementReads = null;
            var candidates = currentStructure.GetMatchingProperties(newContainerType);

            if (candidates.Length == 0)
            {
                return(null);
            }
            var property = default(EdiPropertyDescriptor);

            if (reader.TokenType == EdiToken.ElementStart || currentStructure.CachedReads.Count > 0)
            {
                var elementPath = reader.TokenType == EdiToken.ElementStart ? reader.Path : ((EdiPath)currentStructure.CachedReads.Peek().Path).ToString("E");
                var matches     = candidates.Where(p => p.PathInfo.PathInternal.Equals(elementPath)).ToArray();
                if (matches.Length == 0)
                {
                    property = null;
                }
                else if (matches.Length == 1 && matches[0].Conditions == null)
                {
                    property = matches[0];
                }
                else
                {
                    property = ConditionalMatch(reader, currentStructure, newContainerType, matches);
                }
                if (property != null)
                {
                    elementReads = new Queue <EdiEntry>();
                    var parentCache = currentStructure.CachedReads;
                    while (parentCache.Count > 0 && elementPath == ((EdiPath)parentCache.Peek().Path).ToString("E"))
                    {
                        elementReads.Enqueue(parentCache.Dequeue());
                    }
                    //foreach (var item in currentStructure.CachedReads) {
                    //    if (elementPath == ((EdiPath)item.Path).ToString("E")) {
                    //        elementReads.Enqueue(item);
                    //    }
                    //}
                }
            }
            return(property);
        }
Example #5
0
 private EdiPropertyDescriptor FindForCurrentSegment(EdiReader reader, EdiStructure currentStructure, EdiStructureType newContainerType) {
     currentStructure.CachedReads.Clear();
     var candidates = currentStructure.GetMatchingProperties(newContainerType);
     if (candidates.Length == 0) {
         return null;
     }
     var property = default(EdiPropertyDescriptor);
     if (reader.TokenType == EdiToken.SegmentName) {
         var matches = candidates.Where(p => p.Segment.Equals(reader.Value)).ToArray();
         if (matches.Length == 0) {
             property = null;
         } else if (matches.Length == 1 && matches[0].Conditions == null) {
             property = matches[0];
         } else {
             property = ConditionalMatch(reader, currentStructure, newContainerType, matches);
         }
     }
     return property;
 }