VSTO:缓存交换模式 VS LastModificationTime

发布于 2024-08-21 20:49:46 字数 609 浏览 4 评论 0原文

我正在开发一个 VSTO Outlook 加载项,它依赖于 Outlook 约会的 LastModificationTime 属性。问题是当缓存交换模式打开时,每次关闭 Outlook 时 LastModificationTime 属性都会自动更新。是否有可能的解决方案可以用来获取用户更改约会时的日期和时间,而不是缓存交换模式更改约会时的日期和时间?

看到没有很多回复,我想更详细地描述我的问题 - 这就是发生的情况:

  1. 我更改了一个项目(异常行为仅发生在我更改的项目上)
  2. LastModificationTime 更改为我的时间已保存该项目(我使用 OutlookSpy 看到了更改)。 (例如,LastModificationTime 3:30:00 PM)
  3. 我工作到下午 4:00:00 PM 并检查 LastModificationTime,它仍然显示 3:30:00 PM
  4. 我关闭 Outlook
  5. 我打开 Outlook 并检查 LastModificationTime。现在,LastModificationTime 显示 3:30:42,而不是 3:30:00。 为什么我重新打开 Outlook 后又多了 42 秒?

感谢您给我的任何建议。

I am developing a VSTO Outlook Add-In that is relying on the LastModificationTime property of Outlook Appointment. The problem is when Cached exchange mode is turned On, the LastModificationTime property auto updates each time I close Outlook. Is there possible solution I can use to get the date and time when user changed the appointment, instead of date and time when cached exchange mode changed the appointment?

Seeing that there are not a lot of responses I wanted to describe my problem in more detail - this is what happens:

  1. I change an item (the abnormal behavior happens only to items I've changed)
  2. LastModificationTime is changed to the time when I've saved the item (I see the change with OutlookSpy). (eg. LastModificationTime 3:30:00 PM)
  3. I work until 4:00:00 PM and check the LastModificationTime and it still shows 3:30:00 PM
  4. I close outlook
  5. I open outlook and check LastModificationTime. Now the LastModificationTime shows 3:30:42 instead of 3:30:00.
    Why did it add extra 42 seconds after I had reopened the Outlook?

Thank you for any suggestions you can give me.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-08-28 20:49:46

我找到了解决问题的两种解决方法,#1 对我来说不可接受,#2 我实际使用过:

解决方案 #1:使用注册表项在加载项关闭时禁用 Exchange 服务器,并在加载项启动时重新启用它。下面是示例代码:

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    Try
        Dim regTopKey As String = "HKEY_CURRENT_USER"
        Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
        Dim oldValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601_Backup", Nothing)
        If oldValue IsNot Nothing Then
            Registry.SetValue(regTopKey & regPath, "00036601", oldValue, RegistryValueKind.Binary)
        End If
    Catch
    End Try
End Sub

Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    Try
        Dim disableExchangeMode As Byte() = {4, 0, 0, 0}
        Dim regTopKey As String = "HKEY_CURRENT_USER"
        Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
        Dim currentValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601", Nothing)
        If currentValue IsNot Nothing Then
            Registry.SetValue(regTopKey & regPath, "00036601_Backup", currentValue, RegistryValueKind.Binary)
        End If
        Registry.SetValue(regTopKey & regPath, "00036601", disableExchangeMode, RegistryValueKind.Binary)
    Catch
    End Try
End Sub

解决方案 #2:检测用户何时更改约会项目并将更改保存在用户定义的属性字段中。以下是示例代码:

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 > 500 Then
                _lastFolderSwitch = dateNow
                Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
                If (dateNow - appointmentItem.LastModificationTime).TotalMilliseconds < 100 Then
                    Dim lastModifiedDate As Outlook.UserProperty = appointmentItem.UserProperties.Add("lastModifiedDate", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, True)
                    lastModifiedDate.Value = dateNow.ToString
                    appointmentItem.Save()
                End If
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

谢谢大家的帮助

I was able to find two workarounds for my problem, #1 being unacceptable for me and #2 I actually used:

Solution #1: Use registry entries to disable exchange server on add-in shutdown and re-enable it on add-in startup. Below is sample code:

    Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
    Try
        Dim regTopKey As String = "HKEY_CURRENT_USER"
        Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
        Dim oldValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601_Backup", Nothing)
        If oldValue IsNot Nothing Then
            Registry.SetValue(regTopKey & regPath, "00036601", oldValue, RegistryValueKind.Binary)
        End If
    Catch
    End Try
End Sub

Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
    Try
        Dim disableExchangeMode As Byte() = {4, 0, 0, 0}
        Dim regTopKey As String = "HKEY_CURRENT_USER"
        Dim regPath As String = "\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles\Outlook\13dbb0c8aa05101a9bb000aa002fc45a"
        Dim currentValue As Byte() = Registry.GetValue(regTopKey & regPath, "00036601", Nothing)
        If currentValue IsNot Nothing Then
            Registry.SetValue(regTopKey & regPath, "00036601_Backup", currentValue, RegistryValueKind.Binary)
        End If
        Registry.SetValue(regTopKey & regPath, "00036601", disableExchangeMode, RegistryValueKind.Binary)
    Catch
    End Try
End Sub

Solution #2: Detect when user changes an appointment item and save the change in user defined property field. Below is sample code:

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 > 500 Then
                _lastFolderSwitch = dateNow
                Dim appointmentItem As Outlook.AppointmentItem = CType(Item, Outlook.AppointmentItem)
                If (dateNow - appointmentItem.LastModificationTime).TotalMilliseconds < 100 Then
                    Dim lastModifiedDate As Outlook.UserProperty = appointmentItem.UserProperties.Add("lastModifiedDate", Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText, True)
                    lastModifiedDate.Value = dateNow.ToString
                    appointmentItem.Save()
                End If
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)
    End Try
End Sub

Thank You everybody that helped

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文