How to publish presence in UCMA without using XML
Michael Green published a great article about how to publish presence using UCMA, but it involves using XML. If you hate XML as much as I do, this article is for you.
Note that the code presented here is a snippet and therefore won’t compile/work by itself.
Publishing states
The process for publishing your state is the same for any of the four states (user state, machine state, phone state, calendar state). Let’s look at how to publish the user state:
var userState = new UserState(availability, activity);
_endpoint.LocalOwnerPresence.BeginPublishPresence(
new PresenceCategory[] { userState },
PublishPresenceCompleted,
null);
Wow, that was tough! The other three states have similar classes you can use: MachineState, PhoneState, and CalendarState, all of which are located in the Microsoft.Rtc.Internal.Collaboration namespace. PublishPresenceCompleted is as about as dumb as you might expect:
_endpoint.LocalOwnerPresence.EndPublishPresence(result);
What if you don’t have activity (anything you want it to be)? Don’t pass anything in, and Communicator will show the default activity for your availability.
Publishing device capabilities
Publishing the device capabilities is slightly more involved:
var capability = new DeviceCapability(true, true, true);
var capabilities = new DeviceCapabilities(_endpoint.InnerEndpoint.Uri);
// Set capabilities; i.e., capabilities.Text = capability
var device = new Device(
_endpoint.InnerEndpoint.Id, _
new DeviceCapabilities[] { capabilities });
Like the *State classes, Device derives from PresenceCategory. You can view the XML that will be generated by calling PresenceCategory.GetCategoryDataXml() method.