我正在处理与日历约会相关的Outlook Addin。我的问题是我需要保存初始约会标题,然后检查保存是否更新以触发其他操作。我知道Addin / Ribbon只有一个实例。我最初使用静态变量,但它没有帮助,因为打开多个窗口然后标题混淆。我的问题是: 1)在哪里存储与约会相关的变量? 2)如何检测哪个对象一直在调用write / save / send / methods?
以下是我的代码的相关摘录:
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);
}
}
非常感谢任何帮助。