1

这似乎很基本,但我在网上找不到如何做到这一点。

我有以下代码:

public static void StartChatWithUser(Microsoft.Lync.Model.Contact imContact, string title = null)
{
    try
    {
        var lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();

        var conversation = lyncClient.ConversationManager.AddConversation();
        conversation.AddParticipant(imContact);
        if (!string.IsNullOrEmpty(title))
        {
            conversation.Properties[Microsoft.Lync.Model.Conversation.ConversationProperty.Subject] = title;
        }
        var im = conversation.Modalities[Microsoft.Lync.Model.Conversation.ModalityTypes.InstantMessage];
        if (im.CanInvoke(Microsoft.Lync.Model.Conversation.ModalityAction.Connect))
        {
            im.BeginConnect((ar) => { if (ar.IsCompleted) { ((Microsoft.Lync.Model.Conversation.InstantMessageModality)ar.AsyncState).EndConnect(ar); } }, im);
        }
    }
    catch( Exception x )
    {
        //Handle exception
    }
}

这种“某种”有效,因为它打开了联系人窗口并开始聊天——这意味着对方被要求加入聊天。

有没有办法让我在不启动与其他用户聊天的情况下打开对话窗口(我希望它与双击 Lync 联系人列表中的用户时一样)。

在 Lync Client Dev 上发布了相同的问题。TechNet 论坛: http: //lksz.me/s8Yn8a

提前致谢。


我的最终结果

感谢 MOHAMED A. SAKAR 和 ckeller 提供的答案,我修复了我的代码,这是我的新方法。多谢你们

需要以下 using 子句:

using Microsoft.Lync.Model.Extensibility;

这是新代码:

public static void StartChatWithUser(Microsoft.Lync.Model.Contact imContact, string title = null)
{
    try
    {
        var lyncAutomation = Microsoft.Lync.Model.LyncClient.GetAutomation();

        var inviteeList = new string[] { imContact.Uri };
        var modalitySettings = new Dictionary<AutomationModalitySettings, object>();
        modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, false);
        if (string.IsNullOrEmpty(title))
        {
            modalitySettings.Add(AutomationModalitySettings.Subject, title);
        }

        lyncAutomation.BeginStartConversation(
            AutomationModalities.InstantMessage,
            inviteeList,
            modalitySettings,
            (ar) => { if (ar.IsCompleted) { ((Automation)ar.AsyncState).EndStartConversation(ar); }},
            lyncAutomation);
    }
    catch( Exception x )
    {
        //Handle exception
    }
}
4

1 回答 1

1

您应该首先创建 AutomationModalitySettings 及其值的字典:

private Dictionary<AutomationModalitySettings, object> _modalitySettings;

之后,您应该启动这些模式:

_modalitySettings = new Dictionary<AutomationModalitySettings, object>();
_modalitySettings.Add(AutomationModalitySettings.SendFirstInstantMessageImmediately, false);

之后你可以发起通话

_asyncResult = _automation.BeginStartConversation(
             _chosenMode,
             _inviteeList,
             _modalitySettings,
             null,
             null);

我希望这可以帮助你

于 2011-10-30T08:44:18.000 回答