C# _i联系人和组scallback.OnLookUp

C# _i联系人和组scallback.OnLookUp,c#,office-interop,C#,Office Interop,我想为办公室提供即时通讯等服务,请遵循来自的指南 回应 IContactManager.Lookup(string _lookupString, object _contactsAndGroupsCallback = null, object _state = Type.Missing) 我需要打电话 Microsoft.Office.Uc._IContactsAndGroupsCallback.OnLookup(ContactManager _source, object _lookupRe

我想为办公室提供即时通讯等服务,请遵循来自的指南

回应

IContactManager.Lookup(string _lookupString, object _contactsAndGroupsCallback = null, object _state = Type.Missing)
我需要打电话

Microsoft.Office.Uc._IContactsAndGroupsCallback.OnLookup(ContactManager _source, object _lookupResult, AsynchronousOperation _asyncOperation);
第二个参数没有很好的记录:

当Office无法确定联系人的SIP地址时,它会调用 使用IM查找SIP的IContactManager.Lookup方法 服务在这里,Office传递它能为客户找到的最佳数据 联系人(例如,仅联系人的电子邮件地址)。这个 查找方法异步返回AsynchronousOperation对象。 当它调用回调时,Lookup方法应该返回 操作的成功或失败,以及 联系方式

我尝试将不同的结果作为lookupResult(uri字符串、.NET uri对象、联系人对象)传递,但没有成功


所需的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("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);
  }
}
[ComImport,Guid(MyImApp.ClassId)]
公共类MyImApp
{
内部常量字符串ClassId=“”;
}
公共类MyContactAndGroupsCallback:\u i ContactAndGroupScallBack
{
ADDCustomGroup上的公共无效(ContactManager\u源,异步操作\u异步操作)
{
}
ADDDDistributionGroup上的公共无效(ContactManager\u源,异步操作\u异步操作)
{
}
public void OnLookup(ContactManager\u source、object\u lookupResult、AsynchronousOperation\u AsynchronousOperation)
{
}
从所有组移除ContactManager时的公共无效(ContactManager\u源,异步操作\u异步操作)
{
}
公用void OnRemoveGroup(ContactManager\u源,异步操作\u异步操作)
{
}
public void OnSearch(ContactManager\u源、SearchResults\u SearchResults、AsynchronousOperation\u AsynchronousOperation)
{
}
}
班级计划
{
静态bool cancelPressed=false;
静态MyContactAndGroupsCallback myContactsAndGroupsCallback=新MyContactAndGroupsCallback();
静态void Main(字符串[]参数)
{
MyImApp imApp=新的MyImApp();
if(imApp==null)返回;
UCOfficeIntegration officeIntegration=(UCOfficeIntegration)imApp;
if(officeIntegration==null)返回;
officeIntegration.OnShuttingDown+=officeIntegration\u OnShuttingDown;
字符串officeVersion=“15.0.0.0”;
字符串authInfo=officeIntegration.GetAuthenticationInfo(officeVersion);
OIFeature supportedFeatures=officeIntegration.GetSupportedFeatures(officeVersion);//skype报告:-122
LyncClient LyncClient=(LyncClient)officeIntegration.GetInterface(officeVersion,OIInterface.OIInterfaceLyncClient);
if(lyncClient==null)返回;
stringuri=lyncClient.uri;
IAutomation automation=(IAutomation)officeIntegration.GetInterface(officeVersion,OIInterface.oiinterfaceeiautomation);
//LyncClientCapabilityTypes capabilities=lyncClient.capabilities;//skype:未实现
lyncClient.OnStateChanged+=lyncClient\u OnStateChanged;
ContactManager ContactManager=lyncClient.ContactManager;
if(contactManager==null)返回;
AsynchronousOperation async=contactManager.Lookup(“test@test.com,MyContacts和GroupScallBack,类型。缺少);
Contact=contactManager.GetContactByUri(“test@test.com");
如果(联系人!=null)
{
动态结果=contact.GetContactInformation(ContactInformationType.ucPresenceInstantMessageAddresss);
ContactSettingDictionary设置=contact.settings;
ContactSetting[]键=设置。键;
如果(键!=null)
{
foreach(触点设置键入键)
{
对象值=空;
设置.TryGetValue(键,输出值);
}
}
}
Console.CancelKeyPress+=Console\u CancelKeyPress;
Console.WriteLine(“按Ctrl-C退出”);
做
{
系统线程线程睡眠(1000);
}同时(!取消按下);
}
静态无效officeIntegration_OnShuttingDown()
{
Console.WriteLine(“IM应用程序正在关闭”);
}
静态无效contactManager_OnSearchProviderStateChanged(contactManager_eventSource,SearchProviderStateChangedEventData_eventData)
{
}
静态无效控制台\u取消按键(对象发送器、控制台取消按钮)
{
cancelPressed=true;
}
静态无效Lync客户端\u OnStateChanged(客户端\u事件源、客户端状态更改DeventData \u事件数据)
{
WriteLine(“状态已更改:{0}->{1},{2}”,_eventData.OldState,_eventData.NewState,_eventData.StatusCode);
}
}

您能让集成正常工作吗?我在OnContactInformation Changed事件中遇到问题。触发事件后,Outlook
GetContactInformation
使用
UCPresenceInstantMessageAddresss
而不是
ucPresenceAvailability
。并且状态显示没有更新。我也面临这个问题,这意味着使用UCPresenceInstantMessageAddresss触发Outlook GetContactInformation事件。请让我知道是否有人修复了它?我使用的是与您在这里给出的相同的模拟。IM客户端到模拟应用程序的所有事件都工作正常。但这些都不适用于Outlook 2013。你能帮我解决这个问题吗?事件:OnStateChanged、OnContactInformation Changed等。