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);
        }
        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 SaveViews(string domainName, NumberViews numberViews)
        {
            PutAttributesRequest putViewsAttrRequest = new PutAttributesRequest()
                .WithDomainName(domainName)
                .WithItemName(Convert.ToString(numberViews.ViewsID));
            putViewsAttrRequest.
                WithAttribute(new ReplaceableAttribute
                {
                    Name = "ViewsID",
                    Value = Convert.ToString(numberViews.ViewsID),
                    Replace = false
                },

                              new ReplaceableAttribute
                              {
                                  Name = "NewsID",
                                  Value = numberViews.NewsID,
                                  Replace = false
                              },
                              new ReplaceableAttribute
                              {
                                  Name = "Views",
                                  Value = Convert.ToString(numberViews.Views),
                                  Replace = true
                              });
            sdbClient.PutAttributes(putViewsAttrRequest);
        }
        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 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);
        }
Exemple #8
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);
            }
        }
Exemple #9
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);
            }
        }