UCMA设置lync在线状态
摘要
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()); } }
-
博客地址:http://www.cnblogs.com/wolf-sun/
博客版权:如果文中有不妥或者错误的地方还望高手的你指出,以免误人子弟。如果觉得本文对你有所帮助不如【推荐】一下!如果你有更好的建议,不如留言一起讨论,共同进步! 再次感谢您耐心的读完本篇文章。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义