public TableEntityValueBinder(TableEntityContext entityContext, ITableEntity entity, Type valueType)
 {
     _entityContext = entityContext;
     _value = entity;
     _valueType = valueType;
     _originalProperties = DeepClone(entity.WriteEntity(null));
 }
示例#2
0
        /// <summary>
        /// Replace (update) an existing table entity.
        /// </summary>
        /// <param name="tableEntity">Table entity to replace (update).</param>
        public void ReplaceEntity(
            ITableEntity tableEntity)
        {
            var table = GetTableReference(tableEntity.GetType().Name);
            var insertOperation = TableOperation.InsertOrReplace(tableEntity);

            table.Execute(insertOperation);
        }
        /// <summary>
        /// Creates a new instance of the TableOperation class given the
        /// entity to operate on and the type of operation that is being
        /// performed.
        /// </summary>
        /// <param name="entity">The entity that is being operated upon.</param>
        /// <param name="operationType">The type of operation.</param>
        internal TableOperation(ITableEntity entity, TableOperationType operationType)
        {
            if (entity == null && operationType != TableOperationType.Retrieve)
            {
                throw new ArgumentNullException("entity");
            }

            this.Entity = entity;
            this.OperationType = operationType;
        }
 internal static void ErrorWhileImportingEntitiesToAzure(ITableEntity[] entities, Exception ex)
 {
     StringBuilder builder = new StringBuilder();
     int i = 0;
     foreach (var entity in entities)
     {
         builder.AppendLine("[" + i + "] " + entity.RowKey);
         i++;
     }
     _Trace.TraceEvent(TraceEventType.Error, 0, "Error while importing entities (len:" + entities.Length + ") : " + Utils.ExceptionToString(ex) + "\r\n" + builder.ToString());
 }
示例#5
0
        private static async Task<ITableEntity> TryDelete(CloudTable table, ITableEntity entity, int retriesLeft)
        {
            if (retriesLeft == 0)
            {
                return entity;
            }

            try
            {
                await table.DeleteIgnoringNotFound(entity).ConfigureAwait(false);
                return Empty;
            }
            catch (Exception)
            {
                return await TryDelete(table, entity, retriesLeft - 1);
            }
        }
示例#6
0
 private static async Task DeleteIgnoringNotFound(this CloudTable table, ITableEntity entity)
 {
     try
     {
         await table.ExecuteAsync(TableOperation.Delete(entity)).ConfigureAwait(false);
     }
     catch (StorageException ex)
     {
         // Horrible logic to check if item has already been deleted or not
         var webException = ex.InnerException as WebException;
         if (webException?.Response != null)
         {
             var response = (HttpWebResponse) webException.Response;
             if ((int) response.StatusCode != 404)
             {
                 throw;
             }
         }
     }
 }
