Am I Done?

In the Cloud

Using the Communicator Automation API

Using the Communicator Automation API

  • Comments 3

Recent Update to the Presence Controls:
http://www.microsoft.com/downloads/details.aspx?familyid=25A27453-15FF-48AB-AF1B-692CD77AB510&displaylang=en

I'm working on a small project which uses the Communicator Automation API. In fact I'm taking a short cut and a great head start by using the Sample Presence Controls.

If you are new to the Automation API, it isn't very intutive at all. The scenario I ran across was that I wanted to set the presence of the current user logged into Communicator.
Note: You can set the presence of the user logged in to Communicator, but you can not set someone else's presence.

I'm not a big fan of reading the documentation first.. I like to work with and figure it out. I'm the same way with the "some assembly required" items I buy. Ditch the instructions and figure it out.

Thinking that it should farily simple to set your own status, I start with declaring a Communicator object:

     CommunicatorAPI.MessengerClass communicatorObject = new CommunicatorAPI.MessengerClass();

Ok that is simple enough, now to set the presence status of the current user, I find the MyStatus property, which looks like it can be set with the MISTATUS Enum...

      communicatorObject.MyStatus = MISTATUS.MISTATUS_BUSY;

This seems logical syntax wise, it compiles and runs but .... it never sets "MY" Status. I sat an thought about the reasoning why this doesn't work. I mean if you are going to expose a property that isn't readonly and name the property "MyStatus", I should be able to set it, right?

The Solution

First you need to get the current logged in user in an object of type IMessengerContactAdvanced:

     IMessengerContactAdvanced contact = (IMessengerContactAdvanced)communicatorObject.GetContact(communicatorObject.MySigninName, communicatorObject.MyServiceId);

Next you need need to create an Object array, in which the index of the array determines which property to set. There are 8 properties we can set, so our Object array needs an initializer of 8.  This isn't very coder friendly at all....

      object[] presenceProperties = new object[8];

Next you need to set the first object in the array, index of 0, with our status.

     presenceProperties[0] = MISTATUS.MISTATUS_BUSY; 
         or you can use the PresenceProperty Enum
     presenceProperties[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE] = MISTATUS.MISTATUS_BUSY; 

Finally add our Object array to the IMessengerContactAdvanced object.

     contact.PresenceProperties = (object)presenceProperties;

 Final Solution

CommunicatorAPI.MessengerClass communicatorObject = new CommunicatorAPI.MessengerClass();

IMessengerContactAdvanced contact = (IMessengerContactAdvanced)communicatorObject.GetContact(communicatorObject.MySigninName, communicatorObject.MyServiceId);

object[] presenceProperties = new object[8];

presenceProperties[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE] = (MISTATUS) status;

 

contact.PresenceProperties = (object)presenceProperties;

 

I'm not sure of the WHY the the API was designed this way, but this is at least explains the HOW.  For those of you who do read the documentation before implementing, MSDN does contain a lot of good documentation on the HOWs.
http://msdn2.microsoft.com/en-us/library/bb758774.aspx

 

Leave a Comment
  • Please add 6 and 3 and type the answer here:
  • Post
  • I've encountered many frustrations working with the UCC API as well.  The architecture is far from intuitive.  I plan to also do some work with the Automation API, so I'll be referring back to this post for help later.

    Thanks for the sample,

    Ryan

  • Thanks for the post, we need more.  couple of comments:

    1. the final solution doesn't run. It seems the sample code is leaving out the value of "status" but the previous code samples mixed in works.

    not complete:

    presenceProperties[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE] = (MISTATUS) status;

    try:

    presenceProperties[(int)PRESENCE_PROPERTY.PRESENCE_PROP_MSTATE] = MISTATUS.MISTATUS_BUSY;

    2. if there were 8 presenceProperties wouldn't you use

    object[] presenceProperties = new object[7];

    3. However, it looks like there are 12 presenceProperties (shouldn't matter in this case)

    typedef enum{

      PRESENCE_PROP_MSTATE = 0x0,

      PRESENCE_PROP_AVAILABILITY = 0x1,

      PRESENCE_PROP_IS_BLOCKED = 0x2,

      PRESENCE_PROP_PRESENCE_NOTE = 0x3,

      PRESENCE_PROP_IS_OOF = 0x4,

      PRESENCE_PROP_TOOL_TIP = 0x5,

      PRESENCE_PROP_CUSTOM_STATUS_STRING = 0x6,

      PRESENCE_PROP_DEVICE_TYPE = 0x7,

      PRESENCE_PROP_CURRENT_CALENDAR_STATE = 0x8

      PRESENCE_PROP_NEXT_CALENDAR_STATE = 0x9

      PRESENCE_PROP_NEXT_CALENDAR_STATE_TIME = 0xA

      PRESENCE_PROP_MAX = 0xB

    } PRESENCE_PROPERTY;

    thanks,

    Vincent Valdez

  • Hi,

    Whenever a contact is selected in communicator by the user, I want to receive the login name of that contact (or best case, email id) in my windows application.

    Do you think this is doable? I'll appreciate if you can help.

Page 1 of 1 (3 items)