码迷,mamicode.com
首页 > 其他好文 > 详细

UCMA设置lync在线状态

时间:2016-06-19 10:07:01      阅读:342      评论:0      收藏:0      [点我收藏+]

标签:

摘要

UCMA全称Microsoft Unified Communications Managed API,主要用来构建工作在Microsoft Lync Server上的中间层应用程序。开发人员可以使用该平台构建应用程序,以提供对 Microsoft Lync Server增强状态信息、即时消息、电话、视频呼叫和音频/视频会议的访问和控制能力。

在线状态

通过UCMA方式,设置lync客户端的在线状态。设置在线状态为 UCMA Online的SDK方法如下:

  private static AutoResetEvent _PresencePublishComplete = new AutoResetEvent(false);
        private static String _noteXml = "<note xmlns=\"http://schemas.microsoft.com/2006/09/sip/note\" >"
    + "<body type=\"personal\" uri=\"\" >{0}</body></note>";
        private static string _noteValue = "Gone Fishing"; 
public void SetLyncOnline(UserEndpoint uep)
        {
            try
            {
                _localOwnerPresence = uep.LocalOwnerPresence;
                //tColl.Add(_localOwnerPresence.SubscriberEndpoint.OwnerDisplayName,_localOwnerPresence);
                // The CustomPresenceCategory class enables creation of a
                // category using XML. This allows precise crafting of a
                // category, but it is also possible to create a category
                // in other, more simple ways, shown below.
                CustomPresenceCategory _note = new CustomPresenceCategory("note", String.Format(_noteXml, _noteValue));

                // The PresenceState class has several static properties
                // and methods which will provide standard states such as
                // online, busy, and on-the-phone, for example.
                PresenceState _userState = PresenceState.UserAvailable;

                // It is possible to create and publish state with a
                // custom availablity string, shown below. "In a call" will
                // be shown in Microsoft Lync.
                LocalizedString localizedCallString = new LocalizedString(
                    "UCMA Online" /* The string to be displayed. */);

                // Create a PresenceActivity indicating the
                // "In a call" state.
                PresenceActivity inACall = new PresenceActivity(
                    localizedCallString);

                // Set the Availability of the "In a call" state to Busy.
                inACall.SetAvailabilityRange((int)PresenceAvailability.Online,
                    (int)PresenceAvailability.IdleOnline);

                // Microsoft Lync will also show the Busy presence icon.
                PresenceState _phoneState = new PresenceState(
                        (int)PresenceAvailability.Online,
                        inACall,
                        PhoneCallType.Voip,
                        "phone uri");

                // Machine or Endpoint states must always be published to
                // indicate the endpoint is actually online, otherwise it is
                // assumed the endpoint is offline, and no presence
                // published from that endpoint will be displayed.
                PresenceState _machineState = PresenceState.EndpointOnline;

                // It is also possible to create presence categories such
                // as ContactCard, Note, PresenceState, and Services with
                // their constructors.
                // Here we create a ContactCard and change the title.
                ContactCard _contactCard = new ContactCard(3);
                LocalizedString localizedTitleString = new LocalizedString(
                    "" /* The title string to be displayed. */);
                _contactCard.JobTitle = localizedTitleString.Value;

                // Publish a photo
                // If the supplied value for photo is null or empty, then set value of IsAllowedToShowPhoto to false
                _contactCard.IsAllowedToShowPhoto = false;
                _contactCard.PhotoUri = null;

                // Publish all presence categories with new values.
                _localOwnerPresence.BeginPublishPresence(
                        new PresenceCategory[]
                        {
                            _userState,
                            _phoneState,
                            _machineState,
                            _note,
                            _contactCard
                        },
                        PublishPresenceCompleted, /* async callback when publishing operation completes. */

                        true /* value TRUE indicates that presence to be published with new values. */);

                // _PresencePublishComplete.WaitOne();
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during this presence operation such as badly
                // formed sip request, duplicate publications in the same
                // request etc.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are 
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }


        }
  private void PublishPresenceCompleted(IAsyncResult result)
        {
            try
            {
                // Since the same call back function is used to publish
                // presence categories and to delete presence categories,
                // retrieve the flag indicating which operation is desired.


                bool isPublishOperation;
                if (result.AsyncState == null)
                {
                    isPublishOperation = false;
                }
                else
                {
                    bool.TryParse(result.AsyncState.ToString(), out isPublishOperation);
                }


                if (isPublishOperation)
                {
                    // Complete the publishing of presence categories.
                    _localOwnerPresence.EndPublishPresence(result);
                    Console.WriteLine("Presence state has been published.");
                }
                else
                {
                    // Complete the deleting of presence categories.
                    _localOwnerPresence.EndDeletePresence(result);
                    Console.WriteLine("Presence state has been deleted.");
                }
            }
            catch (PublishSubscribeException pse)
            {
                // PublishSubscribeException is thrown when there were
                // exceptions during the publication of this category such as
                // badly formed sip request, duplicate publications in the same
                // request etc
                // TODO (Left to the reader): Include exception handling code
                // here
                Console.WriteLine(pse.ToString());
            }
            catch (RealTimeException rte)
            {
                // RealTimeException is thrown when SIP Transport, SIP
                // Authentication, and credential-related errors are
                // encountered.
                // TODO (Left to the reader): Include exception handling code
                // here.
                Console.WriteLine(rte.ToString());
            }
        }

UCMA设置lync在线状态

标签:

原文地址:http://www.cnblogs.com/wolf-sun/p/5597481.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!