/// <summary> /// Fetches the domain names and populates them to the domain list box. /// </summary> private void PopulateDomainNames() { SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { SimpleDB.Client.OnSimpleDBResponse -= handler; ListDomainsResponse response = args.Response as ListDomainsResponse; if (null != response) { ListDomainsResult listResult = response.ListDomainsResult; if (null != listResult) { this.Dispatcher.BeginInvoke(() => { this.DomainNameList.Clear(); listResult.DomainName.ForEach(domain => this.DomainNameList.Add(domain)); }); } } }; //Show a wait message. this.Dispatcher.BeginInvoke(() => { this.DomainNameList.Clear(); this.DomainNameList.Add("Please wait..."); }); SimpleDB.Client.OnSimpleDBResponse += handler; ListDomainsRequest request = new ListDomainsRequest(); SimpleDB.Client.BeginListDomains(request); }
private void btnGetAttributes_Click(object sender, RoutedEventArgs e) { #region User Input Validation this.Attributes.Clear(); //Validate user input. if (string.IsNullOrEmpty(this.DomainName) || string.IsNullOrEmpty(this.ItemName)) { FetchingOrDeletingAttributeMessage = "Domain-Name or Item-Name cannot be empty."; return; } this.FetchingOrDeletingAttributeMessage = "Please wait..."; #endregion User Input Validation GetAttributesRequest request = new GetAttributesRequest { DomainName = this.DomainName, ItemName = this.ItemName }; //Associate the attributes. GetListAttributeFromString(this.AttributesForQuery).ForEach(v => request.AttributeName.Add(v.Attribute)); SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object senderAmazon, ResponseEventArgs args) { //Unhook from event. SimpleDB.Client.OnSimpleDBResponse -= handler; GetAttributesResponse response = args.Response as GetAttributesResponse; if (null != response) { GetAttributesResult attributeResult = response.GetAttributesResult; if (null != attributeResult) { this.Dispatcher.BeginInvoke(() => { this.Attributes.Clear(); if (attributeResult.Attribute.Count > 0) { FetchingOrDeletingAttributeMessage = "Result count: " + attributeResult.Attribute.Count; foreach (var item in attributeResult.Attribute) { this.Attributes.Add(item); } } else { FetchingOrDeletingAttributeMessage = "No results"; } }); } } }; SimpleDB.Client.OnSimpleDBResponse += handler; SimpleDB.Client.GetAttributes(request); }
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); }
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); }
/// <summary> /// Populates the list of items for the specified domain name. /// </summary> /// <param name="domainName">The domain name.</param> private void PopulateItemsNamesList(string domainName) { SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object sender, ResponseEventArgs args) { //Unhook from event. SimpleDB.Client.OnSimpleDBResponse -= handler; SelectResponse response = args.Response as SelectResponse; if (null != response) { SelectResult selectResult = response.SelectResult; if (null != selectResult) { this.Dispatcher.BeginInvoke(() => { this.ItemsNameList.Clear(); if (selectResult.Item.Count > 0) { selectResult.Item.ForEach(i => this.ItemsNameList.Add(i.Name)); this.ItemsNameMessage = "No of Item: " + selectResult.Item.Count; } else { this.ItemsNameMessage = "No Item"; this.ItemsNameList.Clear(); } }); } } }; this.ItemsNameMessage = "Updating Item names..."; this.ItemsNameList.Clear(); SimpleDB.Client.OnSimpleDBResponse += handler; SimpleDB.Client.Select(new SelectRequest { SelectExpression = "SELECT * FROM " + domainName, ConsistentRead = true }); }
private void btnSelectQuery_Click(object sender, RoutedEventArgs e) { #region User Input Validation if (string.IsNullOrEmpty(this.DomainName)) { this.SelectQueryMessage = "Domain-Name cannot be empty."; return; } this.SelectResultAttributes.Clear(); this.SelectQueryMessage = "Executing query for " + this.DomainName + ". Please wait..."; #endregion User Input Validation SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null; handler = delegate(object senderOriginal, ResponseEventArgs args) { //Unhook from event. SimpleDB.Client.OnSimpleDBResponse -= handler; SelectResponse response = args.Response as SelectResponse; if (null != response) { SelectResult selectResult = response.SelectResult; if (null != selectResult) { this.Dispatcher.BeginInvoke(() => { if (selectResult.Item.Count > 0) { this.SelectResultAttributes.Clear(); int itemsCount = 0; int attributesCount = 0; foreach (var item in selectResult.Item) { item.Attribute.ForEach(attribute => this.SelectResultAttributes.Add(new AttributeAndValue { Attribute = attribute.Name, Value = attribute.Value, ItemName = item.Name })); itemsCount++; attributesCount += item.Attribute.Count; } //Item item = selectResult.Item[0]; //item.Attribute.ForEach(attribute => this.SelectResultAttributes.Add(attribute)); this.SelectQueryMessage = "No of Item: " + itemsCount + ", No of attributes: " + attributesCount; } else { this.SelectQueryMessage = "No results"; this.SelectResultAttributes.Clear(); } }); } } }; SimpleDB.Client.OnSimpleDBResponse += handler; SimpleDB.Client.Select(new SelectRequest { SelectExpression = this.SelectQuery, ConsistentRead = true }); }
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); }