c# lynclient:获取Lync用户的状态信息
本文关键字:状态 信息 用户 Lync lynclient 获取 | 更新日期: 2023-09-27 18:07:15
我是c#新手;我有一个困难的时间找出什么是错误的在以下代码:
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Microsoft.Lync.Model;
namespace test3
{
class Program
{
static void Main(string[] args)
{
LyncClient lyncClient;
try
{
lyncClient = LyncClient.GetClient();
}
catch (ClientNotFoundException clientNotFoundException)
{
Console.WriteLine(clientNotFoundException);
return;
}
catch (NotStartedByUserException notStartedByUserException)
{
Console.Out.WriteLine(notStartedByUserException);
return;
}
catch (LyncClientException lyncClientException)
{
Console.Out.WriteLine(lyncClientException);
return;
}
catch (SystemException systemException)
{
if (IsLyncException(systemException))
{
// Log the exception thrown by the Lync Model API.
Console.WriteLine("Error: " + systemException);
return;
}
else
{
// Rethrow the SystemException which did not come from the Lync Model API.
throw;
}
}
Console.WriteLine("LYNC CLIENT STATE: ", lyncClient.State);
// GET AVAILABILITY
ContactAvailability currentAvailability = 0;
try
{
currentAvailability = (ContactAvailability)
lyncClient.Self.Contact.GetContactInformation(ContactInformationType.Availability);
Console.WriteLine("***********Console.WriteLine(currentAvailability)*********");
// https://code.msdn.microsoft.com/lync/Lync-2013-Use-the-Lync-47ded7b4
// https://msdn.microsoft.com/en-us/library/office/jj933083.aspx
// https://msdn.microsoft.com/en-us/library/office/jj933159.aspx
lyncClient.ContactManager.BeginSearch(
"Humpty,Dumpty",
(ar) =>
{
SearchResults searchResults = lyncClient.ContactManager.EndSearch(ar);
if (searchResults.Contacts.Count > 0)
{
Console.WriteLine(
searchResults.Contacts.Count.ToString() +
" found");
foreach (Contact contact in searchResults.Contacts)
{
Console.WriteLine(
contact.GetContactInformation(ContactInformationType.DisplayName).ToString());
currentAvailability = (ContactAvailability)
contact.GetContactInformation(ContactInformationType.Availability);
Console.WriteLine(currentAvailability);
}
}
},
null);
Console.WriteLine(ContactInformationType.Availability);
Console.WriteLine(lyncClient.Self.ToString());
}
catch (LyncClientException e)
{
Console.WriteLine(e);
}
catch (SystemException systemException)
{
if (IsLyncException(systemException))
{
// Log the exception thrown by the Lync Model API.
Console.WriteLine("Error: " + systemException);
}
else
{
// Rethrow the SystemException which did not come from the Lync Model API.
throw;
}
}
}
static private bool IsLyncException(SystemException ex)
{
return
ex is NotImplementedException ||
ex is ArgumentException ||
ex is NullReferenceException ||
ex is NotSupportedException ||
ex is ArgumentOutOfRangeException ||
ex is IndexOutOfRangeException ||
ex is InvalidOperationException ||
ex is TypeLoadException ||
ex is TypeInitializationException ||
ex is InvalidComObjectException ||
ex is InvalidCastException;
}
}
}
我在输出日志中看到以下内容:
The thread 0x32d4 has exited with code 259 (0x103).
The thread 0x31ec has exited with code 259 (0x103).
The thread 0x28d0 has exited with code 259 (0x103).
'test3.vshost.exe' (CLR v4.0.30319: test3.vshost.exe): Loaded 'c:'users'sw029693'documents'visual studio 2013'Projects'test3'test3'bin'Debug'test3.exe'. Symbols loaded.
'test3.vshost.exe' (CLR v4.0.30319: test3.vshost.exe): Loaded 'c:'users'sw029693'documents'visual studio 2013'Projects'test3'test3'bin'Debug'Microsoft.Lync.Model.dll'. Cannot find or open the PDB file.
Step into: Stepping over non-user code 'test3.Program.<>c__DisplayClass2..ctor'
'test3.vshost.exe' (CLR v4.0.30319: test3.vshost.exe): Loaded 'C:'windows'Microsoft.Net'assembly'GAC_MSIL'Accessibility'v4.0_4.0.0.0__b03f5f7f11d50a3a'Accessibility.dll'. Cannot find or open the PDB file.
A first chance exception of type 'System.TypeInitializationException' occurred in test3.exe
The thread 0xcd8 has exited with code 259 (0x103).
The thread 0x3580 has exited with code 259 (0x103).
The program '[9700] test3.vshost.exe' has exited with code 0 (0x0).
这似乎在以下代码中被打破了:
lyncClient = LyncClient.GetClient();
以下是我的参考文献:
项目引用任何想法吗?
上面的代码不能工作是修改版本的代码张贴在这里:https://code.msdn.microsoft.com/lync/Lync-2013-Use-the-Lync-47ded7b4
链接中的代码可以工作。我无法解读我的版本中缺少了什么。请帮助!
可以是很多不同的东西。TypeInitializationException发生在静态构造函数或类型的静态成员抛出异常时。
这将在LyncClient. getclient()上发生是有意义的,因为这是为LyncClient运行静态构造函数(或初始化静态成员)的第一个点。
不幸的是,TypeInitializationException本身并不能告诉我们太多信息。如果要打印异常消息,您将看到有关失败类型的泛型信息,但除此之外不一定有任何有用的信息。我要做的是在那行代码上设置一个断点。点击后,逐级执行,将在Visual Studio中打开一个Exception对话框。查看异常详细信息,展开"InnerException"。这将包含抛出的实际异常(我打赌它将是与项目中的引用相关的异常)。这个InnerException可以有自己的InnerException。把它们都找出来,把文字记录在记事本上,谷歌搜索一下可能会帮助你找到罪魁祸首。或者更新你的问题,我会看看我是否能给你一个更好的答案与提供额外的上下文。
祝你好运!