Exemple #1
0
        private static void DeleteSampleProduct(int id, string tableName)
        {
            switch (provider)
            {
            case Provider.NOSQL:
                var request = new DeleteItemRequest
                {
                    TableName = tableName,
                    Key       = new Dictionary <string, AttributeValue>()
                    {
                        { "Id", new AttributeValue {
                              N = id.ToString()
                          } }
                    },
                };
                var response = client.DeleteItem(request);
                break;

            case Provider.MSSQL:
                new Product()
                {
                    Id = { Value = id }
                }.Delete();
                break;
            }
        }
Exemple #2
0
        //delete query
        public static void DeleteItem(string id, string tableName)
        {
            try
            {
                AmazonDynamoDBClient client;
                using (client = new AmazonDynamoDBClient(MyAWSConfigs.DynamodbRegion))
                {
                    Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>
                    {
                        { "id", new AttributeValue {
                              S = id
                          } },
                    };

                    DeleteItemRequest deleteItemRequest = new DeleteItemRequest
                    {
                        Key       = key,
                        TableName = tableName,
                    };

                    client.DeleteItem(deleteItemRequest);
                }
            }
            catch (AmazonDynamoDBException e)
            {
                Console.WriteLine("AmazonDynamoDBException: " + e);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
        }
Exemple #3
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);
        }
 public void DeleteArtist(Artist artist)
 {
     Client.DeleteItem(new DeleteItemRequest
     {
         TableName = "Artist",
         Key       = new Dictionary <string, AttributeValue>()
         {
             { "ArtistID", new AttributeValue {
                   N = artist.ArtistId.ToString()
               } },
             { "ArtistName", new AttributeValue {
                   S = artist.ArtistName
               } }
         }
     });
 }
Exemple #5
0
        public void Remove(Organization item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                DeleteItemRequest request = CreateDeleteItemRequest(item.OrganizationId);

                client.DeleteItem(request);
            }
        }
Exemple #6
0
        public void Remove(DataInfo item)
        {
            AmazonDynamoDBClient client = DynamoUtilities.InitializeClient();

            using (client)
            {
                DeleteItemRequest request = CreateDeleteItemRequest(item);

                client.DeleteItem(request);
            }
        }
 private static void DeleteItem(string partitionKey, string sortKey)
 {
     var request = new DeleteItemRequest
     {
         TableName = tableName,
         Key       = new Dictionary <string, AttributeValue>()
         {
             { "Id", new AttributeValue {
                   S = partitionKey
               } },
             { "ReplyDateTime", new AttributeValue {
                   S = sortKey
               } }
         }
     };
     var response = client.DeleteItem(request);
 }
Exemple #8
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);
        }
Exemple #9
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";
        }
Exemple #10
0
 public bool Remove(string key)
 {
     try
     {
         _client.DeleteItem(new DeleteItemRequest
         {
             TableName = CacheTableName,
             Key       = new Key {
                 HashKeyElement = new AttributeValue {
                     S = key
                 }
             }
         });
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public bool Remove(string key)
 {
     try
     {
         var itemKey = new Dictionary <string, AttributeValue> {
             { KeyName, new AttributeValue()
               {
                   S = key
               } }
         };
         _client.DeleteItem(new DeleteItemRequest
         {
             TableName = CacheTableName,
             Key       = itemKey
         });
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemple #12
0
        public void DeleteItem()
        {
            DeleteItemRequest request = new DeleteItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { "Id", new AttributeValue {
                          N = "3"
                      } },
                    { "EmployeeName", new AttributeValue {
                          S = "Mehmet Karagöz"
                      } }
                }
            };
            var response = client.DeleteItem(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Deleted Succcessfully");
            }
            Console.ReadLine();
        }
Exemple #13
0
        public void DeleteItem()
        {
            DeleteItemRequest request = new DeleteItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { "Id", new AttributeValue {
                          N = "3"
                      } },
                    { "Username", new AttributeValue {
                          S = "admin"
                      } }
                }
            };

            var response = client.DeleteItem(request);

            if (response.HttpStatusCode.IsSuccess())
            {
                Console.WriteLine("Item(s) deleted successfully \n");
            }
        }
