我想按照 http://msdn.microsoft.com/en-US/library/office/jj900715.aspx#off15_IMIntegration_ImplementRequired_ILyncClient 的指南为 Office 提供 IM 状态等。
回应
IContactManager.Lookup(string _lookupString, object _contactsAndGroupsCallback = null, object _state = Type.Missing)
我需要打电话
Microsoft.Office.Uc._IContactsAndGroupsCallback.OnLookup(ContactManager _source, object _lookupResult, AsynchronousOperation _asyncOperation);
第二个参数没有很好的记录:
当 Office 无法确定联系人的 SIP 地址时,它会调用 IContactManager.Lookup 方法使用 IM 查找 SIP 服务。 Office 在此传递它可以找到的最佳数据 联系人(例如,仅联系人的电子邮件地址)。这 Lookup 方法异步返回一个 AsynchronousOperation 对象。 当调用回调时,Lookup 方法应返回 除了 URI 之外,还显示操作的成功或失败 联系方式。
我尝试了不同的方式传递不同的结果作为lookupResult(uri字符串,.NET Uri对象,Contact对象),但没有成功。
所需的lookupResult类型是什么?
终于可以解决这个问题了。参数为:
[ClassInterface(ClassInterfaceType.None)]
[ComSourceInterfaces(typeof(_IContactManagerEvents))]
[ComVisible(true)]
public class MyContactManager : ContactManager
{
// Additional implementation details omitted.
}
[ClassInterface(ClassInterfaceType.None)]
[ComVisible(true)]
[ComSourceInterfaces(typeof(_IContactEvents))]
public class MyOfficeContact : Contact
{
// Additional implementation details omitted.
}
[ComVisible(true)]
[ClassInterface(ClassInterfaceType.None)]
public class MyAsyncOperation : AsynchronousOperation
{
// Additional implementation details omitted.
}
提示:当您的 IM 应用程序与 Office 集成时,您应该实现一个简单的 Office 模拟并调用您自己的 IM 应用程序接口。这将有助于发现事件处理等方面的任何问题。
[ComImport, Guid(MyImApp.ClassId)]
public class MyImApp
{
internal const string ClassId = "<your guid>";
}
public class MyContactAndGroupsCallback : _IContactsAndGroupsCallback
{
public void OnAddCustomGroup(ContactManager _source, AsynchronousOperation _asyncOperation)
{
}
public void OnAddDistributionGroup(ContactManager _source, AsynchronousOperation _asyncOperation)
{
}
public void OnLookup(ContactManager _source, object _lookupResult, AsynchronousOperation _asyncOperation)
{
}
public void OnRemoveContactFromAllGroups(ContactManager _source, AsynchronousOperation _asyncOperation)
{
}
public void OnRemoveGroup(ContactManager _source, AsynchronousOperation _asyncOperation)
{
}
public void OnSearch(ContactManager _source, SearchResults _searchResults, AsynchronousOperation _asyncOperation)
{
}
}
class Program
{
static bool cancelPressed = false;
static MyContactAndGroupsCallback myContactsAndGroupsCallback = new MyContactAndGroupsCallback();
static void Main(string[] args)
{
MyImApp imApp = new MyImApp();
if (imApp == null) return;
UCOfficeIntegration officeIntegration = (UCOfficeIntegration)imApp;
if (officeIntegration == null) return;
officeIntegration.OnShuttingDown += officeIntegration_OnShuttingDown;
string officeVersion = "15.0.0.0";
string authInfo = officeIntegration.GetAuthenticationInfo(officeVersion);
OIFeature supportedFeatures = officeIntegration.GetSupportedFeatures(officeVersion); //skype reports: -122
LyncClient lyncClient = (LyncClient)officeIntegration.GetInterface(officeVersion, OIInterface.oiInterfaceILyncClient);
if (lyncClient == null) return;
string uri = lyncClient.Uri;
IAutomation automation = (IAutomation)officeIntegration.GetInterface(officeVersion, OIInterface.oiInterfaceIAutomation);
//LyncClientCapabilityTypes capabilities = lyncClient.Capabilities; //skype: Not implemented
lyncClient.OnStateChanged += lyncClient_OnStateChanged;
ContactManager contactManager = lyncClient.ContactManager;
if (contactManager == null) return;
AsynchronousOperation async = contactManager.Lookup("[email protected]", myContactsAndGroupsCallback, Type.Missing);
Contact contact = contactManager.GetContactByUri("[email protected]");
if (contact != null)
{
dynamic result = contact.GetContactInformation(ContactInformationType.ucPresenceInstantMessageAddresses);
ContactSettingDictionary settings = contact.Settings;
ContactSetting[] keys = settings.Keys;
if (keys != null)
{
foreach (ContactSetting key in keys)
{
object value = null;
settings.TryGetValue(key, out value);
}
}
}
Console.CancelKeyPress += Console_CancelKeyPress;
Console.WriteLine("Press Ctrl-C for exit");
do
{
System.Threading.Thread.Sleep(1000);
} while (!cancelPressed);
}
static void officeIntegration_OnShuttingDown()
{
Console.WriteLine("IM Application is shutting down");
}
static void contactManager_OnSearchProviderStateChanged(ContactManager _eventSource, SearchProviderStateChangedEventData _eventData)
{
}
static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
{
cancelPressed = true;
}
static void lyncClient_OnStateChanged(Client _eventSource, ClientStateChangedEventData _eventData)
{
Console.WriteLine("Status changed: {0} -> {1}, {2}", _eventData.OldState, _eventData.NewState, _eventData.StatusCode);
}
}
知道为什么
IContact.CanStart
没有被 Outlook 呼叫吗?
除了音频/视频/聊天按钮呈灰色之外,状态效果良好。
我在 IContact 中明确定义了
CanStart
API,但 Outlook 从未调用它。
提前致谢!