private static void AssertBindings(string[] input, List <string> expectedSimpleBindings, List <string> expectedCompoundBindings) { var analyzedBindings = BindingsHelper.AnalyzeBindings(input); Assert.Equal(expectedSimpleBindings, analyzedBindings.SimpleBindings); Assert.Equal(expectedCompoundBindings, analyzedBindings.CompoundBindings); }
public HttpResponseMessage GetDocumentsPreview() { using (var cts = new CancellationTokenSource()) using (cts.TimeoutAfter(DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout)) { try { List <RavenJObject> results; int totalResults; var statusCode = HttpStatusCode.OK; var start = GetStart(); var pageSize = GetPageSize(Database.Configuration.MaxPageSize); var requestedCollection = GetQueryStringValue("collection"); if (string.IsNullOrEmpty(requestedCollection)) { var totalCountQuery = Database.Queries.Query(Constants.DocumentsByEntityNameIndex, new IndexQuery { Start = 0, PageSize = 0 }, cts.Token); totalResults = totalCountQuery.TotalResults; results = new List <RavenJObject>(pageSize); Database.Documents.GetDocuments(start, pageSize, GetEtagFromQueryString(), cts.Token, doc => { if (doc != null) { results.Add(doc.ToJson()); } return(true); }); } else { var indexQuery = new IndexQuery { Query = "Tag:" + RavenQuery.Escape(requestedCollection), Start = start, PageSize = pageSize, SortedFields = new[] { new SortedField("-LastModifiedTicks") } }; var queryResult = Database.Queries.Query(Constants.DocumentsByEntityNameIndex, indexQuery, cts.Token); Database.IndexStorage.SetLastQueryTime(queryResult.IndexName, queryResult.LastQueryTime); totalResults = queryResult.TotalResults; results = queryResult.Results; if (queryResult.NonAuthoritativeInformation) { statusCode = HttpStatusCode.NonAuthoritativeInformation; } } var bindings = GetQueryStringValues("binding"); if (bindings.Length > 0) { var bindingGroups = BindingsHelper.AnalyzeBindings(bindings); return(GetMessageWithObject(new { TotalResults = totalResults, Results = TrimContents(results, bindingGroups) }, statusCode)); } else { // since user does not specified colums/bindings to use to sample input data to find // columns that we use var columns = SampleColumnNames(results); return(GetMessageWithObject(new { TotalResults = totalResults, Results = TrimContents(results, new BindingGroups { SimpleBindings = columns }) }, statusCode)); } } catch (OperationCanceledException e) { throw new TimeoutException(string.Format("The query did not produce results in {0}", DatabasesLandlord.SystemConfiguration.DatabaseOperationTimeout), e); } } }