Back to contents pageHow to get a list of objects using the API

How to get a list of objects using the API

Summary

This article shows how to iterate over the ObjectName relation of a Naming schema to populate a list of its contents.





Prerequisites

None. You can use this article on its own.



Example material

Save this link to get a zip file of the example material


Guide

Before you start

Remember to:



Get a list of the named objects

1) Preparing the schemas

We need to instantiate a cached Naming schema object and connect it to the server:


    // Declaration of the Naming schema object
    Ubisense.ULocation.Naming.Schema namingSchema;

    // Instantiate the Naming schema as a cached schema
    namingSchema = new Ubisense.UName.Naming.Schema(false);

    // Connect the cached naming schema as client to read transactions
    namingSchema.ConnectAsClient();



2) Iterate over your cached Naming schema

Since the instantiated Naming schema object is a cached schema, we can iterate over its ObjectName relation, filtering the results with its index methods to find a specific object. If we don't use a parameter in these methods, we will iterate over the whole table.


    using (Naming.ReadTransaction xact = namingSchema.ReadTransaction())
    {
        foreach (Naming.ObjectName.RowType row
            in Naming.ObjectName.name_(xact))
        {
            DoSomethingWith(row);
        }
    }



3) Disconnect the schema

Once we have finished using the Naming schema object, we should disconnect it from the server and dispose of it:


    namingSchema.Disconnect();
    namingSchema.Dispose();





The sample application

1) What it does



2) Using the sample application

  1. Create some objects using the Site Manager tool.

  2. Run the application and verify that you get the list of the objects you created before.

  3. Try deleting some objects in Site Manager or add some more.

  4. Return to your application and click the button again to update the results.









Back to top