这是我需要做的:
我需要构建一个控制台应用程序,用于登录(不使用当前用户或 lync 会话)到 Lync Server 并向特定联系人 (userUri) 发送消息。就这些。
但是,每次我使用Microsoft.Lync.Model.LyncClient.GetClient()
时,它似乎都会返回当前会话。我已经能够发送消息,所以唯一的问题是在不使用当前用户/会话的情况下登录。
如何设置一个新的?
我注意到的另一件奇怪的事情是:我提到我能够通过控制台应用程序在当前会话中发送一条消息(一条消息发送给我的一位同事并显示)。但是,当我得到SignInConfiguration
fromLyncClient.SignInConfiguration
时,当我假设它应该显示我的用户名/userAndDomain 时,UserName 属性是空白的。
下面的代码:
lyncClient = Microsoft.Lync.Model.LyncClient.GetClient();
if (lyncClient == null)
{
Console.WriteLine("Unable to obtain client interface");
}
if (lyncClient.InSuppressedMode == true)
{
Console.WriteLine("Lync is uninitialized");
}
if (lyncClient.State == ClientState.SignedIn)
{
Console.WriteLine("Lync is signed in");
}
else
{
Console.WriteLine("Lync is NOT signed in");
}
SignInConfiguration config = lyncClient.SignInConfiguration;
internalUrl = config.InternalServerUrl;
externalUrl = config.ExternalServerUrl;
signedInFromIntranet = config.SignedInFromIntranet.ToString();
signedInAvailability = config.SignInAsAvailability.ToString();
signedInAutoRetry = config.SignInAutoRetry.ToString();
signedInUser = config.UserName;
Console.WriteLine("Internal Url: " + internalUrl);
Console.WriteLine("External Url: " + externalUrl);
Console.WriteLine("Signed-in from Intranet: " + signedInFromIntranet);
Console.WriteLine("Signed-in as availability: " + signedInAvailability);
Console.WriteLine("Signed-in as auto-retry: " + signedInAutoRetry);
Console.WriteLine("Signed-in User: " + signedInUser);
conversation = lyncClient.ConversationManager.AddConversation();
conversation.AddParticipant(lyncClient.ContactManager.GetContactByUri(recipientUri));
if (((Microsoft.Lync.Model.Conversation.InstantMessageModality)conversation.Modalities[Microsoft.Lync.Model.Conversation.ModalityTypes.InstantMessage]).CanInvoke(Microsoft.Lync.Model.Conversation.ModalityAction.SendInstantMessage))
{
((Microsoft.Lync.Model.Conversation.InstantMessageModality)conversation.Modalities[Microsoft.Lync.Model.Conversation.ModalityTypes.InstantMessage]).BeginSendMessage(
message,
null,
null
);
}