Ejemplo n.º 1
0
        public DataPivotResponse <ICollection> GetPivotData <T>(DataPivotRequest <T> request)
        {
            DataPivotResponse <ICollection> gridData = new DataPivotResponse <ICollection>();

            gridData.GridId = request.GridGuid;
            gridData.Data   = new List <Dictionary <string, object> >();
            if (request.ColumnHeaders.Count > 0)
            {
                gridData.HeaderMetaData = _metaDataHelper.GetColumnsMetaData(request.ColumnHeaders);
            }
            if (!string.IsNullOrWhiteSpace(request.AlwaysGroupOnColumn))
            {
                if (request.RequestModel.rowGroupCols.Count > 0)
                {
                    if (request.RequestModel.rowGroupCols[request.RequestModel.rowGroupCols.Count - 1].field != request.AlwaysGroupOnColumn)
                    {
                        return(gridData);
                    }
                }
                else
                {
                    return(gridData);
                }
            }
            List <Dictionary <string, object> > data = _pivotRepository.ExtractDataFromCube(request);


            int PageIndex = (request.RequestModel.endRow) / (request.RequestModel.endRow - request.RequestModel.startRow);
            int PageSize  = (request.RequestModel.endRow - request.RequestModel.startRow);



            var queryResult = data.AsEnumerable();

            if (request.RequestModel.sortModel != null && request.RequestModel.sortModel.Count > 0)
            {
                queryResult = Sort(queryResult, string.Join(",", request.RequestModel.sortModel.Select(s => s.ToString())));
            }

            /*if (request.RequestModel.sortModel != null && request.RequestModel.sortModel.Count > 0)
             * {
             *  try
             *  {
             *      queryResult = queryResult.OrderBy(string.Join(",", request.RequestModel.sortModel.Select(s => s.ToString())));
             *  }
             *  catch (Exception ex)
             *  {
             *      //ignore as the grid layout might change and the previsouly-sorted-by column might not exist at all.
             *  }
             * }*/
            if (queryResult.Count() > 0)
            {
                gridData.Data           = queryResult.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToDynamicList();
                gridData.TotalDataCount = queryResult.Count();
            }
            else
            {
                gridData.Data           = queryResult.ToDynamicList();
                gridData.TotalDataCount = queryResult.Count();
            }
            gridData.GridId = request.GridGuid;


            return(gridData);

            /*Task<string> result = GetData(request);
             * result.Wait();
             * string data = result.Result;
             * int PageIndex = (request.RequestModel.endRow) / (request.RequestModel.endRow - request.RequestModel.startRow);
             * int PageSize = (request.RequestModel.endRow - request.RequestModel.startRow);
             * //use the cache instead.
             * DataPivotResponse<ICollection> gridData = JsonConvert.DeserializeObject<DataPivotResponse<ICollection>>(data);
             * int a = 0;
             * ICollection pivotData;
             * if (_cache.TryGetValue(gridData.GridId, out pivotData))
             * {
             *  var queryResult = GenerateFilterQuery(pivotData, request.RequestModel.filterModel);
             *  if (request.RequestModel.sortModel != null && request.RequestModel.sortModel.Count > 0)
             *  {
             *      try
             *      {
             *          queryResult = queryResult.OrderBy(string.Join(",", request.RequestModel.sortModel.Select(s => s.ToString())));
             *      }
             *      catch (Exception ex)
             *      {
             *          //ignore as the grid layout might change and the previsouly-sorted-by column might not exist at all.
             *      }
             *  }
             *  if (queryResult.Count() > 0)
             *  {
             *      gridData.Data = queryResult.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToDynamicList();
             *      gridData.TotalDataCount = queryResult.Count();
             *
             *  }
             *  else
             *  {
             *      gridData.Data = queryResult.ToDynamicList();
             *      gridData.TotalDataCount = queryResult.Count();
             *
             *  }
             *  gridData.GridId = request.GridGuid;
             *
             * }
             * return gridData;*/
            //var response = new DataPivotResponse<ICollection>();
            //string CacheKey=_pivotCacheRepository.GetCacheKey(request.Filters,request.MDXProcedure);
            //string TableName = _pivotCacheRepository.GetCachTable(CacheKey,PivotMode.SERVER);
            //List<string> secondaryColumnFields = null;
            //if (TableName != null)
            //{
            //    secondaryColumnFields = _pivotCacheRepository.GetSecondaryColumns(TableName);
            //}
            //else
            //{
            //    DataTable data=_pivotRepository.GetDataFromDB(request.FieldToProcedureParamLookup, request.MDXProcedure);
            //    TableName = "pvt_" + Guid.NewGuid().ToString();
            //    PivotData pivotData=_pivotRepository.TransformData(data, request.RequestModel);
            //    secondaryColumnFields = pivotData.SecondaryColumns;
            //    _pivotCacheRepository.CachePivotData(TableName, pivotData.Data,pivotData.SecondaryColumns, request.RequestModel);
            //    _pivotCacheRepository.AddSecondaryColumns(TableName, secondaryColumnFields);
            //    _pivotCacheRepository.AddCachTable(CacheKey, TableName,PivotMode.SERVER);
            //}
            //dynamic pivotResult=_pivotCacheRepository.GetDataFromCache(TableName, secondaryColumnFields, request.RequestModel);
            //response.Data = pivotResult.Data;
            //response.TotlaDataCount = pivotResult.RowsCount;
            //response.GridId = TableName;
            //response.SecondaryColumns = secondaryColumnFields;
            //return response;

            /*var response = new DataPivotResponse<ICollection>();
             * string CacheKey = _pivotSegmentCacheRepository.GetCacheKey(request.Filters, request.MDXProcedure,request.RequestModel);
             * string CacheKeyAll = _pivotSegmentCacheRepository.GetCacheKey(request.Filters, request.MDXProcedure, request.FieldToProcedureParamLookup, request.RequestModel);
             *
             * string TableName = _pivotSegmentCacheRepository.GetCachTable(CacheKey, PivotMode.SERVER);
             * string TableNameAll = _pivotSegmentCacheRepository.GetCachTable(CacheKeyAll, PivotMode.SERVER);
             *
             * List<string> secondaryColumnFields = null;
             * if(TableNameAll==null)
             * {
             *  DataTable data = _pivotRepository.GetDataFromDB(request.FieldToProcedureParamLookup, request.MDXProcedure);
             *  TableNameAll = "pvt_" + Guid.NewGuid().ToString();
             *  PivotData pivotData = _pivotRepository.TransformData(data, request.RequestModel);
             *  secondaryColumnFields = pivotData.SecondaryColumns;
             *  _pivotSegmentCacheRepository.CachePivotData(TableNameAll, pivotData.Data, pivotData.SecondaryColumns, request.RequestModel);
             *  _pivotSegmentCacheRepository.AddSecondaryColumns(TableNameAll, secondaryColumnFields);
             *  _pivotSegmentCacheRepository.AddCachTable(CacheKeyAll, TableNameAll, PivotMode.SERVER);
             * }
             * if (TableName != null)
             * {
             *  secondaryColumnFields = _pivotSegmentCacheRepository.GetSecondaryColumns(TableName);
             * }
             * else
             * {
             *  List<MDXParam> Params = new List<MDXParam>();
             *  if (request.RequestModel.pivotCols.Count > 0)
             *  {
             *      List<MDXParam> res = request.FieldToProcedureParamLookup.Where(x => x.FieldName.Equals(request.RequestModel.pivotCols[0].field,StringComparison.CurrentCultureIgnoreCase)).ToList<MDXParam>();
             *      Params.AddRange(res);
             *  }
             *
             *  foreach(PivotColumn pc in request.RequestModel.rowGroupCols)
             *  {
             *      List<MDXParam> param = request.FieldToProcedureParamLookup.Where(x => x.FieldName.Equals(pc.field, StringComparison.CurrentCultureIgnoreCase)).ToList<MDXParam>();
             *          Params.AddRange(param);
             *  }
             *  DataTable data = _pivotRepository.GetDataFromDB(Params, request.MDXProcedure);
             *  TableName = "pvt_" + Guid.NewGuid().ToString();
             *  PivotData pivotData = _pivotRepository.TransformData(data, request.RequestModel);
             *  secondaryColumnFields = pivotData.SecondaryColumns;
             *  _pivotSegmentCacheRepository.CachePivotData(TableName, pivotData.Data, pivotData.SecondaryColumns, request.RequestModel);
             *  _pivotSegmentCacheRepository.AddSecondaryColumns(TableName, secondaryColumnFields);
             *  _pivotSegmentCacheRepository.AddCachTable(CacheKey, TableName, PivotMode.SERVER);
             * }
             * dynamic pivotResult = _pivotSegmentCacheRepository.GetDataFromCache(TableName, secondaryColumnFields, request.RequestModel);
             * response.Data = pivotResult.Data;
             * response.TotlaDataCount = pivotResult.RowsCount;
             * response.GridId = TableNameAll;
             * response.SecondaryColumns = secondaryColumnFields;
             * return response;*/
            return(null);
        }
Ejemplo n.º 2
0
 public List <ColumnMetaData> GetColumnMetaData(List <ColumnHeader> columnHeaders)
 {
     return(_metaDataHelper.GetColumnsMetaData(columnHeaders));
 }