Exemple #14
0
        public void DeleteUser(int userId, string username)
        {
            DeleteItemRequest request = new DeleteItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { "UserId", new AttributeValue {
                          N = userId.ToString()
                      } },
                    { "UserName", new AttributeValue {
                          S = username
                      } }
                }
            };

            var response = client.DeleteItem(request);

            if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
            {
                Console.WriteLine("Item deleted successfully");
            }
        }
        private static void DeleteItem()
        {
            var request = new DeleteItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>()
                {
                    { "Id", new AttributeValue {
                          N = "1000"
                      } }
                },

                // Return the entire item as it appeared before the update.
                ReturnValues             = "ALL_OLD",
                ExpressionAttributeNames = new Dictionary <string, string>()
                {
                    { "#IP", "InPublication" }
                },
                ExpressionAttributeValues = new Dictionary <string, AttributeValue>()
                {
                    { ":inpub", new AttributeValue {
                          BOOL = false
                      } }
                },
                ConditionExpression = "#IP = :inpub"
            };

            var response = client.DeleteItem(request);

            // Check the response.
            var attributeList = response.Attributes; // Attribute list in the response.

            // Print item.
            Console.WriteLine("\nPrinting item that was just deleted ............");
            PrintItem(attributeList);
        }
        public void CRUDSamples()
        {
            EnsureTables();

            PutSample();

            {
                #region GetItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>
                {
                    { "Author", new AttributeValue {
                          S = "Mark Twain"
                      } },
                    { "Title", new AttributeValue {
                          S = "The Adventures of Tom Sawyer"
                      } }
                };

                // Create GetItem request
                GetItemRequest request = new GetItemRequest
                {
                    TableName = "SampleTable",
                    Key       = key,
                };

                // Issue request
                var result = client.GetItem(request);

                // View response
                Console.WriteLine("Item:");
                Dictionary <string, AttributeValue> item = result.Item;
                foreach (var keyValuePair in item)
                {
                    Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                      keyValuePair.Key,
                                      keyValuePair.Value.S,
                                      keyValuePair.Value.N,
                                      string.Join(", ", keyValuePair.Value.SS ?? new List <string>()),
                                      string.Join(", ", keyValuePair.Value.NS ?? new List <string>()));
                }

                #endregion
            }

            {
                #region UpdateItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>
                {
                    { "Author", new AttributeValue {
                          S = "Mark Twain"
                      } },
                    { "Title", new AttributeValue {
                          S = "The Adventures of Tom Sawyer"
                      } }
                };

                // Define attribute updates
                Dictionary <string, AttributeValueUpdate> updates = new Dictionary <string, AttributeValueUpdate>();
                // Update item's Setting attribute
                updates["Setting"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.PUT,
                    Value  = new AttributeValue {
                        S = "St. Petersburg, Missouri"
                    }
                };
                // Remove item's Bibliography attribute
                updates["Bibliography"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.DELETE
                };
                // Add a new string to the item's Genres SS attribute
                updates["Genres"] = new AttributeValueUpdate()
                {
                    Action = AttributeAction.ADD,
                    Value  = new AttributeValue {
                        SS = new List <string> {
                            "Bildungsroman"
                        }
                    }
                };

                // Create UpdateItem request
                UpdateItemRequest request = new UpdateItemRequest
                {
                    TableName        = "SampleTable",
                    Key              = key,
                    AttributeUpdates = updates
                };

                // Issue request
                client.UpdateItem(request);

                #endregion
            }

            {
                #region DeleteItem Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item key
                //  Hash-key of the target item is string value "Mark Twain"
                //  Range-key of the target item is string value "The Adventures of Tom Sawyer"
                Dictionary <string, AttributeValue> key = new Dictionary <string, AttributeValue>
                {
                    { "Author", new AttributeValue {
                          S = "Mark Twain"
                      } },
                    { "Title", new AttributeValue {
                          S = "The Adventures of Tom Sawyer"
                      } }
                };

                // Create DeleteItem request
                DeleteItemRequest request = new DeleteItemRequest
                {
                    TableName = "SampleTable",
                    Key       = key
                };

                // Issue request
                client.DeleteItem(request);

                #endregion
            }
        }
