PutAttributes() public method

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.

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

/// The specified attribute does not exist. /// /// The value for a parameter is invalid. /// /// The request must contain the specified missing parameter. /// /// The specified domain does not exist. /// /// Too many attributes in this domain. /// /// Too many bytes in this domain. /// /// Too many attributes in this item. ///
public PutAttributes ( PutAttributesRequest request ) : PutAttributesResponse
request PutAttributesRequest Container for the necessary parameters to execute the PutAttributes service method.
return 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;
 }
Ejemplo n.º 2
0
        private void UploadEvent(LoggingEvent loggingEvent, AmazonSimpleDBClient client)
        {
            var request = new PutAttributesRequest();
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Name = "UserName",
                        Replace = true,
                        Value = loggingEvent.UserName
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.TimeStamp.ToString(CultureInfo.InvariantCulture),
                        Name = "TimeStamp",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.ThreadName,
                        Name = "ThreadName",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.RenderedMessage,
                        Name = "Message",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.LoggerName,
                        Name = "LoggerName",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.Level.ToString(),
                        Name = "Level",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.Identity,
                        Name = "Identity",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = loggingEvent.Domain,
                        Name = "Domain",
                        Replace = true
                    });
            request.Attributes.Add(
                new ReplaceableAttribute
                    {
                        Value = DateTime.UtcNow.ToString(CultureInfo.InvariantCulture),
                        Name = "CreatedOn",
                        Replace = true
                    });
            request.DomainName = _dbName;
            request.ItemName = Guid.NewGuid().ToString();

            client.PutAttributes(request);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Helper method to write a LogEntry to the configured domain
        /// </summary>
        /// <param name="entry"></param>
        private void WriteLogEntryAsync(Object state)
        {
            try
            {
                LogEntry entry = (LogEntry)state;
                using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(
                   this.AWSAccessKey, this.AWSSecretAccessKey,
                   new AmazonSimpleDBConfig()
                    {
                        ServiceURL = this.AWSServiceUrl,
                        MaxErrorRetry = 20
                    }))
                {
                    PutAttributesRequest request = new PutAttributesRequest();
                    request.DomainName = this.DomainName;

                    // make the key the ActivityId_Guid or just a Guid
                    if (!String.IsNullOrEmpty(entry.ActivityIdString))
                    {
                        request.ItemName = entry.ActivityIdString + "_" + Guid.NewGuid().ToString();
                    }
                    else
                    {
                        request.ItemName = Guid.NewGuid().ToString();
                    }

                    // add the categories
                    if ((entry.CategoriesStrings != null) &&
                        (entry.CategoriesStrings.Length > 0))
                    {
                        StringBuilder sb = new StringBuilder();
                        for (int i = 0; i < entry.CategoriesStrings.Length; i++)
                        {
                            if (i != 0)
                            {
                                sb.Append("_");
                            }
                            sb.Append(entry.CategoriesStrings[i]);
                        }
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "Categories", Value = sb.ToString() });
                    }

                    // add the error message if there is one
                    if (!String.IsNullOrEmpty(entry.ErrorMessages))
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "ErrorMessages", Value = entry.ErrorMessages });
                    }

                    foreach (KeyValuePair<String, Object> kvp in entry.ExtendedProperties)
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = kvp.Key, Value = kvp.Value.ToString() });
                    }

                    if (!String.IsNullOrEmpty(entry.LoggedSeverity))
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "LoggedSeverity", Value = entry.LoggedSeverity });
                    }

                    if (!String.IsNullOrEmpty(entry.MachineName))
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "MachineName", Value = entry.MachineName });
                    }

                    // need to handle if the message is greater than 1024 chars for simple db
                    String[] messages = StringSplitByLength(entry.Message, 1024);
                    for (int i = 0; i < messages.Length; i++)
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "Message" + i.ToString(), Value = messages[i] ?? String.Empty });
                    }
                    request.Attribute.Add(new ReplaceableAttribute() { Name = "Priority", Value = entry.Priority.ToString() });
                    request.Attribute.Add(new ReplaceableAttribute() { Name = "ProcessName", Value = entry.ProcessName ?? String.Empty });
                    request.Attribute.Add(new ReplaceableAttribute() { Name = "Severity", Value = entry.Severity.ToString() });
                    request.Attribute.Add(new ReplaceableAttribute() { Name = "TimeStamp", Value = entry.TimeStampString ?? DateTime.UtcNow.ToString() });
                    if (!String.IsNullOrEmpty(entry.Title))
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "Title", Value = entry.Title ?? String.Empty });
                    }
                    client.PutAttributes(request);
                }
            }
            catch (Exception ex)
            {
                TryWriteEventLogEntry(ex);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper method to write an object graph dump to the configured domain
        /// </summary>
        /// <param name="state"></param>
        private void WriteObjectAsync(Object state)
        {
            try
            {
                Object o = ((Object[])state)[0];
                String category = (String)((Object[])state)[1];

                String message = GetObjectDump(o);

                using (AmazonSimpleDBClient client = new AmazonSimpleDBClient(
                   this.AWSAccessKey, this.AWSSecretAccessKey, new AmazonSimpleDBConfig()
                    {
                        ServiceURL = this.AWSServiceUrl,
                        MaxErrorRetry = 20
                    }))
                {
                    String[] messages = StringSplitByLength(message, 1024);
                    PutAttributesRequest request = new PutAttributesRequest();
                    request.DomainName = this.DomainName;
                    request.ItemName = Guid.NewGuid().ToString();
                    for (int i = 0; i < messages.Length; i++)
                    {
                        request.Attribute.Add(new ReplaceableAttribute() { Name = "Message" + i.ToString(), Value = messages[i] });
                    }
                    request.Attribute.Add(new ReplaceableAttribute() { Name = "Category", Value = category });
                    client.PutAttributes(request);
                }
            }
            catch (Exception ex)
            {
                TryWriteEventLogEntry(ex);
            }
        }
Ejemplo n.º 5
0
        public static void SaveVideoItems(string domainName, Multimedia videoItem, AmazonSimpleDBClient sdbClient)
        {
            try
            {

                PutAttributesRequest putVideoRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(videoItem.VideoId));

                putVideoRequest.WithAttribute(
                     new ReplaceableAttribute
                     {
                         Name = "VideoId",
                         Value = Convert.ToString(videoItem.VideoId),
                         Replace = false
                     },
                        new ReplaceableAttribute
                        {
                            Name = "YoutubeUrl",
                            Value = videoItem.YoutubeUrl,
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Country",
                            Value = videoItem.Country,
                            Replace = true
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Title",
                            Value = Convert.ToString(videoItem.Title),
                            Replace = true
                        }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Content",
                             Value = videoItem.Content,
                             Replace = true
                         });

                sdbClient.PutAttributes(putVideoRequest);
            }

            catch (AmazonSimpleDBException amazonSimpleDBException)
            {
                string val = amazonSimpleDBException.ErrorCode;
            }
        }
