我使用ExchangeService(ExchangeVersion.Exchange2010_SP1)如何接受和使用Exchange Web服務
我想接受並添加分類來RequiredAttendees約會添加類別到RequiredAttendees約會。要做到這一點,我需要找到這些約會。
我在EWS的理解是,對具有新的會議請求爲每個「要求與會者」創建RequiredAttendees預約的保存。
如何我可以訪問了爲'要求與會者的自動創建的約會?這些顯示在所需的與會者日曆作爲約會,以及會議請求。
我已經成功地做到粗找到主題(下面的步驟)
- 連接到服務器作爲組織者
- 創建約會
- 集主題
- 添加必需的與會者
保存預約
連接到服務器的熱曲從步驟IRED與會者4
有主題在步驟3
- 到預約步驟在步驟7
- 添加類別7
- 更新預約接受步驟約會
- 查找預約7
而且這確實有用,但有關用戶會改變主題。
我已經嘗試添加擴展屬性和價值的組織者,然後FindItems在連接作爲必需與會者的約會擴展屬性值創建的約會。這不起作用。
是否有什麼,我試圖完成一個優選的方法是什麼?
謝謝
Private Shared ReadOnly m_organiserEmailAddress As String = "[email protected]"
Private Shared ReadOnly m_eventIdExtendedPropertyDefinition As New ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, "EventId", MapiPropertyType.Long)
'--> start here
Public Shared Function SaveToOutlookCalendar(eventCalendarItem As EventCalendarItem) As String
If eventCalendarItem.Id Is Nothing Then
'new
Dim newAppointment = EventCalendarItemMapper.SaveNewAppointment(eventCalendarItem)
'set the Id
eventCalendarItem.Id = newAppointment.Id.UniqueId.ToString()
'accept the calendar item on behalf of the Attendee
EventCalendarItemMapper.AcceptAppointmentAsAttendees(newAppointment)
Return eventCalendarItem.Id
Else
'update existing appointment
Return EventCalendarItemMapper.UpdateAppointment(eventCalendarItem)
End If
End Function
Private Shared Sub ConnectToServer(Optional autoUser As String = "")
If autoUser = "" Then
_service.Url = New Uri(ExchangeWebServicesUrl)
Else
_service.AutodiscoverUrl(autoUser)
End If
End Sub
Private Shared Sub ImpersonateUser(userEmail As String)
_service.Credentials = New NetworkCredential(ImpersonatorUsername, ImpersonatorPassword, Domain)
_service.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.SmtpAddress, userEmail)
End Sub
Private Shared Function SaveNewAppointment(eventCalendarItem As EventCalendarItem) As Appointment
Try
ConnectToServer(m_organiserEmailAddress)
ImpersonateUser(m_organiserEmailAddress)
Dim appointment As New Appointment(_service) With {
.Subject = eventCalendarItem.Subject}
'add attendees
For Each attendee In eventCalendarItem.Attendees
appointment.RequiredAttendees.Add(attendee.Email)
Next
'add categories
For Each category In eventCalendarItem.Categories
appointment.Categories.Add(Globals.GetEnumDescription(category))
Next
'add EventId = 5059 as an extended property of the appointment
appointment.SetExtendedProperty(m_eventIdExtendedPropertyDefinition, 5059)
appointment.Save(SendInvitationsMode.SendOnlyToAll)
Return appointment
Catch
Throw New Exception("Can't save appointment")
End Try
End Function
Private Shared Sub AcceptAppointmentAsAttendees(appointment As Appointment)
For Each attendee In appointment.RequiredAttendees
Try
ConnectToServer(attendee.Address.ToString())
ImpersonateUser(attendee.Address.ToString())
For Each a In FindRelatedAppiontments(appointment)
a.Categories.Add(Globals.GetEnumDescription(CalendarItemCategory.Workshop))
a.Update(ConflictResolutionMode.AlwaysOverwrite, SendInvitationsOrCancellationsMode.SendToNone)
a.Accept(True)
Next
Catch
Throw
End Try
Next
End Sub
Private Shared Function FindRelatedAppiontments(appointment As Appointment) As List(Of Appointment)
Dim view As New ItemView(1000)
Dim foundAppointments As New List(Of Appointment)
view.PropertySet =
New PropertySet(New PropertyDefinitionBase() {m_eventIdExtendedPropertyDefinition})
'Extended Property value = 5059
Dim searchFilter = New SearchFilter.IsEqualTo(m_eventIdExtendedPropertyDefinition, 5059)
For Each a In _service.FindItems(WellKnownFolderName.Calendar, searchFilter, view)
If a.ExtendedProperties.Count > 0 Then
foundAppointments.Add(appointment.Bind(_service, CType(a.Id, ItemId)))
End If
Next
Return foundAppointments
End Function
爲什麼擴展屬性不起作用?他們是否從組織者複製到與會者? – BraveHeart 2013-02-14 10:12:33
@BraveHeart不幸的是,如果在步驟6我連接到服務器作爲管理器,爲FindItems設置SearchFilter爲我的擴展屬性值返回Appointment。使用相同的代碼,但作爲必需參加者連接到服務器否返回約會。我已經在FindItems WellKnownFolderName.Inbox中爲會議請求嘗試了WellKnownFolderName.Calendar,並在Appointment中嘗試了這種方法。 – 2013-02-14 11:32:25
說實話,我不認爲我真的走了你的意思是100%,或者你爲什麼要這麼做。 也許如果你把你的一些代碼解釋爲你如何作爲組織者或與會者連接到服務器。你有兩個應用程序嗎? 我可能會建議您使用[流式通知](http://msdn.microsoft.com/zh-cn/library/exchange/hh312849(v = exchg.140).aspx),以便您可以檢測到達與會者的日曆。 – BraveHeart 2013-02-14 12:26:35