Example #1
0
        protected override Task<object> ExecuteNonQuery(DataRequest request, Dictionary<string, object> options)
        {
            DataQuery query = request.Query;
            string tableName = request.Query.Collection.Name;

            if (String.IsNullOrEmpty(request.Partition)) {
                throw new Exception("Missing partition information to execute request.");
            }

            CloudTableEntity entity;
            if (request.Item != null) {
                entity = (CloudTableEntity)request.Item;
                Script.DeleteField(entity, "id");
                Script.DeleteField(entity, "_");
            }
            else {
                entity = new CloudTableEntity();
            }
            entity.PartitionKey = request.Partition;
            entity.RowKey = query.ID;

            Deferred<object> deferred = Deferred.Create<object>();

            if (request.Operation == DataOperation.Insert) {
                _tableService.InsertEntity(tableName, entity, delegate(Exception e, CloudTableEntity insertedEntity) {
                    if (e != null) {
                        deferred.Reject(e);
                    }
                    else {
                        deferred.Resolve(true);
                    }
                });
            }
            else if (request.Operation == DataOperation.Update) {
                _tableService.MergeEntity(tableName, entity, delegate(Exception e, CloudTableEntity updatedEntity) {
                    if (e != null) {
                        deferred.Reject(e);
                    }
                    else {
                        deferred.Resolve(true);
                    }
                });
            }
            else if (request.Operation == DataOperation.Delete_) {
                _tableService.DeleteEntity(tableName, entity, delegate(Exception e, bool successful) {
                    deferred.Resolve((e == null) && successful);
                });
            }
            else {
                deferred.Resolve(Script.Undefined);
            }

            return deferred.Task;
        }
Example #2
0
        private void CleanEntity(CloudTableEntity entity)
        {
            Dictionary <string, object> metadata = new Dictionary <string, object>();

            metadata["etag"]      = Script.GetField(Script.GetField(entity, "_"), "etag");
            metadata["timestamp"] = Script.GetField(entity, "Timestamp");
            metadata["partition"] = entity.PartitionKey;

            Script.SetField(entity, "_", metadata);
            Script.SetField(entity, "id", entity.RowKey);

            Script.DeleteField(entity, "Timestamp");
            Script.DeleteField(entity, "PartitionKey");
            Script.DeleteField(entity, "RowKey");
        }
Example #3
0
        protected override Task <object> ExecuteNonQuery(DataRequest request, Dictionary <string, object> options)
        {
            DataQuery query     = request.Query;
            string    tableName = request.Query.Collection.Name;

            if (String.IsNullOrEmpty(request.Partition))
            {
                throw new Exception("Missing partition information to execute request.");
            }

            CloudTableEntity entity;

            if (request.Item != null)
            {
                entity = (CloudTableEntity)request.Item;
                Script.DeleteField(entity, "id");
                Script.DeleteField(entity, "_");
            }
            else
            {
                entity = new CloudTableEntity();
            }
            entity.PartitionKey = request.Partition;
            entity.RowKey       = query.ID;

            Deferred <object> deferred = Deferred.Create <object>();

            if (request.Operation == DataOperation.Insert)
            {
                _tableService.InsertEntity(tableName, entity, delegate(Exception e, CloudTableEntity insertedEntity) {
                    if (e != null)
                    {
                        deferred.Reject(e);
                    }
                    else
                    {
                        deferred.Resolve(true);
                    }
                });
            }
            else if (request.Operation == DataOperation.Update)
            {
                _tableService.MergeEntity(tableName, entity, delegate(Exception e, CloudTableEntity updatedEntity) {
                    if (e != null)
                    {
                        deferred.Reject(e);
                    }
                    else
                    {
                        deferred.Resolve(true);
                    }
                });
            }
            else if (request.Operation == DataOperation.Delete_)
            {
                _tableService.DeleteEntity(tableName, entity, delegate(Exception e, bool successful) {
                    deferred.Resolve((e == null) && successful);
                });
            }
            else
            {
                deferred.Resolve(Script.Undefined);
            }

            return(deferred.Task);
        }
Example #4
0
        private void CleanEntity(CloudTableEntity entity)
        {
            Dictionary<string, object> metadata = new Dictionary<string, object>();
            metadata["etag"] = Script.GetField(Script.GetField(entity, "_"), "etag");
            metadata["timestamp"] = Script.GetField(entity, "Timestamp");
            metadata["partition"] = entity.PartitionKey;

            Script.SetField(entity, "_", metadata);
            Script.SetField(entity, "id", entity.RowKey);

            Script.DeleteField(entity, "Timestamp");
            Script.DeleteField(entity, "PartitionKey");
            Script.DeleteField(entity, "RowKey");
        }