internal PutAttributesResponse PutAttributes(PutAttributesRequest request)
        {
            var task = PutAttributesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
Example #2
0
        public void SaveItem(MCItem item)
        {
            item.Domain = SetDomain(item.Domain);
            PutAttributesRequest        request    = new PutAttributesRequest().WithDomainName(item.Domain).WithItemName(item.ItemName);
            List <ReplaceableAttribute> attributes = new List <ReplaceableAttribute>();

            foreach (string key in item.Attributes.Keys)
            {
                attributes.Add(new ReplaceableAttribute().WithName(key).WithValue(item.Attributes[key].ToString()).WithReplace(true));
            }
            request.Attribute = attributes;
            client.PutAttributes(request);
        }
Example #3
0
        private void btnPutAttributes_Click(object sender, RoutedEventArgs e)
        {
            SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null;

            this.SomeMessage = "Please wait...";
            handler          = delegate(object senderAmazon, ResponseEventArgs args)
            {
                //Unhook from event.
                SimpleDB.Client.OnSimpleDBResponse -= handler;
                PutAttributesResponse response = args.Response as PutAttributesResponse;
                this.Dispatcher.BeginInvoke(() =>
                {
                    if (null != response)
                    {
                        this.SomeMessage = "Attribute put successfully.";
                    }
                    else
                    {
                        AmazonSimpleDBException exception = args.Response as AmazonSimpleDBException;
                        if (null != exception)
                        {
                            this.SomeMessage = "Error: " + exception.Message;
                        }
                    }
                });
            };

            SimpleDB.Client.OnSimpleDBResponse += handler;

            PutAttributesRequest putAttributesRequest = new PutAttributesRequest {
                DomainName = this.DomainName, ItemName = this.ItemName
            };
            List <ReplaceableAttribute> attributesOne = putAttributesRequest.Attribute;

            //Calculate the attributes and their values to put.
            foreach (var item in GetListAttributeAndValueFromString(this.AttributesAndValuesToPut))
            {
                attributesOne.Add(new ReplaceableAttribute().WithName(item.Attribute).WithValue(item.Value));
            }


            //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"));
            SimpleDB.Client.PutAttributes(putAttributesRequest);
        }
        public override string ResetPassword(string userName, string answer)
        {
            string newPassword           = Membership.GeneratePassword(6, 0);
            string passwordAnswer        = String.Empty;
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = Settings.Default.AWSMembershipDomain,
                ItemName       = userName,
                AttributeNames = PasswordStrings
            };

            GetAttributesResponse response = this._simpleDBClient.GetAttributes(request);

            foreach (Attribute att in response.Attributes)
            {
                switch (att.Name)
                {
                case "PasswordAnswer":
                {
                    passwordAnswer = att.Value;
                    break;
                }
                }
            }

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

            ReplaceableAttribute replace = new ReplaceableAttribute()
            {
                Name    = PasswordStrings[0],
                Value   = newPassword,
                Replace = true
            };

            PutAttributesRequest prequest = new PutAttributesRequest()
            {
                DomainName = Settings.Default.AWSMembershipDomain,
                ItemName   = userName,
                Attributes = new List <ReplaceableAttribute>()
                {
                    replace
                }
            };

            this._simpleDBClient.PutAttributes(prequest);
            return(newPassword);
        }
