/// <summary> /// retrieves list of resources according to query parameters /// </summary> /// <param name="queryParams"> hashtable containing query parameters </param> /// <param name="token"> resumption token details </param> /// <param name="isListRecords"> if isListRecords then load resources with authors and tags</param> /// <returns> list of resources </returns> internal List <Core.Resource> GetResources(Hashtable queryParams, MetadataProviderHelper.TokenDetails token, bool isListRecords) { // Algorithm: List <Core.Resource> listOfResources = new List <Core.Resource>(); try { Type set = null; if (queryParams.ContainsKey("set")) { set = CoreHelper.GetSystemResourceType(queryParams["set"] as string); if (null == set) { throw new ArgumentException(MetadataProviderHelper.Error_Message_Invalid_QueryParams, "queryParams"); } } if (null == set) { set = typeof(Core.Resource); } //make generic call MethodInfo getResourceListMethod = getResourceListMethod = this.GetType().GetMethod("GetResourceList", BindingFlags.NonPublic | BindingFlags.Instance); if (null != getResourceListMethod) { listOfResources = (List <Core.Resource>)getResourceListMethod.MakeGenericMethod(set).Invoke(this, new object[] { queryParams, token.QueryExecutionDateTime, isListRecords, true, token }); } } catch (TargetInvocationException ex) { if (null != ex.InnerException) { throw ex.InnerException; } throw; } catch (Exception) { throw; } return(listOfResources); }
private List <Core.Resource> GetResourceList <T>( Hashtable queryParams, DateTime initialQueryExecutionTime, bool isListRecords, bool isResumptionTokenSpecified, MetadataProviderHelper.TokenDetails token) where T : Core.Resource { List <Core.Resource> listOfResources = new List <Core.Resource>(); IQueryable <T> resourceQuery = null; // 1) Build the query DateTime from = DateTime.MinValue; DateTime until = DateTime.MinValue; if (queryParams.ContainsKey("from")) { from = ValidateDate(queryParams["from"], false); } if (queryParams.ContainsKey("until")) { until = ValidateDate(queryParams["until"], true); } using (Core.ZentityContext context = CoreHelper.CreateZentityContext()) { AuthenticatedToken authenticatedToken = GetAuthenticationToken(); if (from != DateTime.MinValue) { if ((until != DateTime.MinValue)) { if (from > until) { throw new ArgumentException(MetadataProviderHelper.Error_Message_Invalid_QueryParams, "queryParams"); } resourceQuery = FilterQuery(context).OfType <T>(). Where(resource => resource.DateModified >= from && resource.DateModified <= until && resource.DateModified < initialQueryExecutionTime) .Authorize("Read", context, authenticatedToken) .OrderByDescending(resource => resource.DateModified); } else { resourceQuery = FilterQuery(context).OfType <T>(). Where(resource => resource.DateModified >= from && resource.DateModified < initialQueryExecutionTime) .Authorize("Read", context, authenticatedToken) .OrderByDescending(resource => resource.DateModified); } } else { resourceQuery = FilterQuery(context).OfType <T>(). Where(resource => resource.DateModified < initialQueryExecutionTime) .Authorize("Read", context, authenticatedToken) .OrderByDescending(resource => resource.DateModified); } // 2) Retrieve resources count this.totalResourceCount = this.actualRecordCount = resourceQuery.Count(); if (this.totalResourceCount <= 0) { throw new ArgumentException(MetadataProviderHelper.Error_Message_NoRecords, "queryParams"); } if (!isResumptionTokenSpecified) { // 3) If count greater than maxharvestcount then // retrieve resources according to harvest count // else // retrieve resources according to original count if (MetadataProviderHelper.IsResumptionRequired(this.totalResourceCount)) { listOfResources = CoreHelper.FilterResources <T>( resourceQuery.Take(PlatformSettings.MaximumHarvestCount), isListRecords); this.actualHarvestedCount = listOfResources.Count; } else { listOfResources = CoreHelper.FilterResources <T>(resourceQuery, isListRecords); } } else { // 4) retrieve pending resources i.e : according to maximum harvest count int noOfRecordsToSkip = token.ActualHarvestedRecords; listOfResources = CoreHelper.FilterResources <T>(resourceQuery. Skip(noOfRecordsToSkip). Take(PlatformSettings.MaximumHarvestCount), isListRecords); this.actualHarvestedCount = noOfRecordsToSkip + listOfResources.Count; } } return(listOfResources); }