Example #1
0
        public async Task <IdentityResult> DeleteAsync(ApplicationUser user, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var tableName = "ApplicationUser";
            Dictionary <string, AttributeValue> deleteDict = new Dictionary <string, AttributeValue>();

            deleteDict.Add("NormalizedUserName", new AttributeValue(user.NormalizedUserName.ToLower()));
            await _client.DeleteItemAsync(tableName, deleteDict, cancellationToken);

            return(IdentityResult.Success);
        }
Example #2
0
        /// <summary>
        /// Delete item from a DynamoDB table.
        /// </summary>
        /// <param name="client">An initialized DynamoDB client.</param>
        /// <param name="table">The table from which the item will be removed.</param>
        /// <param name="id">The Id of the item to remove.</param>
        /// <param name="area">A string representing the value of the Area attribute.</param>
        /// <returns>A DeleteItemResponse object representing the response from the
        /// DeleteItemAsync call.</returns>
        public static async Task <DeleteItemResponse> RemoveItemAsync(
            IAmazonDynamoDB client,
            string table,
            string id,
            string area)
        {
            var request = new DeleteItemRequest
            {
                TableName = table,
                Key       = new Dictionary <string, AttributeValue>()
                {
                    {
                        "ID",
                        new AttributeValue {
                            S = id
                        }
                    },
                    {
                        "Area",
                        new AttributeValue {
                            S = area
                        }
                    },
                },
            };

            var response = await client.DeleteItemAsync(request);

            return(response);
        }
 public async Task DeleteSession(string sessionId)
 {
     await dynamoDb.DeleteItemAsync(TableName, new Dictionary <string, AttributeValue>
     {
         { "SessionId", new AttributeValue(sessionId) }
     });
 }
        public async Task DeleteAllBuddies()
        {
            var request = new ScanRequest
            {
                TableName = _tableName
            };

            var response = await _dynamoDbClient.ScanAsync(request);

            var items = response.Items.Select(Map);

            foreach (var item in items)
            {
                var deleteRequest = new DeleteItemRequest
                {
                    TableName = _tableName,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        ["Id"] = new AttributeValue {
                            S = item.Id
                        }
                    }
                };

                await _dynamoDbClient.DeleteItemAsync(deleteRequest);
            }
        }
        public async Task <APIGatewayProxyResponse> FunctionHandler(APIGatewayProxyRequest request, ILambdaContext context)
        {
            LambdaLogger.Log(JObject.FromObject(request).ToString());
            try {
                var connectionId = request.RequestContext.ConnectionId;
                LambdaLogger.Log("ConnectionId:" + connectionId);

                Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>();
                attributes["ConnectionId"] = new AttributeValue {
                    S = connectionId
                };

                DeleteItemRequest ddbRequest = new DeleteItemRequest()
                {
                    TableName = Environment.GetEnvironmentVariable("DynamoChatTable"),
                    Key       = attributes
                };
                DeleteItemResponse ddbResponse = ddbClient.DeleteItemAsync(ddbRequest).Result;

                return(new APIGatewayProxyResponse
                {
                    StatusCode = 200,
                    Body = "Disconnected."
                });
            } catch (Exception e) {
                context.Logger.LogLine("Error connecting: " + e.Message);
                context.Logger.LogLine(e.StackTrace);
                return(new APIGatewayProxyResponse
                {
                    StatusCode = 500,
                    Body = $"Failed to connect: {e.Message}"
                });
            }
        }
        public async Task ServiceClientExampleAsync()
        {
            try
            {
                var request = new DeleteItemRequest
                {
                    TableName = "RetailDatabase",
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { "pk", new AttributeValue {
                              S = "*****@*****.**"
                          } },
                        { "sk", new AttributeValue {
                              S = "metadata"
                          } }
                    }
                };

                var response = await amazonDynamoDB.DeleteItemAsync(request);

                Console.WriteLine($"DeleteItem succeeded.");
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                throw;
            }
        }
Example #7
0
        public async Task ReleaseLock(string Id)
        {
            if (_mutex.WaitOne())
            {
                try
                {
                    _localLocks.Remove(Id);
                }
                finally
                {
                    _mutex.Set();
                }
            }

            try
            {
                var req = new DeleteItemRequest()
                {
                    TableName = _tableName,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { "id", new AttributeValue(Id) }
                    },
                    ConditionExpression       = "lock_owner = :nodeId",
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                    {
                        { ":nodeId", new AttributeValue(_nodeId) }
                    }
                };
                await _client.DeleteItemAsync(req);
            }
            catch (ConditionalCheckFailedException)
            {
            }
        }
