Container for the parameters to the PutAttributes operation.

The PutAttributes operation creates or replaces attributes in an item. The client may specify new attributes using a combination of the Attribute.X.Name and Attribute.X.Value parameters. The client specifies the first attribute by the parameters Attribute.0.Name and Attribute.0.Value , the second attribute by the parameters Attribute.1.Name and Attribute.1.Value , and so on.

Attributes are uniquely identified in an item by their name/value combination. For example, a single item can have the attributes { "first_name", "first_value" } and { "first_name", second_value" } . However, it cannot have two attribute instances where both the Attribute.X.Name and Attribute.X.Value are the same.

Optionally, the requestor can supply the Replace parameter for each individual attribute. Setting this value to true causes the new attribute value to replace the existing attribute value(s). For example, if an item has the attributes { 'a', '1' } , { 'b', '2'} and { 'b', '3' } and the requestor calls PutAttributes using the attributes { 'b', '4' } with the Replace parameter set to true, the final attributes of the item are changed to { 'a', '1' } and { 'b', '4' } , which replaces the previous values of the 'b' attribute with the new value.

NOTE: Using PutAttributes to replace attribute values that do not exist will not result in an error response.

You cannot specify an empty string as an attribute name.

Because Amazon SimpleDB makes multiple copies of client data and uses an eventual consistency update model, an immediate GetAttributes or Select operation (read) immediately after a PutAttributes or DeleteAttributes operation (write) might not return the updated data.

The following limitations are enforced for this operation:

  • 256 total attribute name-value pairs per item
  • One billion attributes per domain
  • 10 GB of total user data storage per domain

Inheritance: Amazon.Runtime.AmazonWebServiceRequest
        PutAttributesResponse AmazonSimpleDB.PutAttributes(PutAttributesRequest request)
        {
            Dictionary<string, Dictionary<string, string>> domain;

            if (!Domains.TryGetValue(request.DomainName, out domain))
            {
                throw new InvalidOperationException("The specified domain does not exist.");
            }

            Dictionary<string, string> item;

            if (!domain.TryGetValue(request.ItemName, out item))
            {
                item = new Dictionary<string, string>();
                domain.Add(request.ItemName, item);
            }

            foreach (var attribute in request.Attribute)
            {
                item[attribute.Name] = attribute.Value;
            }

            ++PutAttributesCount;
            return new PutAttributesResponse();
        }
 public bool AddUpdateRoute(Route route)
 {
     bool success = true;
     using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(_publicKey, _secretKey))
     {
         PutAttributesRequest request = new PutAttributesRequest
                                            {
                                                DomainName = DomainName,
                                                ItemName = route.Id.ToString()
                                            };
         request.Attribute.Add(new ReplaceableAttribute() { Name = "Name", Replace = true, Value = route.Name });
         request.Attribute.Add(new ReplaceableAttribute() { Name = "Distance", Replace = true, Value = route.Distance.ToString() });
         request.Attribute.Add(new ReplaceableAttribute() { Name = "Id", Replace = true, Value = route.Id.ToString() });
         request.Attribute.Add(new ReplaceableAttribute() { Name = "LastTimeRidden", Replace = true, Value = route.LastTimeRidden.ToShortDateString() });
         request.Attribute.Add(new ReplaceableAttribute() { Name = "Location", Replace = true, Value = route.Location });
         try
         {
             PutAttributesResponse response = client.PutAttributes(request);
         }
         catch(Exception repositoryError)
         {
             success = false;
         }
     }
     return success;
 }
 protected override void ProcessRecord()
 {
     AmazonSimpleDB client = base.GetClient();
     Amazon.SimpleDB.Model.PutAttributesRequest request = new Amazon.SimpleDB.Model.PutAttributesRequest();
     request.DomainName = this._DomainName;
     request.ItemName = this._ItemName;
     Amazon.SimpleDB.Model.PutAttributesResponse response = client.PutAttributes(request);
 }
