static string GetPreAggregateMethodName(string summaryType)
        {
            switch (summaryType)
            {
            case AggregateName.MIN:
                return(nameof(Enumerable.Min));

            case AggregateName.MAX:
                return(nameof(Enumerable.Max));

            case AggregateName.SUM:
                return(nameof(Enumerable.Sum));

            case AggregateName.COUNT_NOT_NULL:
                return(nameof(Enumerable.Count));
            }

            if (CustomAggregators.IsRegistered(summaryType))
            {
                var message = $"The custom aggregate '{summaryType}' cannot be translated to a LINQ expression."
                              + $" Set {nameof(DataSourceLoadOptionsBase)}.{nameof(DataSourceLoadOptionsBase.RemoteGrouping)} to False to enable in-memory aggregate calculation.";
                throw new InvalidOperationException(message);
            }

            throw new NotSupportedException();
        }
예제 #2
0
        public void CustomAggregator()
        {
            CustomAggregatorsBarrier.Run(delegate {
                CustomAggregators.RegisterAggregator("comma", typeof(CommaAggregator <>));

                var data = new[] {
                    new Group {
                        items = new Tuple <int>[] { Tuple.Create(1), Tuple.Create(5) }
                    },
                    new Group {
                        items = new Tuple <int>[] { Tuple.Create(7) }
                    },
                    new Group {
                        items = new Tuple <int>[] { }
                    }
                };

                var calculator = new AggregateCalculator <Tuple <int> >(data, new DefaultAccessor <Tuple <int> >(),
                                                                        new[] { new SummaryInfo {
                                                                                    Selector = "Item1", SummaryType = "comma"
                                                                                } },
                                                                        new[] { new SummaryInfo {
                                                                                    Selector = "Item1", SummaryType = "comma"
                                                                                } }
                                                                        );

                var totals = calculator.Run();

                Assert.Equal("1,5,7", totals[0]);
                Assert.Equal("1,5", data[0].summary[0]);
                Assert.Equal("7", data[1].summary[0]);
                Assert.Equal(string.Empty, data[2].summary[0]);
            });
        }
 public void ShouldCreateRegisteredAggregator()
 {
     StaticBarrier.Run(delegate {
         CustomAggregators.RegisterAggregator(AggregateName.SUM, typeof(SumAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator(AggregateName.SUM, new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <SumAggregator <int> >(aggregator);
     });
 }
 public void ShouldSupportMultipleAggregatorRegistrations()
 {
     StaticBarrier.Run(delegate {
         CustomAggregators.RegisterAggregator("any", typeof(SumAggregator <>));
         CustomAggregators.RegisterAggregator("any", typeof(MinAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator("any", new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <MinAggregator <int> >(aggregator);
     });
 }
예제 #5
0
 public static void Run(Action action)
 {
     lock (SYNC) {
         try {
             action();
         } finally {
             CustomAggregators.Clear();
         }
     }
 }
 public void ShouldCreateRegisteredAggregator()
 {
     try {
         CustomAggregators.RegisterAggregator(AggregateName.SUM, typeof(SumAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator(AggregateName.SUM, new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <SumAggregator <int> >(aggregator);
     } finally {
         CustomAggregators.Clear();
     }
 }
 public void ShouldSupportMultipleAggregatorRegistrations()
 {
     try {
         CustomAggregators.RegisterAggregator("any", typeof(SumAggregator <>));
         CustomAggregators.RegisterAggregator("any", typeof(MinAggregator <>));
         var aggregator = CustomAggregators.CreateAggregator("any", new DefaultAccessor <int>());
         Assert.NotNull(aggregator);
         Assert.IsType <MinAggregator <int> >(aggregator);
     } finally {
         CustomAggregators.Clear();
     }
 }
예제 #8
0
 public static void Run(Action action)
 {
     lock (SYNC) {
         try {
             action();
         } finally {
             CustomAggregators.Clear();
             CustomAccessorCompilers.Clear();
             DataSourceLoadOptionsBase.StringToLowerDefault = null;
         }
     }
 }
예제 #9
0
        public void Configuration(IAppBuilder app)
        {
            CustomAggregators.RegisterAggregator("avgRPK", typeof(RPKAggregator <>));
            ConfigureAuth(app);

            //HttpConfiguration config = new HttpConfiguration();
            //config.EnableDependencyInjection();
            //ConfigureAuth(app);

            ////app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            ////atrina
            //app.UseWebApi(config);
            //WebApiConfig.Register(config);
            GlobalConfiguration.Configuration.EnableDependencyInjection();
        }
        public void CustomAggregator()
        {
            try {
                CustomAggregators.RegisterAggregator("totalSales", typeof(TotalSalesAggregator <>));

                var data = new[] {
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 4.04M, Quantity = 5, Discount = 0.10M
                            },
                            new CustomAggregatorDataItem {
                                UnitPrice = 10.10M, Quantity = 2, Discount = 0.20M
                            }
                        }
                    },
                    new Group {
                        items = new[] {
                            new CustomAggregatorDataItem {
                                UnitPrice = 15.15M, Quantity = 4, Discount = 0.30M
                            }
                        }
                    },
                    new Group {
                        items = new CustomAggregatorDataItem[] { }
                    }
                };

                var calculator = new AggregateCalculator <CustomAggregatorDataItem>(data, new DefaultAccessor <CustomAggregatorDataItem>(),
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } },
                                                                                    new[] { new SummaryInfo {
                                                                                                Selector = "this", SummaryType = "totalSales"
                                                                                            } }
                                                                                    );

                var totals = calculator.Run();

                Assert.Equal(76.76M, totals[0]);
                Assert.Equal(34.34M, data[0].summary[0]);
                Assert.Equal(42.42M, data[1].summary[0]);
                Assert.Equal(0M, data[2].summary[0]);
            } finally {
                CustomAggregators.Clear();
            }
        }
 public void ShouldNotReturnUnexistingAggregator()
 {
     StaticBarrier.Run(delegate {
         Assert.Null(CustomAggregators.CreateAggregator("custom", new DefaultAccessor <int>()));
     });
 }
 public void ShouldNotReturnUnexistingAggregator()
 {
     Assert.Null(CustomAggregators.CreateAggregator("custom", new DefaultAccessor <int>()));
 }