Example #8
0
        public async Task <DeleteItemResponse> DeleteItems <T>(T tabelaInterna, string nomeTabela)
        {
            try
            {
                table = Table.LoadTable(_dynamoClient, nomeTabela);
                //
                DynamoDBContext db = new DynamoDBContext(_dynamoClient);
                //
                Document documentRequest = db.ToDocument(tabelaInterna);
                //Mapeando os campos
                chave = table.ToAttributeMap(documentRequest);
                //Verificar quais campos são necessarios
                chave = Utils.VerificarChaves(chave, table);
                //
                var deleteRequest = new DeleteItemRequest(nomeTabela, chave);
                //
                var deleteResponse = await _dynamoClient.DeleteItemAsync(deleteRequest, cancellationToken);

                //
                db.Dispose();
                //
                return(deleteResponse);
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task ReleaseLock(string Id)
        {
            _lockTracker.Remove(Id);

            try
            {
                var req = new DeleteItemRequest()
                {
                    TableName = _tableName,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { "id", new AttributeValue(Id) }
                    },
                    ConditionExpression       = "lock_owner = :node_id",
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                    {
                        { ":node_id", new AttributeValue(_nodeId) }
                    }
                };
                await _client.DeleteItemAsync(req);
            }
            catch (ConditionalCheckFailedException)
            {
            }
        }
Example #10
0
 public static async Task Movies_Remove(this IAmazonDynamoDB ddb, Guid id)
 {
     await ddb.DeleteItemAsync(new DeleteItemRequest
     {
         TableName = TableNames.Movies,
         Key       = Keys.Movies(id),
     });
 }
Example #11
0
 public Task DeleteTask(string messgageId)
 {
     return(_dynamoClient.DeleteItemAsync(_tableName, new Dictionary <string, AttributeValue> {
         [TASK_ID] = new AttributeValue {
             S = messgageId
         }
     }));
 }
Example #12
0
 public Task DeleteRowAsync(string connectionId)
 => _dynamoDbClient.DeleteItemAsync(new DeleteItemRequest {
     TableName = _tableName,
     Key       = new Dictionary <string, AttributeValue> {
         ["ConnectionId"] = new AttributeValue {
             S = connectionId
         }
     }
 });
Example #13
0
 public async Task DeleteItemAsync(string pkId, string skId)
 {
     var dbItemKey = DynamoDBKey(pkId, skId);
     var delItemRq = new DeleteItemRequest
     {
         TableName = TableName,
         Key       = dbItemKey.ToDictionary()
     };
     var result = await _dynamoDbClient.DeleteItemAsync(delItemRq);
 }
Example #14
0
        public static async Task <DeleteItemResponse> DeleteItem(this IAmazonDynamoDB ddb, IDynamoConfig cfg, string pk, string sk)
        {
            var request = new DeleteItemRequest {
                TableName = cfg.TableName
            };

            request.Key.Add(cfg.PkName, new AttributeValue(pk));
            request.Key.Add(cfg.SkName, new AttributeValue(sk));
            return(await ddb.DeleteItemAsync(request));
        }
Example #15
0
        public async Task Delete <T>(T entity) where T : Base, new()
        {
            var request = new DeleteItemRequest
            {
                TableName = entity.GetTableName(),
                Key       = entity.GetKey()
            };

            if (writeActions == null)
            {
                await amazonDynamoDB.DeleteItemAsync(request);
            }
            else
            {
                writeActions.Add(new TransactWriteItem
                {
                    Delete = request.Map()
                });
            }
        }
Example #16
0
        public async Task <int> DeleteItemAsync(Entity item)
        {
            var dbItem = new Dictionary <string, AttributeValue>();

            dbItem.Add("user_id", new AttributeValue(item.UserId));
            dbItem.Add("entity_id", new AttributeValue(item.Id));

            var result = await _dynamoDbClient.DeleteItemAsync(_tableName, dbItem, ReturnValue.ALL_OLD);

            return(result.Attributes.Count);
        }
 public async Task TerminateSubscription(string eventSubscriptionId, CancellationToken cancellationToken = default)
 {
     var request = new DeleteItemRequest
     {
         TableName = $"{_tablePrefix}-{SUBCRIPTION_TABLE}",
         Key       = new Dictionary <string, AttributeValue>
         {
             { "id", new AttributeValue(eventSubscriptionId) }
         }
     };
     await _client.DeleteItemAsync(request, cancellationToken);
 }
 public async Task ClearTableItems(ICollection <TestEntity> entities)
 {
     foreach (var entity in entities)
     {
         await _dynamoDbClient.DeleteItemAsync(_configuration.TableName,
                                               new Dictionary <string, AttributeValue>
         {
             { _configuration.PartitionKey, new AttributeValue(entity.PartitionKey) },
             { _configuration.SortKey, new AttributeValue(entity.SortKey) }
         });
     }
 }
Example #19
0
 public void Delete(int tableNumber)
 {
     _client.DeleteItemAsync(
         tableName: _tableName,
         key: new Dictionary <string, AttributeValue>
     {
         { "tableNumber", new AttributeValue {
               N = tableNumber.ToString()
           } }
     }
         ).Wait();
 }
        public async Task <DeleteItemResponse> DeleteDetails(DeleteItemRequest request)
        {
            try
            {
                var response = await _amazonDynamoDb.DeleteItemAsync(request);

                return(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public async Task DeleteRecordByKey(string key)
        {
            var item = new ItemRecord();

            var response = await _dynamoClient.DeleteItemAsync(_tableName, ConstructKeyDictionary(key));

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                return;
            }

            throw new Exception($"Delete failed, server returned status {response.HttpStatusCode}");
        }
Example #22
0
        public async Task <APIGatewayProxyResponse> OnDisconnect(APIGatewayProxyRequest request, ILambdaContext context)
        {
            try
            {
                // Using JObject instead of APIGatewayProxyRequest till APIGatewayProxyRequest gets updated with DomainName and ConnectionId
                var connectionId = request.RequestContext.ConnectionId;
                context.Logger.LogLine($"ConnectionId: {connectionId}");
                var body       = JObject.FromObject(request).ToString();
                var ddbRequest = new DeleteItemRequest
                {
                    TableName = Constants.WEBSOCKET_TABLE,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { Constants.ConnectionIdField, new AttributeValue {
                              S = connectionId
                          } }
                    }
                };

                await _ddbClient.DeleteItemAsync(ddbRequest);

                return(new APIGatewayProxyResponse
                {
                    StatusCode = 200,
                    Body = "Disconnected."
                });
            }
            catch (Exception e)
            {
                context.Logger.LogLine("Error disconnecting: " + e.Message);
                context.Logger.LogLine(e.StackTrace);
                return(new APIGatewayProxyResponse
                {
                    StatusCode = 500,
                    Body = $"Failed to disconnect: {e.Message}"
                });
            }
        }
        public async Task DeletePokemon(int pokemonNumber)
        {
            var request = new DeleteItemRequest
            {
                TableName = _tableName,
                Key       = new Dictionary <string, AttributeValue> {
                    { "Number", new AttributeValue {
                          N = pokemonNumber.ToString()
                      } }
                }
            };

            await _amazonDynamoDb.DeleteItemAsync(request);
        }
Example #24
0
 /// <summary>
 /// Deletes a user by id.
 /// </summary>
 /// <param name="id">Id of the user to be deleted.</param>
 public async void Delete(int id)
 {
     await _dynamoDBClient.DeleteItemAsync(new DeleteItemRequest()
     {
         TableName = "dotnetcore-react-redux-users",
         Key       = new Dictionary <string, AttributeValue>()
         {
             ["id"] = new AttributeValue()
             {
                 N = id.ToString()
             }
         }
     });
 }
Example #25
0
        public async Task <Item> DeleteItems(int id)
        {
            var deleteItem        = _getItem.GetItems(id);
            var registerDateTime  = deleteItem.Result.Items.Select(x => x.RegisterDateTime).FirstOrDefault();
            var deleteItemRequest = DeleteItemRequest(id, registerDateTime);
            var response          = await _amazonDynamoDB.DeleteItemAsync(deleteItemRequest);

            return(new Item
            {
                Id = Convert.ToInt32(response.Attributes["Id"].N),
                Price = Convert.ToDouble(response.Attributes["Price"].N),
                RegisterDateTime = response.Attributes["RegisterDateTime"].N
            });
        }
        public async Task DeleteImage(string id)
        {
            var attributes = new Dictionary <string, AttributeValue>
            {
                { "Id", new AttributeValue {
                      S = id
                  } }
            };

            _log.LogInformation($"Begin delete row data");
            await _dynamoDb.DeleteItemAsync(
                tableName : "azb.our-photos.images.test",
                key : attributes
                );

            _log.LogInformation($"End delete row data");

            _log.LogInformation($"Begin S3 delete thumbnail");
            var thumbnail = new DeleteObjectRequest
            {
                BucketName = _options.FullImage,
                Key        = id
            };
            await _s3client.DeleteObjectAsync(thumbnail);

            _log.LogInformation($"End S3 S3 delete thumbnail");

            _log.LogInformation($"Begin S3 delete image");
            var fullImage = new DeleteObjectRequest
            {
                BucketName = _options.FullImage,
                Key        = id
            };
            await _s3client.DeleteObjectAsync(fullImage);

            _log.LogInformation($"End S3 S3 delete image");
        }
        public async Task <Result> DeleteItemsComplex(int iteration)
        {
            var request = new DeleteItemRequest
            {
                TableName = "Benchmarking",
                Key       = new Dictionary <string, AttributeValue>
                {
                    { "Id", new AttributeValue {
                          N = "0"
                      } }
                }
            };
            var result    = new Result();
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            for (int i = 0; i < iteration; ++i)
            {
                request.Key["Id"] = new AttributeValue {
                    N = $"{i}"
                };

                await amazonDynamoDB.DeleteItemAsync(request);
            }

            stopwatch.Stop();

            result.Count       = iteration;
            result.TimeTaken   = stopwatch.Elapsed;
            result.Description = $"Delete {iteration} items in table (Complex)";
            result.Service     = repositoryName;
            result.Simple      = false;
            result.Method      = "Delete";

            return(result);
        }
Example #28
0
        public async Task Delete(string id)
        {
            var request = new DeleteItemRequest
            {
                TableName = TableName,
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "id", new AttributeValue {
                          S = id
                      } }
                }
            };

            await _amazonDynamoDb.DeleteItemAsync(request);
        }