Exemplo n.º 4
0
 public void Put(string domainName, string itemName, List<ReplaceableAttribute> replaceableAttributes)
 {
     var putAttributesRequest = new PutAttributesRequest
                          {
                              DomainName = domainName,
                              ItemName = itemName,
                              Attribute = replaceableAttributes
                          };
     var putAttributesResponse = _simpleDbClient.PutAttributes(putAttributesRequest);
 }
Exemplo n.º 5
0
        public void Put(string domain, string id, Dictionary<string, string> properties, bool replace = false)
        {
            PutAttributesRequest request = new PutAttributesRequest()
                .WithDomainName(domain)
                .WithItemName(id)
                .WithAttribute(properties.Select(kv =>
                                                 new ReplaceableAttribute().WithName(kv.Key).WithValue(kv.Value).
                                                     WithReplace(replace)).ToArray());
            //    .WithExpected(new UpdateCondition())

            _simpleDbClient.PutAttributes(request);
        }
Exemplo n.º 6
0
        public void Save()
        {
            PutAttributesRequest putRequest = new PutAttributesRequest().WithDomainName(Domain.CourseList).WithItemName(Name);
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(NameField).WithValue(Name));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(IdField).WithValue(Id));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(SortOrderField).WithValue(SortOrder.ToString()));

            using (AmazonSimpleDB client = ClientFactory.CreateDBClient())
            {
                client.PutAttributes(putRequest);
            }
        }
        public void Save()
        {
            PutAttributesRequest putRequest = new PutAttributesRequest().WithDomainName(Domain.CourseScoreList).WithItemName(CourseId+Email);

            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(CourseIdField).WithValue(CourseId));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(EmailField).WithValue(Email));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(PassingDateField).WithValue(PassingDate.ToString()));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(IsPassingScoreField).WithValue(IsPassingScore.ToString()));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(PercentCompleteField).WithValue(PercentComplete.ToString()));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(LastSavedOnDateField).WithValue(DateTime.UtcNow.ToString()));

            using (AmazonSimpleDB client = ClientFactory.CreateDBClient())
            {
                client.PutAttributes(putRequest);
            }
        }
Exemplo n.º 8
0
        public void Save()
        {
            PutAttributesRequest putRequest = new PutAttributesRequest().WithDomainName(Domain.UserList).WithItemName(Email);
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(NameField).WithValue(Name));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(EmailField).WithValue(Email));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(PasswordField).WithValue(Password));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(IsStudentAdminField).WithValue(IsStudentAdmin.ToString()));
            putRequest.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(IsSystemAdminField).WithValue(IsSystemAdmin.ToString()));
            CourseAccesses.ForEach( s =>
                    putRequest.Attribute.Add(new ReplaceableAttribute().WithName(CourseAccessField).WithValue(s)));

            using (AmazonSimpleDB client = ClientFactory.CreateDBClient())
            {
                client.PutAttributes(putRequest);
            }
        }
        /// <summary>
        /// Notifies subscription to a given feature.  If it fails for any reason, logs the error and raises the exception.
        /// </summary>
        /// <param name="applicationName">Name of the application the feature is in</param>
        /// <param name="featureName">Name of the feature</param>
        /// <param name="subscriber">Who subscribed to the feature</param>
        /// <param name="subscribedAt">When it was subscribed at.  If null, defaults to the current date/time</param>
        public void NotifyFeatureSubscription( string applicationName, string featureName, string subscriber, DateTime? subscribedAt = new DateTime?() )
        {
            // Make sure the domain exists
            CreateDomain(_domainName);

            // Create the request
            var request = new PutAttributesRequest()
                .WithDomainName(_domainName)
                .WithItemName(Guid.NewGuid().ToString())
                .WithAttribute(new[]
                                   {
                                       new ReplaceableAttribute().WithName("application").WithValue(applicationName ?? ""),
                                       new ReplaceableAttribute().WithName("feature").WithValue(featureName ?? ""),
                                       new ReplaceableAttribute().WithName("subscriber").WithValue(subscriber ?? ""),
                                       new ReplaceableAttribute().WithName("subscribedAt").WithValue((subscribedAt ?? DateTime.Now).ToString())
                                   });

            // Send the request
            _simpleDbClient.PutAttributes(request);
        }
