VSTO Addin项相关变量&调用项标识

VSTO Addin item related variable & calling item identification

我正在开发与日历约会相关的 Outlook 插件。我的问题是我需要保存初始约会标题,然后在保存时检查它是否已更新以触发其他操作。我了解到 Addin/Ribbon 只有一个实例。我最初使用静态变量但它没有帮助,因为当打开多个 windows 然后标题混淆。我的问题是: 1)在哪里存储与约会相关的变量? 2) 如何检测哪个 object 调用了 write/save/send/ 方法?

这是我的代码的相关摘录:

public partial class ThisAddIn
{

    public static Outlook.AppointmentItem appointmentItem;
    public static Addin_Ribbon ribbon;
    Outlook.Inspectors inspectors;

// Needs to be saved for each appointments
public static string initialMeetingSubject = "";

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        inspectors = this.Application.Inspectors;
        inspectors.NewInspector +=
        new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler(Inspectors_NewInspector);
    }

    protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    {
        ribbon = new MyAddin_Ribbon();
        return ribbon;
    }

    void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        // Save current appointment reference
        appointmentItem = Inspector.CurrentItem as Outlook.AppointmentItem;

        if (appointmentItem != null)
        {
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += _appointment_Send;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).BeforeDelete += _appointment_Delete;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Write += _appointment_Write;    
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Open += _appointment_Open;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += _appointment_Close;

            // Save initial value to compare during appointment save
            ThisAddIn.initialMeetingSubject = appointmentItem.Subject;

        }
    }

    private void _appointment_Write(ref bool Cancel)
    {
        Logger.WriteLine(LogLevel.Debug, "Appointment WRITE Initial Subject: " +initialMeetingSubject + “ Updated Subject: “ + ThisAddIn.appointmentItem.Subject);
    }
}

如有任何帮助,我们将不胜感激。

好的,我在之前的评论中发布的 Microsoft 教程实际上非常清晰有效。按照说明,我为约会项目创建了一个包装器 class,效果非常好。可以下载一个测试工程here