public bool ExistsWorkStep(string path)
        {
            var getAttributesRequest = new GetAttributesRequest { ItemName = path, DomainName = _domain };
            var getAttributesResponse = _client.GetAttributes(getAttributesRequest);

            return getAttributesResponse.GetAttributesResult.Attribute.Count > 0;
        }
 public void Get(string domain, string id)
 {
     GetAttributesRequest request = new GetAttributesRequest()
         .WithDomainName(domain)
         .WithItemName(id);
     var response = _simpleDbClient.GetAttributes(request);
 }
 protected override void ProcessRecord()
 {
     AmazonSimpleDB client = base.GetClient();
     Amazon.SimpleDB.Model.GetAttributesRequest request = new Amazon.SimpleDB.Model.GetAttributesRequest();
     request.DomainName = this._DomainName;
     request.ItemName = this._ItemName;
     if (string.IsNullOrEmpty(this._AttributeName))
     {
         request.AttributeName.Add(this._AttributeName);
     }
     request.ConsistentRead = this._ConsistentRead;
     Amazon.SimpleDB.Model.GetAttributesResponse response = client.GetAttributes(request);
     base.WriteObject(response.GetAttributesResult, true);
 }
示例#4
0
 /// <summary>
 /// Returns a SIMPLEDB object with ALL attributes.
 /// </summary>
 /// <param name="ItemName">Same as the item ID.</param>
 /// <param name="Domain"></param>
 /// <returns></returns>
 public override MCItem GetItem(string ItemName, string Domain)
 {
     string sdbDomain = SetDomain(Domain);
     GetAttributesRequest request = new GetAttributesRequest().WithDomainName(sdbDomain).WithItemName(ItemName);
     GetAttributesResponse response = client.GetAttributes(request);
     MCItem item = new MCItem();
     item.Domain = Domain;
     item.ItemName = ItemName;
     item.Attributes = new Hashtable();
     foreach (Attribute attribute in response.GetAttributesResult.Attribute)
     {
         item.Attributes.Add(attribute.Name, attribute.Value);
     }
     return item;
 }
		internal GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var task = GetAttributesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
        public override string ResetPassword(string userName, string answer)
        {
            string newPassword = Membership.GeneratePassword(6, 0);
            string passwordAnswer = String.Empty;
            GetAttributesRequest request = new GetAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttributeName(PasswordStrings);
            GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult;
            if (result != null)
            {
                foreach (Attribute att in result.Attribute)
                {
                    switch (att.Name)
                    {
                        case "PasswordAnswer":
                        {
                            passwordAnswer = att.Value;
                            break;
                        }
                    }
                }
            }
            else
            {
                throw new MembershipPasswordException("User not found");
            }

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

            ReplaceableAttribute replace = new ReplaceableAttribute()
                .WithName(PasswordStrings[0])
                .WithValue(newPassword)
                .WithReplace(true);
            PutAttributesRequest prequest = new PutAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttribute(replace);
            this._simpleDBClient.PutAttributes(prequest);
            return newPassword;
        }
        public override string GetPassword(string userName, string answer)
        {
            GetAttributesRequest request = new GetAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttributeName(PasswordStrings);
            string password = String.Empty;
            GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult;
            if (result != null)
            {
                foreach (Attribute att in result.Attribute)
                {
                    switch (att.Name)
                    {
                        case "Password":
                        {
                            password = att.Value;
                            break;
                        }
                    }
                }
            }

            return password;
        }
	    GetAttributesResponse AmazonSimpleDB.GetAttributes(GetAttributesRequest request)
	    {
	        throw new NotImplementedException();
	    }
