コード例 #1
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetAttributes operation.
        /// <seealso cref="Amazon.SimpleDB.IAmazonSimpleDB.GetAttributes"/>
        /// </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, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new GetAttributesRequestMarshaller();
            var unmarshaller = GetAttributesResponseUnmarshaller.GetInstance();

            return(Invoke <IRequest, GetAttributesRequest, GetAttributesResponse>(request, marshaller, unmarshaller, signer, cancellationToken));
        }
コード例 #2
0
ファイル: Profile.cs プロジェクト: kouweizhong/multicore
        /// <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);
        }
コード例 #3
0
        /// <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="Amazon.SimpleDB.Model.InvalidParameterValueException">
        /// The value for a parameter is invalid.
        /// </exception>
        /// <exception cref="Amazon.SimpleDB.Model.MissingParameterException">
        /// The request must contain the specified missing parameter.
        /// </exception>
        /// <exception cref="Amazon.SimpleDB.Model.NoSuchDomainException">
        /// The specified domain does not exist.
        /// </exception>
        public virtual GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var marshaller   = GetAttributesRequestMarshaller.Instance;
            var unmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return(Invoke <GetAttributesRequest, GetAttributesResponse>(request, marshaller, unmarshaller));
        }
コード例 #4
0
        internal GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var marshaller   = new GetAttributesRequestMarshaller();
            var unmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return(Invoke <GetAttributesRequest, GetAttributesResponse>(request, marshaller, unmarshaller));
        }
コード例 #5
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetAttributes operation.
        /// </summary>
        /// <param name="request">Get Attribute  request</param>
        /// <remarks>
        /// Returns all of the attributes associated with the item. Optionally, the attributes returned can be limited to
        /// the specified AttributeName parameter.
        /// If the item does not exist on the replica that was accessed for this operation, an empty attribute is
        /// returned. The system does not return an error as it cannot guarantee the item does not exist on other
        /// replicas.
        /// </remarks>
        public void BeginGetAttributes(GetAttributesRequest request)
        {
            IDictionary <string, string> parameters = ConvertGetAttributes(request);
            SDBAsyncResult result = new SDBAsyncResult(parameters, null);

            invoke <GetAttributesResponse>(result);
        }
コード例 #6
0
        /**
         * Convert GetAttributesRequest to name value pairs
         */
        private static IDictionary <string, string> ConvertGetAttributes(GetAttributesRequest request)
        {
            IDictionary <string, string> parameters = new Dictionary <string, string>();

            parameters["Action"] = "GetAttributes";
            if (request.IsSetDomainName())
            {
                parameters["DomainName"] = request.DomainName;
            }
            if (request.IsSetItemName())
            {
                parameters["ItemName"] = request.ItemName;
            }
            List <string> getAttributesRequestAttributeNameList      = request.AttributeName;
            int           getAttributesRequestAttributeNameListIndex = 1;

            foreach (string getAttributesRequestAttributeName in getAttributesRequestAttributeNameList)
            {
                parameters[String.Concat("AttributeName", ".", getAttributesRequestAttributeNameListIndex)] = getAttributesRequestAttributeName;
                getAttributesRequestAttributeNameListIndex++;
            }
            if (request.IsSetConsistentRead())
            {
                parameters["ConsistentRead"] = request.ConsistentRead.ToString().ToLower(CultureInfo.InvariantCulture);
            }

            return(parameters);
        }
コード例 #7
0
        public override string GetPassword(string userName, string answer)
        {
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = Settings.Default.AWSMembershipDomain,
                ItemName       = userName,
                AttributeNames = PasswordStrings
            };

            string password = String.Empty;
            GetAttributesResponse response = this._simpleDBClient.GetAttributes(request);

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

            return(password);
        }
コード例 #8
0
        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()
            {
                DomainName     = Settings.Default.AWSMembershipDomain,
                ItemName       = userName,
                AttributeNames = PasswordStrings
            };
            GetAttributesResponse response = this._simpleDBClient.GetAttributes(request);

            foreach (Attribute att in response.Attributes)
            {
                switch (att.Name)
                {
                case "Password":
                {
                    dbpassword = att.Value;
                    break;
                }
                }
            }
            retval = dbpassword == password;

            return(retval);
        }
コード例 #9
0
        private void TestGetAttributes()
        {
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = domainName,
                ItemName       = FOO_ITEM.Name,
                AttributeNames = new List <string>()
                {
                    FOO_ITEM.Attributes[0].Name, FOO_ITEM.Attributes[1].Name
                },
                ConsistentRead = true
            };

            GetAttributesResult getAttributesResult                      = Client.GetAttributes(request);
            List <Amazon.SimpleDB.Model.Attribute> attributes            = getAttributesResult.Attributes;
            Dictionary <string, string>            attributeValuesByName = ConvertAttributesToMap(attributes);

            Assert.AreEqual <int>(2, attributeValuesByName.Count);

            List <ReplaceableAttribute> attrs = new List <ReplaceableAttribute>();

            attrs.Add(FOO_ITEM.Attributes[0]);
            attrs.Add(FOO_ITEM.Attributes[1]);

            foreach (ReplaceableAttribute expectedAttribute in attrs)
            {
                string expectedAttributeName = expectedAttribute.Name;
                Assert.IsTrue(attributeValuesByName.ContainsKey(expectedAttributeName));
                Assert.AreEqual <string>(expectedAttribute.Value, attributeValuesByName[expectedAttributeName]);
            }
        }
