예제 #1
0
        internal static async Task <TableQuerySegment <TResult> > QueryCollectionsAsync <TResult>(int?maxItemCount, string filterString, TableContinuationToken token, CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            ValidateContinuationToken(token);
            FeedOptions defaultFeedOptions = GetDefaultFeedOptions(requestOptions);

            defaultFeedOptions.RequestContinuation = token?.NextRowKey;
            FeedResponse <DocumentCollection> feedResponse;

            if (string.IsNullOrEmpty(filterString))
            {
                feedResponse = await client.DocumentClient.CreateDocumentCollectionQuery(UriFactory.CreateDatabaseUri("TablesDB"), defaultFeedOptions).AsDocumentQuery().ExecuteNextAsync <DocumentCollection>();
            }
            else
            {
                string sqlQuery = QueryTranslator.GetSqlQuery("*", filterString, isLinqExpression: false, isTableQuery: true, null);
                feedResponse = await client.DocumentClient.CreateDocumentCollectionQuery(UriFactory.CreateDatabaseUri("TablesDB"), sqlQuery, defaultFeedOptions).AsDocumentQuery().ExecuteNextAsync <DocumentCollection>();
            }
            operationContext.RequestResults.Add(feedResponse.ToRequestResult());
            List <TResult> list = new List <TResult>();

            foreach (DocumentCollection item in feedResponse)
            {
                list.Add((TResult)(object)new DynamicTableEntity
                {
                    Properties =
                    {
                        {
                            "TableName",
                            new EntityProperty(item.Id)
                        }
                    }
                });
            }
            TableQuerySegment <TResult> tableQuerySegment = new TableQuerySegment <TResult>(list);

            if (!string.IsNullOrEmpty(feedResponse.ResponseContinuation))
            {
                tableQuerySegment.ContinuationToken = new TableContinuationToken
                {
                    NextRowKey = feedResponse.ResponseContinuation
                };
            }
            tableQuerySegment.RequestCharge = feedResponse.RequestCharge;
            return(tableQuerySegment);
        }
예제 #2
0
        internal static async Task <TableQuerySegment <TResult> > QueryDocumentsAsync <TResult>(int?maxItemCount, string filterString, IList <string> selectColumns, TableContinuationToken token, CloudTableClient client, CloudTable table, EntityResolver <TResult> resolver, TableRequestOptions requestOptions, OperationContext operationContext, bool isLinqExpression, IList <OrderByItem> orderByItems, string tombstoneKey)
        {
            ValidateContinuationToken(token);
            selectColumns = ((selectColumns != null) ? new List <string>(selectColumns) : null);
            Dictionary <string, bool> selectedSystemProperties = new Dictionary <string, bool>();
            string      sqlQuery           = QueryTranslator.GetSqlQuery(GetSelectList(selectColumns, requestOptions, out selectedSystemProperties), filterString, isLinqExpression, isTableQuery: false, orderByItems, tombstoneKey, enableTimestampQuery: true);
            FeedOptions defaultFeedOptions = GetDefaultFeedOptions(requestOptions);

            if (maxItemCount.HasValue)
            {
                defaultFeedOptions.MaxItemCount = maxItemCount;
            }
            defaultFeedOptions.SessionToken        = requestOptions.SessionToken;
            defaultFeedOptions.RequestContinuation = token?.NextRowKey;
            FeedResponse <Document> feedResponse = await client.DocumentClient.CreateDocumentQuery <Document>(table.GetCollectionUri(), sqlQuery, defaultFeedOptions).AsDocumentQuery().ExecuteNextAsync <Document>();

            operationContext.RequestResults.Add(feedResponse.ToRequestResult());
            List <TResult> list = new List <TResult>();

            foreach (Document item in feedResponse)
            {
                var itemETag = EtagHelper.ConvertFromBackEndETagFormat(item.ETag);
                item.SetPropertyValue("_etag", itemETag);
                IDictionary <string, EntityProperty> entityPropertiesFromDocument = EntityTranslator.GetEntityPropertiesFromDocument(item, selectColumns);
                list.Add(resolver(selectedSystemProperties["PartitionKey"] ? item.GetPropertyValue <string>("$pk") : null, selectedSystemProperties["RowKey"] ? item.GetPropertyValue <string>("$id") : null, selectedSystemProperties["Timestamp"] ? ((DateTimeOffset)item.Timestamp) : default(DateTimeOffset), entityPropertiesFromDocument, selectedSystemProperties["Etag"] ? item.ETag : null));
            }
            TableQuerySegment <TResult> tableQuerySegment = new TableQuerySegment <TResult>(list);

            if (!string.IsNullOrEmpty(feedResponse.ResponseContinuation))
            {
                tableQuerySegment.ContinuationToken = new TableContinuationToken
                {
                    NextRowKey = feedResponse.ResponseContinuation
                };
            }
            tableQuerySegment.RequestCharge = feedResponse.RequestCharge;
            return(tableQuerySegment);
        }