Example #5
0
        /// <summary>
        /// Add 50 items using the synchronized API.
        /// </summary>
        static void AddDataSynchronized()
        {
            Console.WriteLine("Start testing synchronized method.");
            const string domainName = "AsyncDomain";

            sdb.CreateDomain(new CreateDomainRequest {
                DomainName = domainName
            });

            var results = new Results();

            try
            {
                long start = DateTime.Now.Ticks;

                for (int i = 0; i < MAX_ROWS; i++)
                {
                    try
                    {
                        var request = new PutAttributesRequest
                        {
                            DomainName = domainName,
                            ItemName   = "ItemName" + i,
                            Attributes = new List <ReplaceableAttribute>
                            {
                                new ReplaceableAttribute {
                                    Name = "Value", Value = 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 {
                    DomainName = domainName
                });
            }
        }
Example #6
0
        private void TestPutAttributes()
        {
            PutAttributesRequest request = new PutAttributesRequest()
            {
                DomainName = domainName,
                ItemName   = FOO_ITEM.Name,
                Attributes = FOO_ITEM.Attributes
            };

            Client.PutAttributes(request);
            assertItemsStoredInDomain(Client, new List <ReplaceableItem> {
                FOO_ITEM
            }, domainName);
        }
Example #7
0
        private static IDictionary <string, string> ConvertPutAttributes(PutAttributesRequest request)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["Action"] = "PutAttributes";
            if (request.IsSetDomainName())
            {
                dictionary["DomainName"] = request.DomainName;
            }
            if (request.IsSetItemName())
            {
                dictionary["ItemName"] = request.ItemName;
            }
            List <ReplaceableAttribute> list = request.Attribute;
            int num = 1;

            foreach (ReplaceableAttribute attribute in list)
            {
                if (attribute.IsSetName())
                {
                    dictionary[string.Concat(new object[] { "Attribute", ".", num, ".", "Name" })] = attribute.Name;
                }
                if (attribute.IsSetValue())
                {
                    dictionary[string.Concat(new object[] { "Attribute", ".", num, ".", "Value" })] = attribute.Value;
                }
                if (attribute.IsSetReplace())
                {
                    dictionary[string.Concat(new object[] { "Attribute", ".", num, ".", "Replace" })] = attribute.Replace.ToString().ToLower();
                }
                num++;
            }
            if (request.IsSetExpected())
            {
                UpdateCondition expected = request.Expected;
                if (expected.IsSetName())
                {
                    dictionary["Expected" + "." + "Name"] = expected.Name;
                }
                if (expected.IsSetValue())
                {
                    dictionary["Expected" + "." + "Value"] = expected.Value;
                }
                if (expected.IsSetExists())
                {
                    dictionary["Expected" + "." + "Exists"] = expected.Exists.ToString().ToLower();
                }
            }
            return(dictionary);
        }
Example #8
0
 public async Task SaveTodoItemAsync(TodoItem todoItem)
 {
     try {
         var attributeList = ToSimpleDBReplaceableAttributes(todoItem);
         var request       = new PutAttributesRequest()
         {
             DomainName = tableName,
             ItemName   = todoItem.ID,
             Attributes = attributeList
         };
         await client.PutAttributesAsync(request);
     } catch (Exception ex) {
         Debug.WriteLine(@"				ERROR {0}", ex.Message);
     }
 }
Example #9
0
        /// <summary>
        /// Add 50 items using the asynchronized API.
        /// </summary>
        static void AddDataAsynchronized()
        {
            Console.WriteLine("Start testing asynchronized method.");
            const string domainName = "AsyncDomain";

            sdb.CreateDomain(new CreateDomainRequest {
                DomainName = domainName
            });

            var results     = new Results();
            var waitHandles = new List <WaitHandle>();

            try
            {
                long start = DateTime.Now.Ticks;
                for (int i = 0; i < MAX_ROWS; i++)
                {
                    var request = new PutAttributesRequest
                    {
                        DomainName = domainName,
                        ItemName   = "ItemName" + i,
                        Attributes = new List <ReplaceableAttribute>
                        {
                            new ReplaceableAttribute {
                                Name = "Value", Value = 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 {
                    DomainName = domainName
                });
            }
        }
Example #10
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);
        }
Example #11
0
        public string Request(Domain.Update pUpdate)
        {
            #region Update conditions validation

            if (pUpdate.Conditions.Count == 0)
            {
                throw new Exception("SimpleSQL: unparameterized update is not supported.");
            }

            #endregion

            string mDomainName = this.GetDomainName(pUpdate.Table);

            SelectResponse mSelectResponse = this.ProcessSimpleSelect(mDomainName, null, pUpdate.Conditions, pUpdate.Table);

            int mTotalUpdatedItems = 0;

            if (mSelectResponse.IsSetSelectResult())
            {
                foreach (Item mCurrentItem in mSelectResponse.SelectResult.Item)
                {
                    if (mCurrentItem.IsSetName())
                    {
                        List <ReplaceableAttribute> mUpdateTargets = new List <ReplaceableAttribute>();

                        foreach (Condition mTarget in pUpdate.Targets)
                        {
                            mUpdateTargets.Add(new ReplaceableAttribute()
                            {
                                Name    = mTarget.Attribute,
                                Value   = mTarget.Values[0].ToString(),
                                Replace = true
                            }
                                               );
                        }

                        PutAttributesRequest mReplaceAction = new PutAttributesRequest().WithDomainName(mDomainName).WithItemName(mCurrentItem.Name).WithAttribute(mUpdateTargets.ToArray());

                        this.aSimpleDBClient.PutAttributes(mReplaceAction);

                        mTotalUpdatedItems++;
                    }
                }
            }

            return(mTotalUpdatedItems.ToString());
        }
Example #12
0
        protected void LikeButton_Click(object sender, EventArgs e)
        {
            if (!Context.User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
                return;
            }

            DomainHelper.CheckForDomain(Settings.Default.PetBoardFriendsDomain, _simpleDBClient);
            string ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

            if (!String.IsNullOrEmpty(ip))
            {
                string[] ipRange = ip.Split(',');
                int      le      = ipRange.Length - 1;
                string   trueIP  = ipRange[le];
            }
            else
            {
                ip = Request.ServerVariables["REMOTE_ADDR"];
            }

            PutAttributesRequest request = new PutAttributesRequest()
            {
                DomainName = Settings.Default.PetBoardFriendsDomain,
                ItemName   = ip,
                Attributes = new List <ReplaceableAttribute>()
                {
                    new ReplaceableAttribute
                    {
                        Name    = "Member",
                        Value   = this.Context.User.Identity.Name,
                        Replace = true
                    },
                    new ReplaceableAttribute
                    {
                        Name    = "Pet",
                        Value   = this._petIdString,
                        Replace = true
                    }
                }
            };

            _simpleDBClient.PutAttributes(request);
            this.Response.Redirect(this.Request.RawUrl);
        }
        public override void UpdateUser(MembershipUser user)
        {
            List <ReplaceableAttribute> attributes = new List <ReplaceableAttribute> {
                new ReplaceableAttribute()
                {
                    Name    = "Email",
                    Value   = user.Email,
                    Replace = true
                }
            };
            PutAttributesRequest request = new PutAttributesRequest()
            {
                DomainName = Settings.Default.AWSMembershipDomain,
                ItemName   = user.UserName
            };

            request.Attributes = attributes;
            this._simpleDBClient.PutAttributes(request);
        }
        /// <summary>
        /// Creates single item
        /// </summary>
        public async Task <HttpStatusCode> CreateItemAsync(SdbItem item)
        {
            try
            {
                //Add additional attribute for the Exists flag on the newly created item
                item.Attributes = item.Attributes.Concat(new[] { new SdbItemAttribute(ExistsAttributeName, "1"), });

                var convertedAttributes = SimpleDbHelper.ConvertItemAttributesToReplaceableAttributes(item.Attributes);
                var putRequest          = new PutAttributesRequest(_simpleDbDomain, item.ItemName, convertedAttributes.ToList());
                var putResponse         = await _client.PutAttributesAsync(putRequest);

                return(putResponse.HttpStatusCode);
            }
            catch (AmazonSimpleDBException e)
            {
                Console.WriteLine(e.StackTrace);
                throw;
            }
        }
        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 T Upsert(T asset)
        {
            PutAttributesRequest request = new PutAttributesRequest();

            request.DomainName = m_objectMapper.TableName;
            request.ItemName   = asset.Id.ToString();
            request.Attribute  = new List <ReplaceableAttribute>();
            Dictionary <MetaDataMember, object> allPropertyValues = m_objectMapper.GetAllValues(asset);

            foreach (KeyValuePair <MetaDataMember, object> propertyValue in allPropertyValues)
            {
                if (!propertyValue.Key.IsPrimaryKey)
                {
                    if (propertyValue.Value != null)
                    {
                        request.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(propertyValue.Key.MappedName.ToLower()).WithValue(GetValue(propertyValue.Value)));

                        /*if (propertyValue.Key.Type == typeof(DateTime) || propertyValue.Key.Type == typeof(Nullable<DateTime>)) {
                         *  //logger.Debug("Upsert adding attribute name=" + propertyValue.Key.Name.ToLower() + ", value=" + ((DateTime)propertyValue.Value).ToString("o") + ".");
                         *  request.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(propertyValue.Key.MappedName.ToLower()).WithValue(((DateTime)propertyValue.Value).ToString("o")));
                         * }
                         * else {
                         *  //logger.Debug("Upsert adding attribute name=" + propertyValue.Key.Name + ", value=" + propertyValue.Value.ToString() + ".");
                         *  request.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(propertyValue.Key.MappedName.ToLower()).WithValue(propertyValue.Value.ToString()));
                         * }*/
                    }
                    //else {
                    //     request.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(propertyValue.Key.Name).WithValue(null));
                    // }
                }
            }

            PutAttributesResponse response = m_simpleDBClient.PutAttributes(request);

            if (response.IsSetResponseMetadata())
            {
                ResponseMetadata responseMetadata = response.ResponseMetadata;
                //logger.Debug("Upsert response for " + request.DomainName + ", id=" + request.ItemName + ", attributes=" + request.Attribute.Count + ": " + responseMetadata.RequestId);
            }

            return(asset);
        }
        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);
            }
        }