示例#7
0
 public static Include Delete(ITableEntity entity)
 {
     return new Include(IncludeType.Delete, new EntityOperation.Delete(entity));
 }
 public void Add(ITableEntity note)
 {
     var insertOperation = TableOperation.Insert(note);
     _table.Execute(insertOperation);
 }
 /// <summary>
 /// Appends an incrementing index to the row key to ensure that it will
 /// not conflict with existing rows created at the same time / with the
 /// same partition key.
 /// </summary>
 /// <param name="logEventEntity"></param>
 void EnsureUniqueRowKey(ITableEntity logEventEntity)
 {
     logEventEntity.RowKey += "|" + Interlocked.Increment(ref _rowKeyIndex);
 }
        /// <summary>
        /// Creates a new table operation that replaces the contents of
        /// the given entity in a table.
        /// </summary>
        /// <param name="entity">The <see cref="ITableEntity"/> object to be replaced.</param>
        /// <returns>The <see cref="TableOperation"/> object.</returns>
        public static TableOperation Replace(ITableEntity entity)
        {
            // Validate the arguments.
            CommonUtility.AssertNotNull("entity", entity);

            // Replace requires an ETag.
            if (string.IsNullOrEmpty(entity.ETag))
            {
                throw new ArgumentException(SR.ETagMissingForReplace);
            }

            // Create and return the table operation.
            return new TableOperation(entity, TableOperationType.Replace);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableTransactionAction"/>
 /// </summary>
 /// <param name="actionType"> The operation type to be applied to the <paramref name="entity"/></param>
 /// <param name="entity">The table entity to which the <paramref name="actionType"/> will be applied.</param>
 /// <param name="etag"> The <see cref="ETag"/> to apply to this action.</param>
 public TableTransactionAction(TableTransactionActionType actionType, ITableEntity entity, ETag etag = default)
 {
     ActionType = actionType;
     Entity     = entity;
     ETag       = etag;
 }
示例#12
0
 /// <summary>
 /// Inserts or replace the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>A new instance of <see cref="Include"/> class</returns>
 /// <exception cref="ArgumentNullException">If given <paramref name="entity"/> is <c>null</c>.</exception>
 public static Include InsertOrReplace(ITableEntity entity)
 {
     Requires.NotNull(entity, "entity");
     return new Include(IncludeType.InsertOrReplace, new EntityOperation.InsertOrReplace(entity));
 }
示例#13
0
 EntityOperation(ITableEntity entity)
 {
     Entity = entity;
 }
示例#14
0
 protected override void Operate(TableBatchOperation batchOperation, ITableEntity entity)
 {
     batchOperation.Replace(entity);
 }
示例#15
0
 public async Task CreateEntityAsync(ITableEntity entity)
 {
     await _table.ExecuteAsync(TableOperation.Insert(entity));
 }
        public static void TrackFailedTableResult(this TelemetryClient telemetryClient, TableResult result, ITableEntity operationEntity = null)
        {
            var resultEntity = result.Result as ITableEntity;
            var properties   = new Dictionary <string, string>
            {
                { "OperationEntity-PartitionKey", operationEntity?.PartitionKey ?? "<none>" },
                { "OperationEntity-RowKey", operationEntity?.RowKey ?? "<none>" },
                { "Result-HttpStatusCode", result.HttpStatusCode.ToString() },
                { "ResultEntity-PartitionKey", resultEntity?.PartitionKey ?? "<none>" },
                { "ResultEntity-RowKey", resultEntity?.RowKey ?? "<none>" },
            };

            telemetryClient.TrackEvent("FailedTableResult", properties);
        }
        public static void TrackInvalidTableEntry(this TelemetryClient telemetryClient, ITableEntity entity)
        {
            var properties = new Dictionary <string, string>
            {
                { "PartitionKey", entity.PartitionKey },
                { "RowKey", entity.RowKey },
            };

            telemetryClient.TrackEvent("InvalidTableEntry", properties);
        }
示例#18
0
 public static Include Replace(ITableEntity entity)
 {
     return new Include(IncludeType.Replace, new EntityOperation.Replace(entity));
 }
示例#19
0
 public InsertOrMerge(ITableEntity entity)
     : base(entity)
 {
 }
        internal static void ReadAndUpdateTableEntityWithEdmTypeResolver(ITableEntity entity, Dictionary <string, string> entityAttributes, EntityReadFlags flags, Func <string, string, string, string, EdmType> propertyResolver, OperationContext ctx)
        {
            Dictionary <string, EntityProperty> entityProperties           = (flags & EntityReadFlags.Properties) > 0 ? new Dictionary <string, EntityProperty>() : null;
            Dictionary <string, EdmType>        propertyResolverDictionary = null;

            // Try to add the dictionary to the cache only if it is not a DynamicTableEntity. If DisablePropertyResolverCache is true, then just use reflection and generate dictionaries for each entity.
            if (entity.GetType() != typeof(DynamicTableEntity))
            {
#if WINDOWS_DESKTOP && !WINDOWS_PHONE
                if (!TableEntity.DisablePropertyResolverCache)
                {
                    propertyResolverDictionary = TableEntity.PropertyResolverCache.GetOrAdd(entity.GetType(), TableOperationHttpResponseParsers.CreatePropertyResolverDictionary);
                }
                else
                {
                    Logger.LogVerbose(ctx, SR.PropertyResolverCacheDisabled);
                    propertyResolverDictionary = TableOperationHttpResponseParsers.CreatePropertyResolverDictionary(entity.GetType());
                }
#else
                propertyResolverDictionary = TableOperationHttpResponseParsers.CreatePropertyResolverDictionary(entity.GetType());
#endif
            }

            if (flags > 0)
            {
                foreach (KeyValuePair <string, string> prop in entityAttributes)
                {
                    if (prop.Key == TableConstants.PartitionKey)
                    {
                        entity.PartitionKey = (string)prop.Value;
                    }
                    else if (prop.Key == TableConstants.RowKey)
                    {
                        entity.RowKey = (string)prop.Value;
                    }
                    else if (prop.Key == TableConstants.Timestamp)
                    {
                        if ((flags & EntityReadFlags.Timestamp) == 0)
                        {
                            continue;
                        }

                        entity.Timestamp = DateTime.Parse(prop.Value, CultureInfo.InvariantCulture);
                    }
                    else if ((flags & EntityReadFlags.Properties) > 0)
                    {
                        if (propertyResolver != null)
                        {
                            Logger.LogVerbose(ctx, SR.UsingUserProvidedPropertyResolver);
                            try
                            {
                                EdmType type = propertyResolver(entity.PartitionKey, entity.RowKey, prop.Key, prop.Value);
                                Logger.LogVerbose(ctx, SR.AttemptedEdmTypeForTheProperty, prop.Key, type.GetType().ToString());
                                try
                                {
                                    entityProperties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value, type.GetType()));
                                }
                                catch (FormatException ex)
                                {
                                    throw new StorageException(string.Format(CultureInfo.InvariantCulture, SR.FailParseProperty, prop.Key, prop.Value, type.ToString()), ex)
                                          {
                                              IsRetryable = false
                                          };
                                }
                            }
                            catch (StorageException)
                            {
                                throw;
                            }
                            catch (Exception ex)
                            {
                                throw new StorageException(SR.PropertyResolverThrewError, ex)
                                      {
                                          IsRetryable = false
                                      };
                            }
                        }
                        else if (entity.GetType() != typeof(DynamicTableEntity))
                        {
                            EdmType edmType;
                            Logger.LogVerbose(ctx, SR.UsingDefaultPropertyResolver);

                            if (propertyResolverDictionary != null)
                            {
                                propertyResolverDictionary.TryGetValue(prop.Key, out edmType);
                                Logger.LogVerbose(ctx, SR.AttemptedEdmTypeForTheProperty, prop.Key, edmType);
                                entityProperties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value, edmType));
                            }
                        }
                        else
                        {
                            Logger.LogVerbose(ctx, SR.NoPropertyResolverAvailable);
                            entityProperties.Add(prop.Key, EntityProperty.CreateEntityPropertyFromObject(prop.Value, typeof(string)));
                        }
                    }
                }

                if ((flags & EntityReadFlags.Properties) > 0)
                {
                    entity.ReadEntity(entityProperties, ctx);
                }
            }
        }