Ejemplo n.º 6
0
        public static void SaveNewItems(string domainName, string bucketName, NewsComponents newsItem, AmazonSimpleDBClient sdbClient, AmazonS3Client s3Client)
        {
            try
            {

                foreach (var stream in newsItem.Images)
                {
                    PutObjectRequest putObjectRequest = new PutObjectRequest();
                    putObjectRequest.WithBucketName(bucketName);
                    putObjectRequest.CannedACL = S3CannedACL.PublicRead;
                    putObjectRequest.Key = stream.fileName;
                    putObjectRequest.InputStream = stream.photostreams;

                    using (S3Response response = s3Client.PutObject(putObjectRequest))
                    {
                        WebHeaderCollection headers = response.Headers;
                        foreach (string key in headers.Keys)
                        {
                            //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key));
                        }
                    }
                }

                PutObjectRequest putObjectNewsItem = new PutObjectRequest();
                putObjectNewsItem.WithBucketName(newsItem.BucketName);
                putObjectNewsItem.CannedACL = S3CannedACL.PublicRead;
                putObjectNewsItem.Key = Convert.ToString(newsItem.NewsID);
                putObjectNewsItem.ContentType = "text/html";
                putObjectNewsItem.ContentBody = newsItem.NewsItem;

                using (S3Response response = s3Client.PutObject(putObjectNewsItem))
                {
                    WebHeaderCollection headers = response.Headers;
                    foreach (string key in headers.Keys)
                    {
                        //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key));
                    }
                }

                PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(newsItem.NewsID));

                putAttrRequest.WithAttribute(
                     new ReplaceableAttribute
                        {
                            Name = "NewsID",
                            Value = Convert.ToString(newsItem.NewsID),
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Source",
                            Value = newsItem.Source,
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "NewsHeadline",
                            Value = newsItem.NewsHeadline,
                            Replace = true
                        },
                        new ReplaceableAttribute
                        {
                            Name = "NewsAdded",
                            Value = Convert.ToString(newsItem.NewsAdded),
                            Replace = true
                        }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Summary",
                             Value = newsItem.Summary,
                             Replace = true
                         }
                         ,
                         new ReplaceableAttribute
                         {
                             Name = "SummaryContent",
                             Value = newsItem.SummaryContent,
                             Replace = true
                         }
                          ,
                         new ReplaceableAttribute
                         {
                             Name = "Imagelabel",
                             Value = newsItem.Imagelabel,
                             Replace = true
                         },
                         new ReplaceableAttribute
                         {
                             Name = "Photos",
                             Value = newsItem.NewsPhotoUrl,
                             Replace = true
                         }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Category",
                             Value = newsItem.Category,
                             Replace = true
                         }
                         ,
                         new ReplaceableAttribute
                         {
                             Name = "TimeStamp",
                             Value = Convert.ToString(newsItem.TimeStamp),
                             Replace = true
                         });

                sdbClient.PutAttributes(putAttrRequest);
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null && (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    //log exception - ("Please check the provided AWS Credentials.");
                }
                else
                {
                    //log exception -("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
                }
            }
            catch (AmazonSimpleDBException amazonSimpleDBException)
            {
                string val = amazonSimpleDBException.ErrorCode;
            }
        }
