public Data.DataTable GetDataTable(string suffix, WordTemplateLogic.WordContext context) { var userChart = Database.Query <UserChartEntity>().SingleOrDefault(a => a.Guid == Guid.Parse(suffix)); using (CurrentEntityConverter.SetCurrentEntity(context.Entity)) { var chartRequest = UserChartLogic.ToChartRequest(userChart); ResultTable result = ChartLogic.ExecuteChartAsync(chartRequest, CancellationToken.None).Result; var tokens = chartRequest.Columns.Where(a => a.Token != null).ToList(); if (chartRequest.GroupResults && tokens.Count(a => a.IsGroupKey.Value) == 2 && tokens.Count(a => !a.IsGroupKey.Value) == 1) { var firstKeyIndex = tokens.FindIndex(a => a.IsGroupKey.Value); var secondKeyIndex = tokens.FindIndex(firstKeyIndex + 1, a => a.IsGroupKey.Value); var valueIndex = tokens.FindIndex(a => !a.IsGroupKey.Value); return(result.ToDataTablePivot(secondKeyIndex, firstKeyIndex, valueIndex)); } else { return(result.ToDataTable()); } } }
public Data.DataTable GetDataTable(string suffix, Entity entity) { var userChart = Database.Query <UserChartEntity>().SingleEx(a => a.Guid == Guid.Parse(suffix)); using (CurrentEntityConverter.SetCurrentEntity(entity)) { var chartRequest = UserChartLogic.ToChartRequest(userChart); ResultTable result = ChartLogic.ExecuteChartAsync(chartRequest, CancellationToken.None).Result; var tokens = chartRequest.Columns.Select(a => a.Token).NotNull().ToList(); //TODO: Too specific. Will be better if controlled by some parameters. if (chartRequest.HasAggregates() && tokens.Count(a => !(a.Token is AggregateToken)) == 2 && tokens.Count(a => a.Token is AggregateToken) == 1) { var firstKeyIndex = tokens.FindIndex(a => !(a.Token is AggregateToken)); var secondKeyIndex = tokens.FindIndex(firstKeyIndex + 1, a => !(a.Token is AggregateToken)); var valueIndex = tokens.FindIndex(a => a.Token is AggregateToken); return(result.ToDataTablePivot(secondKeyIndex, firstKeyIndex, valueIndex)); } else { return(result.ToDataTable()); } } }