Outlook加载项,如何判断用户是否从会议请求中选择电子邮件中的新时间

时间:2016-07-26 22:29:00

标签: c# outlook outlook-addin

如果用户正在使用预览窗格。 NewInspector事件不会触发。 我该怎么做?

如果用户打开消息,我会收到此事件。

Application.Inspectors.NewInspector += InspectorOnNewInspector; 

From there i can hook to

var appointmentItem = ((Outlook.AppointmentItem) inspector.CurrentItem);
((Outlook.ItemEvents_10_Event) appointmentItem).PropertyChange += ThisAddIn_PropertyChange;

完整代码

public Outlook.Inspector CurrentInspector {get;组; }         public string Organizer {get;组; }

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        Application.Inspectors.NewInspector += InspectorOnNewInspector;
        Application.ActiveExplorer().SelectionChange += MeetingDurationAddIn_SelectionChange;
    }

    private void MeetingDurationAddIn_SelectionChange()
    {
        try
        {
            var currentView = Application.ActiveExplorer().CurrentView;

            if (currentView is Outlook.CalendarView)
            {
                Console.WriteLine("");
            }
        }
        catch
            (Exception e)
        {
            Console.WriteLine(e);
        }
    }

    private void InspectorOnNewInspector(Outlook.Inspector inspector)
    {
        try
        {
            if (inspector.CurrentItem is Outlook.AppointmentItem)
            {
                CurrentInspector = inspector;
                var creationTime = ((Outlook.AppointmentItem)CurrentInspector.CurrentItem).CreationTime;
                if (creationTime == DateTime.Parse("1/1/4501 12:00:00 AM"))
                {
                    NewAppointment = true;
                }
                if (CurrentInspector.CurrentItem is Outlook.AppointmentItem)
                {
                    Appointment = true;
                }
                if (CurrentInspector.CurrentItem is Outlook.MeetingItem)
                {
                    Appointment = false;
                }
                var appointmentItem = ((Outlook.AppointmentItem)CurrentInspector.CurrentItem);
                ((Outlook.ItemEvents_10_Event) appointmentItem).Send += OnSend;
                ((Outlook.ItemEvents_10_Event) appointmentItem).PropertyChange += ThisAddIn_PropertyChange;
                MeetingId = appointmentItem.GlobalAppointmentID;
                Organizer = appointmentItem.Organizer;

                EditDuration();
            }
        }
        catch
            (Exception e)
        {
            Console.WriteLine(e);
        }
    }

1 个答案:

答案 0 :(得分:0)

触发事件的对象(检查器)必须存储在全局(类)变量中,以防止它被垃圾回收。您在隐式变量(Application.Inspectors)上设置事件处理程序,该变量将在下次GC运行时释放。

其次,预览窗格不是检查器,因此将触发NewIsnpector事件。使用Explorer.SelectionChanged事件。