Example #29
0
        public async Task <bool> RemoveAsync(int subscriptionId)
        {
            var deleteItemRequest = new DeleteItemRequest
            {
                TableName = _tableName,
                Key       = new Dictionary <string, AttributeValue> {
                    { "chatid", new AttributeValue {
                          S = subscriptionId.ToString()
                      } }
                }
            };
            var response = await _amazonDynamoDB.DeleteItemAsync(deleteItemRequest);

            return(response.HttpStatusCode == System.Net.HttpStatusCode.OK);
        }
Example #30
0
        public void AddUpdateNginxConfigRepository(string pidUriString)
        {
            Uri pidUri = new Uri(pidUriString);
            Dictionary <string, AttributeValue> attributes = new Dictionary <string, AttributeValue>();

            // PidUri is hash-key
            attributes["pid_uri"] = new AttributeValue {
                S = pidUri.ToString()
            };

            //Try deleting if there is an existing entry in dynamoDB
            try
            {
                _amazonDynamoDbService.DeleteItemAsync(_nginxConfigDynamoDbTable, attributes);
            }
            catch (System.Exception ex)
            {
                _logger.LogInformation($"ProxyConfigService: could not delete Nginx Config before Added/Updated for : {pidUri} Error {ex.StackTrace}", pidUri, ex);
            }

            // Title is range-key
            attributes["configString"] = new AttributeValue {
                S = GetProxyConfigurationByPidUri(pidUri)
            };

            //Add new Entry
            try
            {
                _amazonDynamoDbService.PutItemAsync(_nginxConfigDynamoDbTable, attributes);
                _logger.LogInformation($"ProxyConfigService: Nginx Config Added/Updated for : {pidUri}", pidUri);
            }
            catch (System.Exception ex)
            {
                _logger.LogError($"ProxyConfigService: Error occured while Add & Update DynamoDb: {ex.StackTrace}", ex);
            }
        }