示例#21
0
 public Delete(ITableEntity entity)
     : base(entity)
 {
 }
示例#22
0
 /// <summary>
 /// Insert or update the record in table
 /// </summary>
 /// <param name="entity">Entity</param>
 public virtual async Task <TableResult> InsertOrReplace(ITableEntity entity)
 {
     return(await this.reference.ExecuteAsync(TableOperation.InsertOrReplace(entity)).ConfigureAwait(false));
 }
示例#23
0
 void InsertTestEntity(ITableEntity entity)
 {
     entity.PartitionKey = partition.PartitionKey;
     table.Execute(TableOperation.Insert(entity));
 }
示例#24
0
 /// <summary>
 /// Creates a new table operation that inserts the given entity
 /// into a table.
 /// </summary>
 /// <param name="entity">The <see cref="ITableEntity"/> object to be inserted into the table.</param>
 /// <returns>The <see cref="TableOperation"/> object.</returns>
 public static TableOperation Insert(ITableEntity entity)
 {
     return(Insert(entity, false));
 }
        /// <summary>
        /// Creates a new table operation that inserts the given entity
        /// into a table if the entity does not exist; if the entity does
        /// exist then its contents are replaced with the provided entity.
        /// </summary>
        /// <param name="entity">The <see cref="ITableEntity"/> object to be inserted or replaced.</param>
        /// <returns>The <see cref="TableOperation"/> object.</returns>
        public static TableOperation InsertOrReplace(ITableEntity entity)
        {
            // Validate the arguments.
            CommonUtility.AssertNotNull("entity", entity);

            // Create and return the table operation.
            return new TableOperation(entity, TableOperationType.InsertOrReplace);
        }