Ejemplo n.º 7
0
        public static void SaveVideoItems(string domainName, Multimedia videoItem, AmazonSimpleDBClient sdbClient, AmazonS3Client s3Client)
        {
            try
            {

                PutObjectRequest putObjectRequest = new PutObjectRequest();
                putObjectRequest.WithBucketName(videoItem.BucketNameUrl);
                putObjectRequest.CannedACL = S3CannedACL.PublicRead;
                putObjectRequest.Key = videoItem.fileName;
                putObjectRequest.InputStream = videoItem.photostreams;

                using (S3Response response = s3Client.PutObject(putObjectRequest))
                {
                    WebHeaderCollection headers = response.Headers;
                    foreach (string key in headers.Keys)
                    {
                        //log headers ("Response Header: {0}, Value: {1}", key, headers.Get(key));
                    }
                }

                PutAttributesRequest putVideoRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(videoItem.VideoId));

                putVideoRequest.WithAttribute(
                     new ReplaceableAttribute
                     {
                         Name = "VideoId",
                         Value = Convert.ToString(videoItem.VideoId),
                         Replace = false
                     },
                        new ReplaceableAttribute
                        {
                            Name = "YoutubeUrl",
                            Value = videoItem.YoutubeUrl,
                            Replace = false
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Country",
                            Value = videoItem.Country,
                            Replace = true
                        },
                        new ReplaceableAttribute
                        {
                            Name = "Title",
                            Value = Convert.ToString(videoItem.Title),
                            Replace = true
                        }
                        ,
                        new ReplaceableAttribute
                        {
                            Name = "Publish",
                            Value = Convert.ToString(videoItem.Publish),
                            Replace = true
                        }
                        ,
                         new ReplaceableAttribute
                         {
                             Name = "Content",
                             Value = videoItem.Content,
                             Replace = true
                         }
                          ,
                         new ReplaceableAttribute
                         {
                             Name = "Url",
                             Value = videoItem.Url,
                             Replace = true
                         }
                          ,
                         new ReplaceableAttribute
                         {
                             Name = "Category",
                             Value = videoItem.Category,
                             Replace = true
                         }
                         ,
                         new ReplaceableAttribute
                         {
                             Name = "YouTubeAdded",
                             Value = Convert.ToString(videoItem.YouTubeAdded),
                             Replace = true
                         });

                sdbClient.PutAttributes(putVideoRequest);
            }

            catch (AmazonSimpleDBException amazonSimpleDBException)
            {
                string val = amazonSimpleDBException.ErrorCode;
            }
        }
Ejemplo n.º 8
0
        public static void SaveTagNames(string domainName, Tags tags, AmazonSimpleDBClient sdbClient)
        {
            PutAttributesRequest putTagRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(tags.TagId));

            putTagRequest.WithAttribute(
                new ReplaceableAttribute
                {
                    Name = "TagId",
                    Value = Convert.ToString(tags.TagId),
                    Replace = false
                },
                new ReplaceableAttribute
                {
                    Name = "TagName",
                    Value = tags.TagName,
                    Replace = false
                }
                ,
                new ReplaceableAttribute
                {
                    Name = "Country",
                    Value = tags.Country,
                    Replace = false
                });
            sdbClient.PutAttributes(putTagRequest);
        }