Exemplo n.º 10
0
        public void Add(string storeIdentifier, string requestIdentifier, string[] responseItems)
        {
            EnsureDomain(storeIdentifier);

            foreach (var responseItem in responseItems)
            {
                var itemName = Guid.NewGuid().ToString();
                var putRequest = new PutAttributesRequest()
                                        .WithDomainName(storeIdentifier)
                                        .WithItemName(itemName);
                List<ReplaceableAttribute> attributes = putRequest.Attribute;
                attributes.Add(new ReplaceableAttribute()
                                    .WithName("RequestId")
                                    .WithValue(requestIdentifier));
                attributes.Add(new ReplaceableAttribute()
                                    .WithName("ResponseItem")
                                    .WithValue(responseItem));
                _simpleDb.PutAttributes(putRequest);
            }
        }
        /// <summary>
        /// Logs usage of a given feature.  If it fails for any reason, logs the error and raises the exception.
        /// </summary>
        /// <param name="applicationName">Name of the application the feature is in</param>
        /// <param name="featureName">Name of the feature</param>
        /// <param name="usedBy">Who used the feature</param>
        /// <param name="usedAt">When it was used at</param>
        /// <param name="usageDetails">Details of the usage</param>
        public void NotifyFeatureUsage( string applicationName, string featureName, string usageDetails = null, string usedBy = null, DateTime? usedAt = new DateTime?() )
        {
            // Make sure the domain exists
            CreateDomain(_domainName);

            // Create the request
            var request = new PutAttributesRequest()
                .WithDomainName(_domainName)
                .WithItemName(Guid.NewGuid().ToString())
                .WithAttribute(new[]
                                   {
                                       new ReplaceableAttribute().WithName("application").WithValue(applicationName ?? ""),
                                       new ReplaceableAttribute().WithName("feature").WithValue(featureName ?? ""),
                                       new ReplaceableAttribute().WithName("detail").WithValue(usageDetails ?? ""),
                                       new ReplaceableAttribute().WithName("usedBy").WithValue(usedBy ?? ""),
                                       new ReplaceableAttribute().WithName("usedAt").WithValue((usedAt ?? DateTime.Now).ToString())
                                   });

            // Send the request
            _simpleDbClient.PutAttributes(request);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Add 50 items using the asynchronized API.
        /// </summary>
        static void addDataAsynchronized()
        {
            Console.WriteLine("Start testing asynchronized method.");
            string domainName = "AsyncDomain";
            sdb.CreateDomain(new CreateDomainRequest()
                .WithDomainName(domainName));

            Results results = new Results();
            List<WaitHandle> waitHandles = new List<WaitHandle>();
            try
            {
                long start = DateTime.Now.Ticks;
                for (int i = 0; i < MAX_ROWS; i++)
                {
                    PutAttributesRequest request = new PutAttributesRequest()
                        .WithDomainName(domainName)
                        .WithItemName("ItemName" + i)
                        .WithAttribute(new ReplaceableAttribute()
                            .WithName("Value")
                            .WithValue(i.ToString()));

                    // Start the put attributes operation.  The callback method will be called when the put attributes operation
                    // is complete or an error occurs.
                    IAsyncResult asyncResult = sdb.BeginPutAttributes(request, new AsyncCallback(Program.callBack), results);
                    waitHandles.Add(asyncResult.AsyncWaitHandle);
                }

                // Wait till all the requests that were started are completed.
                WaitHandle.WaitAll(waitHandles.ToArray());

                TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start);
                Console.WriteLine("Time: {0} ms Successes: {1} Errors: {2}", ts.TotalMilliseconds, results.Successes, results.Errors);
            }
            finally
            {
                sdb.DeleteDomain(new DeleteDomainRequest()
                    .WithDomainName(domainName));
            }
        }