Example #18
0
        /// <summary>
        /// Puts attribiutes in SimpleDB
        /// </summary>
        /// <param name="domainName"></param>
        /// <param name="itemName"></param>
        /// <param name="name"></param>
        /// <param name="replace"></param>
        /// <param name="value"></param>
        public void PutAttribute(string domainName, string itemName, string name, bool replace, string value)
        {
            var replaceableAttribute = new ReplaceableAttribute
            {
                Name    = name,
                Replace = replace,
                Value   = value
            };

            var request = new PutAttributesRequest
            {
                DomainName = domainName,
                ItemName   = itemName,
                Attribute  = new List <ReplaceableAttribute>()
                {
                    replaceableAttribute
                }
            };

            Client.PutAttributes(request);
        }
Example #19
0
        //
        // System.Web.Security.RoleProvider methods.
        //

        //
        // RoleProvider.AddUsersToRoles
        //

        public override void AddUsersToRoles(string[] usernames, string[] rolenames)
        {
            foreach (string username in usernames)
            {
                if (username.Contains(","))
                {
                    throw new ArgumentException("User names cannot contain commas.");
                }

                foreach (string rolename in rolenames)
                {
                    string id = username + "-" + rolename;
                    PutAttributesRequest        request    = new PutAttributesRequest().WithDomainName(domain).WithItemName(id);
                    List <ReplaceableAttribute> attributes = new List <ReplaceableAttribute>();
                    attributes.Add(new ReplaceableAttribute().WithName("Username").WithValue(username).WithReplace(true));
                    attributes.Add(new ReplaceableAttribute().WithName("Rolename").WithValue(rolename).WithReplace(true));
                    request.Attribute = attributes;
                    client.PutAttributes(request);
                }
            }
        }