示例#26
0
 /// <summary>
 /// Creates a new instance of the <see cref="TableOperation"/> class given the
 /// entity to operate on and the type of operation that is being
 /// performed.
 /// </summary>
 /// <param name="entity">The entity on which the operation is being performed.</param>
 /// <param name="operationType">The type of operation.</param>
 internal TableOperation(ITableEntity entity, TableOperationType operationType)
     : this(entity, operationType, true)
 {
 }
 /// <summary>
 /// Creates a new instance of the <see cref="TableOperation"/> class given the
 /// entity to operate on and the type of operation that is being
 /// performed.
 /// </summary>
 /// <param name="entity">The entity on which the operation is being performed.</param>
 /// <param name="operationType">The type of operation.</param>
 internal TableOperation(ITableEntity entity, TableOperationType operationType)
     : this(entity, operationType, true)
 {
 }
示例#28
0
        public static async Task <TableResult> InsertWithRetryAsync(this CloudTable table, ITableEntity entity, int retries = 5)
        {
            var op = TableOperation.Insert(entity);

            TableResult result = null;

            for (int i = 0; i < retries; i++)
            {
                try
                {
                    result = await table.ExecuteAsync(op);

                    break;
                }
                catch (StorageException)
                {
                    table.CreateIfNotExists();
                }
            }

            return(result);
        }
 //データの追加関数
 void Execute(ITableEntity name) {
   TableOperation insertOperation = TableOperation.Insert(name);
   table.Execute(insertOperation);
 }
        void TranslateOperationForNewTable(
            TableOperation op, MTableEntity existingEntity, bool leaveTombstones,
            ref TableOperation newOp, ref HttpStatusCode?errorCode)
        {
            ITableEntity       passedEntity = op.GetEntity();
            TableOperationType opType       = op.GetOperationType();

            switch (opType)
            {
            case TableOperationType.Insert:
                if (existingEntity == null)
                {
                    newOp = TableOperation.Insert(ChainTableUtils.CopyEntity <MTableEntity>(passedEntity));
                }
                else if (existingEntity.deleted)
                {
                    newOp = TableOperation.Replace(ImportWithIfMatch(passedEntity, existingEntity.ETag));
                }
                else
                {
                    errorCode = HttpStatusCode.Conflict;
                }
                break;

            case TableOperationType.Replace:
                if ((errorCode = CheckExistingEntity(passedEntity, existingEntity)) == null)
                {
                    newOp = TableOperation.Replace(ImportWithIfMatch(passedEntity, existingEntity.ETag));
                }
                break;

            case TableOperationType.Merge:
                if ((errorCode = CheckExistingEntity(passedEntity, existingEntity)) == null)
                {
                    newOp = TableOperation.Merge(ImportWithIfMatch(passedEntity, existingEntity.ETag));
                }
                break;

            case TableOperationType.Delete:
                string buggablePartitionKey, buggableRowKey;
                if (IsBugEnabled(MTableOptionalBug.DeletePrimaryKey))
                {
                    buggablePartitionKey = buggableRowKey = null;
                }
                else
                {
                    buggablePartitionKey = passedEntity.PartitionKey;
                    buggableRowKey       = passedEntity.RowKey;
                }
                if (leaveTombstones)
                {
                    if (passedEntity.ETag == ChainTable2Constants.ETAG_DELETE_IF_EXISTS)
                    {
                        newOp = TableOperation.InsertOrReplace(new MTableEntity {
                            PartitionKey = buggablePartitionKey, RowKey = buggableRowKey, deleted = true
                        });
                    }
                    else if ((errorCode = CheckExistingEntity(passedEntity, existingEntity)) == null)
                    {
                        newOp = TableOperation.Replace(new MTableEntity {
                            PartitionKey = buggablePartitionKey, RowKey = buggableRowKey,
                            deleted      = true, ETag = existingEntity.ETag
                        });
                    }
                }
                else
                {
                    if (passedEntity.ETag == ChainTable2Constants.ETAG_DELETE_IF_EXISTS)
                    {
                        newOp = TableOperation.Delete(new MTableEntity {
                            PartitionKey = buggablePartitionKey, RowKey = buggableRowKey,
                            // It's OK to delete the entity and return success whether or not
                            // the entity is a tombstone by the time it is actually deleted.
                            ETag = IsBugEnabled(MTableOptionalBug.DeleteNoLeaveTombstonesETag) ? null : ChainTable2Constants.ETAG_DELETE_IF_EXISTS
                        });
                    }
                    else if ((errorCode = CheckExistingEntity(passedEntity, existingEntity)) == null)
                    {
                        // Another client in USE_NEW_WITH_TOMBSTONES could concurrently replace the
                        // entity with a tombstone, in which case we need to return 404 to the caller,
                        // hence this needs to be conditioned on the existing ETag.
                        newOp = TableOperation.Delete(new MTableEntity {
                            PartitionKey = buggablePartitionKey, RowKey = buggableRowKey,
                            ETag         = IsBugEnabled(MTableOptionalBug.DeleteNoLeaveTombstonesETag) ? null : existingEntity.ETag
                        });
                    }
                }
                break;

            case TableOperationType.InsertOrReplace:
                newOp = TableOperation.InsertOrReplace(ChainTableUtils.CopyEntity <MTableEntity>(passedEntity));
                break;

            case TableOperationType.InsertOrMerge:
                newOp = TableOperation.InsertOrMerge(ChainTableUtils.CopyEntity <MTableEntity>(passedEntity));
                break;

            default:
                throw new NotImplementedException();
            }
        }
 public void Delete(ITableEntity note)
 {
     // Create the Delete TableOperation.
     var deleteOperation = TableOperation.Delete(note);
     // Execute the operation.
     _table.Execute(deleteOperation);
 }
        async Task <IList <TableResult> > ExecuteBatchOnNewTableAsync(MTableConfiguration config,
                                                                      TableBatchOperation batch, TableRequestOptions requestOptions, OperationContext operationContext)
        {
            string partitionKey = ChainTableUtils.GetBatchPartitionKey(batch);

            await EnsurePartitionSwitchedAsync(partitionKey, requestOptions, operationContext);

            if (config.state <= TableClientState.PREFER_NEW)
            {
                await EnsureAffectedRowsMigratedAsync(batch, requestOptions, operationContext);
            }

            Attempt:
            // Batch on new table.
            var query = GenerateQueryForAffectedRows(batch);
            IList <MTableEntity> newRows = await newTable.ExecuteQueryAtomicAsync(query, requestOptions, operationContext);

            Dictionary <string, MTableEntity> newDict = newRows.ToDictionary(ent => ent.RowKey);
            // NOTE!  At this point, the read has not yet been annotated.  It is annotated below.

            var newBatch = new TableBatchOperation();
            var inputToNewTableIndexMapping = new List <int?>();

            for (int i = 0; i < batch.Count; i++)
            {
                TableOperation op             = batch[i];
                ITableEntity   passedEntity   = op.GetEntity();
                MTableEntity   existingEntity = newDict.GetValueOrDefault(passedEntity.RowKey);
                TableOperation newOp          = null;
                HttpStatusCode?errorCode      = null;

                TranslateOperationForNewTable(
                    op, existingEntity, config.state <= TableClientState.USE_NEW_WITH_TOMBSTONES,
                    ref newOp, ref errorCode);

                if (errorCode != null)
                {
                    Debug.Assert(newOp == null);
                    await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true);

                    throw ChainTableUtils.GenerateBatchException(errorCode.Value, i);
                }
                Debug.Assert(newOp != null);
                inputToNewTableIndexMapping.Add(newBatch.Count);
                newBatch.Add(newOp);
            }
            await monitor.AnnotateLastBackendCallAsync();

            IList <TableResult> newResults;

            try
            {
                newResults = await newTable.ExecuteBatchAsync(newBatch, requestOptions, operationContext);
            }
            catch (ChainTableBatchException)
            {
                // XXX: Try to distinguish expected concurrency exceptions from unexpected exceptions?
                await monitor.AnnotateLastBackendCallAsync();

                goto Attempt;
            }

            // We made it!
            var results = new List <TableResult>();

            for (int i = 0; i < batch.Count; i++)
            {
                ITableEntity passedEntity  = batch[i].GetEntity();
                int?         newTableIndex = inputToNewTableIndexMapping[i];
                string       newETag       =
                    (IsBugEnabled(MTableOptionalBug.TombstoneOutputETag)
                    ? newTableIndex != null
                    : batch[i].GetOperationType() == TableOperationType.Delete)
                    ? null : newResults[newTableIndex.Value].Etag;
                if (newETag != null)
                {
                    passedEntity.ETag = newETag;
                }
                results.Add(new TableResult
                {
                    HttpStatusCode = (int)(
                        (batch[i].GetOperationType() == TableOperationType.Insert) ? HttpStatusCode.Created : HttpStatusCode.NoContent),
                    Etag   = newETag,
                    Result = passedEntity,
                });
            }
            await monitor.AnnotateLastBackendCallAsync(wasLinearizationPoint : true, successfulBatchResult : results);

            return(results);
        }