示例#9
0
 public GetGroupsResponse GetGroups(GetGroupsRequest request)
 {
     var getAttributesRequest =
         new GetAttributesRequest().WithDomainName(_config.StoreName).WithItemName(request.UserName);
     var results = _client.GetAttributes(getAttributesRequest).GetAttributesResult;
     var groups = new List<String>();
     foreach (var attribute in results.Attribute.Where(a => a.Name == "Groups"))
     {
         groups.Add(attribute.Value);
     }
     return new GetGroupsResponse {Groups = groups, UserName = request.UserName};
 }
        /// <summary>
        /// Initiates the asynchronous execution of the GetAttributes operation.
        /// <seealso cref="Amazon.SimpleDB.IAmazonSimpleDB"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the GetAttributes operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<GetAttributesResponse> GetAttributesAsync(GetAttributesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetAttributesRequestMarshaller();
            var unmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return InvokeAsync<GetAttributesRequest,GetAttributesResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
 /// <summary>
 /// Initiates the asynchronous execution of the GetAttributes operation.
 /// <seealso cref="Amazon.SimpleDB.IAmazonSimpleDB.GetAttributes"/>
 /// </summary>
 /// 
 /// <param name="getAttributesRequest">Container for the necessary parameters to execute the GetAttributes operation on AmazonSimpleDB.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndGetAttributes
 ///         operation.</returns>
 public IAsyncResult BeginGetAttributes(GetAttributesRequest getAttributesRequest, AsyncCallback callback, object state)
 {
     return invokeGetAttributes(getAttributesRequest, callback, state, false);
 }
 /// <summary>
 /// <para> Returns all of the attributes associated with the specified item. Optionally, the attributes returned can be limited to one or more
 /// attributes by specifying an attribute name parameter. </para> <para> If the item does not exist on the replica that was accessed for this
 /// operation, an empty set is returned. The system does not return an error as it cannot guarantee the item does not exist on other replicas.
 /// </para> <para><b>NOTE:</b> If GetAttributes is called without being passed any attribute names, all the attributes for the item are
 /// returned. </para>
 /// </summary>
 /// 
 /// <param name="getAttributesRequest">Container for the necessary parameters to execute the GetAttributes service method on
 ///          AmazonSimpleDB.</param>
 /// 
 /// <returns>The response from the GetAttributes service method, as returned by AmazonSimpleDB.</returns>
 /// 
 /// <exception cref="InvalidParameterValueException"/>
 /// <exception cref="NoSuchDomainException"/>
 /// <exception cref="MissingParameterException"/>
 public GetAttributesResponse GetAttributes(GetAttributesRequest getAttributesRequest)
 {
     IAsyncResult asyncResult = invokeGetAttributes(getAttributesRequest, null, null, true);
     return EndGetAttributes(asyncResult);
 }
示例#13
0
        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;
            string dbpassword = "";
            try
            {
                GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" });
                GetAttributesResponse response = client.GetAttributes(request);
                if (response.IsSetGetAttributesResult())
                {
                    GetAttributesResult result = response.GetAttributesResult;
                    foreach (Attribute att in result.Attribute)
                    {
                        switch (att.Name)
                        {
                            case "Password": dbpassword = att.Value; break;
                            default: break;
                        }
                    }
                }
                else throw new MembershipPasswordException("User not found");
                if (dbpassword == password) return true;
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ValidateUser");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            return isValid;
        }
示例#14
0
        public override string ResetPassword(string username, string answer)
        {
            if (!EnablePasswordReset)
            {
                throw new NotSupportedException("Password reset is not enabled.");
            }

            if (answer == null && RequiresQuestionAndAnswer)
            {
                throw new ProviderException("Password answer required for password reset.");
            }

            string newPassword =
              System.Web.Security.Membership.GeneratePassword(6, 0);

            string passwordAnswer = "";

            try
            {
                GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttributeName(new string[] { "Password", "PasswordAnswer" });
                GetAttributesResponse response = client.GetAttributes(request);
                if (response.IsSetGetAttributesResult())
                {
                    GetAttributesResult result = response.GetAttributesResult;
                    foreach (Attribute att in result.Attribute)
                    {
                        switch (att.Name)
                        {
                            case "PasswordAnswer": passwordAnswer = att.Value; break;
                            default: break;
                        }
                    }
                }
                else throw new MembershipPasswordException("User not found");

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

                // Update the new password here
                ReplaceableAttribute replace = new ReplaceableAttribute().WithName("Password").WithValue(newPassword).WithReplace(true);
                PutAttributesRequest prequest = new PutAttributesRequest().WithDomainName(domain).WithItemName(username).WithAttribute(replace);
                client.PutAttributes(prequest);
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "ResetPassword");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }

            return newPassword;
        }
