All Classes Namespaces Functions Properties Pages
Collection

For details of how to create a project that uses the TotalAgility SDK please see here.


Creating code that uses collections

For this example code will created that logs on to the system and then calls GetResources2 and uses the returned data to call GetResourcesEmailAddresses to retrieve a list of their email addresses.

Logging on to the system

The code will log the current Windows user in and extract the session id to use in further calls:

// Set up a UserService object and log on to get a seeion id
TotalAgility.Sdk.UserService userService = new TotalAgility.Sdk.UserService();
string sessionId = userService.LogOnWithWindowsAuthentication2(7, true).SessionId;
Get the resources

To make the call to GetResources2 a ResourceFilter2 object will be created and the search criteria populated.
The test system was set up with two users, TestUser1 and TestUser2. To find these users the SearchText member of the filter will be set to "TestUser":

// set up the parameters needed to call GetResources2
filter.SearchText = "TestUser";

Next the code will make thwe call to GetResources2 and capture the return data:

// Set up the ResourceService object and call GetResources2, setting the resourceIconSettings parameter to null
TotalAgility.Sdk.ResourceService resourceService = new TotalAgility.Sdk.ResourceService();
Agility.Sdk.Model.Resources.ResourceSummaryCollection resourceSummaryCollection = resourceService.GetResources2(sessionId, filter, null);
Get the email addresses

The call to GetResourcesEmailAddresses requires a ResourceIdentityCollection which means that some code will be needed to create a new ResourceIdentityCollection and populate it from the ResourceSummaryCollection returned by GetResources2:

// Create a RescourceIdentityCollection for the call to GetResourcesEmailAddresses
// Add the resource identities returned by GetResources2
foreach (Agility.Sdk.Model.Resources.ResourceSummary resourceSummary in resourceSummaryCollection)
{
idCollection.Add(resourceSummary.Identity);
}

The call to GetResourcesEmailAddresses can now be made:

// Call GetResourcesEmailAddresses using the new ResourceIdentityCollection object
Agility.Sdk.Model.Resources.ResourceIdentity2Collection emailAddresses = resourceService.GetResourcesEmailAddresses(sessionId, idCollection);
The whole package

Putting all the code together:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UsingCollections
{
class Program
{
static void Main(string[] args)
{
// Set up a UserService object and log on to get a seeion id
TotalAgility.Sdk.UserService userService = new TotalAgility.Sdk.UserService();
string sessionId = userService.LogOnWithWindowsAuthentication2(7, true).SessionId;
// set up the parameters needed to call GetResources2
filter.SearchText = "TestUser";
// Set up the ResourceService object and call GetResources2, setting the resourceIconSettings parameter to null
TotalAgility.Sdk.ResourceService resourceService = new TotalAgility.Sdk.ResourceService();
Agility.Sdk.Model.Resources.ResourceSummaryCollection resourceSummaryCollection = resourceService.GetResources2(sessionId, filter, null);
// Create a RescourceIdentityCollection for the call to GetResourcesEmailAddresses
// Add the resource identities returned by GetResources2
foreach (Agility.Sdk.Model.Resources.ResourceSummary resourceSummary in resourceSummaryCollection)
{
idCollection.Add(resourceSummary.Identity);
}
// Call GetResourcesEmailAddresses using the new ResourceIdentityCollection object
Agility.Sdk.Model.Resources.ResourceIdentity2Collection resourceIds = resourceService.GetResourcesEmailAddresses(sessionId, idCollection);
// Make simple use of the returned data - print out the email addresses
foreach (Agility.Sdk.Model.Resources.ResourceIdentity2 resourceId2 in resourceIds)
{
System.Console.WriteLine("User's email address is: " + resourceId2.EmailAddress);
}
// Log the user off again
userService.LogOff(sessionId);
}
}
}
The result

Running the code in Visual Studio gives the following output:

CodeGetEmailsOutput.png