_IContactsAndGroupsCallback.OnLookUp

我想按照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对象。 当它调用回调时,除了联系人的URI之外,Lookup方法还应该返回操作的成功或失败。

我尝试了不同的结果作为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 = ""; } 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("test@test.com", myContactsAndGroupsCallback, Type.Missing); Contact contact = contactManager.GetContactByUri("test@test.com"); 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); } }