为了账号安全,请及时绑定邮箱和手机立即绑定

UCMA设置lync在线状态

标签:
SQL Server

摘要

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());            }        }

复制代码

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消