获取从 Exchange 传入 Outlook 的值

发布于 2024-08-22 22:29:07 字数 2966 浏览 5 评论 0原文

我编写了一个 VSTO 加载项,需要从交换服务器获取约会信息。

在交换 (Outlook Web Access) 中,我更改约会的主题行。当我看到 Outlook 将主题行更改为新值时,我尝试以编程方式获取新值,大多数时候它会获取旧值,而不是 Outlook 中出现的值。

我尝试处理 ItemChange 事件并使用 .save 函数保存项目,但似乎没有任何区别。

有谁知道为什么我不能在 Outlook 约会到达 Outlook 后立即以编程方式获取这些值?

现在可以使用的代码非常丑陋,但这是一项重大工作,如下所示:

Public _idOfAppointmentCurrentlySyncing As New List(Of String)
Public _idOfAppointmentCurrentlySyncingNormal As New List(Of String)

Private Sub appointmentSave(ByVal Item As Object) Handles _m_olAppointment.ItemChange, _m_olAppointment.ItemAdd
    Try
        Dim dateNow As Date = Date.Now
        If TypeOf Item Is Outlook.AppointmentItem Then
            If (dateNow - _lastFolderSwitch).TotalMilliseconds > 3000 Then
                Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
                Dim lastModifiedDates As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "lastModifiedDates")
                If _idOfAppointmentCurrentlySyncing.Contains(appointmentItem.EntryID) Then
                    Dim outlookLastSyncTime As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "OutlookLastSyncTime")
                    If outlookLastSyncTime <> Date.MaxValue And Date.Compare(lastModifiedDates, outlookLastSyncTime) <> 0 Then
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", outlookLastSyncTime)
                        appointmentItem.Save()
                    Else
                        _idOfAppointmentCurrentlySyncing.Remove(appointmentItem.EntryID)
                    End If
                Else
                    If _idOfAppointmentCurrentlySyncingNormal.Contains(appointmentItem.EntryID) = False Then
                        DebugWriter("Normal Save: " + appointmentItem.Start.ToString)
                        Try
                            If appointmentItem.Body <> "" Then
                                appointmentItem.Body += " "
                            End If
                        Catch ex As Exception
                        End Try
                        _idOfAppointmentCurrentlySyncingNormal.Add(appointmentItem.EntryID)
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", dateNow.ToString)
                        appointmentItem.Save()
                        Marshal.FinalReleaseComObject(appointmentItem)
                        appointmentItem = Nothing
                        GC.Collect()
                    Else
                        _idOfAppointmentCurrentlySyncingNormal.Remove(appointmentItem.EntryID)
                    End If
                End If
            Else
                _lastFolderSwitch = _lastFolderSwitch.AddMilliseconds(100)
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

提前非常感谢。

I have written a VSTO add-in that needs to get the an appointment information from the exchange server.

On exchange (Outlook Web Access) I change a subject line of an appointment. When I see that Outlook changed the subject line to a new value, I try to grab the new value programmatically and most of the time it grabs old values, instead of the values that have appeared in Outlook.

I tried handling the ItemChange event and saving the item using .save function, but it doesn't seem to make any difference.

Does anybody know why can't I grab values from Outlook appointment programmatically as soon as they arrive to Outlook?

The code that kind of works right now, which is very ugly and which is one big work around is the following:

Public _idOfAppointmentCurrentlySyncing As New List(Of String)
Public _idOfAppointmentCurrentlySyncingNormal As New List(Of String)

Private Sub appointmentSave(ByVal Item As Object) Handles _m_olAppointment.ItemChange, _m_olAppointment.ItemAdd
    Try
        Dim dateNow As Date = Date.Now
        If TypeOf Item Is Outlook.AppointmentItem Then
            If (dateNow - _lastFolderSwitch).TotalMilliseconds > 3000 Then
                Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
                Dim lastModifiedDates As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "lastModifiedDates")
                If _idOfAppointmentCurrentlySyncing.Contains(appointmentItem.EntryID) Then
                    Dim outlookLastSyncTime As Date = commonToolsMethod.getAppointmentDateParameter(appointmentItem, "OutlookLastSyncTime")
                    If outlookLastSyncTime <> Date.MaxValue And Date.Compare(lastModifiedDates, outlookLastSyncTime) <> 0 Then
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", outlookLastSyncTime)
                        appointmentItem.Save()
                    Else
                        _idOfAppointmentCurrentlySyncing.Remove(appointmentItem.EntryID)
                    End If
                Else
                    If _idOfAppointmentCurrentlySyncingNormal.Contains(appointmentItem.EntryID) = False Then
                        DebugWriter("Normal Save: " + appointmentItem.Start.ToString)
                        Try
                            If appointmentItem.Body <> "" Then
                                appointmentItem.Body += " "
                            End If
                        Catch ex As Exception
                        End Try
                        _idOfAppointmentCurrentlySyncingNormal.Add(appointmentItem.EntryID)
                        commonTools.addPropertyToAppointment(appointmentItem, "lastModifiedDates", dateNow.ToString)
                        appointmentItem.Save()
                        Marshal.FinalReleaseComObject(appointmentItem)
                        appointmentItem = Nothing
                        GC.Collect()
                    Else
                        _idOfAppointmentCurrentlySyncingNormal.Remove(appointmentItem.EntryID)
                    End If
                End If
            Else
                _lastFolderSwitch = _lastFolderSwitch.AddMilliseconds(100)
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Many thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文