托管Exchange Web服务,获取已删除的约会

时间:2011-09-14 14:48:47

标签: exchangewebservices exchange-server-2007 ews-managed-api

我即将编写一个ews应用程序来连接与另一个日历程序的交换。发生了什么,我怎么知道,哪些约会在交换中被删除?有办法告诉吗?我在API和文档中找不到它。

提前致谢。

2 个答案:

答案 0 :(得分:6)

根据用户删除约会(或任何项目)的方式,可以执行不同的操作:

  • 软删除:项目被移动到邮箱的回收站。
  • 硬删除:该项目会立即删除。

您有多种方法可以获取有关已删除项目的信息:

  • 使用FindItems调用查询文件夹,并在ItemView的Traversal属性中选择ItemTraversal.Associated。注意:这需要Exchange 2010。
  • 一次使用SyncFolderItems并将同步cookie存储在某处。稍后,使用先前存储的cookie再次执行SyncFolderItems。 Exchange现在将为您提供文件夹中发生的更改的详细列表。
  • 查询回收站以了解约会。它们很可能来自用户的默认日历。

答案 1 :(得分:0)

我编写了一个将EWS日历约会同步到Sql表的服务。

如果在插入/更新更改后删除,如果数据库中有行而不是EWS中的行,我将删除它,因为这意味着它已在Exchange中删除。我使用GUID跟踪数据库和交换中的约会。 Exchange web services: why is ItemId not constant? [continued]

只有几十个约会,性能很不错,我会在更大的数据集上尝试。

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
相关问题