private void btnPutAttributes_Click(object sender, RoutedEventArgs e) { SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; this.SomeMessage = "Please wait..."; handler = delegate(object senderAmazon, ResponseEventArgs args) { //Unhook from event. SimpleDB.Client.OnSimpleDBResponse -= handler; PutAttributesResponse response = args.Response as PutAttributesResponse; this.Dispatcher.BeginInvoke(() => { if (null != response) { this.SomeMessage = "Attribute put successfully."; } else { AmazonSimpleDBException exception = args.Response as AmazonSimpleDBException; if (null != exception) { this.SomeMessage = "Error: " + exception.Message; } } }); }; SimpleDB.Client.OnSimpleDBResponse += handler; PutAttributesRequest putAttributesRequest = new PutAttributesRequest { DomainName = this.DomainName, ItemName = this.ItemName }; List <ReplaceableAttribute> attributesOne = putAttributesRequest.Attribute; //Calculate the attributes and their values to put. foreach (var item in GetListAttributeAndValueFromString(this.AttributesAndValuesToPut)) { attributesOne.Add(new ReplaceableAttribute().WithName(item.Attribute).WithValue(item.Value)); } //attributesOne.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); //attributesOne.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Sweater")); //attributesOne.Add(new ReplaceableAttribute().WithName("Name").WithValue("Cathair Sweater")); //attributesOne.Add(new ReplaceableAttribute().WithName("Color").WithValue("Siamese")); //attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Small")); //attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Medium")); //attributesOne.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large")); SimpleDB.Client.PutAttributes(putAttributesRequest); }
void SimpleDBErrorResponse(AmazonSimpleDBException error) { StringBuilder errorBuilder = new StringBuilder(); errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "ERROR CODE: {0}", error.ErrorCode)); errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "INNER EXCEPTION: {0}", error.InnerException)); errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "MESSAGE: {0}", error.Message)); errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "REQUEST ID: {0}", error.RequestId)); errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "STATUS CODE: {0}", error.StatusCode));; errorBuilder.AppendLine(string.Format(CultureInfo.InvariantCulture, "\nERROR RESPONSE:\n {0}", error.XML)); this.Dispatcher.BeginInvoke(() => { MessageBox.Show(errorBuilder.ToString(), "Error Occured", MessageBoxButton.OK); }); }
private void btnDeletetAttributes_Click(object sender, RoutedEventArgs e) { SimpleDBResponseEventHandler <object, ResponseEventArgs> responseHandler = null; responseHandler = delegate(object senderAmazon, ResponseEventArgs args) { SimpleDB.Client.OnSimpleDBResponse -= responseHandler; DeleteAttributesResponse deleteResponse = args.Response as DeleteAttributesResponse; this.Dispatcher.BeginInvoke(() => { this.Attributes.Clear(); string message = string.Empty; if (null != deleteResponse) { message = "Attribute(s) deleted successfully."; } else { AmazonSimpleDBException exception = args.Response as AmazonSimpleDBException; if (null != exception) { message = "Error: " + exception.Message; } } this.FetchingOrDeletingAttributeMessage = message; }); }; SimpleDB.Client.OnSimpleDBResponse += responseHandler; DeleteAttributesRequest deleteRequest = new DeleteAttributesRequest() { DomainName = this.DomainName, ItemName = this.ItemName }; List <Amazon.SimpleDB.Model.Attribute> deleteItem = deleteRequest.Attribute; List <AttributeAndValue> aAndV = GetListAttributeAndValueFromString(this.AttributesAndValuesToPut); aAndV.ForEach(a => deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName(a.Attribute).WithValue(a.Value))); //deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Category").WithValue("Clothes")); //deleteItem.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Subcategory").WithValue("Sweater")); SimpleDB.Client.DeleteAttributes(deleteRequest); }
void BatchPutAttributeWebResponse(object sender, ResponseEventArgs args) { ISimpleDBResponse result = args.Response; SimpleDB.Client.OnSimpleDBResponse -= BatchPutAttributeWebResponse; this.Dispatcher.BeginInvoke(() => { BatchPutAttributesResponse response = result as BatchPutAttributesResponse; if (null != response) { this.BatchPutMessage = "Batch attributes put successfully"; } else { AmazonSimpleDBException exception = result as AmazonSimpleDBException; if (null != exception) { this.BatchPutMessage = "Error: " + exception.Message; } } }); }
private void btnBatchDeleteAttributes_Click(object sender, RoutedEventArgs e) { SimpleDBResponseEventHandler <object, ResponseEventArgs> responseHandler = null; responseHandler = delegate(object senderOriginal, ResponseEventArgs args) { ISimpleDBResponse result = args.Response; SimpleDB.Client.OnSimpleDBResponse -= responseHandler; this.Dispatcher.BeginInvoke(() => { BatchDeleteAttributesResponse response = result as BatchDeleteAttributesResponse; if (null != response) { this.BatchDeleteMessage = "Batch attributes deleted successfully"; } else { AmazonSimpleDBException exception = result as AmazonSimpleDBException; if (null != exception) { this.BatchDeleteMessage = "Error: " + exception.Message; } } }); }; this.BatchDeleteMessage = "Please wait..."; SimpleDB.Client.OnSimpleDBResponse += responseHandler; BatchDeleteAttributesRequest deleteRequest = new BatchDeleteAttributesRequest() { DomainName = this.DomainName }; List <DeleteableItem> deleteItem = deleteRequest.Item; //List<Amazon.SimpleDB.Model.Attribute> attributeItem1 = new List<Amazon.SimpleDB.Model.Attribute>(); //List<Amazon.SimpleDB.Model.Attribute> attributeItem2 = new List<Amazon.SimpleDB.Model.Attribute>(); List <AttributeAndValue> aAndV1 = GetListAttributeAndValueFromString(this.AttributesAndValuesToPut); DeleteableItem item1 = new DeleteableItem { ItemName = "OneAttribute" }; DeleteableItem item2 = new DeleteableItem { ItemName = "TwoAttribute" }; int index = 0; foreach (var item in aAndV1) { if (index <= aAndV1.Count / 2) { item1.Attribute.Add(new Amazon.SimpleDB.Model.Attribute().WithName(item.Attribute).WithValue(item.Value)); } else { item2.Attribute.Add(new Amazon.SimpleDB.Model.Attribute().WithName(item.Attribute).WithValue(item.Value)); } index++; } //attributeItem1.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Category").WithValue("Clothes")); //attributeItem1.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Subcategory").WithValue("Sweater")); //attributeItem2.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Size").WithValue("Small")); //attributeItem2.Add(new Amazon.SimpleDB.Model.Attribute().WithName("Color").WithValue("Siamese")); #region Commented //Commented because of changes in the Attribute property definition change during resolving FxCop warnings. //deleteItem.Add(new DeleteableItem() { Attribute = attributeItem1, ItemName = "OneAttribute" }); //deleteItem.Add(new DeleteableItem() { Attribute = attributeItem2, ItemName = "TwoAttribute" }); #endregion Commented deleteItem.Add(item1); deleteItem.Add(item2); SimpleDB.Client.BatchDeleteAttributes(deleteRequest); }