我正在使用 finditem() 和 getitems() 来返回 calendaritemtype 和加载的属性。这个电话是在用户提交约会后正好 10 秒发出的,我可以确认我在提交后一秒钟收到了来自房间或资源的接受。由于我网站上的高流量,我需要在创建后立即检查约会以获得房间的接受或拒绝,这可以防止同时预订。我拼凑了下面的方法来返回与会者的响应,这样我就可以在确认时传递真假。当我运行此方法时,它列出了很多约会,但从来没有我刚刚创建的约会。
请记住,我立即从房间收到 ACCEPT,我只是无法进入 calendaritemtype(约会)以编程方式获得 ACCEPT。
- 我是否需要调整我的 findItem 搜索以便返回我的 calendaritemtype(约会)?
- 我需要考虑同步吗?
我在我的属性中看到手头项目的参加者,它只是不正确的项目。
这是我所说的方法:
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;
}