public static List<NewsComponents> GetNewsStories(string domainName, AmazonSimpleDBClient sdbClient) { List<NewsComponents> newsItems = new List<NewsComponents>(); NewsComponents newsItem = null; String selectExpression = "Select NewsID,Source,Section,Publish,NewsHeadline,NewsAdded,Photos,Summary,Category From " + domainName; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdbClient.Select(selectRequestAction); if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { newsItem = new NewsComponents(); if (item.IsSetName()) { } int i = 0; foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { if (attribute.IsSetName()) { string name = attribute.Name; } if (attribute.IsSetValue()) { switch (attribute.Name) { case "NewsID": newsItem.NewsID = Guid.Parse(attribute.Value); break; case "Source": newsItem.Source = attribute.Value; break; case "Section": newsItem.Section = attribute.Value; break; case "NewsItem": newsItem.NewsItem = attribute.Value; break; case "NewsHeadline": newsItem.NewsHeadline = attribute.Value; break; case "Publish": newsItem.Publish = Convert.ToBoolean(attribute.Value); break; case "NewsAdded": newsItem.NewsAdded = Convert.ToDateTime(attribute.Value); break; case "Photos": newsItem.NewsPhotoUrl = attribute.Value; break; case "Summary": newsItem.NewsItem = GetTheHtml(attribute.Value); break; case "Category": newsItem.Category = attribute.Value; break; case "SummaryContent": newsItem.SummaryContent = attribute.Value; break; } i++; } } newsItems.Add(newsItem); } } return newsItems; }
public static NewsComponents GetNewsItem(string domainName, string itemName, AmazonSimpleDBClient sdbClient) { NewsComponents newsItem = new NewsComponents(); GetAttributesRequest getAttributeRequest = new GetAttributesRequest() .WithDomainName(domainName) .WithItemName(itemName); GetAttributesResponse getAttributeResponse = sdbClient.GetAttributes(getAttributeRequest); List<Amazon.SimpleDB.Model.Attribute> attrs = null; if (getAttributeResponse.IsSetGetAttributesResult()) { attrs = getAttributeResponse.GetAttributesResult.Attribute; int i = 0; foreach (Amazon.SimpleDB.Model.Attribute attribute in attrs) { if (attribute.IsSetName()) { string name = attribute.Name; } if (attribute.IsSetValue()) { switch (i) { case 0: newsItem.NewsID = Guid.Parse(attribute.Value); break; case 1: newsItem.Source = attribute.Value; break; case 2: newsItem.Section = attribute.Value; break; case 3: newsItem.NewsItem = attribute.Value; break; case 4: newsItem.NewsHeadline = attribute.Value; break; case 5: newsItem.NewsAdded = Convert.ToDateTime(attribute.Value); break; case 7: newsItem.Summary = attribute.Value; break; case 8: newsItem.Category = attribute.Value; break; } i++; } } } return newsItem; }