Exemplo n.º 1
0
        public void Delete(long id)
        {
            var request = new DeleteItemRequest
            {
                TableName = "employee",
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "id", new AttributeValue {
                          S = id.ToString()
                      } }
                },
                ReturnValues = new ReturnValue("ALL_OLD"),
            };

            DeleteItemResponse x = dynamodbClient.DeleteItemAsync(request).Result;

            if (x.HttpStatusCode != System.Net.HttpStatusCode.OK && x.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception("Unable to delete Employee");
            }

            if (x.Attributes.Count == 0)
            {
                throw new KeyNotFoundException("Employee not found");
            }

            return;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteItemResponse response = new DeleteItemResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("Attributes", targetDepth))
                {
                    var unmarshaller = new DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.Instance, AttributeValueUnmarshaller.Instance);
                    response.Attributes = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ConsumedCapacity", targetDepth))
                {
                    var unmarshaller = ConsumedCapacityUnmarshaller.Instance;
                    response.ConsumedCapacity = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("ItemCollectionMetrics", targetDepth))
                {
                    var unmarshaller = ItemCollectionMetricsUnmarshaller.Instance;
                    response.ItemCollectionMetrics = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Exemplo n.º 3
0
        protected override void deleteItem()
        {
            var request = new DeleteItemRequest().WithTableName(tableName).WithKey(
                new Key().WithHashKeyElement(new AttributeValue().WithS(dataOwnerID)));

            DeleteItemResponse r = client.DeleteItem(request);
        }
Exemplo n.º 4
0
        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}"
                });
            }
        }
Exemplo n.º 5
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            var request = new DeleteItemRequest().WithTableName("Snapshot").WithKey(new Key().WithHashKeyElement(new AttributeValue().WithS("1")).
                                                                                    WithRangeKeyElement(new AttributeValue().WithN("1")));

            DeleteItemResponse r = client.DeleteItem(request);
        }
Exemplo n.º 6
0
        public async Task <DeletePointResult> DeletePointAsync(DeletePointRequest deletePointRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (deletePointRequest == null)
            {
                throw new ArgumentNullException("deletePointRequest");
            }

            var geohash = S2Manager.GenerateGeohash(deletePointRequest.GeoPoint);
            var hashKey = S2Manager.GenerateHashKey(geohash, _config.HashKeyLength);

            var deleteItemRequest = deletePointRequest.DeleteItemRequest;

            deleteItemRequest.TableName = _config.TableName;

            var hashKeyValue = new AttributeValue
            {
                N = hashKey.ToString(CultureInfo.InvariantCulture)
            };

            deleteItemRequest.Key[_config.HashKeyAttributeName]  = hashKeyValue;
            deleteItemRequest.Key[_config.RangeKeyAttributeName] = deletePointRequest.RangeKeyValue;

            DeleteItemResponse deleteItemResult = await _config.DynamoDBClient.DeleteItemAsync(deleteItemRequest, cancellationToken).ConfigureAwait(false);

            var deletePointResult = new DeletePointResult(deleteItemResult);

            return(deletePointResult);
        }
Exemplo n.º 7
0
        /**
         * Invalidate (delete) any access tokens that exist for the specified user.
         */
        internal static async Task InvalidateUserAccessTokens(AmazonDynamoDBClient dbClient, string userId)
        {
            Debug.Untested();
            Debug.AssertValid(dbClient);
            Debug.AssertID(userId);

            Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>();

            key.Add(IdentityServiceDataLayer.FIELD_ACCESS_TOKENS_USER_ID, new AttributeValue(userId));
            DeleteItemResponse deleteResponse = await dbClient.DeleteItemAsync(IdentityServiceDataLayer.DATASET_ACCESS_TOKENS_INDEX_USER_ID, key);

            Debug.AssertValid(deleteResponse);
            //??++CHECK RESPONSE?
            //??-- List<string> accessTokens = new List<string>();
            // foreach (var item in AccessTokens) {
            //     Debug.AssertValid(item);
            //     Debug.AssertString(item.Key);
            //     Debug.AssertValidOrNull(item.Value);
            //     if (item.Value != null) {
            //         Debug.Assert(item.Value.ID == item.Key);
            //         Debug.AssertValidOrNull(item.Value.User);
            //         if (item.Value.User != null) {
            //             if (item.Value.User.ID == userId) {
            //                 accessTokens.Add(item.Key);
            //             }
            //         }
            //     }
            // }
            // foreach (var accessToken in accessTokens) {
            //     Debug.AssertString(accessToken);
            //     AccessTokens.Remove(accessToken);
            // }
        }