Exemplo n.º 13
0
        public void AddBroadcastMessage(string userName, string body, IEnumerable<MessageAttachment> attachments)
        {
            int broadcastDomainNumber = new Random().Next(0, 7);

            List<ReplaceableAttribute> attrs = new List<ReplaceableAttribute>()
            {
                new ReplaceableAttribute()
                        .WithName("body")
                        .WithValue(body),

                new ReplaceableAttribute()
                        .WithName("time")
                        .WithValue(AmazonSimpleDBUtil.FormattedCurrentTimestamp)
            };

            int i = 0;
            foreach (var attachment in attachments)
            {
                attrs.Add(new ReplaceableAttribute()
                    .WithName(String.Format("Attachment_{0}_URL", i))
                    .WithValue(attachment.CloudFrontURI.AbsoluteUri));

                attrs.Add(new ReplaceableAttribute()
                    .WithName(String.Format("Attachment_{0}_Description", i))
                    .WithValue(attachment.Description));

                ++i;
            }

            PutAttributesRequest request = new PutAttributesRequest()
                .WithDomainName(m_BroadcastMessagesDomain + broadcastDomainNumber.ToString())
                .WithItemName(userName + "_" + Guid.NewGuid());

            request.Attribute = attrs;

            PutAttributesResponse resoponse = m_simpleDBClient.PutAttributes(request);
        }
        public override MembershipUser CreateUser(string userName, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            MembershipUser user = this.GetUser(userName, false);
            if (user == null)
            {
                string existingUser = this.GetUserNameByEmail(email);
                if (String.IsNullOrEmpty(existingUser))
                {
                    List<ReplaceableAttribute> data = new List<ReplaceableAttribute>();
                    data.Add(new ReplaceableAttribute().WithName("Email").WithValue(email));
                    data.Add(new ReplaceableAttribute().WithName("Password").WithValue(password));
                    if (passwordQuestion != null)
                    {
                        data.Add(new ReplaceableAttribute().WithName("PasswordQuestion").WithValue(passwordQuestion));
                    }

                    if (passwordAnswer != null)
                    {
                        data.Add(new ReplaceableAttribute().WithName("PasswordAnswer").WithValue(passwordAnswer));
                    }

                    data.Add(new ReplaceableAttribute().WithName("IsApproved").WithValue(isApproved.ToString()));
                    PutAttributesRequest request = new PutAttributesRequest()
                        .WithDomainName(Settings.Default.AWSMembershipDomain)
                        .WithItemName(userName);
                    request.Attribute = data;
                    this._simpleDBClient.PutAttributes(request);
                    status = MembershipCreateStatus.Success;
                    user = this.GetUser(userName, false);
                }
                else
                {
                    status = MembershipCreateStatus.DuplicateEmail;
                }
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return user;
        }
        public override bool ChangePassword(string userName, string oldPwd, string newPwd)
        {
            if (!this.ValidateUser(userName, oldPwd))
            {
                return false;
            }

            PutAttributesRequest request = new PutAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttribute(new ReplaceableAttribute
                    {
                        Name = "Password",
                        Value = newPwd,
                        Replace = true
                    }
                );
            this._simpleDBClient.PutAttributes(request);
            return true;
        }
        public void Persist(Daffodil daffodil)
        {
            #if DEBUG
            Assert.Fail(()=>(!String.IsNullOrWhiteSpace(_serviceUrl)), "You are a big dummy!");
            #endif

            this.CreateDomainIfNecessary("daffodil");

            var client = this.GetClient();
            var attributes = new List<ReplaceableAttribute>
                                 {
                                     new ReplaceableAttribute
                                         {
                                             Name = "Id",
                                             Replace = true,
                                             Value = daffodil.Id,
                                         },
                                     new ReplaceableAttribute
                                         {
                                             Name = "Data",
                                             Replace = true,
                                             Value = daffodil.Data,
                                         }
                                 };

            var request = new PutAttributesRequest
                              {
                                  DomainName = "daffodil",
                                  Attribute = attributes,
                                  ItemName = daffodil.Id
                              };
            client.PutAttributes(request);
        }
	    IAsyncResult AmazonSimpleDB.BeginPutAttributes(PutAttributesRequest request, AsyncCallback callback, object state)
	    {
	        throw new NotImplementedException();
	    }
Exemplo n.º 18
0
 /// <summary>
 /// Creates a user. 
 /// </summary>
 /// <param name="request"></param>
 public void CreateUser(CreateUserRequest request)
 {
     var putRequest = new PutAttributesRequest().WithDomainName(_config.StoreName)
         .WithItemName(request.UserName)
         .WithAttribute(new ReplaceableAttribute().WithName("Password").WithValue(request.Password))
         ;
     _client.PutAttributes(putRequest);
 }
Exemplo n.º 19
0
        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();
        }
