Tôi đã viết một dịch vụ đồng bộ các cuộc hẹn lịch EWS với bảng Sql.
Để xóa sau khi chèn/cập nhật thay đổi nếu có hàng trong cơ sở dữ liệu và không phải trong EWS tôi sẽ xóa nó, điều này có nghĩa là nó đã bị xóa trong Exchange. Tôi sử dụng GUID để theo dõi cuộc hẹn trong cơ sở dữ liệu và trao đổi. Exchange web services: why is ItemId not constant? [continued]
Hiệu suất là phong nha chỉ với vài chục cuộc hẹn, tôi sẽ thử nó trên tập dữ liệu lớn hơn nhiều.
Dim appointmentGuid As New List(Of String)
For Each appointment In appointments 'appointments is IEnumerable(Of Appointment) from EWS
Dim guid As String = GetGuidForAppointment(appointment)
If String.IsNullOrEmpty(guid) Then
SetGuidForAppointment(appointment)
guid = GetGuidForAppointment(appointment)
End If
appointmentGuid.Add(guid)
'Upsert rows
...
Next
'Delete orphaned rows
Using sqlConnection As New SqlConnection(ConnectionString)
Dim deleteScript As New StringBuilder()
Using sqlCmd As New SqlCommand("SELECT ID FROM Appointments", sqlConnection)
Using sqlDataReader As SqlDataReader = sqlCmd.ExecuteReader()
sqlConnection.Open()
While sqlDataReader.Read()
Dim guid As String = sqlDataReader.GetString(0)
If Not appointmentGuid.Contains(guid) Then
deleteScript.AppendFormat("DELETE FROM Appointments WHERE ID = '{0}'; ", guid)
End If
End While
End Using
End Using
If deleteScript.Length > 0 Then
Using sqlCmd As New SqlCommand(deleteScript.ToString(), sqlConnection)
sqlCmd.ExecuteNonQuery()
End Using
End If
End Using
Cảm ơn câu trả lời, tôi đã thực sự bị mất ở đó: -D – markus
Một tùy chọn khác là so sánh dữ liệu cuộc hẹn bạn có và trao đổi hàng không tồn tại trong EWS. Hiệu suất là khủng khiếp cho rằng mặc dù. – Brent