Exemplo n.º 8
0
        protected override void deleteItem()
        {
            var request = new DeleteItemRequest().WithTableName(tableName).WithKey(
                new Key().WithHashKeyElement(new AttributeValue().WithN(bufferID.ToString())).
                WithRangeKeyElement(new AttributeValue().WithN(serieID.ToString())));

            DeleteItemResponse r = client.DeleteItem(request);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteItemResponse response = new DeleteItemResponse();

            context.Read();

            UnmarshallResult(context, response);
            return(response);
        }
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DeleteItemResponse response = new DeleteItemResponse();

            context.Read();
            response.DeleteItemResult = DeleteItemResultUnmarshaller.GetInstance().Unmarshall(context);

            return(response);
        }
Exemplo n.º 11
0
        public DeletePointResult(DeleteItemResponse deleteItemResult)
        {
            if (deleteItemResult == null)
            {
                throw new ArgumentNullException("deleteItemResult");
            }

            DeleteItemResult = deleteItemResult;
        }
        private static void UnmarshallResult(JsonUnmarshallerContext context, DeleteItemResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            while (context.Read())
            {
                if (context.TestExpression("Attributes", targetDepth))
                {
                    context.Read();
                    response.Attributes = new Dictionary <String, AttributeValue>();
                    if (context.CurrentTokenType == JsonToken.Null)
                    {
                        continue;
                    }
                    KeyValueUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance());
                    while (context.Read())
                    {
                        JsonToken token = context.CurrentTokenType;
                        if (token == JsonToken.ArrayStart || token == JsonToken.ObjectStart)
                        {
                            continue;
                        }
                        if (token == JsonToken.ArrayEnd || token == JsonToken.ObjectEnd)
                        {
                            break;
                        }
                        KeyValuePair <string, AttributeValue> kvp = unmarshaller.Unmarshall(context);
                        response.Attributes.Add(kvp.Key, kvp.Value);
                    }
                    continue;
                }

                if (context.TestExpression("ConsumedCapacity", targetDepth))
                {
                    context.Read();
                    response.ConsumedCapacity = ConsumedCapacityUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.TestExpression("ItemCollectionMetrics", targetDepth))
                {
                    context.Read();
                    response.ItemCollectionMetrics = ItemCollectionMetricsUnmarshaller.GetInstance().Unmarshall(context);
                    continue;
                }

                if (context.CurrentDepth <= originalDepth)
                {
                    return;
                }
            }

            return;
        }
Exemplo n.º 13
0
        public async Task <Response <Revisao> > DeletarAsync(Revisao revisao)
        {
            var resp = new Response <Revisao>();

            using (var client = this._context.GetClientInstance())
            {
                DeleteItemRequest request = new DeleteItemRequest
                {
                    TableName = _context.TableName,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { "id", new AttributeValue {
                              N = revisao.Id.ToString()
                          } },
                        { "tipo", new AttributeValue {
                              S = "revisao"
                          } }
                    },
                    ConditionExpression      = "#status = :status OR #tpArq = :tpArq",
                    ExpressionAttributeNames = new Dictionary <string, string>
                    {
                        { "#status", "status" },
                        { "#tpArq", "tp-arquivo" },
                    },
                    ExpressionAttributeValues = new Dictionary <string, AttributeValue>
                    {
                        { ":status", new AttributeValue {
                              S = revisao.StatusRevisao.ToString()
                          } },
                        { ":tpArq", new AttributeValue {
                              S = TipoArquivo.Correcao.ToString()
                          } }
                    }
                };

                try
                {
                    DeleteItemResponse response = await client.DeleteItemAsync(request);

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        resp.ErrorMessages.Add("Falha ao deletar revisão.");
                        _logger.LogError("Falha ao deletar revisão.");
                    }
                }
                catch (Exception e)
                {
                    resp.ErrorMessages.Add(e.Message);
                    _logger.LogError(e.Message);
                }

                return(resp);
            }
        }
