摘要

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();
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在线状态的更多相关文章

  1. 用smack+openfire做即时通讯

    首发:个人博客 必须说明:smack最新的4.1.1,相对之前版本变化很大,而且资料缺乏,官方文档也不好,所以还是用老版本3.2.2吧.这篇博文中的代码是4.1.1版的,但不推荐用它.用openfir ...

  2. 【Android进阶】为什么要创建Activity基类以及Activity基类中一般有哪些方法

    现在也算是刚刚基本完成了自己的第一个商业项目,在开发的过程中,参考了不少人的代码风格,然而随着工作经验的积累,终于开始慢慢的了解到抽象思想在面向对象编程中的重要性,这一篇简单的介绍一下我的一点收获. ...

  3. 【Android先进】我们为什么要创建Activity基类Activity什么是一般的基类方法

    今天,它可以被视为只是基本完成了其首个商业项目,在发展过程中,风格,然而随着工作经验的积累.最终開始慢慢的了解到抽象思想在面向对象编程中的重要性,这一篇简单的介绍一下我的一点收获. 首先,在如今的项目 ...

  4. iOS - XMPP 的使用

    1.XMPP XMPP 是一个基于 Socket 通信的即时通讯的协议,它规范了即时通信在网络上数据的传输格式,比如登录,获取好友列表等等的格式.XMPP 在网络传输的数据是 XML 格式. 开发架构 ...

  5. QQ如何开通在线客服

    一. 注册一个网站专用QQ. 二. 到QQ商家设置QQ在线状态:http://wp.qq.com/set.html 1.免费开通 2.根据你的需求设置 3,复制代码放置在html页面上即可,效果如下图

  6. MGR实现分析 - 成员管理与故障恢复实现

    MySQL Group Replication(MGR)框架让MySQL具备了自动主从切换和故障恢复能力,举single primary(单主)模式为例,primary作为主节点对外提供读写服务,是唯 ...

  7. MySQL MGR实现分析 - 成员管理与故障恢复实现

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. MySQL Group Replication(MGR)框架让MySQL具备了自动主从切换和故障恢复能力,举 ...

  8. MySQL MGR源码分析2 - 从start group_replication看MGR代码框架

    此文已由作者温正湖授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 上一篇我们从方案层面讲解了MGR的成员管理和故障恢复.本篇从源码层面捋一捋,通过本篇介绍,除了能够了解如何将 ...

  9. Oracle 11g 学习3——表空间操作

    一.表空间概述 表空间是Oracle中最大的逻辑存储结构,与操作系统中的数据文件相相应: 基本表空间:一般指用户使用的永久性表空间,用于存储用户的永久性数据          暂时表空间: 主要用于存 ...

随机推荐

  1. 【Codeforces-707D】Persistent Bookcase DFS + 线段树

    D. Persistent Bookcase Recently in school Alina has learned what are the persistent data structures: ...

  2. eclipse crash

    SIGSEGV (0xb) at pc=0x00007fbcae8f2c91, pid=5707, tid=140449979574016 JRE version: 7.0_25-b30 Java V ...

  3. [NOIP2012] 提高组 洛谷P1081 开车旅行

    题目描述 小 A 和小 B 决定利用假期外出旅行,他们将想去的城市从 1 到 N 编号,且编号较小的 城市在编号较大的城市的西边,已知各个城市的海拔高度互不相同,记城市 i 的海拔高度为 Hi,城市 ...

  4. c#自适应窗体的实现

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.W ...

  5. CentOS关机

    1. 关机前准备 1.1 查看有谁在线 who 1.2 查看网络联机状态 netstat -a 1.3 查看后台正在执行的程序 ps -aux 1.4 向所有在线用户发出警告信息 shutdown - ...

  6. Windows_7_休眠按钮没有了_如何找回?

    1. 在运行中输入:   powercfg -h on或者在命令行下输入:   powercfg.exe /hibernate on注意:执行这个命令需要管理员权限. “休眠”回来了   2. 还是没 ...

  7. Scala的sealed关键字

    Scala的sealed关键字 缘起 今天在学习Akka的监控策咯过程中看到了下面一段代码: def supervisorStrategy(): SupervisorStrategy = OneFor ...

  8. C++ essentials 之 union

    Extraction from The C++ Programming Language 4th. edition, Bjarne Stroustrup [8.1] A struct is a seq ...

  9. Mac配置一些开发环境(随时补充)

    Mac安装mysql并启动 brew install mysql mysql.server start /usr/local/Cellar/mysql/5.6.10/support-files/mys ...

  10. 感受身边app

    第一款:高考小秘书.http://www.liqucn.com/rj/519571.shtml.下载链接.我认为产品最大的优势在于对高考生非常有利,实用价值大,对于每年的高考生来说,高考资讯和大学资讯 ...