示例#1
0
        internal static IDictionary <string, EntityProperty> GetEntityPropertiesFromDocument(Document document, IList <string> selectColumns)
        {
            string serializedDocument = SerializeObject(document);

            EdmConverter.GetPropertiesFromDocument(selectColumns, serializedDocument, out IDictionary <string, EntityProperty> entityProperties, out IDictionary <string, EntityProperty> _);
            return(entityProperties);
        }
 public static void GetPropertiesFromResourceStream(Stream stream, IList <string> selectColumns, out IDictionary <string, EntityProperty> entityProperties, out IDictionary <string, EntityProperty> documentDBProperties)
 {
     using (StreamReader streamReader = new StreamReader(stream))
     {
         EdmConverter.GetPropertiesFromDocument(selectColumns, streamReader.ReadToEnd(), out entityProperties, out documentDBProperties);
     }
 }
        private static TableResult GetTableResultFromResponse(TableOperation operation, ResourceResponse <Document> response, OperationContext context, TableRequestOptions options, List <string> selectColumns, string sessionToken)
        {
            TableResult tableResult = new TableResult();

            tableResult.Etag           = EtagHelper.ConvertFromBackEndETagFormat(response.ResponseHeaders["ETag"]);
            tableResult.HttpStatusCode = (int)response.StatusCode;
            tableResult.SessionToken   = sessionToken;
            tableResult.RequestCharge  = response.RequestCharge;
            if (operation.Entity != null && !string.IsNullOrEmpty(tableResult.Etag))
            {
                operation.Entity.ETag = tableResult.Etag;
            }
            if (operation.OperationType == TableOperationType.InsertOrReplace || operation.OperationType == TableOperationType.Replace || !operation.EchoContent)
            {
                tableResult.HttpStatusCode = 204;
            }
            if (operation.OperationType != TableOperationType.Retrieve)
            {
                if (operation.OperationType != TableOperationType.Delete)
                {
                    tableResult.Result = operation.Entity;
                    ITableEntity tableEntity = tableResult.Result as ITableEntity;
                    if (tableEntity != null)
                    {
                        if (tableResult.Etag != null)
                        {
                            tableEntity.ETag = tableResult.Etag;
                        }
                        tableEntity.Timestamp = response.Resource.Timestamp;
                    }
                }
            }
            else if (response.Resource != null)
            {
                if (operation.RetrieveResolver == null)
                {
                    tableResult.Result = EntityHelpers.GetEntityFromResourceStream(response.ResponseStream, context, operation.SelectColumns);
                }
                else
                {
                    EntityHelpers.GetPropertiesFromResourceStream(response.ResponseStream, operation.SelectColumns, out IDictionary <string, EntityProperty> entityProperties, out IDictionary <string, EntityProperty> documentDBProperties);
                    if (options.ProjectSystemProperties.Value)
                    {
                        EdmConverter.ValidateDocumentDBProperties(documentDBProperties);
                        EntityProperty entityProperty  = documentDBProperties["$pk"];
                        EntityProperty entityProperty2 = documentDBProperties["$id"];
                        EntityProperty entityProperty3 = documentDBProperties["_etag"];
                        EntityProperty entityProperty4 = documentDBProperties["_ts"];
                        string         arg             = EtagHelper.ConvertFromBackEndETagFormat(entityProperty3.StringValue);
                        DateTime       dateTime        = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(entityProperty4.DoubleValue.Value);
                        tableResult.Result = operation.RetrieveResolver(entityProperty.StringValue, entityProperty2.StringValue, dateTime, entityProperties, arg);
                    }
                    else
                    {
                        tableResult.Result = operation.RetrieveResolver(null, null, default(DateTimeOffset), entityProperties, null);
                    }
                }
            }
            return(tableResult);
        }
        public static ITableEntity GetEntityFromResourceStream(Stream stream, OperationContext context, IList <string> selectColumns)
        {
            GetPropertiesFromResourceStream(stream, selectColumns, out IDictionary <string, EntityProperty> entityProperties, out IDictionary <string, EntityProperty> documentDBProperties);
            EdmConverter.ValidateDocumentDBProperties(documentDBProperties);
            EntityProperty     entityProperty     = documentDBProperties["$pk"];
            EntityProperty     entityProperty2    = documentDBProperties["$id"];
            EntityProperty     entityProperty3    = documentDBProperties["_etag"];
            EntityProperty     entityProperty4    = documentDBProperties["_ts"];
            DynamicTableEntity dynamicTableEntity = new DynamicTableEntity(entityProperty.StringValue, entityProperty2.StringValue);

            dynamicTableEntity.ETag      = entityProperty3.StringValue;
            dynamicTableEntity.Timestamp = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(entityProperty4.DoubleValue.Value);
            dynamicTableEntity.ReadEntity(entityProperties, context);
            return(dynamicTableEntity);
        }