Escribí un servicio que sincroniza las citas de calendario EWS con una tabla Sql.
Para eliminar después de Insertar/Actualizar cambios si hay una fila en la base de datos y no en EWS, la eliminaré, ya que esto significa que fue eliminada en Exchange. Uso GUID para rastrear la cita en la base de datos y el intercambio. Exchange web services: why is ItemId not constant? [continued]
El rendimiento es aceptable, con tan solo un par de docenas de citas, lo probaré en un conjunto de datos mucho más grande.
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
Gracias por la respuesta, yo estaba realmente perdieron allí :-D – markus
Otra opción es comparar los datos cita que tiene sobre lo que ha de cambio y eliminar filas que no existen en el sistema de alerta temprana. Sin embargo, el rendimiento es horrible por eso. – Brent