Exemplo n.º 20
0
 public void AddToGroup(AddToGroupRequest request)
 {
     var putAttribute = new PutAttributesRequest().WithDomainName(_config.StoreName).WithItemName(
         request.UserName)
         .WithAttribute(new ReplaceableAttribute().WithName("Groups").WithValue(request.Group));
     _client.PutAttributes(putAttribute);
 }
        public static void SaveComments(string domainName, Comment comment)
        {
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(comment.CommentID));
            putAttrRequest.WithAttribute(new ReplaceableAttribute
            {
                Name = "NewsID",
                Value = Convert.ToString(comment.NewsID),
                Replace = false
            },

            new ReplaceableAttribute
            {
                Name = "UserName",
                Value = comment.UserName,
                Replace = false
            },
            new ReplaceableAttribute
            {
                Name = "CommentID",
                Value = Convert.ToString(comment.CommentID),
                Replace = false
            },
             new ReplaceableAttribute
             {
                 Name = "CommentAdded",
                 Value = Convert.ToString(comment.CommentAdded),
                 Replace = false
             }
             ,
             new ReplaceableAttribute
             {
                 Name = "CommentItem",
                 Value = SaveHtml(comment.CommentItem),
                 Replace = false
             }
              ,
             new ReplaceableAttribute
             {
                 Name = "CommentReplyID",
                 Value = comment.CommentReplyID,
                 Replace = false
             }
              ,
             new ReplaceableAttribute
             {
                 Name = "Likes",
                 Value = Convert.ToString(comment.Likes),
                 Replace = true
             }
               );
            sdbClient.PutAttributes(putAttrRequest);
        }
        public static void SaveLikes(string domainName, Comment comment)
        {
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(comment.CommentID));
            putAttrRequest.WithAttribute(new ReplaceableAttribute
            {
                Name = "Likes",
                Value = Convert.ToString(comment.Likes),
                Replace = true
            }

               );
            sdbClient.PutAttributes(putAttrRequest);
        }
