Publishing Presence

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Presence can be published either with or without the assistance of a publication grammar. One endpoint type, UserEndpoint, can publish its owner’s presence in either way. The other endpoint type, ApplicationEndpoint, cannot publish presence using a publication grammar.

Publishing Presence Categories Using a Publication Grammar

A UserEndpoint instance can be used to publish presence using a publication grammar using the PresenceCategory class. This type of publication matches that of Office Communicator.

To publish presence categories using a publication grammar

  1. Create a CustomPresenceCategory instance with a category named "state".

  2. Create a List instance whose base type is PresenceCategory.

  3. Add the presence item to the list created in the previous step.

  4. Publish the presence information using BeginPublishPresence and EndPublishPresence. These two methods conform to the .NET asynchronous programming pattern.

The following example code is for purposes of illustration only.

private static String _busyXml = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" manual=\"true\" xsi:type=\"userState\"><availability>{0}</availability></state>";
private static int _busyAvail = 6500;


CustomPresenceCategory customCat = new CustomPresenceCategory("state", String.Format(_busyXml, _busyAvail));
result = _userEndpoint.LocalOwnerPresence.BeginPublishPresence( new PresenceCategory[] { customCat }, PublishPresenceCompleted, _userEndpoint.LocalOwnerPresence);
  


private void PublishPresenceCompleted(IAsyncResult result)
{
  try
  {
    LocalOwnerPresence lop = result.AsyncState as LocalOwnerPresence;
    lop.EndPublishPresence(result);
  }
  catch (PublishSubscribeException pse)
  {
   // Write exception handling code here.
  }
  catch (RealTimeException rte)
  {
   // Write exception handling code here.
  }
}

Publishing Presence Categories without a Publication Grammar

A UserEndpoint instance can be used to publish presence without using the publication grammar by means of the PresenceCategoryWithMetadata class. An ApplicationEndpoint instance cannot use a publication grammar to publish presence, which means that it is responsible for supplying the details of which containers will be published to, the expiry policy for publication, the instance ID, and other information.

To publish presence categories without a publication grammar

  1. Create a PresenceCategoryWithMetadata instance. In the example code, the PresenceCategoryWithMetadata instance is created with a custom presence category named "state".

  2. Create a List instance whose base type is PresenceCategoryWithMetadata.

  3. Add the presence item to the list created in the previous step.

  4. Publish the presence information using BeginPublishPresence and EndPublishPresence. These two methods conform to the .NET asynchronous programming pattern.

The following example code is for purposes of illustration only.

string userStateBody = "<state xmlns=\"http://schemas.microsoft.com/2006/09/sip/state\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:type=\"userState\"><availability>3500</availability></state>";

// Instance ID is 1 and container ID is 0.
PresenceCategoryWithMetadata itemToPublish = new PresenceCategoryWithMetadata(1, 0, new CustomPresenceCategory("state", userStateBody));

List<PresenceCategoryWithMetadata> itemList = new List<PresenceCategoryWithMetadata>();

itemList.Add(itemToPublish);
IAsyncResult result = _userEndpoint.LocalOwnerPresence.BeginPublishPresence(itemList, PublishPresenceCompleted, _userEndpoint.LocalOwnerPresence);
….

private void PublishPresenceCompleted(IAsyncResult result)
{
  try
  {
    LocalOwnerPresence lop = result.AsyncState as LocalOwnerPresence;
    lop.EndPublishPresence(result);
  }
  catch (PublishSubscribeException pse)
  {
    // Write exception handling code here.
  }
  catch (RealTimeException rte)
  {
    // Write exception handling code here.
  }

}

Instance IDs enable a publisher to publish a given category of data multiple times. For example, a publisher can use two different endpoints to publish data. These endpoints can publish the same category, but for the server to consider them as distinct publications, each must have its own instance ID.

Instance IDs are provided by the publishing endpoint. The endpoint might provide a fixed instance ID (for example, 0) when the data logically has only one instance, such as an offline presence note sent by a publisher.

The ExpiryPolicy and Expires properties on a PresenceCategoryWithMetadata instance can be used to control how long container data is published: for the lifetime of the publishing endpoint, for a specific time period, or until the data is changed. If a category is published with ExpiryPolicy.Time and an Expires value of 0, the category instance is deleted.