Click or drag to resize

ProjectOperationsGetProjectClasses Method

Get a list of projects and their associated classes.

Namespace:  Cobra.WebService.ClientAPI.Application.Files
Assembly:  Cobra.WebService.ClientAPI (in Cobra.WebService.ClientAPI.dll) Version: 8.4.717.3176 (8.4.0717.3176)
Syntax
C#
public ProjectClassCollection GetProjectClasses(
	ProjectClassesFilter projectClassesFilterServiceArguments
)

Parameters

projectClassesFilterServiceArguments
Type: Cobra.Model.WebServiceProjectClassesFilter
An instance of ProjectClassesFilter class that contains the filters applied to the list of projects and their associated classes.

Return Value

Type: ProjectClassCollection
An instance of ProjectClassCollection class containing the list of projects and their associated classes.
Exceptions
ExceptionCondition
InvalidOperationExceptionThrown when state of the instance of the CobraServices that generated the current ProjectOperations is not in opened state.
Examples
This example shows how to get list of projects and their associated classes.
C#
using Cobra.Model.WebService;
using Cobra.WebService.ClientAPI.Application.Files;
using Cobra.WebService.ClientAPI.Client;

.
.
.

CobraServices cobraServices = new CobraServices();
cobraServices.ServiceIdentityData.Username = "SYSADMIN";
cobraServices.ServiceIdentityData.SecurePassword = new SecurePassword();
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('P');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('A');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('S');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('S');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('W');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('O');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('R');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('D');
cobraServices.ServiceIdentityData.DataSourceKey = "COBRA";

LoginResult loginResult = cobraServices.Login();
if (!loginResult.Success) {
    Console.WriteLine("Login failed.");
    return;
}

Console.WriteLine("Login Success.");

ProjectOperations projectOperations = cobraServices.CreateServiceOperations<ProjectOperations>();
ProjectClassesFilter projectClassesFilter = projectOperations.CreateProjectOperationsServiceArguments<ProjectClassesFilter>();
projectClassesFilter.ProjectFilter = projectOperations.CreateProjectOperationsServiceArguments<ProjectFilter>();
projectClassesFilter.ProjectFilter.Operator = FilterStringOperator.Like;
projectClassesFilter.ProjectFilter.Value = "Demo%";

Console.WriteLine("Getting projects with their associated classes...");
ProjectClassCollection projectClasses = projectOperations.GetProjectClasses(projectClassesFilter);

bool hasError = false;
foreach (ServiceMessage serviceMessage in projectClasses.GetMessages()) {
    Console.WriteLine("Message Type: {0}", serviceMessage.MessageType);
    Console.WriteLine("Message: {0}", serviceMessage.Message);

    if (serviceMessage.MessageType == MessageType.Error || serviceMessage.MessageType == MessageType.ValidationError) {
        hasError = true;
    }
}

if (!hasError) {
    foreach (ProjectClass project in projectClasses) {
        Console.WriteLine("Name: {0}", project.Name);
        Console.WriteLine("Description: {0}", project.Description);

        Console.WriteLine("Classes:");
        foreach (Class @class in project.Classes) {
            Console.WriteLine("\tName: {0}", @class.Name);
            Console.WriteLine("\tDescription: {0}", @class.Description);
            Console.WriteLine("\tType: {0}", @class.ClassType);
            Console.WriteLine("\tLevel: {0}", @class.Level);
        }
    }

    Console.WriteLine("Getting projects with their associated classes completed successfully.");
}
else
    Console.WriteLine("Getting projects with their associated classes did not completed successfully.");

cobraServices.Logout();
See Also