Exemple #17
0
        public override int ExecuteNonQuery(ServiceCursorDef cursorDef, IDataParameterCollection parms, CommandBehavior behavior)
        {
            Initialize();
            Query query = cursorDef.Query as Query;

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

            if (parms.Count > 0)
            {
                for (int i = 0; i < parms.Count; i++)
                {
                    ServiceParameter parm = parms[i] as ServiceParameter;
                    DynamoDBHelper.GXToDynamoQueryParameter("", values, parm);
                }
            }
            var pattern = @"\((.*) = :(.*)\)";
            Dictionary <string, AttributeValue> keyCondition = new Dictionary <string, AttributeValue>();
            List <string> filters = new List <string>();

            foreach (var keyFilter in query.Filters)
            {
                var    match   = Regex.Match(keyFilter, pattern);
                String varName = match.Groups[2].Value;
                if (match.Groups.Count > 1)
                {
                    keyCondition[match.Groups[1].Value] = values[varName];
                }
            }
            AmazonDynamoDBRequest request = null;

            switch (query.CursorType)
            {
            case ServiceCursorDef.CursorType.Select:
                throw new NotImplementedException();

            case ServiceCursorDef.CursorType.Delete:
                request = new DeleteItemRequest()
                {
                    TableName = query.TableName,
                    Key       = keyCondition
                };
                mDynamoDB.DeleteItem((DeleteItemRequest)request);

                break;

            case ServiceCursorDef.CursorType.Insert:
                request = new PutItemRequest
                {
                    TableName = query.TableName,
                    Item      = values
                };
                mDynamoDB.PutItem((PutItemRequest)request);
                break;

            case ServiceCursorDef.CursorType.Update:
                request = new UpdateItemRequest
                {
                    TableName        = query.TableName,
                    Key              = keyCondition,
                    AttributeUpdates = ToAttributeUpdates(keyCondition, values)
                };
                mDynamoDB.UpdateItem((UpdateItemRequest)request);
                break;

            default:
                break;
            }

            return(0);
        }
        private static void AddLabelToInvalidReports(AmazonDynamoDBClient client, string env)
        {
            var tableName = "LLC-Reports" + env;
            var table     = Table.LoadTable(client, tableName);
            var batch     = table.CreateBatchWrite();

            var results = client.ScanAsync(new ScanRequest
            {
                TableName = tableName
            }).Result;

            // Process the existing items without a Type
            foreach (var r in results.Items)
            {
                if (!r.ContainsKey("ReportType"))
                {
                    r["ReportType"] = new AttributeValue {
                        S = "Warning"
                    };
                    r.Remove("Type");
                    client.PutItem(new PutItemRequest
                    {
                        Item      = r,
                        TableName = tableName
                    });
                }
                else
                {
                    // Temporary, remove me!!
                    if (r["ReportType"].S == "Invalid")
                    {
                        var k = new Dictionary <string, AttributeValue>();
                        k["Id"] = new AttributeValue {
                            N = r["Id"].S
                        };

                        client.DeleteItem(new DeleteItemRequest
                        {
                            TableName = tableName,
                            Key       = k
                        });
                    }
                }
            }

            // Only process Invalid items from the other table
            // If there are NO items of Type "Invalid"
            var rows = client.ScanAsync(new ScanRequest
            {
                ExpressionAttributeValues = new Dictionary <string, AttributeValue> {
                    { ":val", new AttributeValue {
                          S = "Invalid"
                      } }
                },
                FilterExpression = $"ReportType = :val",
                TableName        = tableName
            }).Result;

            // Continue, since this is the first time
            if (rows.Count == 0)
            {
                Console.WriteLine("zero, proceeding...");
                var last = new Dictionary <string, AttributeValue>();
                last["Id"] = new AttributeValue {
                    S = "0"
                };

                while (last.ContainsKey("Id"))
                {
                    var invalid = client.ScanAsync(new ScanRequest
                    {
                        TableName         = "LLC-Links" + env,
                        ExclusiveStartKey = last["Id"].S == "0" ? null : last
                    }).Result;

                    foreach (var i in invalid.Items)
                    {
                        if (!(i.ContainsKey("Valid") && i["Valid"].BOOL))
                        {
                            var document = new Document();
                            AddToDocument(document, "Id", Guid.NewGuid().ToString());
                            AddToDocument(document, "Link", i["Id"].S);
                            AddToDocument(document, "ReportType", "Invalid");
                            AddToDocument(document, "Source", "IDLA S-LOR on AWS");
                            AddToDocument(document, "Url", i["Url"].S);
                            if (i.ContainsKey("DateLastChecked"))
                            {
                                AddToDocument(document, "DateLastChecked", i["DateLastChecked"].S);
                            }
                            if (i.ContainsKey("DateLastFound"))
                            {
                                AddToDocument(document, "DateLastFound", i["DateLastFound"].S);
                            }
                            AddToDocument(document, "AttemptCount", i["AttemptCount"].N);
                            batch.AddDocumentToPut(document);
                        }
                    }

                    last = invalid.LastEvaluatedKey;
                }

                batch.Execute();
            }
        }