コード例 #1
0
        public IDocumentFragment SelectSegment(SegmentPath segmentPath, string value)
        {
            IDocumentFragment segmentDocumentFragment = null;

            // If SegmentPath is conditional group then replace value with conditional value
            if (string.IsNullOrWhiteSpace(segmentPath.Value) == false)
            {
                value = segmentPath.Value;
            }

            if (CurrentSegments.TryGetValue(segmentPath.Path, out segmentDocumentFragment) == false)
            {
                List <IDocumentFragment> unusedSegmentsList;
                if (UnusedSegments.TryGetValue(segmentPath.Path, out unusedSegmentsList) == false)
                {
                    PopulateUnusedSegments(segmentPath);
                }

                List <IDocumentFragment> documentFragments;
                if (UnusedSegments.TryGetValue(segmentPath.Path, out documentFragments))
                {
                    if (documentFragments.Count > 0)
                    {
                        if (string.IsNullOrWhiteSpace(value) == false && documentFragments.Count != 1)
                        {
                            foreach (IDocumentFragment documentFragment in documentFragments)
                            {
                                string segmentValue = documentFragment.GetDataSegmentValue(segmentPath.DataSegmentName);
                                if (string.Equals(segmentValue, value, StringComparison.OrdinalIgnoreCase))
                                {
                                    segmentDocumentFragment = documentFragment;
                                }
                            }
                        }
                        else
                        {
                            segmentDocumentFragment = documentFragments[0];
                        }

                        if (segmentDocumentFragment != null)
                        {
                            documentFragments.Remove(segmentDocumentFragment);
                            CurrentSegments.Add(segmentPath.Path, segmentDocumentFragment);
                        }
                    }
                }
            }

            return(segmentDocumentFragment);
        }
コード例 #2
0
        // Assumptions:
        // 1. Loop DocumentFragment name ends with "Loop" e.g. "N1Loop"
        private void PopulateUnusedSegments(SegmentPath segmentPath)
        {
            List <IDocumentFragment> intermediateDocumentFragments = new List <IDocumentFragment>();
            List <IDocumentFragment> documentFragments             = new List <IDocumentFragment>();

            if (FatpipeDocument.RootFragment != null && FatpipeDocument.RootFragment.Children != null)
            {
                documentFragments.Add(FatpipeDocument.RootFragment);

                // Loop document fragments are special, add all loop fragments to list
                foreach (IDocumentFragment loop in FatpipeDocument.RootFragment.Children)
                {
                    if (string.Equals(loop.Pluglet.Tag, "loop", StringComparison.OrdinalIgnoreCase))
                    {
                        documentFragments.Add(loop);
                    }
                }

                string segmentName;
                for (int i = 0; i < segmentPath.Segments.Count; i++)
                {
                    segmentName = segmentPath.Segments[i];
                    if (i < segmentPath.Segments.Count - 1)
                    {
                        segmentName = segmentName + "Loop";
                    }

                    foreach (IDocumentFragment documentFragment in documentFragments)
                    {
                        foreach (IDocumentFragment child in documentFragment.Children)
                        {
                            if (string.Equals(child.Pluglet.Tag, segmentName, StringComparison.OrdinalIgnoreCase))
                            {
                                intermediateDocumentFragments.Add(child);
                            }
                        }
                    }

                    /*loopDocumentFragments.Clear();
                     * loopDocumentFragments.AddRange(intermediateDocumentFragments);
                     * intermediateDocumentFragments.Clear();*/
                    documentFragments             = intermediateDocumentFragments;
                    intermediateDocumentFragments = new List <IDocumentFragment>();
                }
            }

            UnusedSegments.Add(segmentPath.Path, documentFragments);
        }