Wrappers/WatchedInspector.cs
author Thomas
Thu, 06 Sep 2018 09:29:19 +0200
branchOUT-497
changeset 2359 0e6191d039e4
child 2445 a485c287cb88
permissions -rw-r--r--
Major restructuration: - Remove FormRegionPrivacyStatus - Create new WatchedWindow as base class for WatchedExplorers and WatchedInspectors - Move all logic from FormRegionPrivacy to WatchedWindow - Use Explorer.SelectionChanged and Inspectors.Newinspector events instead of FormRegionPrivacyStatus.FormRegionShowing to detect opening of mail item. - Rework of RibbonCustomizations. State of pEp button now stored in WatchedWindow instead of FormRegionPrivacyStatus

´╗┐using System;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace pEp
{
    /// <summary>
    /// Stores an Outlook Explorer with connected events.
    /// </summary>
    public class WatchedInspector : WatchedWindow
    {
        private Outlook.Inspector   _Inspector      = null;

        /**************************************************************
         * 
         * Constructors/Destructors
         * 
         *************************************************************/

        /// <summary>
        /// Primary constructor.
        /// </summary>
        /// <param name="inspector">The inspector to watch.</param>
        public WatchedInspector(Outlook.Inspector inspector)
        {
            this._Inspector = inspector;

            if (this._Inspector != null)
            {
                this.ConnectWatchedInspectorEvents();

                // Set mail item
                this.CurrentMailItem = this._Inspector.CurrentItem as Outlook.MailItem;

                if (this.CurrentMailItem != null)
                {
                    this.InitializeMailItem();
                }
                else
                {
                    Log.Error("WatchedInspector: Error getting current mail item.");
                }
            }
        }

        #region Properties
        /// <summary>
        /// Gets the Inspector that is wrapped by this WatchedInspector
        /// </summary>
        public Outlook.Inspector Inspector
        {
            get { return this._Inspector; }
        }

        /// <summary>
        /// Gets the Explorer that is wrapped by this WatchedExplorer.
        /// </summary>
        public override dynamic Window
        {
            get { return this.Inspector; }
        }
        #endregion

        #region Methods
        /**************************************************************
         * 
         * Methods
         * 
         *************************************************************/

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing &&
                this._Inspector != null)
            {
                // Disconnect all events
                this.DisconnectWatchedInspectorEvents();

                // Set Outlook objects to null
                this._Inspector = null;

                // Dispose base class
                base.Dispose();
            }
        }

        /// <summary>
        /// Connects the events for this watched explorer
        /// </summary>
        private void ConnectWatchedInspectorEvents()
        {
            if (this._Inspector != null)
            {
                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close += WatchedInspector_Close;
            }
        }

        /// <summary>
        /// Disconnects the events from this watched explorer
        /// </summary>
        private void DisconnectWatchedInspectorEvents()
        {
            if (this._Inspector != null)
            {
                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close -= WatchedInspector_Close;

            }
        }

        #endregion

        #region Event Handling
        /**************************************************************
         * 
         * Event Handling
         * 
         *************************************************************/

        /// <summary>
        /// Event handler for when a watched inspector is being closed.
        /// </summary>
        private void WatchedInspector_Close()
        {
            Globals.ThisAddIn.RemoveFromWatchedInspectors(this);

            this.Dispose();
        }

        /// <summary>
        /// Event handler for when the processing of an item in the WatchedInspector has finished.
        /// </summary>
        private void Inspector_ProcessingCompleted(object sender, MsgProcessor.ProcessingCompletedEventArgs e)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}