private static IEnumerable <ComparisonUnit> GetHierarchicalComparisonUnits(
            IEnumerable <WithHierarchicalGroupingKey> input,
            int level)
        {
            IEnumerable <IGrouping <string, WithHierarchicalGroupingKey> > grouped = input
                                                                                     .GroupAdjacent(
                whgk => level >= whgk.HierarchicalGroupingArray.Length ? "" : whgk.HierarchicalGroupingArray[level]);

            List <ComparisonUnit> retList = grouped
                                            .Select(gc =>
            {
                if (gc.Key == "")
                {
                    return((IEnumerable <ComparisonUnit>)gc.Select(whgk => whgk.ComparisonUnitWord).ToList());
                }

                string[] spl = gc.Key.Split(':');
                ComparisonUnitGroupType groupType = WmlComparerUtil.ComparisonUnitGroupTypeFromLocalName(spl[0]);
                IEnumerable <ComparisonUnit> childHierarchicalComparisonUnits = GetHierarchicalComparisonUnits(gc, level + 1);
                var newCompUnitGroup = new ComparisonUnitGroup(childHierarchicalComparisonUnits, groupType, level);

                return(new[] { newCompUnitGroup });
            })
                                            .SelectMany(m => m)
                                            .ToList();

            return(retList);
        }
コード例 #2
0
        public ComparisonUnitGroup(
            IEnumerable <ComparisonUnit> comparisonUnitList,
            ComparisonUnitGroupType groupType,
            int level)
        {
            Contents = comparisonUnitList.ToList();
            ComparisonUnitGroupType = groupType;
            ComparisonUnit     first = Contents.First();
            ComparisonUnitAtom comparisonUnitAtom = GetFirstComparisonUnitAtomOfGroup(first);

            XElement[] ancestorsToLookAt = comparisonUnitAtom
                                           .AncestorElements
                                           .Where(e => e.Name == W.tbl || e.Name == W.tr || e.Name == W.tc || e.Name == W.p || e.Name == W.txbxContent)
                                           .ToArray();

            XElement ancestor = ancestorsToLookAt[level];

            if (ancestor == null)
            {
                throw new OpenXmlPowerToolsException("Internal error: ComparisonUnitGroup");
            }

            SHA1Hash           = (string)ancestor.Attribute(PtOpenXml.SHA1Hash);
            CorrelatedSHA1Hash = (string)ancestor.Attribute(PtOpenXml.CorrelatedSHA1Hash);
            StructureSHA1Hash  = (string)ancestor.Attribute(PtOpenXml.StructureSHA1Hash);
        }
コード例 #3
0
        public ComparisonUnitGroup(IEnumerable <ComparisonUnit> comparisonUnitList, ComparisonUnitGroupType groupType, int level)
        {
            Contents = comparisonUnitList.ToList();
            ComparisonUnitGroupType = groupType;
            var   first = comparisonUnitList.First();
            var   comparisonUnitAtom = GetFirstComparisonUnitAtomOfGroup(first);
            XName?ancestorName       = null;

            if (groupType == ComparisonUnitGroupType.Table)
            {
                ancestorName = W.tbl;
            }
            else if (groupType == ComparisonUnitGroupType.Row)
            {
                ancestorName = W.tr;
            }
            else if (groupType == ComparisonUnitGroupType.Cell)
            {
                ancestorName = W.tc;
            }
            else if (groupType == ComparisonUnitGroupType.Paragraph)
            {
                ancestorName = W.p;
            }
            else if (groupType == ComparisonUnitGroupType.Textbox)
            {
                ancestorName = W.txbxContent;
            }

            var ancestorsToLookAt = comparisonUnitAtom.AncestorElements.Where(ae => ae.Name == W.tbl || ae.Name == W.tr || ae.Name == W.tc || ae.Name == W.p || ae.Name == W.txbxContent).ToArray();
            var ancestor          = ancestorsToLookAt[level];

            if (ancestor == null)
            {
                throw new OpenXmlPowerToolsException("Internal error: ComparisonUnitGroup");
            }

            SHA1Hash           = (string)ancestor.Attribute(PtOpenXml.SHA1Hash);
            CorrelatedSHA1Hash = (string)ancestor.Attribute(PtOpenXml.CorrelatedSHA1Hash);
            StructureSHA1Hash  = (string)ancestor.Attribute(PtOpenXml.StructureSHA1Hash);
        }