Ejemplo n.º 9
0
        public static void PutPhoto(string domainName, string itemName, string bucketName, string fileName, Stream fileContent, bool isPublic, AmazonSimpleDBClient sdbClient, AmazonS3Client s3Client)
        {
            if (String.IsNullOrEmpty(fileName))
            {
                return;
            }

            BucketHelper.CheckForBucket(itemName, s3Client);

            PutObjectRequest putObjectRequest = new PutObjectRequest();
            putObjectRequest.WithBucketName(bucketName);
            putObjectRequest.CannedACL = S3CannedACL.PublicRead;
            putObjectRequest.Key = fileName;
            putObjectRequest.InputStream = fileContent;
            S3Response response = s3Client.PutObject(putObjectRequest);
            response.Dispose();

            DomainHelper.CheckForDomain(domainName, sdbClient);
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(itemName);
            putAttrRequest.WithAttribute(new ReplaceableAttribute
                {
                    Name = "PhotoThumbUrl",
                    Value = String.Format(Settings.Default.S3BucketUrlFormat, String.Format(Settings.Default.BucketNameFormat, HttpContext.Current.User.Identity.Name, itemName), fileName),
                    Replace = true
                });
            sdbClient.PutAttributes(putAttrRequest);

            if (isPublic)
            {
                DomainHelper.CheckForDomain(Settings.Default.PetBoardPublicDomainName, sdbClient);
                putAttrRequest.DomainName = Settings.Default.PetBoardPublicDomainName;
                sdbClient.PutAttributes(putAttrRequest);
            }
        }
Ejemplo n.º 10
0
        public void Put(string domainName, string itemName, bool isPublic, AmazonSimpleDBClient sdbClient)
        {
            if (String.IsNullOrEmpty(domainName) ||
                String.IsNullOrEmpty(itemName))
            {
                return;
            }

            DomainHelper.CheckForDomain(domainName, sdbClient);
            PutAttributesRequest putAttrRequest = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemName);
            putAttrRequest.WithAttribute(
                    new ReplaceableAttribute { Name = "Public", Value = isPublic.ToString(), Replace = true },
                    new ReplaceableAttribute { Name = "PhotoThumbUrl", Value = !String.IsNullOrEmpty(this.PhotoThumbUrl) ? this.PhotoThumbUrl : String.Empty, Replace = true },
                    new ReplaceableAttribute { Name = "Name", Value = this.Name, Replace = true },
                    new ReplaceableAttribute { Name = "Type", Value = this.Type, Replace = true },
                    new ReplaceableAttribute { Name = "Breed", Value = this.Breed, Replace = true },
                    new ReplaceableAttribute { Name = "Sex", Value = this.Sex, Replace = true },
                    new ReplaceableAttribute { Name = "Birthdate", Value = this.Birthdate, Replace = true },
                    new ReplaceableAttribute { Name = "Likes", Value = this.Likes, Replace = true },
                    new ReplaceableAttribute { Name = "Dislikes", Value = this.Dislikes, Replace = true }
                );
            sdbClient.PutAttributes(putAttrRequest);

            if (isPublic)
            {
                DomainHelper.CheckForDomain(Settings.Default.PetBoardPublicDomainName, sdbClient);
                putAttrRequest.DomainName = Settings.Default.PetBoardPublicDomainName;
                sdbClient.PutAttributes(putAttrRequest);
            }
            else
            {
                DeleteAttributesRequest deleteAttributeRequest = new DeleteAttributesRequest().WithDomainName(Settings.Default.PetBoardPublicDomainName).WithItemName(itemName);
                sdbClient.DeleteAttributes(deleteAttributeRequest);
            }
        }
Ejemplo n.º 11
0
        static void WriteToSimpleDb(AWSCredentials credentials)
        {
            var client = new AmazonSimpleDBClient(credentials, RegionEndpoint.USEast1);

            var request = new CreateDomainRequest("aws-talk");
            var response = client.CreateDomain(request);

            var putData = new PutAttributesRequest("aws-talk", "products/" + Guid.NewGuid().ToString(),
                new List<ReplaceableAttribute>()
                {
                    new ReplaceableAttribute("Name", "Couch", true),
                    new ReplaceableAttribute("Price", "20", true)
                });
            client.PutAttributes(putData);
        }