Exemplo n.º 14
0
        public static DeleteItemResponse Unmarshall(UnmarshallerContext context)
        {
            DeleteItemResponse deleteItemResponse = new DeleteItemResponse();

            deleteItemResponse.HttpResponse = context.HttpResponse;
            deleteItemResponse.RequestId    = context.StringValue("DeleteItem.RequestId");
            deleteItemResponse.Success      = context.BooleanValue("DeleteItem.Success");
            deleteItemResponse.Message      = context.StringValue("DeleteItem.Message");
            deleteItemResponse.Code         = context.IntegerValue("DeleteItem.Code");

            return(deleteItemResponse);
        }
Exemplo n.º 15
0
        public int Delete(Data.DataAspect aspect, Data.ClassFilter filter)
        {
            DeleteItemRequest request = new DeleteItemRequest();

            request.TableName = aspect.StoredName;


            if (filter != null)
            {
                AppendFilter(request.Expected, filter, true);
            }

            DeleteItemResponse response = _Client.DeleteItem(request);

            return(response.DeleteItemResult.ConsumedCapacityUnits > 0 ?
                   1 : 0);
        }
Exemplo n.º 16
0
        public void DeleteItem()
        {
            //Delete Item
            DeleteItemRequest deleteReq = new DeleteItemRequest()
            {
                TableName = "Student",
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Id", new AttributeValue {
                          N = "5"
                      } }
                }
            };
            DeleteItemResponse deleteResponse = new DeleteItemResponse();

            deleteResponse = client.DeleteItem(deleteReq);
            successMessage = deleteResponse.HttpStatusCode == HttpStatusCode.OK ? "Item Deleted " : "Error Occured While Updating";
        }
        public async Task <Response <Postagem> > ExcluirAsync(Postagem postagem)
        {
            var resp = new Response <Postagem>();

            using (var client = this._context.GetClientInstance())
            {
                DeleteItemRequest request = new DeleteItemRequest
                {
                    TableName = _context.TableName,
                    Key       = new Dictionary <string, AttributeValue>
                    {
                        { "id", new AttributeValue {
                              N = postagem.Id.ToString()
                          } },
                        { "tipo", new AttributeValue {
                              S = "postagem"
                          } }
                    }
                };

                try
                {
                    DeleteItemResponse response = await client.DeleteItemAsync(request);

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        resp.ErrorMessages.Add("Falha ao deletar postagem.");
                        _logger.LogError("Falha ao deletar postagem.");
                    }
                }
                catch (Exception e)
                {
                    resp.ErrorMessages.Add(e.Message);
                    _logger.LogError(e.Message);
                }

                return(resp);
            }
        }
Exemplo n.º 18
0
        public DeleteItemResponse Handle(DeleteItemRequest request)
        {
            var response = new DeleteItemResponse();

            response.Errors = Validate(request);

            if (response.HasErrors)
            {
                return(response);
            }
            try
            {
                _itemsRepository.Delete(request.ItemId);

                return(response);
            }
            catch (Exception)
            {
                response.Errors.Add(new ErrorStatus("BAD_REQUEST"));

                return(response);
            }
        }
