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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2359
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     1
´╗┐using System;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     2
using Outlook = Microsoft.Office.Interop.Outlook;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     3
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     4
namespace pEp
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     5
{
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     6
    /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     7
    /// Stores an Outlook Explorer with connected events.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     8
    /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
     9
    public class WatchedInspector : WatchedWindow
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    10
    {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    11
        private Outlook.Inspector   _Inspector      = null;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    12
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    13
        /**************************************************************
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    14
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    15
         * Constructors/Destructors
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    16
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    17
         *************************************************************/
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    18
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    19
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    20
        /// Primary constructor.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    21
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    22
        /// <param name="inspector">The inspector to watch.</param>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    23
        public WatchedInspector(Outlook.Inspector inspector)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    24
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    25
            this._Inspector = inspector;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    26
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    27
            if (this._Inspector != null)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    28
            {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    29
                this.ConnectWatchedInspectorEvents();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    30
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    31
                // Set mail item
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    32
                this.CurrentMailItem = this._Inspector.CurrentItem as Outlook.MailItem;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    33
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    34
                if (this.CurrentMailItem != null)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    35
                {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    36
                    this.InitializeMailItem();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    37
                }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    38
                else
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    39
                {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    40
                    Log.Error("WatchedInspector: Error getting current mail item.");
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    41
                }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    42
            }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    43
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    44
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    45
        #region Properties
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    46
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    47
        /// Gets the Inspector that is wrapped by this WatchedInspector
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    48
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    49
        public Outlook.Inspector Inspector
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    50
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    51
            get { return this._Inspector; }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    52
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    53
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    54
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    55
        /// Gets the Explorer that is wrapped by this WatchedExplorer.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    56
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    57
        public override dynamic Window
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    58
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    59
            get { return this.Inspector; }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    60
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    61
        #endregion
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    62
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    63
        #region Methods
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    64
        /**************************************************************
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    65
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    66
         * Methods
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    67
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    68
         *************************************************************/
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    69
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    70
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    71
        /// Clean up any resources being used.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    72
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    73
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    74
        protected override void Dispose(bool disposing)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    75
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    76
            if (disposing &&
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    77
                this._Inspector != null)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    78
            {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    79
                // Disconnect all events
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    80
                this.DisconnectWatchedInspectorEvents();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    81
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    82
                // Set Outlook objects to null
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    83
                this._Inspector = null;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    84
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    85
                // Dispose base class
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    86
                base.Dispose();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    87
            }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    88
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    89
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    90
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    91
        /// Connects the events for this watched explorer
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    92
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    93
        private void ConnectWatchedInspectorEvents()
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    94
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    95
            if (this._Inspector != null)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    96
            {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    97
                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close += WatchedInspector_Close;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    98
            }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
    99
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   100
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   101
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   102
        /// Disconnects the events from this watched explorer
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   103
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   104
        private void DisconnectWatchedInspectorEvents()
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   105
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   106
            if (this._Inspector != null)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   107
            {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   108
                ((Outlook.InspectorEvents_10_Event)this._Inspector).Close -= WatchedInspector_Close;
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   109
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   110
            }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   111
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   112
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   113
        #endregion
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   114
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   115
        #region Event Handling
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   116
        /**************************************************************
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   117
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   118
         * Event Handling
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   119
         * 
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   120
         *************************************************************/
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   121
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   122
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   123
        /// Event handler for when a watched inspector is being closed.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   124
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   125
        private void WatchedInspector_Close()
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   126
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   127
            Globals.ThisAddIn.RemoveFromWatchedInspectors(this);
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   128
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   129
            this.Dispose();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   130
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   131
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   132
        /// <summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   133
        /// Event handler for when the processing of an item in the WatchedInspector has finished.
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   134
        /// </summary>
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   135
        private void Inspector_ProcessingCompleted(object sender, MsgProcessor.ProcessingCompletedEventArgs e)
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   136
        {
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   137
            throw new NotImplementedException();
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   138
        }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   139
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   140
        #endregion
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   141
    }
0e6191d039e4 Major restructuration:
Thomas
parents:
diff changeset
   142
}