示例#33
0
 public static Include Insert(ITableEntity entity)
 {
     return new Include(IncludeType.Insert, new EntityOperation.Insert(entity));
 }
示例#34
0
 protected abstract void Operate(TableBatchOperation batchOperation, ITableEntity entity);
示例#35
0
 public Insert(ITableEntity entity)
     : base(entity)
 {
 }
示例#36
0
        internal ExecutionInfo Bind()
        {
            ExecutionInfo retVal = new ExecutionInfo();

            // IQueryable impl
            if (this.Expression != null)
            {
                Dictionary <Expression, Expression> normalizerRewrites = new Dictionary <Expression, Expression>(ReferenceEqualityComparer <Expression> .Instance);

                // Step 1. Evaluate any local evaluatable expressions ( lambdas etc)
                Expression partialEvaluatedExpression = Evaluator.PartialEval(this.Expression);

                // Step 2. Normalize expression, replace String Comparisons etc.
                Expression normalizedExpression = ExpressionNormalizer.Normalize(partialEvaluatedExpression, normalizerRewrites);

                // Step 3. Bind Expression, Analyze predicates and create query option expressions. End result is a single ResourceSetExpression
                Expression boundExpression = ResourceBinder.Bind(normalizedExpression);

                // Step 4. Parse the Bound expression into sub components, i.e. take count, filter, select columns, request options, opcontext, etc.
                ExpressionParser parser = new ExpressionParser();
                parser.Translate(boundExpression);

                // Step 5. Store query components & params
                this.TakeCount          = parser.TakeCount;
                this.FilterString       = parser.FilterString;
                this.SelectColumns      = parser.SelectColumns;
                retVal.RequestOptions   = parser.RequestOptions;
                retVal.OperationContext = parser.OperationContext;

                // Step 6. If projection & no resolver then generate a resolver to perform the projection
                if (parser.Resolver == null)
                {
                    if (parser.Projection != null && parser.Projection.Selector != ProjectionQueryOptionExpression.DefaultLambda)
                    {
                        Type intermediateType = parser.Projection.Selector.Parameters[0].Type;

                        // Convert Expression to take type object as input to allow for direct invocation.
                        ParameterExpression paramExpr = Expression.Parameter(typeof(object));

                        Func <object, TElement> projectorFunc = Expression.Lambda <Func <object, TElement> >(
                            Expression.Invoke(parser.Projection.Selector, Expression.Convert(paramExpr, intermediateType)), paramExpr).Compile();

                        // Generate a resolver to do the projection.
                        retVal.Resolver = (pk, rk, ts, props, etag) =>
                        {
                            // Parse to intermediate type
                            ITableEntity intermediateObject = (ITableEntity)EntityUtilities.InstantiateEntityFromType(intermediateType);
                            intermediateObject.PartitionKey = pk;
                            intermediateObject.RowKey       = rk;
                            intermediateObject.Timestamp    = ts;
                            intermediateObject.ReadEntity(props, parser.OperationContext);
                            intermediateObject.ETag = etag;

                            // Invoke lambda expression
                            return(projectorFunc(intermediateObject));
                        };
                    }
                    else
                    {
                        // No op - No resolver or projection specified.
                    }
                }
                else
                {
                    retVal.Resolver = (EntityResolver <TElement>)parser.Resolver.Value;
                }
            }

            retVal.RequestOptions   = TableRequestOptions.ApplyDefaults(retVal.RequestOptions, this.queryProvider.Table.ServiceClient);
            retVal.OperationContext = retVal.OperationContext ?? new OperationContext();
            return(retVal);
        }
