Click or drag to resize

ResourceManagementClientGetResourceByKey Method (String, DictionaryString, Object, IEnumerableString, CultureInfo)

Gets a resource from the resource management service using a set of unique attribute and value combinations, retrieving the specified attributes for the resource

Namespace:  Lithnet.ResourceManagement.Client
Assembly:  Lithnet.ResourceManagement.Client (in Lithnet.ResourceManagement.Client.dll) Version: 1.0.6435.24467
Syntax
public ResourceObject GetResourceByKey(
	string objectType,
	Dictionary<string, Object> attributeValuePairs,
	IEnumerable<string> attributesToGet,
	CultureInfo locale
)

Parameters

objectType
Type: SystemString
The type of object to retrieve
attributeValuePairs
Type: System.Collections.GenericDictionaryString, Object
A list of attribute value pairs that make this object unique
attributesToGet
Type: System.Collections.GenericIEnumerableString
The list of attributes to retrieve
locale
Type: System.GlobalizationCultureInfo
The culture to use to request a localized version of the object

Return Value

Type: ResourceObject
A resource that matches the specified criteria, or null of no object was found
Exceptions
ExceptionCondition
TooManyResultsExceptionThe method will throw this exception when more that one match was found for the specified criteria
Examples
The following example shows how get a user by using the AccountName and Domain pair of anchor attributes
Example
public ResourceObject GetPersonByUsernameAndDomain(string username, string domain)
{
    ResourceManagementClient client = new ResourceManagementClient();

    Dictionary<string, object> anchorPairs = new Dictionary<string, object>();
    anchorPairs.Add("AccountName", username);
    anchorPairs.Add("Domain", domain);

    // Specify the list of attributes that we are interested in
    List<string> attributesToGet = new List<string>() { "DisplayName", "FirstName", "LastName" };

    try
    {
        ResourceObject resource = client.GetResourceByKey("Person", anchorPairs, attributesToGet);

        if (resource == null)
        {
            // The resource was not found, throw an exception
            throw new ResourceNotFoundException();
        }

        return resource;
    }
    catch (TooManyResultsException)
    {
        // More than one match was found
        throw;
    }
}
See Also