使用 Microsoft.Office.Interop.Outlook 查找所有可用的会议室

Find All Available Meeting Rooms using Microsoft.Office.Interop.Outlook

我正在开发一个应用程序,我想从 outlook 通讯录的 "All Rooms" 中检索可用房间。我能够从 "All Rooms" 地址条目列表中检索所有房间条目。然后可以通过调用 AddressEntry.GetFreeBusy() 来搜索单个房间的可用性。 但我面临的问题是代码的时间性能。如果房间数量很多(比如 500 个),那么搜索房间可用性的时间(最坏情况下可用房间位于列表的最后一个附近)会非常长。

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application()
var allRooms = app.Session.AddressLists["All Rooms"].Cast<Microsoft.Office.Interop.Outlook.AddressEntry>().ToLis();
DateTime today = DateTime.Today;
foreach(var room in allRooms)
{
    //the below function will return the room status in a string of 1&0 for an interval of 1 min
    string status = room.GetFreeBusy(today, 1, true); //sequentially calling this method is costly. What improvement can I do here?
    //process the status and make some if free for certain time period add to list of available list
}

GetFreeBusy method accepts three parameters and the default value for the MinPerChar parameter is 30 minutes. But your code only checks the first minute of the appointment. You need to go over the whole duration of your meeting (at least 30 minutes). Take a look at the similar 论坛帖子。

如果您是 .Net 开发人员,请为此使用 Microsoft Graph API。我用了

POST /me/calendar/getSchedule POST/users/{id|userPrincipalName}/calendar/getSchedule

从实现这个。您可以作为您的用户 ID 登录并使用 ME 选项,或者您可以使用应用程序模式登录登录并使用 {id|userPrincipalName} 获取房间的日历详细信息。

此 link 提供了有关如何登录的基础知识,并提供了一般 Graph 的良好示例。

https://developer.microsoft.com/en-us/graph/graph-explorer

参考: https://docs.microsoft.com/en-us/graph/api/calendar-getschedule?view=graph-rest-1.0&tabs=http