Exemplo n.º 19
0
        public async Task TestMusicRepositoryDBClientAsync()
        {
            IAmazonDynamoDB DDBClient = new AmazonDynamoDBClient("dummy", "dummy",
                                                                 new AmazonDynamoDBConfig
            {
                ServiceURL = "http://localhost:8000",
                UseHttp    = true,
            }
                                                                 );

            MusicRepository repo = new MusicRepository(DDBClient);

            string hashKey  = "No One You Know";
            string rangeKey = "My Doc Spot";

            Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue>
            {
                { "Artist", new AttributeValue {
                      S = hashKey
                  } },
                { "SongTitle", new AttributeValue {
                      S = rangeKey
                  } },
                { "AlbumTitle", new AttributeValue {
                      S = "Hey Now"
                  } },
                { "CriticRating", new AttributeValue {
                      N = "8.4"
                  } },
                { "Genre", new AttributeValue {
                      S = "Country"
                  } },
                { "Year", new AttributeValue {
                      N = "1984"
                  } }
            };

            var putItemResponse = await repo.PutItemAsync(item);

            Assert.IsNotNull(putItemResponse);
            Assert.AreEqual(putItemResponse.HttpStatusCode, HttpStatusCode.OK);


            GetItemResponse getItemResponse = await repo.GetItemAsync(hashKey, rangeKey);

            Assert.IsNotNull(getItemResponse);
            Assert.AreEqual(getItemResponse.HttpStatusCode, HttpStatusCode.OK);

            Assert.IsTrue(getItemResponse.Item.TryGetValue("Artist", out AttributeValue valueArtist));
            Assert.IsNotNull(valueArtist.S);
            Assert.AreEqual(hashKey, valueArtist.S);

            Assert.IsTrue(getItemResponse.Item.TryGetValue("SongTitle", out AttributeValue valueSongTitle));
            Assert.IsNotNull(valueSongTitle.S);
            Assert.AreEqual(rangeKey, valueSongTitle.S);

            DeleteItemResponse deleteItemResponse = await repo.DeleteItemAsync(hashKey, rangeKey);

            Assert.IsNotNull(deleteItemResponse);
            Assert.AreEqual(deleteItemResponse.HttpStatusCode, HttpStatusCode.OK);


            GetItemResponse getItemResponse2 = await repo.GetItemAsync(hashKey, rangeKey);

            Assert.IsNotNull(getItemResponse2);
            Assert.AreEqual(getItemResponse2.HttpStatusCode, HttpStatusCode.OK);
            Assert.AreEqual(getItemResponse2.Item.Count, 0);
        }
        public async Task TestMusicDBClientAsync()
        {
            IAmazonDynamoDB DDBClient = new AmazonDynamoDBClient("dummy", "dummy",
                                                                 new AmazonDynamoDBConfig
            {
                ServiceURL = "http://localhost:8000",
                UseHttp    = true,
            }
                                                                 );

            Dictionary <string, AttributeValue> item = new Dictionary <string, AttributeValue>
            {
                { "Artist", new AttributeValue {
                      S = "No One You Know"
                  } },
                { "SongTitle", new AttributeValue {
                      S = "My Doc Spot"
                  } },
                { "AlbumTitle", new AttributeValue {
                      S = "Hey Now"
                  } },
                { "CriticRating", new AttributeValue {
                      N = "8.4"
                  } },
                { "Genre", new AttributeValue {
                      S = "Country"
                  } },
                { "Year", new AttributeValue {
                      N = "1984"
                  } }
            };

            await DDBClient.PutItemAsync("Music", item);

            var request = new GetItemRequest
            {
                TableName = "Music",
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Artist", new AttributeValue {
                          S = "No One You Know"
                      } },
                    { "SongTitle", new AttributeValue {
                          S = "My Doc Spot"
                      } }
                }
            };

            GetItemResponse response = await DDBClient.GetItemAsync(request);

            Assert.IsNotNull(response);
            Assert.AreEqual(response.HttpStatusCode, HttpStatusCode.OK);

            Assert.IsTrue(response.Item.TryGetValue("Artist", out AttributeValue valueArtist));
            Assert.IsNotNull(valueArtist.S);
            Assert.AreEqual("No One You Know", valueArtist.S);

            Assert.IsTrue(response.Item.TryGetValue("SongTitle", out AttributeValue valueSongTitle));
            Assert.IsNotNull(valueSongTitle.S);
            Assert.AreEqual("My Doc Spot", valueSongTitle.S);

            var requestDelete = new DeleteItemRequest
            {
                TableName = "Music",
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Artist", new AttributeValue {
                          S = "No One You Know"
                      } },
                    { "SongTitle", new AttributeValue {
                          S = "My Doc Spot"
                      } }
                }
            };
            DeleteItemResponse responseDelete = await DDBClient.DeleteItemAsync(requestDelete);

            Assert.IsNotNull(responseDelete);
            Assert.AreEqual(responseDelete.HttpStatusCode, HttpStatusCode.OK);

            var request2 = new GetItemRequest
            {
                TableName = "Music",
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Artist", new AttributeValue {
                          S = "No One You Know"
                      } },
                    { "SongTitle", new AttributeValue {
                          S = "My Doc Spot"
                      } }
                }
            };
            GetItemResponse response2 = await DDBClient.GetItemAsync(request2);

            Assert.IsNotNull(response2);
            Assert.AreEqual(response2.Item.Count, 0);
        }