public bool Exists(string storeIdentifier, string requestIdentifier) { EnsureDomain(storeIdentifier); var count = 0; var select = string.Format("select count(*) from `{0}` where RequestId = '{1}'", storeIdentifier, requestIdentifier); var selectRequest = new SelectRequest().WithSelectExpression(select); var selectResponse = _simpleDb.Select(selectRequest); Console.WriteLine("Fetching select: {0}", select); if (selectResponse.IsSetSelectResult()) { var selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { foreach (var attribute in item.Attribute) { if (attribute.IsSetName() && attribute.Name == "Count") { int.TryParse(attribute.Value, out count); break; } } } } return count > 0; }
protected void Page_Load(object sender, EventArgs e) { this._domainName = String.Format(Settings.Default.SimpleDbDomainNameFormat, this.Context.User.Identity.Name); if (!this.Page.IsPostBack) { using (AmazonSimpleDBClient sdbClient = new AmazonSimpleDBClient(Amazon.RegionEndpoint.USWest2)) { DomainHelper.CheckForDomain(this._domainName, sdbClient); SelectRequest selectRequest = new SelectRequest().WithSelectExpression(String.Format("select * from `{0}`", this._domainName)); SelectResponse selectResponse = sdbClient.Select(selectRequest); List<Item> items = selectResponse.SelectResult.Item; List<Pet> pets = items.Select(l => new Pet { Id = l.Name, PhotoThumbUrl = l.Attribute.First(a => a.Name == "PhotoThumbUrl").Value, Name = l.Attribute.First(a => a.Name == "Name").Value, Birthdate = l.Attribute.First(a => a.Name == "Birthdate").Value, Sex = l.Attribute.First(a => a.Name == "Sex").Value, Type = l.Attribute.First(a => a.Name == "Type").Value, Breed = l.Attribute.First(a => a.Name == "Breed").Value }).ToList(); this.PetRepeater.DataSource = pets; this.PetRepeater.DataBind(); } } }
public void GetAll() { SelectRequest request = new SelectRequest() .WithConsistentRead(true) .WithSelectExpression("SELECT * FROM WHERE"); var response = _simpleDbClient.Select(request); }
public Routes GetAllRoutes() { Routes routes = new Routes(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT * FROM Routes ")); SelectResponse response = client.Select(request); foreach (Item item in response.SelectResult.Item) { string value = item.Attribute.GetValueByName("Id"); Route route = new Route { Id = Guid.Parse(item.Attribute.GetValueByName("Id")), Distance = item.Attribute.GetDoubleValueByName("Distance"), LastTimeRidden = item.Attribute.GetDateTimeValueByName("LastTimeRidden"), Name = item.Attribute.GetValueByName("Name"), Location = item.Attribute.GetValueByName("Location"), }; routes.Add(route); } } return routes; }
public Profiles GetProfileList() { Profiles profiles = new Profiles(); using(AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest { SelectExpression = "SELECT * FROM Profiles" }; SelectResponse response = client.Select(request); var list = from item in response.SelectResult.Item select new Profile() { Id = Guid.Parse(item.Attribute.GetValueByName("Id")), Description = item.Attribute.GetValueByName("Description"), Location = item.Attribute.GetValueByName("Location"), Name = item.Attribute.GetValueByName("Name") }; foreach (Profile profile in list) { profiles.Add(profile); } } return profiles; }
public List<WorkItem> GetWorkItems() { String selectExpression = "Select * From WorkItems"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); if (!selectResponse.IsSetSelectResult()) { throw new ApplicationException("No Select Result"); } SelectResult selectResult = selectResponse.SelectResult; var list = new List<WorkItem>(); foreach(Item item in selectResult.Item) { int id = 0; Int32.TryParse(item.Name, out id); var workItem = new WorkItem() { WorkItemID = id }; foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { //TODO: Break this out into a method that accepts an attribute and a workItem switch (attribute.Name) { case "Name": workItem.Name = attribute.Value; break; case "Type": workItem.Type = attribute.Value; break; case "Description": workItem.Description = attribute.Value; break; case "Attachments": workItem.Attachments = attribute.Value; break; case "EntryDate": workItem.EntryDate = attribute.Value; break; case "EnteredBy": workItem.EnteredBy = attribute.Value; break; } }//end foreach attribute list.Add(workItem); }//end foreach item return list; }//end method
public IEnumerable<WorkStep> GetChildWorkSteps(string path) { var selectRequest = new SelectRequest(); selectRequest.SelectExpression = string.Format("select * from {0} where ParentPath='{1}'",_domain,path); var selectResponse = _client.Select(selectRequest); foreach (var item in selectResponse.SelectResult.Item) { yield return GenerateWorkStep(item.Name, item.Attribute); } }
public IEnumerable<WorkStep> GetAllWorkSteps() { var selectRequest = new SelectRequest { SelectExpression = string.Format("select * from {0}", _domain) }; var selectResponse = _client.Select(selectRequest); foreach (var item in selectResponse.SelectResult.Item) { yield return GenerateWorkStep(item.Name, item.Attribute); } }
public static List<Tags> GetTags(string domainName, AmazonSimpleDBClient sdbClient) { List<Tags> tagses = new List<Tags>(); Tags tags; String selectExpression = "Select TagId,TagName,Country 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) { tags = new Tags(); ; 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 "TagId": tags.TagId = Guid.Parse(attribute.Value); break; case "TagName": tags.TagName = attribute.Value; break; case "Country": tags.Country = attribute.Value; break; } i++; } } tagses.Add(tags); } } return tagses; }
public bool CheckAuthentication(string userName, string password) { bool success = false; using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression(string.Format("SELECT Id FROM Profiles where Username = '******' and Password='******'", userName, password)); SelectResponse response = client.Select(request); if (response.SelectResult.Item.Count>0) { success = true; AuthenticatedUser = Guid.Parse(response.SelectResult.Item.First().Name); } } return success; }
public List<Route> GetUsersRoutes(Guid userId) { List<Route> list = new List<Route>(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT RouteId FROM ProfileRoutes where ProfileId = '{0}'", userId)); SelectResponse response = client.Select(request); foreach (Item routeItem in response.SelectResult.Item) { list.Add(new Route() { Id =Guid.Parse(routeItem.Attribute.GetValueByName("RouteId")) }); } } return list; }
protected void Page_Load(object sender, EventArgs e) { if (!this.Page.IsPostBack) { List<Item> items = null; DomainHelper.CheckForDomain(Settings.Default.PetBoardPublicDomainName, _simpleDBClient); SelectRequest selectRequest = new SelectRequest() .WithSelectExpression(String.Format("select * from `{0}`", Settings.Default.PetBoardPublicDomainName)); SelectResponse selectResponse = _simpleDBClient.Select(selectRequest); items = selectResponse.SelectResult.Item; bool noSampledData = (this.Request.Cookies["UseSampleData"] != null && "false".Equals(this.Request.Cookies["UseSampleData"].Value)); if (items.Count == 0 && noSampledData == false) { this.SampleDataPromptPanel.Visible = true; if (User.Identity.IsAuthenticated) { PostSignInMessage.Visible = true; } else { PreSignInMessage.Visible = true; } } else { List<Pet> pets = items.Select(l => new Pet { Id = l.Name, PhotoThumbUrl = l.Attribute.First(a => a.Name == "PhotoThumbUrl").Value, Name = l.Attribute.First(a => a.Name == "Name").Value, Birthdate = l.Attribute.First(a => a.Name == "Birthdate").Value, Sex = l.Attribute.First(a => a.Name == "Sex").Value, Type = l.Attribute.First(a => a.Name == "Type").Value, Breed = l.Attribute.First(a => a.Name == "Breed").Value }).ToList(); this.PetRepeater.DataSource = pets; this.PetRepeater.DataBind(); } } }
public Profile GetProfileById(Guid id) { Profile profile; using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression(string.Format("SELECT * FROM Profiles where Id = '{0}'",id)); SelectResponse response = client.Select(request); profile = (from item in response.SelectResult.Item select new Profile() { Id = Guid.Parse(item.Attribute.GetValueByName("Id")), Description = item.Attribute.GetValueByName("Description"), Location = item.Attribute.GetValueByName("Location"), Name = item.Attribute.GetValueByName("Name") }).First(); } return profile; }
public Contacts GetContactsByName(string contactName) { Contacts myContacts = new Contacts(); SelectRequest request = new SelectRequest { SelectExpression = string.Format("SELECT * FROM {0} where Name='{1}' ", DomainName, contactName) }; SelectResponse response = SimpleDBProxy.Service.Select(request); var contacts = from item in response.SelectResult.Item select new Contact() { Email = item.Attribute.GetValueByName("Email"), Name = item.Attribute.GetValueByName("Name"), Phone = item.Attribute.GetValueByName("Phone"), ID = item.Name }; myContacts.AddRange(contacts); return myContacts; }
public Route GetRouteById(Guid routeId) { Route route = new Route(); using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey)) { SelectRequest request = new SelectRequest().WithSelectExpression( string.Format("SELECT * FROM Routes where Id = '{0}'", routeId)); SelectResponse response = client.Select(request); if (response.SelectResult.Item.Count>0) { route.Id = Guid.Parse(response.SelectResult.Item[0].Attribute.GetValueByName("Id")); route.Distance = response.SelectResult.Item[0].Attribute.GetDoubleValueByName("Distance"); route.LastTimeRidden = response.SelectResult.Item[0].Attribute.GetDateTimeValueByName("LastTimeRidden"); } } return route; }
SelectResponse AmazonSimpleDB.Select(SelectRequest request) { var match = QueryAnalyzer.Match(request.SelectExpression); if (!match.Success) { throw new InvalidOperationException("The specified request does not contain a valid select expression."); } var attributes = match.Groups[1].Value; var domain = match.Groups[2].Value; Dictionary<string, Dictionary<string, string>> items; if (!Domains.TryGetValue(domain, out items)) { throw new InvalidOperationException("The specified domain does not exist."); } var skip = 0; if (request.IsSetNextToken()) { int.TryParse(request.NextToken, out skip); } var result = new SelectResponse() .WithSelectResult(new SelectResult() .WithItem(IntoItem(items .Skip(skip) .Take(MaxItems)))); if (result.SelectResult.Item.Count == MaxItems) { result.SelectResult.WithNextToken((skip + MaxItems).ToString()); } ++SelectCount; return result; }
public override IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria) { var request = new SelectRequest().WithSelectExpression("select * from " + tableName); while (request != null) { var response = client.Select(request); foreach (var item in response.SelectResult.Item) { yield return ConvertToDictionary(item); } if (response.SelectResult.IsSetNextToken()) { request.NextToken = response.SelectResult.NextToken; } else { request = null; } } }
public static void Main(string[] args) { AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(RegionEndpoint.USWest2); try { Console.WriteLine("==========================================="); Console.WriteLine("Getting Started with Amazon SimpleDB"); Console.WriteLine("===========================================\n"); // Creating a domain Console.WriteLine("Creating domain called MyStore.\n"); String domainName = "MyStore"; CreateDomainRequest createDomain = (new CreateDomainRequest()).WithDomainName(domainName); sdb.CreateDomain(createDomain); // Listing domains ListDomainsResponse sdbListDomainsResponse = sdb.ListDomains(new ListDomainsRequest()); if (sdbListDomainsResponse.IsSetListDomainsResult()) { ListDomainsResult listDomainsResult = sdbListDomainsResponse.ListDomainsResult; Console.WriteLine("List of domains:\n"); foreach (String domain in listDomainsResult.DomainName) { Console.WriteLine(" " + domain); } } Console.WriteLine(); // Putting data into a domain Console.WriteLine("Putting data into MyStore domain.\n"); String itemNameOne = "Item_01"; PutAttributesRequest putAttributesActionOne = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameOne); List<ReplaceableAttribute> attributesOne = putAttributesActionOne.Attribute; 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")); sdb.PutAttributes(putAttributesActionOne); String itemNameTwo = "Item_02"; PutAttributesRequest putAttributesActionTwo = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameTwo); List<ReplaceableAttribute> attributesTwo = putAttributesActionTwo.Attribute; attributesTwo.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); attributesTwo.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Pants")); attributesTwo.Add(new ReplaceableAttribute().WithName("Name").WithValue("Designer Jeans")); attributesTwo.Add(new ReplaceableAttribute().WithName("Color").WithValue("Paisley Acid Wash")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("30x32")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("32x32")); attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("32x34")); sdb.PutAttributes(putAttributesActionTwo); String itemNameThree = "Item_03"; PutAttributesRequest putAttributesActionThree = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameThree); List<ReplaceableAttribute> attributesThree = putAttributesActionThree.Attribute; attributesThree.Add(new ReplaceableAttribute().WithName("Category").WithValue("Clothes")); attributesThree.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Pants")); attributesThree.Add(new ReplaceableAttribute().WithName("Name").WithValue("Sweatpants")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Blue")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Yellow")); attributesThree.Add(new ReplaceableAttribute().WithName("Color").WithValue("Pink")); attributesThree.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large")); attributesThree.Add(new ReplaceableAttribute().WithName("Year").WithValue("2006")); attributesThree.Add(new ReplaceableAttribute().WithName("Year").WithValue("2007")); sdb.PutAttributes(putAttributesActionThree); String itemNameFour = "Item_04"; PutAttributesRequest putAttributesActionFour = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameFour); List<ReplaceableAttribute> attributesFour = putAttributesActionFour.Attribute; attributesFour.Add(new ReplaceableAttribute().WithName("Category").WithValue("Car Parts")); attributesFour.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Engine")); attributesFour.Add(new ReplaceableAttribute().WithName("Name").WithValue("Turbos")); attributesFour.Add(new ReplaceableAttribute().WithName("Make").WithValue("Audi")); attributesFour.Add(new ReplaceableAttribute().WithName("Model").WithValue("S4")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2000")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2001")); attributesFour.Add(new ReplaceableAttribute().WithName("Year").WithValue("2002")); sdb.PutAttributes(putAttributesActionFour); String itemNameFive = "Item_05"; PutAttributesRequest putAttributesActionFive = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameFive); List<ReplaceableAttribute> attributesFive = putAttributesActionFive.Attribute; attributesFive.Add(new ReplaceableAttribute().WithName("Category").WithValue("Car Parts")); attributesFive.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Emissions")); attributesFive.Add(new ReplaceableAttribute().WithName("Name").WithValue("O2 Sensor")); attributesFive.Add(new ReplaceableAttribute().WithName("Make").WithValue("Audi")); attributesFive.Add(new ReplaceableAttribute().WithName("Model").WithValue("S4")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2000")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2001")); attributesFive.Add(new ReplaceableAttribute().WithName("Year").WithValue("2002")); sdb.PutAttributes(putAttributesActionFive); // Getting data from a domain Console.WriteLine("Print attributes with the attribute Category that contain the value Clothes.\n"); String selectExpression = "Select * From MyStore Where Category = 'Clothes'"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; foreach (Item item in selectResult.Item) { Console.WriteLine(" Item"); if (item.IsSetName()) { Console.WriteLine(" Name: {0}", item.Name); } foreach (Amazon.SimpleDB.Model.Attribute attribute in item.Attribute) { Console.WriteLine(" Attribute"); if (attribute.IsSetName()) { Console.WriteLine(" Name: {0}", attribute.Name); } if (attribute.IsSetValue()) { Console.WriteLine(" Value: {0}", attribute.Value); } } } } Console.WriteLine(); // Deleting values from an attribute Console.WriteLine("Deleting Blue attributes in Item_O3.\n"); Amazon.SimpleDB.Model.Attribute deleteValueAttribute = new Amazon.SimpleDB.Model.Attribute().WithName("Color").WithValue("Blue"); DeleteAttributesRequest deleteValueAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteValueAttribute); sdb.DeleteAttributes(deleteValueAction); //Deleting an attribute Console.WriteLine("Deleting attribute Year in Item_O3.\n"); Amazon.SimpleDB.Model.Attribute deleteAttribute = new Amazon.SimpleDB.Model.Attribute().WithName("Year"); DeleteAttributesRequest deleteAttributeAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(deleteAttribute); sdb.DeleteAttributes(deleteAttributeAction); //Replacing an attribute Console.WriteLine("Replace Size of Item_03 with Medium.\n"); ReplaceableAttribute replaceableAttribute = new ReplaceableAttribute().WithName("Size").WithValue("Medium").WithReplace(true); PutAttributesRequest replaceAction = new PutAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03").WithAttribute(replaceableAttribute); sdb.PutAttributes(replaceAction); //Deleting an item Console.WriteLine("Deleting Item_03 item.\n"); DeleteAttributesRequest deleteItemAction = new DeleteAttributesRequest().WithDomainName("MyStore").WithItemName("Item_03"); sdb.DeleteAttributes(deleteAttributeAction); //Deleting a domain Console.WriteLine("Deleting MyStore domain.\n"); DeleteDomainRequest deleteDomainAction = new DeleteDomainRequest().WithDomainName("MyStore"); sdb.DeleteDomain(deleteDomainAction); } catch (AmazonSimpleDBException ex) { Console.WriteLine("Caught Exception: " + ex.Message); Console.WriteLine("Response Status Code: " + ex.StatusCode); Console.WriteLine("Error Code: " + ex.ErrorCode); Console.WriteLine("Error Type: " + ex.ErrorType); Console.WriteLine("Request ID: " + ex.RequestId); Console.WriteLine("XML: " + ex.XML); } Console.WriteLine("Press Enter to continue..."); Console.Read(); }
/// <summary> /// Put the user's reco into the ZigMeRecos domain in SimpleDB /// </summary> /// <returns></returns> private bool SaveRecoToSimpleDB(string myFBId) { AmazonSimpleDB sdb = GetSDB(); // Creating a domain String domainName = "ZigMeRecos"; CreateDomainRequest createDomain = (new CreateDomainRequest()).WithDomainName(domainName); sdb.CreateDomain(createDomain); // Check to see how many recos this FB user id has stored in our domain String selectExpression = "Select * From ZigMeRecos Where FBId = '" + myFBId + "'"; SelectRequest selectRequestAction = new SelectRequest().WithSelectExpression(selectExpression); SelectResponse selectResponse = sdb.Select(selectRequestAction); int cRecos = 0; // Now store the actual recommendation item if (selectResponse.IsSetSelectResult()) { SelectResult selectResult = selectResponse.SelectResult; cRecos = selectResult.Item.Count; } cRecos++; String recoItem = "Reco_" + myFBId + "_" + cRecos; PutAttributesRequest putAttributesRecoItem = new PutAttributesRequest().WithDomainName(domainName).WithItemName(recoItem); List<ReplaceableAttribute> attributesRecoItem = putAttributesRecoItem.Attribute; attributesRecoItem.Add(new ReplaceableAttribute().WithName("FBId").WithValue(myFBId)); attributesRecoItem.Add(new ReplaceableAttribute().WithName("Name").WithValue(RecoName.Text)); attributesRecoItem.Add(new ReplaceableAttribute().WithName("Email").WithValue(ContactEmail.Text)); attributesRecoItem.Add(new ReplaceableAttribute().WithName("City").WithValue(RecoCity.Text)); attributesRecoItem.Add(new ReplaceableAttribute().WithName("Service").WithValue(RecoService.SelectedValue)); PutAttributesResponse putAttributesResponse = sdb.PutAttributes(putAttributesRecoItem); return putAttributesResponse.IsSetResponseMetadata(); }
/// <summary> /// Initiates the asynchronous execution of the Select operation. /// <seealso cref="Amazon.SimpleDB.IAmazonSimpleDB"/> /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the Select operation.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// <returns>The task object representing the asynchronous operation.</returns> public Task<SelectResponse> SelectAsync(SelectRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SelectRequestMarshaller(); var unmarshaller = SelectResponseUnmarshaller.Instance; return InvokeAsync<SelectRequest,SelectResponse>(request, marshaller, unmarshaller, cancellationToken); }
internal SelectResponse Select(SelectRequest request) { var task = SelectAsync(request); try { return task.Result; } catch(AggregateException e) { throw e.InnerException; } }
public override MembershipUserCollection GetAllUsers(int pageIndex, int pageSize, out int totalRecords) { MembershipUserCollection users = new MembershipUserCollection(); SelectRequest request = new SelectRequest() .WithSelectExpression(String.Concat("Select * from `", Settings.Default.AWSMembershipDomain, "`")); SelectResult result = this._simpleDBClient.Select(request).SelectResult; if (result != null) { totalRecords = result.Item.Count; string userName = String.Empty; string email = String.Empty; string passwordQuestion = String.Empty; bool isApproved = false; foreach (Item item in result.Item) { List<Attribute> attributes = item.Attribute; foreach (Attribute att in attributes) { switch (att.Name) { case "Email": { email = att.Value; break; } case "PasswordQuestion": { passwordQuestion = att.Value; break; } case "IsApproved": { isApproved = bool.Parse(att.Value); break; } default: break; } } userName = item.Name; users.Add(new MembershipUser( this.Name, userName, String.Empty, email, passwordQuestion, String.Empty, isApproved, false, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today )); } } else { totalRecords = 0; } return users; }
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; }
IAsyncResult AmazonSimpleDB.BeginSelect(SelectRequest request, AsyncCallback callback, object state) { throw new NotImplementedException(); }
public virtual List<Daffodil> ReadDaffodils() { var daffodils = new List<Daffodil>(); var client = this.GetClient(); var request = new SelectRequest { SelectExpression = "SELECT * FROM daffodil", }; var response = client.Select(request); var items = response.SelectResult.Item; foreach(var item in items) { var idFromDb = item.Attribute.First(x => x.Name == "Id").Value; var dataFromDb = item.Attribute.First(x => x.Name == "Data").Value; var daffodil = new Daffodil { Id = idFromDb, Data = dataFromDb, }; daffodils.Add(daffodil); } return daffodils; }
public static List<Comment> GetComments(string domainName) { List<Comment> comments = new List<Comment>(); Comment comment; String selectExpression = "Select * 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) { comment = new Comment(); 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": comment.NewsID = attribute.Value; break; case "UserName": comment.UserName = attribute.Value; break; case "CommentID": comment.CommentID = Guid.Parse(attribute.Value); break; case "CommentAdded": comment.CommentAdded = Convert.ToDateTime(attribute.Value); break; case "Likes": comment.Likes = Convert.ToInt32(attribute.Value); break; case "CommentItem": comment.CommentItem = attribute.Value.Contains("/") ? GetTheHtml(attribute.Value) : ""; break; case "CommentReplyID": comment.CommentReplyID = attribute.Value; break; } i++; } } comments.Add(comment); } } return comments; }
public override string GetUserNameByEmail(string email) { this.VerifyKeys(); if (!String.IsNullOrEmpty(email)) { DomainHelper.CheckForDomain(Settings.Default.AWSMembershipDomain, _simpleDBClient); SelectRequest request = new SelectRequest(); request.SelectExpression = String.Concat( "Select * from `", Settings.Default.AWSMembershipDomain, "` where Email='", email, "'" ); SelectResult result = this._simpleDBClient.Select(request).SelectResult; if (result == null || result.Item.Count == 0) { return String.Empty; } else { return result.Item[0].Name; } } throw new ArgumentNullException("email", "The email passed in is null"); }
public override object Execute(Expression expression) { try { Type elementType = TypeSystem.GetElementType(expression.Type); string methodName = ((MethodCallExpression)expression).Method.Name; bool isIQueryable = expression.Type.FullName.StartsWith("System.Linq.IQueryable"); string queryString = String.Format(this.Translate(expression), m_domainName); if (!OrderBy.IsNullOrBlank()) { string orderByField = (OrderBy.IndexOf(' ') != -1) ? OrderBy.Substring(0, OrderBy.IndexOf(' ')) : OrderBy; // SimpleDB queries with an order clause must have the order field included as a predicate. // If the select query does not contain the a predicate with the order field add it here. if (!queryString.Contains(orderByField)) { queryString += " and " + orderByField + " like '%'"; } queryString += " order by " + OrderBy; } if (Count != Int32.MaxValue) { queryString += " limit " + Count; } //logger.Debug(queryString); if (!queryString.IsNullOrBlank()) { //logger.Debug("SimpleDB select: " + queryString + "."); SelectRequest request = new SelectRequest(); request.SelectExpression = queryString; SelectResponse response = m_service.Select(request); if (response.IsSetSelectResult()) { if (elementType == typeof(Int32)) { return Convert.ToInt32(response.SelectResult.Item[0].Attribute[0].Value); } else { object result = Activator.CreateInstance( typeof(SimpleDBObjectReader<>).MakeGenericType(elementType), BindingFlags.Instance | BindingFlags.Public, null, new object[] { response.SelectResult, m_setter }, null); if (isIQueryable) { return result; } else { IEnumerator enumerator = ((IEnumerable)result).GetEnumerator(); if (enumerator.MoveNext()) { return enumerator.Current; } else { return null; } } } } throw new ApplicationException("No results for SimpleDB query."); } else { throw new ApplicationException("The expression translation by the SimpleDBQueryProvider resulted in an empty select string."); } } catch (Exception excp) { logger.Error("Exception SimpleDBQueryProvider Execute. " + expression.ToString() + ". " + excp.Message); throw; } }
/// <summary> /// <para> The <c>Select</c> operation returns a set of attributes for <c>ItemNames</c> that match the select expression. <c>Select</c> is /// similar to the standard SQL SELECT statement. </para> <para> The total size of the response cannot exceed 1 MB in total size. Amazon /// SimpleDB automatically adjusts the number of items returned per page to enforce this limit. For example, if the client asks to retrieve 2500 /// items, but each individual item is 10 kB in size, the system returns 100 items and an appropriate <c>NextToken</c> so the client can access /// the next page of results. </para> <para> For information on how to construct select expressions, see Using Select to Create Amazon SimpleDB /// Queries in the Developer Guide. </para> /// </summary> /// /// <param name="selectRequest">Container for the necessary parameters to execute the Select service method on AmazonSimpleDB.</param> /// /// <returns>The response from the Select service method, as returned by AmazonSimpleDB.</returns> /// /// <exception cref="T:Amazon.SimpleDB.Model.InvalidParameterValueException" /> /// <exception cref="T:Amazon.SimpleDB.Model.InvalidQueryExpressionException" /> /// <exception cref="T:Amazon.SimpleDB.Model.RequestTimeoutException" /> /// <exception cref="T:Amazon.SimpleDB.Model.InvalidNumberPredicatesException" /> /// <exception cref="T:Amazon.SimpleDB.Model.NoSuchDomainException" /> /// <exception cref="T:Amazon.SimpleDB.Model.InvalidNextTokenException" /> /// <exception cref="T:Amazon.SimpleDB.Model.TooManyRequestedAttributesException" /> /// <exception cref="T:Amazon.SimpleDB.Model.MissingParameterException" /> /// <exception cref="T:Amazon.SimpleDB.Model.InvalidNumberValueTestsException" /> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> public async Task<SelectResponse> SelectAsync(SelectRequest selectRequest, CancellationToken cancellationToken = default(CancellationToken)) { var marshaller = new SelectRequestMarshaller(); var unmarshaller = SelectResponseUnmarshaller.GetInstance(); var response = await Invoke<IRequest, SelectRequest, SelectResponse>(selectRequest, marshaller, unmarshaller, signer, cancellationToken) .ConfigureAwait(continueOnCapturedContext: false); return response; }
/// <summary> /// The <code>Select</code> operation returns a set of attributes for <code>ItemNames</code> /// that match the select expression. <code>Select</code> is similar to the standard SQL /// SELECT statement. /// /// /// <para> /// The total size of the response cannot exceed 1 MB in total size. Amazon SimpleDB /// automatically adjusts the number of items returned per page to enforce this limit. /// For example, if the client asks to retrieve 2500 items, but each individual item is /// 10 kB in size, the system returns 100 items and an appropriate <code>NextToken</code> /// so the client can access the next page of results. /// </para> /// /// <para> /// For information on how to construct select expressions, see Using Select to Create /// Amazon SimpleDB Queries in the Developer Guide. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the Select service method.</param> /// /// <returns>The response from the Select service method, as returned by SimpleDB.</returns> /// <exception cref="InvalidNextTokenException"> /// The specified NextToken is not valid. /// </exception> /// <exception cref="InvalidNumberPredicatesException"> /// Too many predicates exist in the query expression. /// </exception> /// <exception cref="InvalidNumberValueTestsException"> /// Too many predicates exist in the query expression. /// </exception> /// <exception cref="InvalidParameterValueException"> /// The value for a parameter is invalid. /// </exception> /// <exception cref="InvalidQueryExpressionException"> /// The specified query expression syntax is not valid. /// </exception> /// <exception cref="MissingParameterException"> /// The request must contain the specified missing parameter. /// </exception> /// <exception cref="NoSuchDomainException"> /// The specified domain does not exist. /// </exception> /// <exception cref="RequestTimeoutException"> /// A timeout occurred when attempting to query the specified domain with specified query /// expression. /// </exception> /// <exception cref="TooManyRequestedAttributesException"> /// Too many attributes requested. /// </exception> public SelectResponse Select(SelectRequest request) { var marshaller = new SelectRequestMarshaller(); var unmarshaller = SelectResponseUnmarshaller.Instance; return Invoke<SelectRequest,SelectResponse>(request, marshaller, unmarshaller); }