使用 finditem() 和 getitems() 获取 EWS 约会
本文关键字:EWS 约会 获取 finditem 使用 getitems | 更新日期: 2023-09-27 18:31:19
我正在使用finditem()和getitems()来返回日历项类型和加载的属性。此调用是在用户提交约会后正好 10 秒进行的,我可以确认我收到了来自聊天室或资源的接受,就像提交后的一秒钟一样。由于我的网站流量很大,我需要在创建后立即检查约会以获得房间的接受或拒绝,这会阻止同时预订。我拼凑了下面的方法来返回与会者响应,以便我可以在确认时传递真或假。当我运行此方法时,它会列出很多约会,但永远不会列出我刚刚创建的约会。
请记住,我立即从房间收到接受,我只是无法进入日历项类型(约会)以编程方式获取接受。
- 我是否需要调整我的查找项搜索,以便我可以返回我的日历项类型(约会)?
- 同步是我需要考虑的事情吗?
我在我的属性中看到手头项目的与会者,它只是不是正确的项目。
这是我所说的方法:
public static ResponseInfo GetCalendarEvents(ExchangeServiceBinding esb, DateTime starttime, Reservation res, Patron pat)
{
var startts = new TimeSpan(0, 0, 0, 0);
var endts = new TimeSpan(0, 23, 59, 0);
var endtime = new DateTime();
//set timespan of date to beginning of dayy
starttime = starttime.Date + startts;
endtime = starttime.Date + endts;
// Form the FindItem request.
var findItemRequest = new FindItemType();
var ce = new ResponseInfo();
var calendarView = new CalendarViewType
{
StartDate = starttime,
EndDate = endtime,
MaxEntriesReturned = 100,
MaxEntriesReturnedSpecified = true
};
findItemRequest.Item = calendarView;
// Define which item properties are returned in the response.
var itemProperties = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.IdOnly };
// Define the traversal type.
findItemRequest.Traversal = ItemQueryTraversalType.Shallow;
// Use the Default shape for the response.
findItemRequest.ItemShape = itemProperties;
// Identify which folders to search to find items.
var folderIDArray = new DistinguishedFolderIdType[2];
folderIDArray[0] = new DistinguishedFolderIdType();
folderIDArray[0].Id = DistinguishedFolderIdNameType.calendar;
// Add folders to the request.
findItemRequest.ParentFolderIds = folderIDArray;
try
{
// Send the FindItem request and get the response.
var findItemResponse = esb.FindItem(findItemRequest);
// Next, enumerate through the Items returned by FindItem.
foreach (FindItemResponseMessageType responseMessage in findItemResponse.ResponseMessages.Items)
{
if (responseMessage.ResponseClass == ResponseClassType.Success)
{
var mailboxItems = (ArrayOfRealItemsType)responseMessage.RootFolder.Item;
for (int itemCount = 0; itemCount < mailboxItems.Items.Length; itemCount++)
{
var inboxItem = mailboxItems.Items[itemCount];
// Call GetItem on each ItemId to retrieve the
// item's Body property and any AttachmentIds.
// Form the GetItem request.
var getItemRequest = new GetItemType
{
ItemShape = new ItemResponseShapeType { BaseShape = DefaultShapeNamesType.AllProperties }
};
// AllProperties on a GetItem
getItemRequest.ItemIds = new ItemIdType[1];
getItemRequest.ItemIds[0] = inboxItem.ItemId;
var getItemResponse = esb.GetItem(getItemRequest);
// We only passed in one ItemId to the GetItem
// request. Therefore, we can assume that
// we got at most one Item back.
var getItemResponseMessage = getItemResponse.ResponseMessages.Items[0] as ItemInfoResponseMessageType;
if (getItemResponseMessage != null)
{
if (getItemResponseMessage.ResponseClass == ResponseClassType.Success && getItemResponseMessage.Items.Items != null && getItemResponseMessage.Items.Items.Length > 0)
{
inboxItem = getItemResponseMessage.Items.Items[0];
var e = (CalendarItemType)inboxItem;
if (e.Start == res.Start && e.End == res.End)
{
foreach (AttendeeType at in e.RequiredAttendees)
{
//attendee must accept meeting & attendee email must match email in reservation
if (at.ResponseType == ResponseTypeType.Accept && at.Mailbox.EmailAddress == res.EmailAddress)
{
ce.Mailbox = at.Mailbox.EmailAddress;
ce.ApptStart = e.Start;
ce.ApptEnd = e.Start;
ce.ApptResponse = ResponseTypeType.Accept;
return ce;
}
}
}
}
else
{
ce.Mailbox = "getItemResponseMessage.ResponseClass";
return ce;
}
}
else
{
ce.Mailbox = "getItemResponseMessage is null";
return ce;
}
}
}
else
{
ce.Mailbox = "findItemResponseMessage is null";
return ce;
}
}
}
catch (ServiceRequestException ex)
{
Logger.LogStringError("****Error****: GetCalendarEvents()...ServiceRequestException= " + ex);
}
catch (WebException ex)
{
Logger.LogStringError("****Error****: GetCalendarEvents()...WebException= " + ex);
}
catch (Exception ex)
{
Logger.LogStringError("****Error****: GetCalendarEvents()...Exception= " + ex);
}
return ce;
}
更新:我的物品一直在系统中,但由于这些原因我找不到它......
-
Exchange 以 UTC 格式存储时间,因此如果我将窗口留为一天(即上午 12 点 - 晚上 11:59),并且我正在寻找晚上 9 点到 11 点之间的约会,finditem() 不会抓住约会,因为它被定义为交换的 UTC 时间(在我的情况下,UTC 时间提前 5 小时,所以约会被存储为凌晨 2-4 点)。确保你的窗口足够大,以处理UTC时间的差异......
var calendarView = new CalendarViewType { StartDate = DateTime.Now.AddDays(-1), EndDate = DateTime.Now.AddDays(1), MaxEntriesReturned = 100, MaxEntriesReturnedSpecified = true };
-
确保在比较项目的属性时间时,将时间转换为本地时间()...
if (e.Start.ToLocalTime() == res.Start && e.End.ToLocalTime() == res.End) { foreach (AttendeeType at in e.RequiredAttendees) { //attendee must accept meeting & attendee email must match email in reservation if (at.ResponseType == ResponseTypeType.Accept && at.Mailbox.EmailAddress == res.EmailAddress) { ce.Mailbox = at.Mailbox.EmailAddress; ce.ApptStart = e.Start; ce.ApptEnd = e.Start; ce.ApptResponse = ResponseTypeType.Accept; calevents.Add(ce); } } }