コード例 #10
0
        private static IDictionary <string, string> ConvertGetAttributes(GetAttributesRequest request)
        {
            IDictionary <string, string> dictionary = new Dictionary <string, string>();

            dictionary["Action"] = "GetAttributes";
            if (request.IsSetDomainName())
            {
                dictionary["DomainName"] = request.DomainName;
            }
            if (request.IsSetItemName())
            {
                dictionary["ItemName"] = request.ItemName;
            }
            List <string> attributeName = request.AttributeName;
            int           num           = 1;

            foreach (string str in attributeName)
            {
                dictionary["AttributeName" + "." + num] = str;
                num++;
            }
            if (request.IsSetConsistentRead())
            {
                dictionary["ConsistentRead"] = request.ConsistentRead.ToString().ToLower();
            }
            return(dictionary);
        }
コード例 #11
0
        /// <summary>
        /// Initiates the asynchronous execution of the GetAttributes operation.
        /// </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 virtual Task <GetAttributesResponse> GetAttributesAsync(GetAttributesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = GetAttributesRequestMarshaller.Instance;
            var unmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return(InvokeAsync <GetAttributesRequest, GetAttributesResponse>(request, marshaller,
                                                                             unmarshaller, cancellationToken));
        }
コード例 #12
0
        private void btnGetAttributes_Click(object sender, RoutedEventArgs e)
        {
            #region User Input Validation

            this.Attributes.Clear();
            //Validate user input.
            if (string.IsNullOrEmpty(this.DomainName) || string.IsNullOrEmpty(this.ItemName))
            {
                FetchingOrDeletingAttributeMessage = "Domain-Name or Item-Name cannot be empty.";
                return;
            }
            this.FetchingOrDeletingAttributeMessage = "Please wait...";

            #endregion User Input Validation

            GetAttributesRequest request = new GetAttributesRequest {
                DomainName = this.DomainName, ItemName = this.ItemName
            };

            //Associate the attributes.
            GetListAttributeFromString(this.AttributesForQuery).ForEach(v => request.AttributeName.Add(v.Attribute));

            SimpleDBResponseEventHandler <object, ResponseEventArgs> handler = null;

            handler = delegate(object senderAmazon, ResponseEventArgs args)
            {
                //Unhook from event.
                SimpleDB.Client.OnSimpleDBResponse -= handler;
                GetAttributesResponse response = args.Response as GetAttributesResponse;

                if (null != response)
                {
                    GetAttributesResult attributeResult = response.GetAttributesResult;
                    if (null != attributeResult)
                    {
                        this.Dispatcher.BeginInvoke(() =>
                        {
                            this.Attributes.Clear();
                            if (attributeResult.Attribute.Count > 0)
                            {
                                FetchingOrDeletingAttributeMessage = "Result count: " + attributeResult.Attribute.Count;
                                foreach (var item in attributeResult.Attribute)
                                {
                                    this.Attributes.Add(item);
                                }
                            }
                            else
                            {
                                FetchingOrDeletingAttributeMessage = "No results";
                            }
                        });
                    }
                }
            };

            SimpleDB.Client.OnSimpleDBResponse += handler;
            SimpleDB.Client.GetAttributes(request);
        }
コード例 #13
0
        /// <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>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        ///
        /// <returns>The response from the GetAttributes service method, as returned by SimpleDB.</returns>
        /// <exception cref="Amazon.SimpleDB.Model.InvalidParameterValueException">
        /// The value for a parameter is invalid.
        /// </exception>
        /// <exception cref="Amazon.SimpleDB.Model.MissingParameterException">
        /// The request must contain the specified missing parameter.
        /// </exception>
        /// <exception cref="Amazon.SimpleDB.Model.NoSuchDomainException">
        /// The specified domain does not exist.
        /// </exception>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sdb-2009-04-15/GetAttributes">REST API Reference for GetAttributes Operation</seealso>
        public virtual Task <GetAttributesResponse> GetAttributesAsync(GetAttributesRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetAttributesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return(InvokeAsync <GetAttributesResponse>(request, options, cancellationToken));
        }
コード例 #14
0
        public bool ExistsWorkStep(string path)
        {
            var getAttributesRequest = new GetAttributesRequest {
                ItemName = path, DomainName = _domain
            };
            var getAttributesResponse = _client.GetAttributes(getAttributesRequest);

            return(getAttributesResponse.GetAttributesResult.Attribute.Count > 0);
        }
コード例 #15
0
        internal virtual GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = GetAttributesRequestMarshaller.Instance;
            options.ResponseUnmarshaller = GetAttributesResponseUnmarshaller.Instance;

            return(Invoke <GetAttributesResponse>(request, options));
        }