Exemplo n.º 23
0
		internal PutAttributesResponse PutAttributes(PutAttributesRequest request)
        {
            var task = PutAttributesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        public override string ResetPassword(string userName, string answer)
        {
            string newPassword = Membership.GeneratePassword(6, 0);
            string passwordAnswer = String.Empty;
            GetAttributesRequest request = new GetAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttributeName(PasswordStrings);
            GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult;
            if (result != null)
            {
                foreach (Attribute att in result.Attribute)
                {
                    switch (att.Name)
                    {
                        case "PasswordAnswer":
                        {
                            passwordAnswer = att.Value;
                            break;
                        }
                    }
                }
            }
            else
            {
                throw new MembershipPasswordException("User not found");
            }

            if (this.RequiresQuestionAndAnswer && !this.CheckPassword(answer, passwordAnswer))
            {
                throw new MembershipPasswordException("Incorrect password answer.");
            }

            ReplaceableAttribute replace = new ReplaceableAttribute()
                .WithName(PasswordStrings[0])
                .WithValue(newPassword)
                .WithReplace(true);
            PutAttributesRequest prequest = new PutAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttribute(replace);
            this._simpleDBClient.PutAttributes(prequest);
            return newPassword;
        }
 public override void UpdateUser(MembershipUser user)
 {
     List<ReplaceableAttribute> attributes = new List<ReplaceableAttribute> { 
         new ReplaceableAttribute()
             .WithName("Email")
             .WithValue(user.Email)
             .WithReplace(true) 
     };
     PutAttributesRequest request = new PutAttributesRequest()
         .WithDomainName(Settings.Default.AWSMembershipDomain)
         .WithItemName(user.UserName);
     request.Attribute = attributes;
     this._simpleDBClient.PutAttributes(request);
 }
Exemplo n.º 26
0
        /// <summary>
        /// The PutAttributes operation creates or replaces attributes in an item. The client
        /// may specify new attributes using a combination of the <code>Attribute.X.Name</code>
        /// and <code>Attribute.X.Value</code> parameters. The client specifies the first attribute
        /// by the parameters <code>Attribute.0.Name</code> and <code>Attribute.0.Value</code>,
        /// the second attribute by the parameters <code>Attribute.1.Name</code> and <code>Attribute.1.Value</code>,
        /// and so on. 
        /// 
        ///  
        /// <para>
        ///  Attributes are uniquely identified in an item by their name/value combination. For
        /// example, a single item can have the attributes <code>{ "first_name", "first_value"
        /// }</code> and <code>{ "first_name", second_value" }</code>. However, it cannot have
        /// two attribute instances where both the <code>Attribute.X.Name</code> and <code>Attribute.X.Value</code>
        /// are the same. 
        /// </para>
        ///  
        /// <para>
        ///  Optionally, the requestor can supply the <code>Replace</code> parameter for each
        /// individual attribute. Setting this value to <code>true</code> causes the new attribute
        /// value to replace the existing attribute value(s). For example, if an item has the
        /// attributes <code>{ 'a', '1' }</code>, <code>{ 'b', '2'}</code> and <code>{ 'b', '3'
        /// }</code> and the requestor calls <code>PutAttributes</code> using the attributes <code>{
        /// 'b', '4' }</code> with the <code>Replace</code> parameter set to true, the final attributes
        /// of the item are changed to <code>{ 'a', '1' }</code> and <code>{ 'b', '4' }</code>,
        /// which replaces the previous values of the 'b' attribute with the new value. 
        /// </para>
        ///  
        /// <para>
        ///  You cannot specify an empty string as an attribute name. 
        /// </para>
        ///  
        /// <para>
        ///  Because Amazon SimpleDB makes multiple copies of client data and uses an eventual
        /// consistency update model, an immediate <a>GetAttributes</a> or <a>Select</a> operation
        /// (read) immediately after a <a>PutAttributes</a> or <a>DeleteAttributes</a> operation
        /// (write) might not return the updated data. 
        /// </para>
        ///  
        /// <para>
        ///  The following limitations are enforced for this operation: <ul> <li>256 total attribute
        /// name-value pairs per item</li> <li>One billion attributes per domain</li> <li>10 GB
        /// of total user data storage per domain</li> </ul> 
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the PutAttributes service method.</param>
        /// 
        /// <returns>The response from the PutAttributes service method, as returned by SimpleDB.</returns>
        /// <exception cref="AttributeDoesNotExistException">
        /// The specified attribute does not exist.
        /// </exception>
        /// <exception cref="InvalidParameterValueException">
        /// The value for a parameter is invalid.
        /// </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="NumberDomainAttributesExceededException">
        /// Too many attributes in this domain.
        /// </exception>
        /// <exception cref="NumberDomainBytesExceededException">
        /// Too many bytes in this domain.
        /// </exception>
        /// <exception cref="NumberItemAttributesExceededException">
        /// Too many attributes in this item.
        /// </exception>
        public PutAttributesResponse PutAttributes(PutAttributesRequest request)
        {
            var marshaller = new PutAttributesRequestMarshaller();
            var unmarshaller = PutAttributesResponseUnmarshaller.Instance;

            return Invoke<PutAttributesRequest,PutAttributesResponse>(request, marshaller, unmarshaller);
        }
Exemplo n.º 27
0
        /// <summary>
        /// <para> The PutAttributes operation creates or replaces attributes in an item. The client may specify new attributes using a combination of
        /// the <c>Attribute.X.Name</c> and <c>Attribute.X.Value</c> parameters. The client specifies the first attribute by the parameters
        /// <c>Attribute.0.Name</c> and <c>Attribute.0.Value</c> ,
        /// the second attribute by the parameters <c>Attribute.1.Name</c> and <c>Attribute.1.Value</c> , and so on. </para> <para> Attributes are
        /// uniquely identified in an item by their name/value combination. For example, a single item can have the attributes <c>{ "first_name",
        /// "first_value" }</c> and <c>{ "first_name", second_value" }</c> . However, it cannot have two attribute instances where both the
        /// <c>Attribute.X.Name</c> and <c>Attribute.X.Value</c> are the same. </para> <para> Optionally, the requestor can supply the <c>Replace</c>
        /// parameter for each individual attribute. Setting this value to <c>true</c> causes the new attribute value to replace the existing attribute
        /// value(s). For example, if an item has the attributes <c>{ 'a', '1' }</c> ,
        /// 
        /// <c>{ 'b', '2'}</c> and <c>{ 'b', '3' }</c> and the requestor calls <c>PutAttributes</c> using the attributes <c>{ 'b',
        /// '4' }</c> with the <c>Replace</c> parameter set to true, the final attributes of the item are changed to <c>{ 'a', '1' }</c> and <c>{ 'b',
        /// '4' }</c> , which replaces the previous values of the 'b' attribute with the new value. </para> <para><b>NOTE:</b> Using PutAttributes to
        /// replace attribute values that do not exist will not result in an error response. </para> <para> You cannot specify an empty string as an
        /// attribute name. </para> <para> Because Amazon SimpleDB makes multiple copies of client data and uses an eventual consistency update model,
        /// an immediate GetAttributes or Select operation (read) immediately after a PutAttributes or DeleteAttributes operation (write) might not
        /// return the updated data. </para> <para> The following limitations are enforced for this operation:
        /// <ul>
        /// <li>256 total attribute name-value pairs per item</li>
        /// <li>One billion attributes per domain</li>
        /// <li>10 GB of total user data storage per domain</li>
        /// 
        /// </ul>
        /// </para>
        /// </summary>
        /// 
        /// <param name="putAttributesRequest">Container for the necessary parameters to execute the PutAttributes service method on
        /// AmazonSimpleDB.</param>
        /// 
        /// <exception cref="T:Amazon.SimpleDB.Model.InvalidParameterValueException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.NumberDomainBytesExceededException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.NumberDomainAttributesExceededException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.NoSuchDomainException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.NumberItemAttributesExceededException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.AttributeDoesNotExistException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.MissingParameterException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public async Task<PutAttributesResponse> PutAttributesAsync(PutAttributesRequest putAttributesRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutAttributesRequestMarshaller();
            var unmarshaller = PutAttributesResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, PutAttributesRequest, PutAttributesResponse>(putAttributesRequest, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
Exemplo n.º 28
0
        /// <summary>
        /// Initiates the asynchronous execution of the PutAttributes operation.
        /// <seealso cref="Amazon.SimpleDB.IAmazonSimpleDB"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the PutAttributes 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<PutAttributesResponse> PutAttributesAsync(PutAttributesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutAttributesRequestMarshaller();
            var unmarshaller = PutAttributesResponseUnmarshaller.Instance;

            return InvokeAsync<PutAttributesRequest,PutAttributesResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Add 50 items using the synchronized API.
        /// </summary>
        static void addDataSynchronized()
        {
            Console.WriteLine("Start testing synchronized method.");
            string domainName = "AsyncDomain";
            sdb.CreateDomain(new CreateDomainRequest()
                .WithDomainName(domainName));

            Results results = new Results();
            try
            {
                long start = DateTime.Now.Ticks;

                for (int i = 0; i < MAX_ROWS; i++)
                {
                    try
                    {
                        PutAttributesRequest request = new PutAttributesRequest()
                            .WithDomainName(domainName)
                            .WithItemName("ItemName" + i)
                            .WithAttribute(new ReplaceableAttribute()
                                .WithName("Value")
                                .WithValue(i.ToString()));
                        sdb.PutAttributes(request);
                        results.Successes++;
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        results.Errors++;
                    }
                }

                TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start);
                Console.WriteLine("Time: {0} ms Successes: {1} Errors: {2}", ts.TotalMilliseconds, results.Successes, results.Errors);
            }
            finally
            {
                sdb.DeleteDomain(new DeleteDomainRequest()
                    .WithDomainName(domainName));
            }
        }
Exemplo n.º 30
0
        /// <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();
        }