示例#37
0
 public InsertOrReplace(ITableEntity entity)
     : base(entity)
 {
 }
 internal static void ReadAndUpdateTableEntityWithEdmTypeResolver(ITableEntity entity, Dictionary <string, string> entityAttributes, EntityReadFlags flags, Func <string, string, string, string, EdmType> propertyResolver, OperationContext ctx)
 {
     throw new System.NotImplementedException();
 }
示例#39
0
 public Replace(ITableEntity entity)
     : base(entity)
 {
 }
        private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer)
        {
            ODataEntry entry = new ODataEntry()
            {
                Properties = GetPropertiesWithKeys(entity, ctx)
            };

            if (operationType != TableOperationType.Insert && operationType != TableOperationType.Retrieve)
            {
                entry.ETag = entity.ETag;
            }

            writer.WriteStart(entry);
            writer.WriteEnd();
            writer.Flush();
        }
示例#41
0
 private static ITableEntity ResetETag(ITableEntity entity)
 {
     entity.ETag = entity.ETag ?? "*";
     return entity;
 }
        private static void WriteOdataEntity(ITableEntity entity, TableOperationType operationType, OperationContext ctx, ODataWriter writer, TableRequestOptions options)
        {
            ODataEntry entry = new ODataEntry()
            {
                Properties = GetPropertiesWithKeys(entity, ctx, operationType, options),
                TypeName = "account.sometype"
            };

            entry.SetAnnotation(new SerializationTypeNameAnnotation { TypeName = null });
            writer.WriteStart(entry);
            writer.WriteEnd();
            writer.Flush();
        }