Example #20
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.BucketName  = bucketName;
            putObjectRequest.CannedACL   = S3CannedACL.PublicRead;
            putObjectRequest.Key         = fileName;
            putObjectRequest.InputStream = fileContent;
            s3Client.PutObject(putObjectRequest);

            DomainHelper.CheckForDomain(domainName, sdbClient);
            PutAttributesRequest putAttrRequest = new PutAttributesRequest()
            {
                DomainName = domainName,
                ItemName   = itemName
            };

            putAttrRequest.Attributes.Add(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);
            }
        }
Example #21
0
        public string Request(Domain.Insert pInsert)
        {
            #region Attributes and values validation

            if (pInsert.Attributes.Count != pInsert.Values.Count)
            {
                throw new Exception("SimpleSQL: insert command has different attributes and values.");
            }

            #endregion

            PutAttributesRequest mPutAction = new PutAttributesRequest().WithDomainName(this.GetDomainName(pInsert.Table)).WithItemName(pInsert.ItemID.ToString());

            List <ReplaceableAttribute> mPutAttributes = mPutAction.Attribute;
            ReplaceableAttribute        mAttribute;

            #region Add attributes to the SimpleDB object

            int mTotalAttributes = pInsert.Attributes.Count;
            for (int mIndex = 0; mIndex < mTotalAttributes; mIndex++)
            {
                mAttribute = new ReplaceableAttribute()
                {
                    Name  = pInsert.Attributes[mIndex],
                    Value = pInsert.Values[mIndex].ToString()
                };

                mPutAttributes.Add(mAttribute);
            }

            #endregion

            mPutAttributes.Add(new ReplaceableAttribute().WithName(this.aSimpleSQLTableName).WithValue(pInsert.Table));

            PutAttributesResponse mResponse = this.aSimpleDBClient.PutAttributes(mPutAction);

            return(mResponse.ToString());
        }
