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; }
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); }
/// <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); } }
/// <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); } }
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; } }
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; } }
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; } }
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); }
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); } }
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); } }
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); }