打开约会项目时显示自定义任务窗格(会议发生和个人会议)

Display custom task pane when appointment item is opened (meeting occurrence & individual meeting)

我在发送的会议邀请中嵌入了一些文本。我想在用户从包含我指定的文本的日历中打开约会时启动自定义任务窗格。

我正在使用 InspectorsEvents_NewInspectorEventHandler 获取打开事件并检查约会项目是否已打开。在约会的情况下,我调用代码来显示自定义任务窗格。

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

void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
    {
        Outlook.AppointmentItem appointmentItem = Inspector.CurrentItem as Outlook.AppointmentItem;
        if (appointmentItem != null)
        {
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Open += _appointment_Open;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += ThisAddIn_Close;

        }

    }

private void _appointment_Open(ref bool Cancel)
    {
        if ((Globals.ThisAddIn.ribbonObj as Ribbon) != null && (Globals.ThisAddIn.ribbonObj as Ribbon).IsLoggedOn)
        {
            Object selObject = this.Application.ActiveExplorer().Selection[1];
            if (selObject is Outlook.AppointmentItem)
            {
                Outlook.AppointmentItem apptItem = (selObject as Outlook.AppointmentItem);
//Without display() the taskpane is displayed on the calendar screen
                apptItem.Display();
                //Dispose already open task panes
                (Globals.ThisAddIn.ribbonObj as Ribbon).DisposeCustomTaskPanes();

                if (FindCustomId(apptItem.Body))
                {                        
                    (Globals.ThisAddIn.ribbonObj as Ribbon).edit_Cick(null);
                }
            }
            Marshal.ReleaseComObject(selObject);
        }
    }

edit_click()
{
CustomTaskPane myCustomTaskPane = 
Globals.ThisAddIn.CustomTaskPanes.Add(myUserControl, "edit pane");
}

通过使用 apptItem.Display();打开约会,然后任务窗格只显示打开的项目。如果未使用 display(),则任务窗格将在 outlook 的日历视图中打开,而不是在打开的项目上打开。

当我打开和重复项时,此方法会出现问题。如果我打开 'just this one' 项目,那么场景就可以正常工作。但是,如果我打开 'open entire series',则会触发 open() 事件两次并打开两个 windows,一个与会议发生有关,另一个与会议系列有关。如果我删除 display() 方法调用,'open series' 将只打开一个 window。

我的目标是避免在用户打开会议系列时打开自定义任务窗格。仅当用户打开会议事件或个人会议时才会显示任务窗格。 此外,有没有办法区分约会何时作为会议事件或会议系列打开。在 open_event 中,对于这两种情况,我都将 Appointment.RecurrenceState 作为 olApptOccurrence。

不要使用 AppointmentItem.Open 事件来显示任务窗格 - 使用 NewInspector 事件。

在新检查器中,我区分主事件和事件项

Outlook.OlRecurrenceState rState = appointmentItem.RecurrenceState;
            if (rState == Outlook.OlRecurrenceState.olApptMaster)
                return;
            appointmentItem.Open += AppointmentItem_Open;
            (appointmentItem as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Close += ThisAddIn_Close;

然后在打开事件中我将打开自定义任务窗格。有了这个,我能够达到预期的结果。一旦所有测试用例通过,将更新为答案。