如何在“挂起”状态下显示Lync对话窗口?

时间:2011-10-26 16:29:51

标签: c# lync

这看起来很基本,但我在网上找不到如何做到这一点。

我有以下代码:

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
    }
}

1 个答案:

答案 0 :(得分: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);

我希望这有助于你