コード例 #16
0
        private async Task <List <Attribute> > RetrieveItemAttributesFromDb(string itemId, bool consistentRead = false)
        {
            var request = new GetAttributesRequest(_simpleDbDomain, itemId)
            {
                ConsistentRead = consistentRead
            };
            var response = await _client.GetAttributesAsync(request);

            return(response.Attributes);
        }
コード例 #17
0
        public WorkItem GetWorkItem(string id)
        {
            var getAttributesRequest = new GetAttributesRequest {
                ItemName = id, DomainName = _domain
            };
            var getAttributesResponse = _client.GetAttributes(getAttributesRequest);

            var attributes = getAttributesResponse.GetAttributesResult.Attribute;

            return(GenerateWorkItem(id, attributes));
        }
コード例 #18
0
        public WorkStep GetWorkStep(string path)
        {
            var getAttributesRequest = new GetAttributesRequest {
                ItemName = path, DomainName = _domain
            };
            var getAttributesResponse = _client.GetAttributes(getAttributesRequest);

            var attributes = getAttributesResponse.GetAttributesResult.Attribute;

            return(GenerateWorkStep(path, attributes));
        }
コード例 #19
0
        internal async Task <int> GetNextId()
        {
            var client = GetClient();
            int nextId = -1;

            GetAttributesRequest request = new GetAttributesRequest();

            request.DomainName     = _domain;
            request.ItemName       = "NextId";
            request.AttributeNames = new List <string> {
                "Id"
            };
            request.ConsistentRead = true;

            try
            {
                GetAttributesResponse response = await client.GetAttributesAsync(request);

                if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    if (response.Attributes.Count > 0)
                    {
                        nextId = Convert.ToInt32(response.Attributes[0].Value);
                    }

                    PutAttributesRequest putRequest = new PutAttributesRequest();
                    putRequest.DomainName = _domain;
                    putRequest.ItemName   = "NextId";
                    putRequest.Attributes.Add(
                        new ReplaceableAttribute {
                        Name = "Id", Value = numberToString(++nextId), Replace = true
                    }
                        );

                    try
                    {
                        PutAttributesResponse putResponse = await client.PutAttributesAsync(putRequest);
                    }
                    catch (AmazonSimpleDBException ex)
                    {
                        _logger.LogError(ex, $"Error Code: {ex.ErrorCode}, Error Type: {ex.ErrorType}");
                        throw;
                    }
                }
            }
            catch (System.Exception)
            {
                throw;
            }

            return(nextId);
        }
コード例 #20
0
		internal GetAttributesResponse GetAttributes(GetAttributesRequest request)
        {
            var task = GetAttributesAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
コード例 #21
0
        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);
        }
コード例 #22
0
ファイル: Role.cs プロジェクト: kouweizhong/multicore
        //
        // RoleProvider.IsUserInRole
        //

        public override bool IsUserInRole(string username, string rolename)
        {
            GetAttributesRequest  request  = new GetAttributesRequest().WithDomainName(domain).WithItemName(username + "-" + rolename);
            GetAttributesResponse response = client.GetAttributes(request);

            if (response.GetAttributesResult.Attribute.Count > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #23
0
ファイル: Membership.cs プロジェクト: kouweizhong/multicore
        //
        // 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;
                }
            }
        }
コード例 #24
0
ファイル: SDBProvider.cs プロジェクト: kouweizhong/multicore
        /// <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);
        }
コード例 #25
0
ファイル: Membership.cs プロジェクト: kouweizhong/multicore
        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);
        }
コード例 #26
0
        private static string GetAuthToken(string tenantId)
        {
            string authToken;

            try
            {
                var simpleDbrequest = new GetAttributesRequest(_tableName, tenantId);
                var response        = _simpleDbClient.GetAttributesAsync(simpleDbrequest).Result;
                authToken = response.Attributes.Single(x => x.Name == "Auth_Token").Value;
            }
            catch (Exception)
            {
                throw new AuthenticationException(
                          $"Error retrieving authentication token. Is {tenantId} a valid tenantId?");
            }
            return(authToken);
        }
コード例 #27
0
        bool DoAttributesExistForItem(IAmazonSimpleDB sdb, String itemName, String domainName, List <String> attributeNames)
        {
            GetAttributesRequest request = new GetAttributesRequest()
            {
                DomainName     = domainName,
                AttributeNames = attributeNames,
                ItemName       = itemName,
                ConsistentRead = true
            };

            GetAttributesResult         result = sdb.GetAttributes(request);
            Dictionary <string, string> attributeValuesByName = ConvertAttributesToMap(result.Attributes);

            foreach (string expectedAttributeName in attributeNames)
            {
                if (!attributeValuesByName.ContainsKey(expectedAttributeName))
                {
                    return(false);
                }
            }
            return(true);
        }
コード例 #28
0
        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);
        }
コード例 #29
0
ファイル: Profile.cs プロジェクト: kouweizhong/multicore
        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);
        }
コード例 #30
0
        /// <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);
        }