Example #22
0
        public bool sendAmazonSimpleDbImage(String filename, String partNo, String part)
        {
            AmazonSimpleDB sdb = AWSClientFactory.CreateAmazonSimpleDBClient(RegionEndpoint.USWest2);

            try
            {
                String domainName = "";

                CreateDomainRequest createDomain3 = (new CreateDomainRequest()).WithDomainName("Images");
                sdb.CreateDomain(createDomain3);

                domainName = "Images";
                String itemNameThree = itemNo.ToString();
                PutAttributesRequest        putAttributesActionThree = new PutAttributesRequest().WithDomainName(domainName).WithItemName(itemNameThree);
                List <ReplaceableAttribute> attributesThree          = putAttributesActionThree.Attribute;
                attributesThree.Add(new ReplaceableAttribute().WithName("ImgID").WithValue("TestImage01"));
                attributesThree.Add(new ReplaceableAttribute().WithName("indexID").WithValue("1"));
                attributesThree.Add(new ReplaceableAttribute().WithName("Extension").WithValue("jpg"));
                attributesThree.Add(new ReplaceableAttribute().WithName("location").WithValue(filename));
                attributesThree.Add(new ReplaceableAttribute().WithName("imgPart").WithValue(partNo.ToString()));
                attributesThree.Add(new ReplaceableAttribute().WithName("raw").WithValue(part));
                sdb.PutAttributes(putAttributesActionThree);
            }
            catch (AmazonSimpleDBException ex)
            {
                failCount++;
                log("Caught Exception: " + ex.Message);
                log("Response Status Code: " + ex.StatusCode);
                log("Error Code: " + ex.ErrorCode);
                log("Error Type: " + ex.ErrorType);
                log("Request ID: " + ex.RequestId);
                log("XML: " + ex.XML);

                return(false);
            }
            itemNo++;
            return(true);
        }
Example #23
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());
        }
