private int maxItemsPerRequest = 25; // simpledb has max 25 items per batch put request

        #endregion Fields

        #region Methods

        protected override void SendBuffer(log4net.Core.LoggingEvent[] events)
        {
            var client = new AmazonSimpleDBClient(); // access and secret keys in web.config

            for (var i = 0; i < (events.Count() / maxItemsPerRequest) + 1; i++)
            {
                try
                {
                    var request = new BatchPutAttributesRequest();

                    foreach (var e in events.Skip(i * maxItemsPerRequest).Take(maxItemsPerRequest))
                    {
                        var batchItem = new ReplaceableItem()
                                            {
                                                ItemName = Guid.NewGuid().ToString()
                                            };

                        batchItem.Attribute.Add(GetAttribute("Thread", e.ThreadName));
                        batchItem.Attribute.Add(GetAttribute("Level", e.Level.Name));
                        batchItem.Attribute.Add(GetAttribute("CustomLevel", GetCustomProperty(e, "CustomLevel")));
                        batchItem.Attribute.Add(GetAttribute("Url", GetCustomProperty(e, "Url")));
                        batchItem.Attribute.Add(GetAttribute("Machine", GetCustomProperty(e, "Machine")));
                        batchItem.Attribute.Add(GetAttribute("Product", GetCustomProperty(e, "Product")));
                        batchItem.Attribute.Add(GetAttribute("UserId", GetCustomProperty(e, "UserId")));
                        batchItem.Attribute.Add(GetAttribute("UserName", GetCustomProperty(e, "UserName")));
                        batchItem.Attribute.Add(GetAttribute("TimeStamp", e.TimeStamp.ToUniversalTime().ToString("o")));
                        batchItem.Attribute.Add(GetAttribute("Message", e.RenderedMessage));
                        batchItem.Attribute.Add(GetAttribute("FormattedMessage", GetCustomProperty(e, "FormattedMessage")));
                        batchItem.Attribute.Add(GetAttribute("StackTrace", e.GetExceptionString()));

                        request.Item.Add(batchItem);
                    }

                    // Assumes Domain has already been created
                    if(!string.IsNullOrEmpty(ConfigurationManager.AppSettings["SimpleDBLogName"]))
                        request.DomainName = ConfigurationManager.AppSettings["SimpleDBLogName"];
                    else
                        request.DomainName = "Log";

                    client.BatchPutAttributes(request);
                }
                finally
                {

                }
            }
        }
        public void AttributeTestA_BatchPutAttribute()
        {
            bool hasCallbackArrived = false;
            bool actualValue = false;
            bool expectedValue = true;
            SimpleDBResponseEventHandler<object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                //Unhook from event.
                _client.OnSimpleDBResponse -= handler;
                BatchPutAttributesResponse response = args.Response as BatchPutAttributesResponse;
                if (null != response)
                {
                    actualValue = true;
                }
                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSimpleDBResponse += handler;
            BatchPutAttributesRequest request = new BatchPutAttributesRequest() { DomainName = _domainName_UnitTesting };

            //List<ReplaceableAttribute> itemA = new List<ReplaceableAttribute>();
            ReplaceableItem itemA = new ReplaceableItem { ItemName = "ItemA" };
            itemA.Attribute.Add(new ReplaceableAttribute().WithName("Category").WithValue("Company"));
            itemA.Attribute.Add(new ReplaceableAttribute().WithName("Subcategory").WithValue("Private Limited"));
            itemA.Attribute.Add(new ReplaceableAttribute().WithName("Name").WithValue("Neudesic Technologies"));

            //List<ReplaceableAttribute> itemB = new List<ReplaceableAttribute>();
            ReplaceableItem itemB = new ReplaceableItem { ItemName = "ItemB" };
            itemB.Attribute.Add(new ReplaceableAttribute().WithName("Sector").WithValue("IT"));
            itemB.Attribute.Add(new ReplaceableAttribute().WithName("Location").WithValue("Hydrabad"));
            itemB.Attribute.Add(new ReplaceableAttribute().WithName("Location").WithValue("Bangalore"));
            itemB.Attribute.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large"));

            List<ReplaceableItem> replacableItem = request.Items;

            replacableItem.Add(itemA);
            replacableItem.Add(itemB);
            _client.BatchPutAttributes(request);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public static void SaveNewsStory(string domainName, string bucketName, List<NewsComponents> newsItems, AmazonSimpleDBClient sdbClient, AmazonS3Client s3Client)
        {
            //BucketHelper.CheckForBucket(itemName, s3Client);

            //foreach (var stream in newsItems.Images)
            //{
            //    PutObjectRequest putObjectRequest = new PutObjectRequest();
            //    putObjectRequest.WithBucketName(bucketName);
            //    putObjectRequest.CannedACL = S3CannedACL.PublicRead;
            //    putObjectRequest.Key = stream.fileName;
            //    putObjectRequest.InputStream = stream.photostreams;
            //    S3Response response = s3Client.PutObject(putObjectRequest);
            //    response.Dispose();
            //}
            DomainHelper.CheckForDomain(domainName, sdbClient);
            BatchPutAttributesRequest batchPutAttributesRequest = new BatchPutAttributesRequest();
            batchPutAttributesRequest.WithDomainName(domainName);
            ReplaceableItem replaceableItem;
            foreach (var list in newsItems)
            {
                replaceableItem = new ReplaceableItem();

                replaceableItem.WithItemName(Convert.ToString(list.NewsID));
                var list1 = new List<ReplaceableAttribute>{
                    new ReplaceableAttribute
                    {
                        Name = "NewsID",
                        Value = Convert.ToString(list.NewsID),
                        Replace = false
                    },
                    new ReplaceableAttribute
                    {
                        Name = "Source",
                        Value = list.Source,
                        Replace = false
                    },
                    new ReplaceableAttribute
                    {
                        Name = "Section",
                        Value = list.Section,
                        Replace = false
                    },
                    new ReplaceableAttribute
                    {
                        Name = "NewsItem",
                        Value = list.NewsItem,
                        Replace = false
                    },
                    new ReplaceableAttribute
                    {
                        Name = "NewsHeadline",
                        Value = list.NewsHeadline,
                        Replace = true
                    },
                    new ReplaceableAttribute
                    {
                        Name = "NewsAdded",
                        Value = Convert.ToString(list.NewsAdded),
                        Replace = true
                    },
                     new ReplaceableAttribute
                     {
                         Name = "Photos",
                         Value = list.NewsPhotoUrl,
                         Replace = true
                     }
                     ,
                     new ReplaceableAttribute
                     {
                         Name = "Summary",
                         Value = list.Summary,
                         Replace = true
                     },
                     new ReplaceableAttribute
                     {
                         Name = "Category",
                         Value = list.Category,
                         Replace = true
                     }
                     ,
                     new ReplaceableAttribute
                     {
                         Name = "TimeStamp",
                         Value = Convert.ToString(list.TimeStamp),
                         Replace = true
                    }
                };
                replaceableItem.WithAttribute(list1.ToArray());
                batchPutAttributesRequest.Item.Add(replaceableItem);
            }

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

            // sdbClient.PutAttributes(putAttrRequest);
            sdbClient.BatchPutAttributes(batchPutAttributesRequest);
        }
        private void btnBatchPutAttributes_Click(object sender, RoutedEventArgs e)
        {
            SimpleDB.Client.OnSimpleDBResponse += BatchPutAttributeWebResponse;
            BatchPutAttributesRequest request = new BatchPutAttributesRequest() { DomainName = this.DomainName };
            this.BatchPutMessage = "Please wait...";
            List<ReplaceableAttribute> attributesOne = new List<ReplaceableAttribute>();
            List<ReplaceableAttribute> attributesTwo = new List<ReplaceableAttribute>();

            List<AttributeAndValue> aAndV = GetListAttributeAndValueFromString(this.AttributesAndValuesToPut);

            int index = 0;
            foreach (var item in aAndV)
            {
                if (index <= aAndV.Count / 2)
                    attributesOne.Add(new ReplaceableAttribute().WithName(item.Attribute).WithValue(item.Value));
                else
                    attributesTwo.Add(new ReplaceableAttribute().WithName(item.Attribute).WithValue(item.Value));
                index++;
            }

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

            //attributesTwo.Add(new ReplaceableAttribute().WithName("Color").WithValue("Siamese"));
            //attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("Small"));
            //attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("Medium"));
            //attributesTwo.Add(new ReplaceableAttribute().WithName("Size").WithValue("Large"));

            List<ReplaceableItem> replacableItem = request.Items;

            //Get the item-names.
            foreach (var item in GetItemNames(this.ItemName))
            {
                ReplaceableItem repItem = new ReplaceableItem() { ItemName = item };
                attributesOne.ForEach(a => repItem.Attribute.Add(a));
                replacableItem.Add(repItem);
            }
            //replacableItem.Add(new ReplaceableItem() { Attribute = attributesOne, ItemName = "OneAttribute" });
            //replacableItem.Add(new ReplaceableItem() { Attribute = attributesTwo, ItemName = "TwoAttribute" });
            SimpleDB.Client.BatchPutAttributes(request);
        }
        public static void AmazonBatchPutPost(List<ForumPost> awsPosts,int threadIndex)
        {
            SimpleDB.Client.OnSimpleDBResponse += BatchPutAttributeWebResponse;
            BatchPutAttributesRequest request = new BatchPutAttributesRequest() { DomainName = "coreDB" };
            ReplaceableAttribute attributesOne = new ReplaceableAttribute().WithName("votes").WithValue("0").WithReplace(true);
            ReplaceableAttribute attributesTwo = new ReplaceableAttribute().WithName("module").WithValue(data.modules[data.curModuleIndex].CourseCode.ToString());
            ReplaceableAttribute attributesThree = new ReplaceableAttribute().WithName("AWSTimestamp").WithValue(data.modules[data.curModuleIndex].lastUpdated.ToString()).WithReplace(true);
            ReplaceableAttribute attributesFour;
            ReplaceableAttribute attributesFive = new ReplaceableAttribute().WithName("root").WithValue(data.modules[data.curModuleIndex].jPosts["Results"][0]["Threads"][threadIndex]["ID"].ToString());

            //int forumIndex = 0;
            //int i = 0;

            List<ReplaceableItem> replacableItem = request.Items;
            int t = 0;

            //List<ForumPostTitle> titles = fetchForumTitles(data.curModuleIndex, data.curForumIndex, 0);
            foreach (var post in awsPosts)
            {

                attributesFour = new ReplaceableAttribute().WithName("title").WithValue(post.Heading.ToString());
                //attributesFive = new ReplaceableAttribute().WithName("subscriber").WithValue(data.modules[data.curModuleIndex].lastUpdated.ToString());

                ReplaceableItem repItem = new ReplaceableItem() { ItemName = post.ID.ToString() };
                repItem.Attribute.Add(attributesOne);
                repItem.Attribute.Add(attributesTwo);
                repItem.Attribute.Add(attributesThree);
                repItem.Attribute.Add(attributesFour);
                repItem.Attribute.Add(attributesFive);
                replacableItem.Add(repItem);
                t++;

            }

            SimpleDB.Client.BatchPutAttributes(request);
        }