gpt4 book ai didi

c# - _IContsAndGroupsCallback.OnLookUp

转载 作者:行者123 更新时间:2023-11-30 23:33:40 27 4
gpt4 key购买 nike

我想按照 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);

第二个参数没有很好的记录:

When Office cannot determine the SIP address for the contact, it calls the IContactManager.Lookup method to find the SIP by using the IM service. Here Office passes in the best data that it can find for the contact (for example, just the email address for the contact). The Lookup method asynchronously returns an AsynchronousOperation object. When it invokes the callback, the Lookup method should return the success or failure of the operation in addition to the URI of the contact.

我尝试将不同的结果作为 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 mock 并调用您自己的 IM 应用程序接口(interface)。这将有助于发现事件处理等方面的任何问题。

[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);
}
}

关于c# - _IContsAndGroupsCallback.OnLookUp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33830124/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com