Ejemplo n.º 1
0
        public void Accessor()
        {
            var o        = new AnonType <int, int>(42, 84);
            var accessor = new AnonTypeAccessor();

            Assert.Equal(42, accessor.Read(o, "I0"));
            Assert.Equal(84, accessor.Read(o, "I1"));
        }
Ejemplo n.º 2
0
        public static RemoteGroupingResult Run(IEnumerable <AnonType> flatGroups, int groupCount, ContosoRetail.SharedKernel.DataAccess.DataLoader.SummaryInfo[] totalSummary, ContosoRetail.SharedKernel.DataAccess.DataLoader.SummaryInfo[] groupSummary)
        {
            var accessor = new AnonTypeAccessor();

            var markup = new RemoteGroupTypeMarkup(
                groupCount,
                totalSummary != null ? totalSummary.Length : 0,
                groupSummary != null ? groupSummary.Length : 0
                );

            List <Group> hierGroups = null;

            if (groupCount > 0)
            {
                hierGroups = new GroupHelper <AnonType>(accessor).Group(
                    flatGroups,
                    Enumerable.Range(0, groupCount).Select(i => new ContosoRetail.SharedKernel.DataAccess.DataLoader.GroupingInfo {
                    Selector = AnonType.ITEM_PREFIX + (RemoteGroupTypeMarkup.KeysStartIndex + i)
                }).ToArray()
                    );
            }

            IEnumerable dataToAggregate = hierGroups;

            if (dataToAggregate == null)
            {
                dataToAggregate = flatGroups;
            }

            var transformedTotalSummary = TransformSummary(totalSummary, markup.TotalSummaryStartIndex);
            var transformedGroupSummary = TransformSummary(groupSummary, markup.GroupSummaryStartIndex);

            transformedTotalSummary.Add(new SummaryInfo {
                SummaryType = "remoteCount"
            });

            var totals     = new AggregateCalculator <AnonType>(dataToAggregate, accessor, transformedTotalSummary, transformedGroupSummary).Run();
            var totalCount = (int)totals.Last();

            totals = totals.Take(totals.Length - 1).ToArray();
            if (totals.Length < 1)
            {
                totals = null;
            }

            return(new RemoteGroupingResult
            {
                Groups = hierGroups,
                Totals = totals,
                TotalCount = totalCount
            });
        }