示例#15
0
        //
        // MembershipProvider.GetUser(string, bool)
        //
        public override MembershipUser GetUser(string username, bool userIsOnline)
        {
            try
            {
                GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username);
                GetAttributesResponse response = client.GetAttributes(request);
                GetAttributesResult result = response.GetAttributesResult;
                // if we have no attributes we have no user
                if (result.Attribute.Count == 0) return null;
                string email = "";
                string passwordQuestion = "";
                bool isApproved = false;
                List<Attribute> attributes = result.Attribute;
                foreach (Attribute att in attributes)
                {
                    switch (att.Name)
                    {
                        case "Email": email = att.Value; break;
                        case "PasswordQuestion": passwordQuestion = att.Value; break;
                        case "IsApproved": isApproved = bool.Parse(att.Value); break;
                        default: break;
                    }
                }

                MembershipUser user = new MembershipUser(this.Name, username,
                    "", email, passwordQuestion, "", isApproved, false,
                    DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today, DateTime.Today);
                return user;
            }
            catch (Exception e)
            {
                if (WriteExceptionsToEventLog)
                {
                    WriteToEventLog(e, "GetUser(String, Boolean)");

                    throw new ProviderException(exceptionMessage);
                }
                else
                {
                    throw e;
                }
            }
        }
        public static NewsComponents GetNewsItem(string domainName, string itemName, AmazonSimpleDBClient sdbClient)
        {
            NewsComponents newsItem = new NewsComponents();

            GetAttributesRequest getAttributeRequest = new GetAttributesRequest()
                      .WithDomainName(domainName)
                      .WithItemName(itemName);
            GetAttributesResponse getAttributeResponse = sdbClient.GetAttributes(getAttributeRequest);
            List<Amazon.SimpleDB.Model.Attribute> attrs = null;
            if (getAttributeResponse.IsSetGetAttributesResult())
            {
                attrs = getAttributeResponse.GetAttributesResult.Attribute;
                int i = 0;
                foreach (Amazon.SimpleDB.Model.Attribute attribute in attrs)
                {

                    if (attribute.IsSetName())
                    {
                        string name = attribute.Name;
                    }
                    if (attribute.IsSetValue())
                    {
                        switch (i)
                        {
                            case 0:
                                newsItem.NewsID = Guid.Parse(attribute.Value);
                                break;
                            case 1:
                                newsItem.Source = attribute.Value;
                                break;
                            case 2:
                                newsItem.Section = attribute.Value;
                                break;
                            case 3:
                                newsItem.NewsItem = attribute.Value;
                                break;
                            case 4:
                                newsItem.NewsHeadline = attribute.Value;
                                break;
                            case 5:
                                newsItem.NewsAdded = Convert.ToDateTime(attribute.Value);
                                break;
                            case 7:
                                newsItem.Summary = attribute.Value;
                                break;
                            case 8:
                                newsItem.Category = attribute.Value;
                                break;
                        }
                        i++;
                    }
                }
            }
            return newsItem;
        }
        /// <summary>
        /// Returns all of the attributes associated with the specified item. Optionally, the
        /// attributes returned can be limited to one or more attributes by specifying an attribute
        /// name parameter. 
        /// 
        ///  
        /// <para>
        ///  If the item does not exist on the replica that was accessed for this operation, an
        /// empty set is returned. The system does not return an error as it cannot guarantee
        /// the item does not exist on other replicas. 
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the GetAttributes service method.</param>
        /// 
        /// <returns>The response from the GetAttributes service method, as returned by SimpleDB.</returns>
        /// <exception cref="InvalidParameterValueException">
        /// The value for a parameter is invalid.
        /// </exception>
        /// <exception cref="MissingParameterException">
        /// The request must contain the specified missing parameter.
        /// </exception>
        /// <exception cref="NoSuchDomainException">
        /// The specified domain does not exist.
        /// </exception>
        public GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var marshaller = new GetAttributesRequestMarshaller();
            var unmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return Invoke<GetAttributesRequest,GetAttributesResponse>(request, marshaller, unmarshaller);
        }
 IAsyncResult invokeGetAttributes(GetAttributesRequest getAttributesRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new GetAttributesRequestMarshaller().Marshall(getAttributesRequest);
     var unmarshaller = GetAttributesResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
示例#19
0
 public bool Authenticate(AutheticateRequest request)
 {
     var getAttribute =
         new GetAttributesRequest().WithDomainName(_config.StoreName).WithItemName(request.UserName);
     var result = _client.GetAttributes(getAttribute).GetAttributesResult;
     if (result == null) return false;
     return result.Attribute.Any(a => a.Name == "Password" && a.Value == request.Password);
 }
        /// <summary>
        /// Get a single attribute back from the item.
        /// </summary>
        /// <param name="domainName"></param>
        /// <param name="itemName"></param>
        /// <param name="name"></param>
        /// <returns>Returns the value of the attribute if it exists, otherwise an empty string.</returns>
        /// <remarks>Can't do multiple as no guarantee as to order.</remarks>
        public string GetAttribute(string domainName, string itemName, string name)
        {
            var request = new GetAttributesRequest
                              {
                                  DomainName = domainName,
                                  ItemName = itemName,
                                  AttributeName = new List<string> { name }
                              };

            GetAttributesResponse response = Client.GetAttributes(request);

            if (response.IsSetGetAttributesResult())
            {
                if (response.GetAttributesResult.Attribute.Count > 0)
                {
                    return response.GetAttributesResult.Attribute[0].Value;
                }
            }

            return string.Empty;
        }
	    IAsyncResult AmazonSimpleDB.BeginGetAttributes(GetAttributesRequest request, AsyncCallback callback, object state)
	    {
	        throw new NotImplementedException();
	    }
        public void Test_GetAttributes_And_Check_For_Attribute_Count()
        {
            bool hasCallbackArrived = false;
            int actualValue = 0;
            int expectedValue = 4;

            SimpleDBResponseEventHandler<object, ResponseEventArgs> handler = null;

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

            //Hook to event
            _client.OnSimpleDBResponse += handler;

            //Create request object.
            //List<string> attributes = new List<string>();
            GetAttributesRequest getAttributesRequest = new GetAttributesRequest
            {
                DomainName = _domainName_UnitTesting,
                ItemName = _itemName_UnitTesting
            };

            _client.GetAttributes(getAttributesRequest);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public virtual Daffodil Read(string domain, string id)
        {
            var client = this.GetClient();
            var request = new GetAttributesRequest
                              {
                                  ItemName = id,
                                  DomainName = domain,
                              };

            var response = client.GetAttributes(request);
            var attributes = response.GetAttributesResult.Attribute;
            var idFromDb = attributes.First(x => x.Name == "Id").Value;
            var dataFromDb = attributes.First(x => x.Name == "Data").Value;

            var daffodil = new Daffodil
                               {
                                   Id = idFromDb,
                                   Data = dataFromDb,
                               };

            return daffodil;
        }
        public void Test_GetAttributes_With_NonExisting_Attribute_And_Expect_Zero_Result()
        {
            bool hasCallbackArrived = false;
            int actualValue = -1;
            int expectedValue = 0;
            string nonExistingAttribute = "poiu";

            SimpleDBResponseEventHandler<object, ResponseEventArgs> handler = null;

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

            //Hook to event
            _client.OnSimpleDBResponse += handler;

            //Create request object.
            //Commented because of AttributeName property change during resolving FxCop warining.
            //List<string> attributes = new List<string>{ nonExistingAttribute };
            GetAttributesRequest getAttributesRequest = new GetAttributesRequest
            {
                DomainName = _domainName_UnitTesting,
                ItemName = _itemName_UnitTesting,
            };
            getAttributesRequest.AttributeName.Add(nonExistingAttribute);

            _client.GetAttributes(getAttributesRequest);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public override MembershipUser GetUser(string userName, bool userIsOnline)
        {
            this.VerifyKeys();

            MembershipUser user = null;
            if (!String.IsNullOrEmpty(userName))
            {
                DomainHelper.CheckForDomain(Settings.Default.AWSMembershipDomain, _simpleDBClient);
                GetAttributesRequest request = new GetAttributesRequest()
                    .WithDomainName(Settings.Default.AWSMembershipDomain)
                    .WithItemName(userName);
                GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult;
                if (result == null ||
                    result.Attribute.Count == 0)
                {
                    return null;
                }

                string email = String.Empty;
                string passwordQuestion = String.Empty;
                bool isApproved = false;
                List<Attribute> attributes = result.Attribute;
                foreach (Attribute att in attributes)
                {
                    switch (att.Name)
                    {
                        case "Email":
                        {
                            email = att.Value;
                            break;
                        }
                        case "PasswordQuestion":
                        {
                            passwordQuestion = att.Value;
                            break;
                        }
                        case "IsApproved":
                        {
                            isApproved = bool.Parse(att.Value);
                            break;
                        }
                        default:
                        break;
                    }
                }
                user = new MembershipUser(
                    this.Name, 
                    userName, 
                    String.Empty, 
                    email, 
                    passwordQuestion, 
                    String.Empty, 
                    isApproved, 
                    false, 
                    DateTime.Today, 
                    DateTime.Today, 
                    DateTime.Today, 
                    DateTime.Today, 
                    DateTime.Today
                    );
            }

            return user;
        }
        public void Test_GetAttribute_And_Check_For_Valid_Attribute()
        {
            bool hasCallbackArrived = false;
            string actualValue = string.Empty;
            string expectedValue = "Name_1";

            SimpleDBResponseEventHandler<object, ResponseEventArgs> handler = null;

            handler = delegate(object sender, ResponseEventArgs args)
            {
                //Unhook from event.
                _client.OnSimpleDBResponse -= handler;
                GetAttributesResponse response = args.Response as GetAttributesResponse;
                if (null != response)
                {
                    GetAttributesResult attributeResult = response.GetAttributesResult;
                    if (null != attributeResult)
                    {
                        if (attributeResult.Attribute.Count > 0)
                            actualValue = attributeResult.Attribute[0].Value;
                    }
                }
                hasCallbackArrived = true;
            };

            //Hook to event
            _client.OnSimpleDBResponse += handler;

            //Create request object.
            //Commented because of AttributeName property changed while resolving FxCop warnings.
            //List<string> attributes = new List<string> { "Name" };
            GetAttributesRequest getAttributesRequest = new GetAttributesRequest
            {
                DomainName = _domainName_UnitTesting,
                ItemName = _itemName_UnitTesting
            };
            getAttributesRequest.AttributeName.Add("Name");

            _client.GetAttributes(getAttributesRequest);

            EnqueueConditional(() => hasCallbackArrived);
            EnqueueCallback(() => Assert.IsTrue(expectedValue == actualValue));
            EnqueueTestComplete();
        }
        public override bool ValidateUser(string userName, string password)
        {
            this.VerifyKeys();

            if (String.IsNullOrEmpty(userName) ||
                String.IsNullOrEmpty(password))
            {
                return false;
            }

            bool retval = false;
            string dbpassword = String.Empty;
            GetAttributesRequest request = new GetAttributesRequest()
                .WithDomainName(Settings.Default.AWSMembershipDomain)
                .WithItemName(userName)
                .WithAttributeName(PasswordStrings);
            GetAttributesResult result = this._simpleDBClient.GetAttributes(request).GetAttributesResult;
            if (result != null)
            {
                foreach (Attribute att in result.Attribute)
                {
                    switch (att.Name)
                    {
                        case "Password":
                        {
                            dbpassword = att.Value;
                            break;
                        }
                    }
                }
                retval = dbpassword == password;
            }

            return retval;
        }
示例#28
0
        /// <summary>
        /// Returns a user's profile
        /// Currently assumes a single user will match the token.
        /// </summary>
        /// <param name="authenticationOption"></param>
        /// <param name="usernameToMatch"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="totalRecords"></param>
        /// <returns></returns>
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            // TODO: Take paging into account
            // TODO: Take auth option into account
            totalRecords = 0;

            ProfileInfoCollection profiles = new ProfileInfoCollection();

            GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(usernameToMatch);
            GetAttributesResponse response = client.GetAttributes(request);

            if (response.GetAttributesResult.Attribute.Count > 0)
            {
                ProfileInfo profile = null;
                List<Attribute> attributes = response.GetAttributesResult.Attribute;
                MCItem item = new MCItem();
                item.Domain = domain;
                item.ItemName = usernameToMatch;
                item.Attributes = new Hashtable();
                foreach (Attribute attribute in attributes)
                {
                    item.Attributes.Add(attribute.Name, attribute.Value);
                }
                bool Anon = bool.Parse(item.Get("Anon").Replace("", "false"));
                DateTime LastActivity = DateTime.Parse(item.Get("LastActivity"));
                DateTime LastUpdated = DateTime.Parse(item.Get("LastUpdated"));
                profile = new ProfileInfo(item.Id, Anon, LastActivity, LastUpdated, 0);
                profiles.Add(profile);
            }

            totalRecords = profiles.Count;
            return profiles;
        }
        /// <summary>
        /// <para> Returns all of the attributes associated with the specified item. Optionally, the attributes returned can be limited to one or more
        /// attributes by specifying an attribute name parameter. </para> <para> If the item does not exist on the replica that was accessed for this
        /// operation, an empty set is returned. The system does not return an error as it cannot guarantee the item does not exist on other replicas.
        /// </para> <para><b>NOTE:</b> If GetAttributes is called without being passed any attribute names, all the attributes for the item are
        /// returned. </para>
        /// </summary>
        /// 
        /// <param name="getAttributesRequest">Container for the necessary parameters to execute the GetAttributes service method on
        /// AmazonSimpleDB.</param>
        /// 
        /// <returns>The response from the GetAttributes service method, as returned by AmazonSimpleDB.</returns>
        /// 
        /// <exception cref="T:Amazon.SimpleDB.Model.InvalidParameterValueException" />
        /// <exception cref="T:Amazon.SimpleDB.Model.NoSuchDomainException" />
        /// <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 async Task<GetAttributesResponse> GetAttributesAsync(GetAttributesRequest getAttributesRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new GetAttributesRequestMarshaller();
            var unmarshaller = GetAttributesResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, GetAttributesRequest, GetAttributesResponse>(getAttributesRequest, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
示例#30
0
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext sc, SettingsPropertyCollection collection)
        {
            string username = (string)sc["UserName"];
            SettingsPropertyValueCollection properties = new SettingsPropertyValueCollection();

            GetAttributesRequest request = new GetAttributesRequest().WithDomainName(domain).WithItemName(username);
            GetAttributesResponse response = client.GetAttributes(request);

            // Setup defaults ...

            foreach (SettingsProperty prop in collection)
            {
                SettingsPropertyValue value = new SettingsPropertyValue(prop);
                value.PropertyValue = prop.DefaultValue;
                properties.Add(value);
            }

            if (response.GetAttributesResult.Attribute.Count > 0)
            {
                List<Attribute> attributes = response.GetAttributesResult.Attribute;
                MCItem item = new MCItem();
                item.Domain = domain;
                item.ItemName = username;
                item.Attributes = new Hashtable();
                foreach (Attribute attribute in attributes)
                {
                    item.Attributes.Add(attribute.Name, attribute.Value);
                }
                foreach (SettingsProperty prop in collection)
                {
                    SettingsPropertyValue value = properties[prop.Name];
                    value.PropertyValue = item.Attributes[prop.Name];
                    //value.Deserialized = true;
                }
            }

            return properties;
        }