示例#43
0
 /// <summary>
 /// Deletes the specified entity.
 /// </summary>
 /// <param name="entity">The entity.</param>
 /// <returns>A new instance of <see cref="Include"/> class</returns>
 /// <exception cref="ArgumentNullException">If given <paramref name="entity"/> is <c>null</c>.</exception>
 public static Include Delete(ITableEntity entity)
 {
     Requires.NotNull(entity, "entity");
     return new Include(IncludeType.Delete, new EntityOperation.Delete(entity));
 }
 internal static string ReadAndUpdateTableEntity(ITableEntity entity, ODataEntry entry, EntityReadFlags flags, OperationContext ctx)
 {
     throw new System.NotImplementedException();
 }
        internal static List<ODataProperty> GetPropertiesWithKeys(ITableEntity entity, OperationContext operationContext)
        {
            List<ODataProperty> retProps = GetPropertiesFromDictionary(entity.WriteEntity(operationContext));

            if (entity.PartitionKey != null)
            {
                retProps.Add(new ODataProperty() { Name = TableConstants.PartitionKey, Value = entity.PartitionKey });
            }

            if (entity.RowKey != null)
            {
                retProps.Add(new ODataProperty() { Name = TableConstants.RowKey, Value = entity.RowKey });
            }

            return retProps;
        }
        /// <summary>
        /// Creates a new table operation that inserts the given entity
        /// into a table.
        /// </summary>
        /// <param name="entity">The <see cref="ITableEntity"/> object to be inserted into the table.</param>
        /// <param name="echoContent"><c>true</c> if the message payload should be returned in the response to the insert operation. <c>false</c> otherwise.</param>
        /// <returns>The <see cref="TableOperation"/> object.</returns>
        public static TableOperation Insert(ITableEntity entity, bool echoContent)
        {
            // Validate the arguments.
            CommonUtility.AssertNotNull("entity", entity);

            // Create and return the table operation.
            return new TableOperation(entity, TableOperationType.Insert, echoContent);
        }
        internal static IEnumerable<ODataProperty> GetPropertiesWithKeys(ITableEntity entity, OperationContext operationContext, TableOperationType operationType, TableRequestOptions options)
        {
            if (operationType == TableOperationType.Insert)
            {
                if (entity.PartitionKey != null)
                {
                    yield return new ODataProperty() { Name = TableConstants.PartitionKey, Value = entity.PartitionKey };
                }

                if (entity.RowKey != null)
                {
                    yield return new ODataProperty() { Name = TableConstants.RowKey, Value = entity.RowKey };
                }
            }

            foreach (ODataProperty property in GetPropertiesFromDictionary(entity.WriteEntity(operationContext), options, entity.PartitionKey, entity.RowKey))
            {
                yield return property;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TableTransactionAction"/>
 /// </summary>
 /// <param name="actionType"> The operation type to be applied to the <paramref name="entity"/></param>
 /// <param name="entity">The table entity to which the <paramref name="actionType"/> will be applied.</param>
 public TableTransactionAction(TableTransactionActionType actionType, ITableEntity entity) : this(actionType, entity, default)
 {
 }