Example #24
0
        /**
         * Convert PutAttributesRequest to name value pairs
         */
        private IDictionary <String, String> ConvertPutAttributes(PutAttributesRequest request)
        {
            IDictionary <String, String> parameters = new Dictionary <String, String>();

            parameters.Add("Action", "PutAttributes");
            if (request.IsSetDomainName())
            {
                parameters.Add("DomainName", request.DomainName);
            }
            if (request.IsSetItemName())
            {
                parameters.Add("ItemName", request.ItemName);
            }
            List <ReplaceableAttribute> putAttributesRequestAttributeList = request.Attribute;
            int putAttributesRequestAttributeListIndex = 1;

            foreach (ReplaceableAttribute putAttributesRequestAttribute in putAttributesRequestAttributeList)
            {
                if (putAttributesRequestAttribute.IsSetName())
                {
                    parameters.Add("Attribute" + "." + putAttributesRequestAttributeListIndex + "." + "Name", putAttributesRequestAttribute.Name);
                }
                if (putAttributesRequestAttribute.IsSetValue())
                {
                    parameters.Add("Attribute" + "." + putAttributesRequestAttributeListIndex + "." + "Value", putAttributesRequestAttribute.Value);
                }
                if (putAttributesRequestAttribute.IsSetReplace())
                {
                    parameters.Add("Attribute" + "." + putAttributesRequestAttributeListIndex + "." + "Replace", putAttributesRequestAttribute.Replace + "");
                }

                putAttributesRequestAttributeListIndex++;
            }

            return(parameters);
        }
        public override void UpdateProperty(Guid id, string propertyName, object value)
        {
            try
            {
                PutAttributesRequest request = new PutAttributesRequest();
                request.DomainName = m_objectMapper.TableName;
                request.ItemName   = id.ToString();
                request.Attribute  = new List <ReplaceableAttribute>();
                request.Attribute.Add(new ReplaceableAttribute().WithReplace(true).WithName(propertyName.ToLower()).WithValue(GetValue(value)));

                PutAttributesResponse response = m_simpleDBClient.PutAttributes(request);

                if (response.IsSetResponseMetadata())
                {
                    ResponseMetadata responseMetadata = response.ResponseMetadata;
                    logger.Debug("UpdateProperty response: " + responseMetadata.RequestId);
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception SimpleDBAssetPersistor UpdateProperty (for " + typeof(T).Name + "). " + excp.Message);
                throw;
            }
        }
Example #26
0
 /// <summary>
 /// Put Attributes
 /// </summary>
 /// <param name="request">Put Attributes  request</param>
 /// <returns>Put Attributes  Response from the service</returns>
 /// <remarks>
 /// The PutAttributes operation creates or replaces attributes within an item. You specify new attributes
 /// using a combination of the Attribute.X.Name and Attribute.X.Value parameters. You specify
 /// 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 within 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 value. Setting this value
 /// to true will cause 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 does a
 /// PutAttributes of { 'b', '4' } with the Replace parameter set to true, the final attributes of the
 /// item will be { 'a', '1' } and { 'b', '4' }, replacing the previous values of the 'b' attribute
 /// with the new value.
 ///
 /// </remarks>
 public PutAttributesResponse PutAttributes(PutAttributesRequest request)
 {
     return(Invoke <PutAttributesResponse>(ConvertPutAttributes(request)));
 }
Example #27
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);
        }
        /// <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 Task<PutAttributesResponse> PutAttributesAsync(PutAttributesRequest putAttributesRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new PutAttributesRequestMarshaller();
            var unmarshaller = PutAttributesResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, PutAttributesRequest, PutAttributesResponse>(putAttributesRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
Example #29
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()
            {
                DomainName = domainName,
                ItemName   = itemName
            };

            putAttrRequest.Attributes = new List <ReplaceableAttribute>()
            {
                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()
                {
                    DomainName = Settings.Default.PetBoardPublicDomainName,
                    ItemName   = itemName
                };

                sdbClient.DeleteAttributes(deleteAttributeRequest);
            }
        }
        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()
                    {
                        Name = "Email", Value = email
                    });
                    data.Add(new ReplaceableAttribute()
                    {
                        Name = "Password", Value = password
                    });
                    if (passwordQuestion != null)
                    {
                        data.Add(new ReplaceableAttribute()
                        {
                            Name = "PasswordQuestion", Value = passwordQuestion
                        });
                    }

                    if (passwordAnswer != null)
                    {
                        data.Add(new ReplaceableAttribute()
                        {
                            Name = "PasswordAnswer", Value = passwordAnswer
                        });
                    }

                    data.Add(new ReplaceableAttribute()
                    {
                        Name = "IsApproved", Value = isApproved.ToString()
                    });
                    PutAttributesRequest request = new PutAttributesRequest()
                    {
                        DomainName = Settings.Default.AWSMembershipDomain,
                        ItemName   = userName
                    };

                    request.Attributes = data;
                    this._simpleDBClient.PutAttributes(request);
                    status = MembershipCreateStatus.Success;
                    user   = this.GetUser(userName, false);
                }
                else
                {
                    status = MembershipCreateStatus.DuplicateEmail;
                }
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return(user);
        }