private EdiSegmentGroup ReadGroup(XmlNode node)
        {
            var attributes = node.Attributes?.Cast <XmlAttribute>().AsQueryable()
                             ?? new EnumerableQuery <XmlAttribute>(new List <XmlAttribute>());

            var groupString = attributes.FirstOrDefault(a => a.Name == "id")?.Value;

            if (!int.TryParse(groupString, out var groupInt))
            {
                throw new Exception($"Invalid group id attribute at {node.Name}");
            }

            var segmentGroup = _reader.GetSegmentGroup(groupInt);

            EdiBaseSegment[] children = null;

            if (segmentGroup == null)
            {
                children = ReadChildren(node.ChildNodes);
            }
            else
            {
                var childrenList = new SortedList <int, EdiBaseSegment[]>();

                for (var i = 0; i < segmentGroup.Length; i++)
                {
                    // get children (recursive)
                    children = ReadChildren(node.ChildNodes, segmentGroup[i]);
                    childrenList.Add(i, children);
                }

                children = childrenList.SelectMany(c => c.Value).ToArray();
            }

            if (children == null)
            {
                return(null);
            }

            // create group entity
            var ediGroup = new EdiSegmentGroup(groupInt, children);

            return(ediGroup);
        }
示例#2
0
        private EdiSegmentGroup ReadGroup(XmlNode node)
        {
            var attributes = node.Attributes?.Cast <XmlAttribute>().AsQueryable()
                             ?? new EnumerableQuery <XmlAttribute>(new List <XmlAttribute>());

            var groupString = attributes.FirstOrDefault(a => a.Name == "id")?.Value;

            if (!int.TryParse(groupString, out var groupInt))
            {
                throw new Exception($"Invalid group id attribute at {node.Name}");
            }

            // get children (recursive)
            var children = ReadChildren(node.ChildNodes, groupInt);

            // create group entity
            var ediGroup = new EdiSegmentGroup(groupInt, children);

            return(ediGroup);
        }