Пример #1
0
        public static ITableEntity GetEntityFromDocument(Document document, OperationContext context, IList <string> selectColumns)
        {
            string         partitionKey = null;
            string         rowKey       = null;
            string         eTag         = null;
            DateTimeOffset timestamp    = default(DateTimeOffset);
            IDictionary <string, EntityProperty> entityProperties = null;

            EntityTranslator.GetEntityPropertiesFromDocument(document, selectColumns, out partitionKey, out rowKey, out eTag, out timestamp, out entityProperties);
            DynamicTableEntity dynamicTableEntity = new DynamicTableEntity(partitionKey, rowKey);

            dynamicTableEntity.ETag         = eTag;
            dynamicTableEntity.Timestamp    = timestamp;
            dynamicTableEntity.PartitionKey = partitionKey;
            dynamicTableEntity.ReadEntity(entityProperties, context);
            return(dynamicTableEntity);
        }
Пример #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);
        }
        private static TableResult GetTableResultFromDocument(TableOperation operation, Document response, OperationContext context, TableRequestOptions requestOptions, string sessionToken, double requestCharge)
        {
            var responseETag = EtagHelper.ConvertFromBackEndETagFormat(response.ETag);

            response.SetPropertyValue("_etag", responseETag);
            TableResult tableResult = new TableResult();

            tableResult.Etag           = response.ETag;
            tableResult.HttpStatusCode = GetSuccessStatusCodeFromOperationType(operation.OperationType);
            tableResult.SessionToken   = sessionToken;
            tableResult.RequestCharge  = requestCharge;
            if (operation.OperationType != TableOperationType.Retrieve)
            {
                operation.Entity.ETag = response.ETag;
                tableResult.Result    = operation.Entity;
            }
            else if (operation.RetrieveResolver != null)
            {
                tableResult.Result = operation.RetrieveResolver(response.GetPropertyValue <string>("$pk"), response.Id, response.Timestamp, EntityTranslator.GetEntityPropertiesFromDocument(response, operation.SelectColumns), response.ETag);
            }
            else
            {
                tableResult.Result = EntityHelpers.GetEntityFromDocument(response, context, operation.SelectColumns);
            }
            return(tableResult);
        }