UI/RibbonCustomizations.cs
author Thomas
Tue, 30 Jul 2019 08:18:44 +0200
branchsync
changeset 2687 f7f12cd4dd77
parent 2682 e16dba4f04d7
child 2695 273816414b64
permissions -rw-r--r--
OUT-386: Add Reset Trust context menu entry for contacts
Dean@1079
     1
´╗┐using pEp.UI;
Dean@1375
     2
using pEpCOMServerAdapterLib;
Dean@1079
     3
using System;
Dean@1132
     4
using System.Diagnostics;
Dean@326
     5
using System.IO;
Dean@326
     6
using System.Reflection;
Dean@326
     7
using System.Runtime.InteropServices;
Dean@335
     8
using System.Windows.Forms;
Thomas@2264
     9
using System.Windows.Input;
Dean@326
    10
using Office = Microsoft.Office.Core;
Dean@622
    11
using Outlook = Microsoft.Office.Interop.Outlook;
Dean@326
    12
Dean@326
    13
namespace pEp
Dean@326
    14
{
Dean@326
    15
    [ComVisible(true)]
Dean@340
    16
    public class RibbonCustomizations : Office.IRibbonExtensibility
Dean@326
    17
    {
Dean@1375
    18
        /* Note: Only one instance of the RibbonCustomizations class is created in Outlook.
Dean@1375
    19
         * Any class variables will therefore be global between any relevant UI.
Dean@1375
    20
         *
Dean@1375
    21
         * Additionally, the Ribbon_Load event will also only be called once and only one instance of the ribbon
Dean@1375
    22
         * will exist. For this reason, it's safe to make the ribbon reference a static variable.
Dean@1375
    23
         * Making this static allows for a simple refresh ribbon method.
Dean@340
    24
         */
Dean@1375
    25
        private static Office.IRibbonUI ribbon;
Dean@326
    26
Thomas@2359
    27
        private static bool        DISABLE_FORCE_PROTECTION_DEFAULT    = false;
Thomas@2359
    28
        private static bool        FORCE_PROTECTION_DEFAULT            = false;
Thomas@2359
    29
        private static bool        FORCE_UNENCRYPTED_DEFAULT           = false;
Thomas@2359
    30
        private static bool        IS_DRAFT_DEFAULT                    = false;
Thomas@2359
    31
        private static bool        NEVER_UNSECURE_DEFAULT              = false;
Thomas@2359
    32
        private static pEpRating   RATING_DEFAULT                      = pEpRating.pEpRatingUndefined;
Thomas@2359
    33
Thomas@2359
    34
        private enum MessageProperties
Thomas@2359
    35
        {
Thomas@2359
    36
            DisableForceProtection,
Thomas@2359
    37
            ForceProtection,
Thomas@2359
    38
            ForceUnencrypted,
Thomas@2359
    39
            IsDraft,
Thomas@2359
    40
            NeverUnsecure,
Thomas@2359
    41
            Rating
Thomas@2359
    42
        }
Thomas@2359
    43
Dean@335
    44
        /**************************************************************
Dean@335
    45
         * 
Dean@335
    46
         * Constructors
Dean@335
    47
         * 
Dean@335
    48
         *************************************************************/
Dean@335
    49
Dean@335
    50
        /// <summary>
Dean@335
    51
        /// Default constructor.
Dean@335
    52
        /// </summary>
Dean@340
    53
        public RibbonCustomizations()
Dean@326
    54
        {
Dean@326
    55
        }
Dean@326
    56
Dean@335
    57
        /**************************************************************
Dean@335
    58
         * 
Thomas@2299
    59
         * Property accessors
Thomas@2299
    60
         * 
Thomas@2299
    61
         *************************************************************/
Thomas@2299
    62
Thomas@2299
    63
        /// <summary>
Thomas@2299
    64
        /// Gets whether the Force Protection option is disabled for the current mail item.
Thomas@2299
    65
        /// </summary>
Thomas@2299
    66
        /// <param name="control">The current button control.</param>
Thomas@2299
    67
        /// <returns>True if the Force Protection option is disabled for the current mail item, otherwise false.</returns>
Thomas@2299
    68
        internal bool GetDisableForceProtection(Office.IRibbonControl control)
Thomas@2299
    69
        {
Thomas@2359
    70
            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.DisableForceProtection);
Thomas@2299
    71
        }
Thomas@2299
    72
Thomas@2299
    73
        /// <summary>
Thomas@2299
    74
        /// Sets whether the Force Protection option should be disabled for the current mail item.
Thomas@2299
    75
        /// </summary>
Thomas@2299
    76
        /// <param name="control">The current button control.</param>
Thomas@2299
    77
        /// <param name="disable">Whether to disable the Force Protection option or not</param>
Thomas@2299
    78
        internal void SetDisableForceProtection(Office.IRibbonControl control, bool disable)
Thomas@2299
    79
        {
Thomas@2299
    80
            try
Thomas@2299
    81
            {
Thomas@2359
    82
                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.DisableForceProtection, disable);
Thomas@2299
    83
            }
Thomas@2299
    84
            catch (Exception ex)
Thomas@2299
    85
            {
Thomas@2299
    86
                Log.Error("SetDisableForceProtection: Error setting value. " + ex.ToString());
Thomas@2299
    87
            }
Thomas@2299
    88
        }
Thomas@2299
    89
Thomas@2299
    90
        /// <summary>
Thomas@2299
    91
        /// Gets whether the current mail item is forcefully protected.
Thomas@2299
    92
        /// </summary>
Thomas@2299
    93
        /// <param name="control">The current button control.</param>
Thomas@2299
    94
        /// <returns>True if the current mail item is forcefully protected, otherwise false.</returns>
Thomas@2299
    95
        internal bool GetForceProtection(Office.IRibbonControl control)
Thomas@2299
    96
        {
Thomas@2359
    97
            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.ForceProtection);
Thomas@2299
    98
        }
Thomas@2299
    99
Thomas@2299
   100
        /// <summary>
Thomas@2299
   101
        /// Sets whether the current mail item should be forcefully protected or not.
Thomas@2299
   102
        /// </summary>
Thomas@2299
   103
        /// <param name="control">The current button control.</param>
Thomas@2299
   104
        /// <param name="forceProtection">Whether to enable Force Protection or not.</param>
Thomas@2299
   105
        internal void SetForceProtection(Office.IRibbonControl control, bool forceProtection)
Thomas@2299
   106
        {
Thomas@2299
   107
            try
Thomas@2299
   108
            {
Thomas@2359
   109
                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.ForceProtection, forceProtection);
Thomas@2299
   110
            }
Thomas@2299
   111
            catch (Exception ex)
Thomas@2299
   112
            {
Thomas@2299
   113
                Log.Error("SetForceProtection: Error setting value. " + ex.ToString());
Thomas@2299
   114
            }
Thomas@2299
   115
        }
Thomas@2299
   116
Thomas@2299
   117
        /// <summary>
Thomas@2299
   118
        /// Gets whether the current mail item is forcefully unencrypted.
Thomas@2299
   119
        /// </summary>
Thomas@2299
   120
        /// <param name="control">The current button control.</param>
Thomas@2299
   121
        /// <returns>True if the current mail item is forcefully unencrypted, otherwise false.</returns>
Thomas@2299
   122
        internal bool GetForceUnencrypted(Office.IRibbonControl control)
Thomas@2299
   123
        {
Thomas@2359
   124
            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.ForceUnencrypted);
Thomas@2299
   125
        }
Thomas@2299
   126
Thomas@2299
   127
        /// <summary>
Thomas@2299
   128
        /// Sets whether the current mail item should be forcefully unencrypted or not.
Thomas@2299
   129
        /// </summary>
Thomas@2299
   130
        /// <param name="control">The current button control.</param>
Thomas@2299
   131
        /// <param name="forceUnencrypted">Whether to enable Force Unencrypted or not.</param>
Thomas@2299
   132
        internal void SetForceUnencrypted(Office.IRibbonControl control, bool forceUnencrypted)
Thomas@2299
   133
        {
Thomas@2299
   134
            try
Thomas@2299
   135
            {
Thomas@2359
   136
                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.ForceUnencrypted, forceUnencrypted);
Thomas@2299
   137
            }
Thomas@2299
   138
            catch (Exception ex)
Thomas@2299
   139
            {
Thomas@2299
   140
                Log.Error("SetForceUnencrypted: Error setting value. " + ex.ToString());
Thomas@2299
   141
            }
Thomas@2299
   142
        }
Thomas@2299
   143
Thomas@2299
   144
        /// <summary>
Thomas@2299
   145
        /// Gets whether the current mail item has the Never Unsecure option set
Thomas@2299
   146
        /// </summary>
Thomas@2299
   147
        /// <param name="control">The current button control.</param>
Thomas@2299
   148
        /// <returns>True if the current mail item has the Never Unsecure option set, otherwise false.</returns>
Thomas@2299
   149
        internal bool GetNeverUnsecure(Office.IRibbonControl control)
Thomas@2299
   150
        {
Thomas@2359
   151
            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.NeverUnsecure);
Thomas@2299
   152
        }
Thomas@2299
   153
Thomas@2299
   154
        /// <summary>
Thomas@2299
   155
        /// Sets whether the current mail item should be forcefully unencrypted or not.
Thomas@2299
   156
        /// </summary>
Thomas@2299
   157
        /// <param name="control">The current button control.</param>
Thomas@2359
   158
        /// <param name="neverUnsecure">Whether to enable Never Unsecure or not.</param>
Thomas@2299
   159
        internal void SetNeverUnsecure(Office.IRibbonControl control, bool neverUnsecure)
Thomas@2299
   160
        {
Thomas@2299
   161
            try
Thomas@2299
   162
            {
Thomas@2359
   163
                RibbonCustomizations.SetRibbonProperty(control, MessageProperties.NeverUnsecure, neverUnsecure);
Thomas@2299
   164
            }
Thomas@2299
   165
            catch (Exception ex)
Thomas@2299
   166
            {
Thomas@2299
   167
                Log.Error("SetNeverUnsecure: Error setting value. " + ex.ToString());
Thomas@2299
   168
            }
Thomas@2299
   169
        }
Thomas@2299
   170
Thomas@2299
   171
        /// <summary>
Thomas@2299
   172
        /// Gets the current UI rating as determined in the associated form region.
Thomas@2299
   173
        /// </summary>
Thomas@2299
   174
        /// <param name="control">The current button control.</param>
Thomas@2299
   175
        /// <returns>The pEpRating of the current message or undefined if an error occured.</returns>
Thomas@2299
   176
        private pEpRating GetRating(Office.IRibbonControl control)
Thomas@2299
   177
        {
Thomas@2359
   178
            return RibbonCustomizations.GetRibbonProperty(control, MessageProperties.Rating);
Thomas@2299
   179
        }
Thomas@2299
   180
Thomas@2299
   181
        /**************************************************************
Thomas@2299
   182
         * 
Dean@335
   183
         * Methods
Dean@335
   184
         * 
Dean@335
   185
         *************************************************************/
Dean@335
   186
Dean@335
   187
        /// <summary>
Dean@1375
   188
        /// Invalidates the associated ribbon causing it to be refreshed.
Dean@1375
   189
        /// This is static as Outlook will maintain only one instance of the ribbon.
Dean@1375
   190
        /// </summary>
Dean@1390
   191
        public static void Invalidate()
Dean@1375
   192
        {
Thomas@2246
   193
            RibbonCustomizations.ribbon?.Invalidate();
Thomas@2264
   194
        }
Thomas@2264
   195
Thomas@2264
   196
        /// <summary>
Thomas@2419
   197
        /// Gets the FormRegionPrivacyStatus that is associated with a given control's parent
Thomas@2419
   198
        /// window (Inspector / Explorer). Can return null.
Thomas@2419
   199
        /// </summary>
Thomas@2419
   200
        /// <param name="control">The control to get the associated form region for.</param>
Thomas@2419
   201
        /// <returns>The associated FormRegionPrivacyStatus or null if an error occured.</returns>
Thomas@2419
   202
        private FormRegionPrivacyStatus GetFormRegionPrivacyStatus(Office.IRibbonControl control)
Thomas@2419
   203
        {
Thomas@2419
   204
            dynamic window = null;
Thomas@2419
   205
            FormRegionPrivacyStatus formRegion = null;
Thomas@2419
   206
Thomas@2419
   207
            try
Thomas@2419
   208
            {
Thomas@2419
   209
                // Get the parent window
Thomas@2419
   210
                window = control.Context as Outlook.Explorer;
Thomas@2419
   211
                if (window == null)
Thomas@2419
   212
                {
Thomas@2419
   213
                    window = control.Context as Outlook.Inspector;
Thomas@2419
   214
                }
Thomas@2419
   215
Thomas@2419
   216
                if (window != null)
Thomas@2419
   217
                {
Thomas@2419
   218
                    formRegion = Globals.FormRegions[window].FormRegionPrivacyStatus;
Thomas@2419
   219
                }
Thomas@2419
   220
            }
Thomas@2419
   221
            catch (Exception ex)
Thomas@2419
   222
            {
Thomas@2419
   223
                formRegion = null;
Thomas@2419
   224
                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
Thomas@2419
   225
            }
Thomas@2419
   226
            finally
Thomas@2419
   227
            {
Thomas@2419
   228
                window = null;
Thomas@2419
   229
            }
Thomas@2419
   230
Thomas@2419
   231
            return formRegion;
Thomas@2419
   232
        }
Thomas@2419
   233
Thomas@2682
   234
        /// <summary>
Thomas@2682
   235
        /// Gets a ribbon property value.
Thomas@2682
   236
        /// </summary>
Thomas@2682
   237
        /// <param name="control">The control to get the property value for.</param>
Thomas@2682
   238
        /// <param name="property">The property to get its value.</param>
Thomas@2682
   239
        /// <returns>The property value.</returns>
Thomas@2359
   240
        private static dynamic GetRibbonProperty(Office.IRibbonControl control, MessageProperties property)
Thomas@2359
   241
        {
Thomas@2359
   242
            WatchedWindow window = Globals.ThisAddIn?.GetWatchedWindow(control?.Context);
Thomas@2359
   243
Thomas@2359
   244
            switch (property)
Thomas@2359
   245
            {
Thomas@2359
   246
                case MessageProperties.DisableForceProtection:
Thomas@2359
   247
                    {
Thomas@2359
   248
                        return window?.DisableForceProtection ?? RibbonCustomizations.DISABLE_FORCE_PROTECTION_DEFAULT;
Thomas@2359
   249
                    }
Thomas@2359
   250
                case MessageProperties.ForceProtection:
Thomas@2359
   251
                    {
Thomas@2359
   252
                        return window?.ForceProtection ?? RibbonCustomizations.FORCE_PROTECTION_DEFAULT;
Thomas@2359
   253
                    }
Thomas@2359
   254
                case MessageProperties.ForceUnencrypted:
Thomas@2359
   255
                    {
Thomas@2359
   256
                        return window?.ForceUnencrypted ?? RibbonCustomizations.FORCE_UNENCRYPTED_DEFAULT;
Thomas@2359
   257
                    }
Thomas@2359
   258
                case MessageProperties.IsDraft:
Thomas@2359
   259
                    {
Thomas@2359
   260
                        return window?.IsDraft ?? RibbonCustomizations.IS_DRAFT_DEFAULT;
Thomas@2359
   261
                    }
Thomas@2359
   262
                case MessageProperties.NeverUnsecure:
Thomas@2359
   263
                    {
Thomas@2359
   264
                        return window?.NeverUnsecure ?? RibbonCustomizations.NEVER_UNSECURE_DEFAULT;
Thomas@2359
   265
                    }
Thomas@2359
   266
                case MessageProperties.Rating:
Thomas@2359
   267
                    {
Thomas@2359
   268
                        return window?.Rating ?? RibbonCustomizations.RATING_DEFAULT;
Thomas@2359
   269
                    }
Thomas@2359
   270
                default:
Thomas@2359
   271
                    break;
Thomas@2359
   272
            }
Thomas@2359
   273
Thomas@2359
   274
            return null;
Thomas@2359
   275
        }
Thomas@2359
   276
Thomas@2682
   277
        /// <summary>
Thomas@2682
   278
        /// Sets a ribbon property.
Thomas@2682
   279
        /// </summary>
Thomas@2682
   280
        /// <param name="control">The control to set its property for.</param>
Thomas@2682
   281
        /// <param name="property">The property to set.</param>
Thomas@2682
   282
        /// <param name="value">The value to set.</param>
Thomas@2359
   283
        private static void SetRibbonProperty(Office.IRibbonControl control, MessageProperties property, dynamic value)
Thomas@2359
   284
        {
Thomas@2359
   285
            WatchedWindow window = Globals.ThisAddIn?.GetWatchedWindow(control.Context);
Thomas@2359
   286
Thomas@2359
   287
            if (window != null)
Thomas@2359
   288
            {
Thomas@2359
   289
                switch (property)
Thomas@2359
   290
                {
Thomas@2359
   291
                    case MessageProperties.DisableForceProtection:
Thomas@2359
   292
                        {
Thomas@2359
   293
                            window.DisableForceProtection = (bool)value;
Thomas@2359
   294
                        }
Thomas@2359
   295
                        break;
Thomas@2359
   296
                    case MessageProperties.ForceProtection:
Thomas@2359
   297
                        {
Thomas@2359
   298
                            window.ForceProtection = (bool)value;
Thomas@2359
   299
                        }
Thomas@2359
   300
                        break;
Thomas@2359
   301
                    case MessageProperties.ForceUnencrypted:
Thomas@2359
   302
                        {
Thomas@2359
   303
                            window.ForceUnencrypted = (bool)value;
Thomas@2359
   304
                        }
Thomas@2359
   305
                        break;
Thomas@2359
   306
                    case MessageProperties.IsDraft:
Thomas@2359
   307
                        {
Thomas@2359
   308
                            window.IsDraft = (bool)value;
Thomas@2359
   309
                        }
Thomas@2359
   310
                        break;
Thomas@2359
   311
                    case MessageProperties.NeverUnsecure:
Thomas@2359
   312
                        {
Thomas@2359
   313
                            window.NeverUnsecure = (bool)value;
Thomas@2359
   314
                        }
Thomas@2359
   315
                        break;
Thomas@2359
   316
                    case MessageProperties.Rating:
Thomas@2359
   317
                        {
Thomas@2359
   318
                            window.SetRating((pEpRating)value);
Thomas@2359
   319
                        }
Thomas@2359
   320
                        break;
Thomas@2359
   321
                    default:
Thomas@2359
   322
                        break;
Thomas@2359
   323
                }
Thomas@2359
   324
            }
Thomas@2359
   325
        }
Thomas@2359
   326
Thomas@2337
   327
        /// <summary>
Thomas@2264
   328
        /// Gets the Outlook contact item that is associated with a given control's parent
Thomas@2264
   329
        /// window (Inspector / Explorer). Can return null.
Thomas@2264
   330
        /// </summary>
Thomas@2264
   331
        /// <param name="control">The control to get the associated contact item for.</param>
Thomas@2264
   332
        /// <returns>The associated contact item or null if an error occured.</returns>
Thomas@2264
   333
        private Outlook.ContactItem GetContactItem(Office.IRibbonControl control)
Thomas@2264
   334
        {
Thomas@2264
   335
            Outlook.ContactItem oci = null;
Thomas@2264
   336
            Outlook.Inspector inspector = null;
Thomas@2264
   337
            Outlook.Explorer explorer = null;
Thomas@2264
   338
            Outlook.Selection selection = null;
Thomas@2264
   339
Thomas@2264
   340
            try
Thomas@2264
   341
            {
Thomas@2264
   342
                inspector = control.Context as Outlook.Inspector;
Thomas@2264
   343
                if (inspector != null)
Thomas@2264
   344
                {
Thomas@2264
   345
                    oci = inspector.CurrentItem as Outlook.ContactItem;
Thomas@2264
   346
                }
Thomas@2264
   347
                else
Thomas@2264
   348
                {
Thomas@2264
   349
                    explorer = control.Context as Outlook.Explorer;
Thomas@2264
   350
                    if (explorer != null)
Thomas@2264
   351
                    {
Thomas@2264
   352
                        selection = explorer.Selection;
Thomas@2264
   353
                        if (selection.Count > 0)
Thomas@2264
   354
                        {
Thomas@2264
   355
                            oci = selection[1] as Outlook.ContactItem;
Thomas@2264
   356
                        }
Thomas@2264
   357
                    }
Thomas@2264
   358
                }
Thomas@2264
   359
            }
Thomas@2264
   360
            catch (Exception ex)
Thomas@2264
   361
            {
Thomas@2264
   362
                oci = null;
Thomas@2264
   363
                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
Thomas@2264
   364
            }
Thomas@2264
   365
            finally
Thomas@2264
   366
            {
Thomas@2264
   367
                inspector = null;
Thomas@2264
   368
                explorer = null;
Thomas@2264
   369
                selection = null;
Thomas@2264
   370
            }
Thomas@2264
   371
Thomas@2264
   372
            return oci;
Thomas@2264
   373
        }
Thomas@2264
   374
Thomas@2264
   375
        /// <summary>
Thomas@2264
   376
        /// Gets whether S/MIME encryption or signature is enabled.
Thomas@2264
   377
        /// </summary>
Thomas@2264
   378
        /// <returns>True if S/MIME encryption or signature is enabled, otherwise false.</returns>
Thomas@2264
   379
        private bool GetIsSMIMEEnabled(Office.IRibbonControl control)
Thomas@2264
   380
        {
Thomas@2264
   381
            bool isEnabled = false;
Thomas@2264
   382
            Outlook.MailItem omi = null;
Thomas@2264
   383
Thomas@2264
   384
            try
Thomas@2264
   385
            {
Thomas@2264
   386
                omi = this.GetMailItem(control);
Thomas@2264
   387
                isEnabled = (omi?.GetIsSMIMEEnabled() == true);
Thomas@2264
   388
            }
Thomas@2264
   389
            catch (Exception ex)
Thomas@2264
   390
            {
Thomas@2264
   391
                isEnabled = false;
Thomas@2264
   392
                Log.Error("RibbonCustomizations.GetIsSMIMEEnabled: Error getting whether S/MIME processing is enabled. " + ex.ToString());
Thomas@2264
   393
            }
Thomas@2264
   394
            finally
Thomas@2264
   395
            {
Thomas@2264
   396
                omi = null;
Thomas@2264
   397
            }
Thomas@2264
   398
Thomas@2264
   399
            return isEnabled;
Thomas@2264
   400
        }
Thomas@2264
   401
Thomas@2264
   402
        /// <summary>
Thomas@2264
   403
        /// Gets the Outlook mail item that is associated with a given control's parent
Thomas@2264
   404
        /// window (Inspector / Explorer). Can return null.
Thomas@2264
   405
        /// </summary>
Thomas@2264
   406
        /// <param name="control">The control to get the associated mail item for.</param>
Thomas@2264
   407
        /// <returns>The associated mail item or null if an error occured.</returns>
Thomas@2264
   408
        private Outlook.MailItem GetMailItem(Office.IRibbonControl control)
Thomas@2264
   409
        {
Thomas@2264
   410
            Outlook.MailItem omi = null;
Thomas@2264
   411
            Outlook.Inspector inspector = null;
Thomas@2264
   412
            Outlook.Explorer explorer = null;
Thomas@2264
   413
            Outlook.Selection selection = null;
Thomas@2264
   414
Thomas@2264
   415
            try
Thomas@2264
   416
            {
Thomas@2264
   417
                inspector = control.Context as Outlook.Inspector;
Thomas@2264
   418
                if (inspector != null)
Thomas@2264
   419
                {
Thomas@2264
   420
                    omi = inspector.CurrentItem as Outlook.MailItem;
Thomas@2264
   421
                }
Thomas@2264
   422
                else
Thomas@2264
   423
                {
Thomas@2264
   424
                    explorer = control.Context as Outlook.Explorer;
Thomas@2264
   425
                    if (explorer != null)
Thomas@2264
   426
                    {
Thomas@2264
   427
                        selection = explorer.Selection;
Thomas@2264
   428
                        if (selection.Count > 0)
Thomas@2264
   429
                        {
Thomas@2264
   430
                            omi = selection[1] as Outlook.MailItem;
Thomas@2264
   431
                        }
Thomas@2264
   432
                    }
Thomas@2264
   433
                }
Thomas@2264
   434
            }
Thomas@2264
   435
            catch (Exception ex)
Thomas@2264
   436
            {
Thomas@2264
   437
                omi = null;
Thomas@2264
   438
                Log.Error("GetFormRegionPrivacyStatus: Error getting form region. " + ex.ToString());
Thomas@2264
   439
            }
Thomas@2264
   440
            finally
Thomas@2264
   441
            {
Thomas@2264
   442
                inspector = null;
Thomas@2264
   443
                explorer = null;
Thomas@2264
   444
                selection = null;
Thomas@2264
   445
            }
Thomas@2264
   446
Thomas@2264
   447
            return omi;
Dean@1375
   448
        }
Dean@1375
   449
Dean@1375
   450
        /// <summary>
Dean@340
   451
        /// Shows the options form with the given page selected.
Dean@340
   452
        /// This will manage/save states as well.
Dean@340
   453
        /// </summary>
Dean@340
   454
        /// <param name="page">The page to open the options form to.</param>
Thomas@2264
   455
        private void ShowOptions(FormControlOptions.State.OptionPages page = FormControlOptions.State.OptionPages.Accounts)
Dean@340
   456
        {
Dean@340
   457
            DialogResult result;
Dean@1079
   458
            FormOptions form;
Dean@1089
   459
            FormControlOptions.State state;
Dean@340
   460
Dean@536
   461
            try
Dean@536
   462
            {
Dean@536
   463
                // Update working state
Dean@1089
   464
                state = Globals.ThisAddIn.GetOptionsState();
Dean@1089
   465
                state.SelectedPage = page;
Dean@449
   466
Dean@536
   467
                // Build form and state
Thomas@2507
   468
                form = new FormOptions
Thomas@2507
   469
                {
Thomas@2507
   470
                    StartPosition = FormStartPosition.CenterParent,
Thomas@2507
   471
                    DisplayState = state
Thomas@2507
   472
                };
Dean@340
   473
Dean@1079
   474
                result = form.ShowDialog(); // Must show as dialog to block code
Dean@340
   475
Dean@536
   476
                if (result == DialogResult.OK)
Dean@536
   477
                {
Dean@1377
   478
                    Globals.ThisAddIn.SetOptionsState(form.DisplayState);
Dean@1390
   479
                    RibbonCustomizations.Invalidate();
Dean@536
   480
                }
Dean@536
   481
            }
Dean@536
   482
            catch (Exception ex)
Dean@340
   483
            {
Dean@860
   484
                Globals.StopAndSendCrashReport(ex);
Dean@340
   485
            }
Dean@340
   486
Dean@340
   487
            return;
Dean@340
   488
        }
Dean@340
   489
Dean@340
   490
        /// <summary>
Dean@1390
   491
        /// Determines if the active UI mail item has pEp enabled for it.
Dean@1138
   492
        /// </summary>
Dean@1390
   493
        /// <returns>True if the mail item has pEp enabled, otherwise false.</returns>
Thomas@2264
   494
        private bool GetIsPEPEnabled(Office.IRibbonControl control)
Dean@1138
   495
        {
Thomas@2264
   496
            Outlook.MailItem omi = null;
Thomas@2264
   497
            bool isEnabled = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
Dean@1138
   498
Dean@1375
   499
            try
Dean@1375
   500
            {
Thomas@2264
   501
                omi = this.GetMailItem(control);
Thomas@2264
   502
                isEnabled = omi?.GetIsPEPEnabled() ?? PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
Dean@1375
   503
            }
Dean@1375
   504
            catch (Exception ex)
Dean@1375
   505
            {
Thomas@2264
   506
                isEnabled = PEPSettings.ACCOUNT_SETTING_IS_PEP_ENABLED_DEFAULT;
Thomas@2264
   507
                Log.Error("GetIsPEPEnabled: Error occured. " + ex.ToString());
Thomas@2256
   508
            }
Thomas@2256
   509
            finally
Thomas@2256
   510
            {
Thomas@2256
   511
                omi = null;
Thomas@2242
   512
            }
Thomas@2242
   513
Thomas@2242
   514
            return isEnabled;
Thomas@2242
   515
        }
Thomas@2242
   516
Thomas@2242
   517
        /// <summary>
Thomas@2299
   518
        /// Determines whether the Decrypt Always option is enabled for the current mail item.
Thomas@2264
   519
        /// </summary>
Thomas@2299
   520
        /// <returns>True if the Decrypt Always option is enabled for the current mail item, otherwise false.</returns>
Thomas@2299
   521
        private bool GetIsDecryptAlwaysEnabled(Office.IRibbonControl control)
Thomas@2264
   522
        {
Thomas@2299
   523
            Outlook.MailItem omi = null;
Thomas@2299
   524
            bool isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
Thomas@2299
   525
Thomas@2299
   526
            try
Thomas@2299
   527
            {
Thomas@2299
   528
                omi = this.GetMailItem(control);
Thomas@2299
   529
                isEnabled = omi?.GetIsDecryptAlwaysEnabled() ?? PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
Thomas@2299
   530
            }
Thomas@2299
   531
            catch (Exception ex)
Thomas@2299
   532
            {
Thomas@2299
   533
                isEnabled = PEPSettings.ACCOUNT_SETTING_IS_DECRYPT_ALWAYS_ENABLED_DEFAULT;
Thomas@2299
   534
                Log.Error("GetIsDecryptAlwaysEnabled: Error occured. " + ex.ToString());
Thomas@2299
   535
            }
Thomas@2299
   536
            finally
Thomas@2299
   537
            {
Thomas@2299
   538
                omi = null;
Thomas@2299
   539
            }
Thomas@2299
   540
Thomas@2299
   541
            return isEnabled;
Thomas@2264
   542
        }
Thomas@2264
   543
Thomas@2264
   544
        /// <summary>
Dean@1093
   545
        /// Gets a property of the item associated with the active UI.
Dean@847
   546
        /// </summary>
Dean@1093
   547
        /// <param name="property">The property to get the value for.</param>
Dean@1093
   548
        /// <returns>The property value.</returns>
Thomas@2264
   549
        private object GetProperty(Office.IRibbonControl control,
Thomas@2264
   550
                                   MailItemExtensions.PEPProperty property)
Dean@847
   551
        {
Dean@1094
   552
            object propValue;
Dean@1093
   553
            object result = null;
Thomas@2264
   554
            Outlook.MailItem omi = null;
Thomas@2264
   555
            Outlook.ContactItem oci = null;
Dean@340
   556
Dean@1093
   557
            // Set the default
Dean@1303
   558
            result = MailItemExtensions.GetPEPPropertyDefault(property);
Dean@1093
   559
Thomas@2264
   560
            // If the current item is a mail item
Thomas@2264
   561
            omi = this.GetMailItem(control);
Thomas@2264
   562
            if (omi != null)
Dean@622
   563
            {
Thomas@2264
   564
                try
Thomas@2264
   565
                {
Thomas@2264
   566
                    switch (property)
Thomas@2264
   567
                    {
Thomas@2264
   568
                        case (MailItemExtensions.PEPProperty.ForceUnencrypted):
Thomas@2264
   569
                            {
Thomas@2264
   570
                                // Return status can be ignored here, using the auto default value is good enough
Thomas@2264
   571
                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, out propValue);
Thomas@2264
   572
                                result = (bool)propValue;
Thomas@2264
   573
                                break;
Thomas@2264
   574
                            }
Thomas@2264
   575
                        case (MailItemExtensions.PEPProperty.ForceProtection):
Thomas@2264
   576
                            {
Thomas@2264
   577
                                // Return status can be ignored here, using the auto default value is good enough
Thomas@2264
   578
                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, out propValue);
Thomas@2264
   579
                                result = propValue as string;
Thomas@2264
   580
                                break;
Thomas@2264
   581
                            }
Thomas@2264
   582
                        case (MailItemExtensions.PEPProperty.NeverUnsecure):
Thomas@2264
   583
                            {
Thomas@2264
   584
                                // Return status can be ignored here, using the auto default value is good enough
Thomas@2264
   585
                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, out propValue);
Thomas@2264
   586
                                result = (bool)propValue;
Thomas@2264
   587
                                break;
Thomas@2264
   588
                            }
Thomas@2264
   589
                        case (MailItemExtensions.PEPProperty.EnableProtection):
Thomas@2264
   590
                            {
Thomas@2264
   591
                                // Return status can be ignored here, using the auto default value is good enough
Thomas@2264
   592
                                omi.GetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, out propValue);
Thomas@2264
   593
                                result = (bool)propValue;
Thomas@2264
   594
                                break;
Thomas@2264
   595
                            }
Thomas@2264
   596
                    }
Thomas@2264
   597
                }
Thomas@2264
   598
                catch (Exception ex)
Thomas@2264
   599
                {
Thomas@2264
   600
                    Log.Error("GetProperty: Error occured. " + ex.ToString());
Thomas@2264
   601
                }
Thomas@2264
   602
                finally
Thomas@2264
   603
                {
Thomas@2264
   604
                    omi = null;
Thomas@2264
   605
                }
Thomas@2264
   606
            }
Thomas@2264
   607
            else
Thomas@2264
   608
            {
Thomas@2264
   609
                // If the current item is a contact item
Thomas@2264
   610
                oci = this.GetContactItem(control);
Thomas@2264
   611
                if (oci != null)
Dean@622
   612
                {
Dean@624
   613
                    try
Dean@624
   614
                    {
Dean@1093
   615
                        switch (property)
Dean@1093
   616
                        {
Dean@1303
   617
                            case (MailItemExtensions.PEPProperty.ForceUnencrypted):
Dean@1093
   618
                                {
Thomas@2264
   619
                                    propValue = oci.GetForceUnencrypted();
Dean@1093
   620
Dean@1093
   621
                                    // Don't replace the default if the value is null
Dean@1094
   622
                                    if (propValue != null)
Dean@1093
   623
                                    {
Dean@1094
   624
                                        result = (bool)propValue;
Dean@1093
   625
                                    }
Dean@1093
   626
Dean@1093
   627
                                    break;
Dean@1093
   628
                                }
Dean@1303
   629
                            case (MailItemExtensions.PEPProperty.NeverUnsecure):
Dean@1093
   630
                                {
Dean@1093
   631
                                    // Not supported
Dean@1093
   632
                                    break;
Dean@1093
   633
                                }
Dean@1093
   634
                        }
Dean@624
   635
                    }
Thomas@2264
   636
                    catch (Exception ex)
Thomas@2264
   637
                    {
Thomas@2264
   638
                        Log.Error("GetProperty: Error occured. " + ex.ToString());
Thomas@2264
   639
Thomas@2264
   640
                    }
Dean@624
   641
                    finally
Dean@624
   642
                    {
Thomas@2264
   643
                        oci = null;
Dean@624
   644
                    }
Dean@624
   645
                }
Dean@340
   646
            }
Dean@340
   647
Thomas@2264
   648
            return result;
Dean@340
   649
        }
Dean@340
   650
Dean@340
   651
        /// <summary>
Dean@1093
   652
        /// Sets the given property of the item associated with the active UI.
Dean@1154
   653
        /// Warning: This will call .Save() on the MailItem.
Dean@340
   654
        /// </summary>
Dean@1093
   655
        /// <param name="property">The property to set the value for.</param>
Dean@1093
   656
        /// <param name="value">The value of the property to set.</param>
Thomas@2264
   657
        private void SetProperty(Office.IRibbonControl control,
Thomas@2264
   658
                                 MailItemExtensions.PEPProperty property,
Dean@1303
   659
                                 object value)
Dean@340
   660
        {
Dean@1093
   661
            bool? propertyValue;
Thomas@2264
   662
            Outlook.MailItem omi = null;
Thomas@2264
   663
            Outlook.ContactItem oci = null;
Dean@847
   664
Thomas@2264
   665
            omi = this.GetMailItem(control);
Thomas@2264
   666
Thomas@2264
   667
            // MailItem
Thomas@2264
   668
            if (omi != null)
Dean@622
   669
            {
Thomas@2264
   670
                try
Thomas@2264
   671
                {
Thomas@2264
   672
                    switch (property)
Thomas@2264
   673
                    {
Thomas@2264
   674
                        case (MailItemExtensions.PEPProperty.ForceProtection):
Thomas@2264
   675
                            {
Thomas@2264
   676
                                // Return status can be ignored
Thomas@2264
   677
                                omi.SetPEPProperty(MailItemExtensions.PEPProperty.ForceProtection, value);
Thomas@2264
   678
Thomas@2264
   679
                                // Update UI
Thomas@2298
   680
                                if (string.IsNullOrEmpty(value as string))
Thomas@2298
   681
                                {
Thomas@2359
   682
                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
Thomas@2298
   683
                                }
Thomas@2298
   684
                                else
Thomas@2298
   685
                                {
Thomas@2359
   686
                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.SetRating(pEpRating.pEpRatingReliable);
Thomas@2298
   687
                                }
Thomas@2264
   688
                                break;
Thomas@2264
   689
                            }
Thomas@2264
   690
                        case (MailItemExtensions.PEPProperty.ForceUnencrypted):
Thomas@2264
   691
                            {
Thomas@2279
   692
                                if ((value as bool?) != null)
Thomas@2264
   693
                                {
Thomas@2264
   694
                                    // Return status can be ignored
Thomas@2264
   695
                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.ForceUnencrypted, value);
Thomas@2264
   696
Thomas@2264
   697
                                    // Update UI
Thomas@2409
   698
                                    this.UpdateUI(control);
Thomas@2264
   699
                                }
Thomas@2264
   700
Thomas@2264
   701
                                break;
Thomas@2264
   702
                            }
Thomas@2264
   703
                        case (MailItemExtensions.PEPProperty.NeverUnsecure):
Thomas@2264
   704
                            {
Thomas@2279
   705
                                if ((value as bool?) != null)
Thomas@2264
   706
                                {
Thomas@2264
   707
                                    // Return status can be ignored
Thomas@2264
   708
                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.NeverUnsecure, value);
Thomas@2264
   709
                                }
Thomas@2264
   710
Thomas@2264
   711
                                break;
Thomas@2264
   712
                            }
Thomas@2264
   713
                        case (MailItemExtensions.PEPProperty.EnableProtection):
Thomas@2264
   714
                            {
Thomas@2279
   715
                                if ((value as bool?) != null)
Thomas@2264
   716
                                {
Thomas@2264
   717
                                    // Return status can be ignored
Thomas@2264
   718
                                    omi.SetPEPProperty(MailItemExtensions.PEPProperty.EnableProtection, value);
Thomas@2264
   719
Thomas@2264
   720
                                    // Update UI
Thomas@2359
   721
                                    Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
Thomas@2264
   722
                                }
Thomas@2264
   723
Thomas@2264
   724
                                break;
Thomas@2264
   725
                            }
Thomas@2264
   726
                    }
Thomas@2264
   727
                }
Thomas@2264
   728
                catch (Exception ex)
Thomas@2264
   729
                {
Thomas@2264
   730
                    Log.Error("SetProperty: Error occured. " + ex.ToString());
Thomas@2264
   731
                }
Thomas@2264
   732
                finally
Thomas@2264
   733
                {
Thomas@2264
   734
                    omi = null;
Thomas@2264
   735
                }
Thomas@2264
   736
            }
Thomas@2264
   737
            else
Thomas@2264
   738
            {
Thomas@2264
   739
                // ContactItem
Thomas@2264
   740
                oci = this.GetContactItem(control);
Thomas@2264
   741
                if (oci != null)
Dean@622
   742
                {
Dean@624
   743
                    try
Dean@624
   744
                    {
Dean@1093
   745
                        switch (property)
Dean@624
   746
                        {
Dean@1303
   747
                            case (MailItemExtensions.PEPProperty.ForceUnencrypted):
Dean@1093
   748
                                {
Thomas@2279
   749
                                    if ((value as bool?) != null)
Dean@1093
   750
                                    {
Thomas@2279
   751
                                        if ((value as bool?) == true)
Dean@1093
   752
                                        {
Thomas@2264
   753
                                            oci.SetForceUnencrypted(true);
Dean@1093
   754
                                        }
Dean@1093
   755
                                        else
Dean@1093
   756
                                        {
Thomas@2264
   757
                                            propertyValue = oci.GetForceUnencrypted();
Dean@1093
   758
Dean@1093
   759
                                            // Set the mail item value to false ONLY if it was previously true.
Dean@1093
   760
                                            // This is necessary because the UI will default to false if null (indeterminate).
Thomas@2279
   761
                                            if (propertyValue == true)
Dean@1093
   762
                                            {
Thomas@2264
   763
                                                oci.SetForceUnencrypted(false);
Dean@1093
   764
                                            }
Dean@1093
   765
                                        }
Dean@1093
   766
                                    }
Dean@1093
   767
Dean@1093
   768
                                    break;
Dean@1093
   769
                                }
Dean@1303
   770
                            case (MailItemExtensions.PEPProperty.NeverUnsecure):
Dean@1093
   771
                                {
Dean@1093
   772
                                    // Not supported
Dean@1093
   773
                                    break;
Dean@1093
   774
                                }
Dean@624
   775
                        }
Dean@624
   776
                    }
Thomas@2264
   777
                    catch (Exception ex)
Thomas@2264
   778
                    {
Thomas@2264
   779
                        Log.Error("SetProperty: Error occured. " + ex.ToString());
Thomas@2264
   780
                    }
Dean@624
   781
                    finally
Dean@622
   782
                    {
Thomas@2264
   783
                        oci = null;
Dean@622
   784
                    }
Dean@622
   785
                }
Dean@340
   786
            }
Dean@340
   787
        }
Dean@335
   788
Thomas@2409
   789
        /// <summary>
Thomas@2409
   790
        /// Updates the UI (ribbon and form region).
Thomas@2409
   791
        /// </summary>
Thomas@2409
   792
        /// <param name="control">The control to get its form region.</param>
Thomas@2409
   793
        private void UpdateUI(Office.IRibbonControl control)
Thomas@2409
   794
        {
Thomas@2421
   795
            RibbonCustomizations.Invalidate();
Thomas@2445
   796
            Globals.ThisAddIn.GetWatchedWindow(control?.Context)?.UpdatePrivacyStateAndUI();
Thomas@2467
   797
        }
Thomas@2409
   798
Dean@335
   799
        /**************************************************************
Dean@335
   800
         * 
Dean@1132
   801
         * Callbacks
Dean@340
   802
         * 
Dean@340
   803
         *************************************************************/
Dean@340
   804
Dean@1096
   805
        ///////////////////////////////////////////////////////////
Thomas@2177
   806
        // ContextMenuKeyImport
Dean@1096
   807
        ///////////////////////////////////////////////////////////
Dean@1096
   808
Dean@340
   809
        /// <summary>
Thomas@2172
   810
        /// Callback to get the store context menu key import button text.
Thomas@2172
   811
        /// </summary>
Thomas@2172
   812
        public string ContextMenuKeyImport_GetLabel(Office.IRibbonControl control)
Thomas@2172
   813
        {
Thomas@2177
   814
            return Properties.Resources.StoreContextMenu_KeyImportText;
Thomas@2172
   815
        }
Thomas@2172
   816
Thomas@2172
   817
        /// <summary>
Thomas@2172
   818
        /// Callback to get the visibility of the store context menu key import button.
Thomas@2172
   819
        /// </summary>
Thomas@2172
   820
        public bool ContextMenuKeyImport_GetVisible(Office.IRibbonControl control)
Thomas@2172
   821
        {
Thomas@2172
   822
            bool visible = false;
Thomas@2172
   823
            Outlook.Account account = null;
Thomas@2172
   824
            Outlook.Store store = null;
Thomas@2172
   825
Thomas@2172
   826
            try
Thomas@2172
   827
            {
Thomas@2172
   828
                // If this store has an associated account, show button
Thomas@2172
   829
                store = control.Context as Outlook.Store;
Thomas@2172
   830
                account = store?.GetAccount();
Thomas@2172
   831
Thomas@2172
   832
                visible = (account != null);
Thomas@2172
   833
            }
Thomas@2172
   834
            catch (Exception ex)
Thomas@2172
   835
            {
Thomas@2172
   836
                visible = false;
Thomas@2172
   837
                Log.Error("ContextMenuKeyImport_GetVisible: Error determining visibility. " + ex.ToString());
Thomas@2172
   838
            }
Thomas@2172
   839
            finally
Thomas@2172
   840
            {
Thomas@2172
   841
                account = null;
Thomas@2172
   842
                store = null;
Thomas@2172
   843
            }
Thomas@2172
   844
Thomas@2172
   845
            return visible;
Thomas@2172
   846
        }
Thomas@2172
   847
Thomas@2172
   848
        /// <summary>
Thomas@2172
   849
        /// Callback to get the store context menu key import button image.
Thomas@2172
   850
        /// </summary>
Thomas@2172
   851
        public System.Drawing.Bitmap ContextMenuKeyImport_GetImage(Office.IRibbonControl control)
Thomas@2172
   852
        {
Thomas@2177
   853
            return Properties.Resources.ImageLogoIcon;
Thomas@2177
   854
        }
Thomas@2177
   855
Thomas@2177
   856
        ///////////////////////////////////////////////////////////
Thomas@2177
   857
        // ContextMenuKeyImportButtonPEP
Thomas@2177
   858
        ///////////////////////////////////////////////////////////   
Thomas@2177
   859
Thomas@2177
   860
        /// <summary>
Thomas@2177
   861
        /// Callback to get the store context menu key import button text.
Thomas@2177
   862
        /// </summary>
Thomas@2177
   863
        public string ContextMenuKeyImportButtonPEP_GetLabel(Office.IRibbonControl control)
Thomas@2177
   864
        {
Thomas@2177
   865
            return Properties.Resources.StoreContextMenu_OpenPEPKeyImportWizard;
Thomas@2177
   866
        }
Thomas@2177
   867
Thomas@2177
   868
        ///////////////////////////////////////////////////////////
Thomas@2177
   869
        // ContextMenuKeyImportButtonPGP
Thomas@2177
   870
        ///////////////////////////////////////////////////////////   
Thomas@2177
   871
Thomas@2177
   872
        /// <summary>
Thomas@2177
   873
        /// Callback to get the store context menu key import button text.
Thomas@2177
   874
        /// </summary>
Thomas@2177
   875
        public string ContextMenuKeyImportButtonPGP_GetLabel(Office.IRibbonControl control)
Thomas@2177
   876
        {
Thomas@2177
   877
            return Properties.Resources.StoreContextMenu_OpenPGPKeyImportWizard;
Thomas@2172
   878
        }
Thomas@2172
   879
Thomas@2172
   880
        ///////////////////////////////////////////////////////////
Thomas@2687
   881
        // ContextMenuResetContactTrust
Thomas@2687
   882
        ///////////////////////////////////////////////////////////
Thomas@2687
   883
Thomas@2687
   884
        /// <summary>
Thomas@2687
   885
        /// Callback to get the store context menu key import button text.
Thomas@2687
   886
        /// </summary>
Thomas@2687
   887
        public string ContextMenuResetContactTrust_GetLabel(Office.IRibbonControl control)
Thomas@2687
   888
        {
Thomas@2687
   889
            return Properties.Resources.PrivacyStatus_ResetTrust;
Thomas@2687
   890
        }
Thomas@2687
   891
Thomas@2687
   892
        /// <summary>
Thomas@2687
   893
        /// Callback to get the store context menu key import button image.
Thomas@2687
   894
        /// </summary>
Thomas@2687
   895
        public System.Drawing.Bitmap ContextMenuResetContactTrust_GetImage(Office.IRibbonControl control)
Thomas@2687
   896
        {
Thomas@2687
   897
            return Properties.Resources.ImageLogoIcon;
Thomas@2687
   898
        }
Thomas@2687
   899
Thomas@2687
   900
        ///////////////////////////////////////////////////////////
Thomas@2264
   901
        // ButtonPrivacyStatus
Thomas@2264
   902
        ///////////////////////////////////////////////////////////
Thomas@2264
   903
Thomas@2264
   904
        /// <summary>
Thomas@2264
   905
        /// Event handler for when the Privacy Status button is clicked.
Thomas@2264
   906
        /// This will open the Options dialog.
Thomas@2264
   907
        /// </summary>
Thomas@2264
   908
        public void ButtonPrivacyStatus_Click(Office.IRibbonControl control)
Thomas@2264
   909
        {
Thomas@2264
   910
            try
Thomas@2264
   911
            {
Thomas@2264
   912
                Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
Thomas@2359
   913
                Globals.ThisAddIn.GetWatchedWindow(control.Context)?.BuildAndShowManager();
Thomas@2264
   914
            }
Thomas@2264
   915
            catch (Exception ex)
Thomas@2264
   916
            {
Thomas@2264
   917
                Globals.StopAndSendCrashReport(ex);
Thomas@2264
   918
            }
Thomas@2264
   919
        }
Thomas@2264
   920
Thomas@2264
   921
        /// <summary>
Thomas@2264
   922
        /// Callback to get the image of the ButtonPrivacyStatus.
Thomas@2264
   923
        /// </summary>
Thomas@2264
   924
        public System.Drawing.Bitmap ButtonPrivacyStatus_GetImage(Office.IRibbonControl control)
Thomas@2264
   925
        {
Thomas@2445
   926
            return Globals.ThisAddIn.GetWatchedWindow(control?.Context)?.PrivacyState?.Image;
Thomas@2264
   927
        }
Thomas@2264
   928
Thomas@2264
   929
        /// <summary>
Thomas@2264
   930
        /// Callback to get the label of the ButtonPrivacyStatus.
Thomas@2264
   931
        /// </summary>
Thomas@2264
   932
        public string ButtonPrivacyStatus_GetLabel(Office.IRibbonControl control)
Thomas@2264
   933
        {
Thomas@2445
   934
            string label = Globals.ThisAddIn.GetWatchedWindow(control?.Context)?.PrivacyState?.Label;
Thomas@2264
   935
Thomas@2409
   936
            // Workaround to show ampersands correctly
Thomas@2410
   937
            if (label?.Contains(" & ") == true)
Thomas@2264
   938
            {
Thomas@2409
   939
                label = label.Replace(" & ", " && ");
Thomas@2264
   940
            }
Thomas@2409
   941
            return label;
Thomas@2264
   942
        }
Thomas@2264
   943
Thomas@2264
   944
        /// <summary>
Thomas@2337
   945
        /// Callback to get the supertip of the ButtonPrivacyStatus.
Thomas@2337
   946
        /// </summary>
Thomas@2337
   947
        public string ButtonPrivacyStatus_GetScreentip(Office.IRibbonControl control)
Thomas@2337
   948
        {
Thomas@2409
   949
            return Properties.Resources.PrivacyStatus_FormText;
Thomas@2337
   950
        }
Thomas@2337
   951
Thomas@2337
   952
        /// <summary>
Thomas@2264
   953
        /// Callback to get whether the ButtonPrivacyStatus is visible.
Thomas@2264
   954
        /// </summary>
Thomas@2264
   955
        public bool ButtonPrivacyStatus_GetVisible(Office.IRibbonControl control)
Thomas@2264
   956
        {
Thomas@2299
   957
            /* Visible if pEp enabled.
Thomas@2299
   958
             * If pEp is disabled, only visible in draft windows (so user can Enable Protection)
Thomas@2299
   959
             * or if DecryptAlways option is set.
Thomas@2299
   960
             */
Thomas@2299
   961
            bool visible = true;
Thomas@2299
   962
Thomas@2299
   963
            if (this.GetIsPEPEnabled(control) == false)
Thomas@2299
   964
            {
Thomas@2299
   965
                visible = false;
Thomas@2299
   966
                dynamic window = null;
Thomas@2299
   967
                Outlook.MailItem omi = null;
Thomas@2299
   968
Thomas@2299
   969
                try
Thomas@2299
   970
                {
Thomas@2299
   971
                    // Get the parent window
Thomas@2299
   972
                    window = control.Context as Outlook.Explorer;
Thomas@2299
   973
                    if (window != null)
Thomas@2299
   974
                    {
Thomas@2299
   975
                        visible = this.GetIsDecryptAlwaysEnabled(control);
Thomas@2299
   976
                    }
Thomas@2299
   977
                    else
Thomas@2299
   978
                    {
Thomas@2299
   979
                        window = control.Context as Outlook.Inspector;
Thomas@2299
   980
                        if (window != null)
Thomas@2299
   981
                        {
Thomas@2299
   982
                            omi = this.GetMailItem(control);
Thomas@2299
   983
                            visible = ((omi?.GetIsDraft() == true) ||
Thomas@2409
   984
                                       (this.GetIsDecryptAlwaysEnabled(control)));
Thomas@2299
   985
                        }
Thomas@2299
   986
                    }
Thomas@2299
   987
                }
Thomas@2299
   988
                catch (Exception ex)
Thomas@2299
   989
                {
Thomas@2299
   990
                    Log.Error("ButtonPrivacyStatus_GetVisible: Error occured. " + ex.ToString());
Thomas@2299
   991
                }
Thomas@2299
   992
                finally
Thomas@2299
   993
                {
Thomas@2299
   994
                    omi = null;
Thomas@2299
   995
                    window = null;
Thomas@2299
   996
                }
Thomas@2299
   997
            }
Thomas@2299
   998
Thomas@2299
   999
            return visible;
Thomas@2264
  1000
        }
Thomas@2264
  1001
Thomas@2264
  1002
        /// <summary>
Thomas@2264
  1003
        /// Event handler for when the builtin Encrypt Message button is clicked.
Thomas@2264
  1004
        /// </summary>
Thomas@2264
  1005
        public void ButtonSMIME_Clicked(Office.IRibbonControl control, bool pressed, ref bool cancel)
Thomas@2264
  1006
        {
Thomas@2264
  1007
            cancel = false;
Thomas@2359
  1008
            Globals.ThisAddIn.GetWatchedWindow(control.Context)?.RequestRatingAndUIUpdate();
Thomas@2264
  1009
        }
Thomas@2264
  1010
Thomas@2264
  1011
        ///////////////////////////////////////////////////////////
Thomas@2172
  1012
        // ToggleButtonForceUnencrypted
Thomas@2172
  1013
        ///////////////////////////////////////////////////////////
Thomas@2172
  1014
Thomas@2172
  1015
        /// <summary>
Thomas@2264
  1016
        /// Event handler for when the ToggleButtonForceUnencrypted is clicked.
Thomas@2264
  1017
        /// </summary>
Thomas@2264
  1018
        public void ToggleButtonForceUnencrypted_Click(Office.IRibbonControl control, bool isPressed)
Thomas@2264
  1019
        {
Thomas@2299
  1020
            this.SetForceUnencrypted(control, isPressed);
Thomas@2305
  1021
Thomas@2305
  1022
            // Disable Force Protection and Never Unsecure if needed
Thomas@2305
  1023
            if (isPressed)
Thomas@2305
  1024
            {
Thomas@2305
  1025
                this.SetForceProtection(control, false);
Thomas@2305
  1026
                this.SetNeverUnsecure(control, false);
Thomas@2305
  1027
            }
Thomas@2305
  1028
Thomas@2409
  1029
            this.UpdateUI(control);
Thomas@2264
  1030
        }
Thomas@2264
  1031
Thomas@2264
  1032
        /// <summary>
Dean@1093
  1033
        /// Callback to get whether the ToggleButtonForceUnencrypted is enabled.
Dean@1093
  1034
        /// </summary>
Dean@1093
  1035
        public bool ToggleButtonForceUnencrypted_GetEnabled(Office.IRibbonControl control)
Dean@1093
  1036
        {
Thomas@2305
  1037
            /* The button is disabled if
Thomas@2305
  1038
             *  - Rating is lower than reliable
Thomas@2305
  1039
             *  - Force Protection or Never Unsecure are enabled and not overridden
Thomas@2409
  1040
             */
Thomas@2305
  1041
            if (((this.GetRating(control) < pEpRating.pEpRatingReliable) ||
Thomas@2305
  1042
                 (this.GetNeverUnsecure(control))) ||
Thomas@2305
  1043
                 ((this.GetForceProtection(control)) && (this.GetDisableForceProtection(control) == false)))
Dean@1093
  1044
            {
Thomas@2264
  1045
                return false;
Thomas@2409
  1046
            }
Dean@1093
  1047
            else
Dean@1093
  1048
            {
Thomas@2264
  1049
                return true;
Dean@1093
  1050
            }
Dean@1093
  1051
        }
Dean@1093
  1052
Dean@1093
  1053
        /// <summary>
Dean@847
  1054
        /// Callback to get the label text for the ToggleButtonForceUnencrypted.
Dean@847
  1055
        /// </summary>
Dean@847
  1056
        public string ToggleButtonForceUnencrypted_GetLabel(Office.IRibbonControl control)
Dean@847
  1057
        {
Thomas@2264
  1058
            return Properties.Resources.Ribbon_ForceUnencrypted;
Dean@847
  1059
        }
Dean@847
  1060
Dean@847
  1061
        /// <summary>
Dean@859
  1062
        /// Callback to get whether the ToggleButtonForceUnencrypted is pressed.
Dean@859
  1063
        /// </summary>
Dean@859
  1064
        public bool ToggleButtonForceUnencrypted_GetPressed(Office.IRibbonControl control)
Dean@859
  1065
        {
Thomas@2299
  1066
            return this.GetForceUnencrypted(control);
Dean@859
  1067
        }
Dean@859
  1068
nikolaj@1711
  1069
        /// <summary>
nikolaj@1711
  1070
        /// Callback to get the supertip/description text for the ToggleButtonForceUnencrypted.
nikolaj@1711
  1071
        /// </summary>
nikolaj@1711
  1072
        public string ToggleButtonForceUnencrypted_GetSupertip(Office.IRibbonControl control)
Dean@847
  1073
        {
Thomas@2264
  1074
            return Properties.Resources.Ribbon_ForceUnencryptedDesc;
Dean@847
  1075
        }
Dean@847
  1076
Dean@847
  1077
        /// <summary>
Dean@859
  1078
        /// Callback to get whether the ToggleButtonForceUnencrypted is visible.
Dean@847
  1079
        /// </summary>
Dean@859
  1080
        public bool ToggleButtonForceUnencrypted_GetVisible(Office.IRibbonControl control)
Dean@847
  1081
        {
Thomas@1870
  1082
            return ((Globals.RELEASE_MODE != Globals.ReleaseMode.Reader) &&
Thomas@2264
  1083
                    (this.GetIsPEPEnabled(control)));
Dean@847
  1084
        }
Dean@847
  1085
Dean@1096
  1086
        ///////////////////////////////////////////////////////////
Thomas@1817
  1087
        // ToggleButtonEnableProtection
Thomas@1795
  1088
        ///////////////////////////////////////////////////////////
Thomas@1795
  1089
Thomas@1795
  1090
        /// <summary>
Thomas@2264
  1091
        /// Event handler for when the ToggleButtonEnableProtection is clicked.
Thomas@2264
  1092
        /// </summary>
Thomas@2264
  1093
        public void ToggleButtonEnableProtection_Click(Office.IRibbonControl control, bool isPressed)
Thomas@2264
  1094
        {
Thomas@2264
  1095
            this.SetProperty(control, MailItemExtensions.PEPProperty.EnableProtection, isPressed);
Thomas@2264
  1096
Thomas@2306
  1097
            // If protection is disabled, disable also force protected and never unsecure
Thomas@2264
  1098
            if (isPressed == false)
Thomas@2264
  1099
            {
Thomas@2306
  1100
                this.SetForceProtection(control, false);
Thomas@2306
  1101
                this.SetNeverUnsecure(control, false);
Thomas@2264
  1102
            }
Thomas@2264
  1103
        }
Thomas@2264
  1104
Thomas@2264
  1105
        /// <summary>
Thomas@1817
  1106
        /// Callback to get whether the ToggleButtonEnableProtection is enabled.
Thomas@1795
  1107
        /// </summary>
Thomas@1817
  1108
        public bool ToggleButtonEnableProtection_GetEnabled(Office.IRibbonControl control)
Thomas@1795
  1109
        {
Thomas@1795
  1110
            // If button is visible, it is also enabled
Thomas@1795
  1111
            return true;
Thomas@1795
  1112
        }
Thomas@1795
  1113
Thomas@1795
  1114
        /// <summary>
Thomas@1817
  1115
        /// Callback to get the label text for the ToggleButtonEnableProtection.
Thomas@1817
  1116
        /// </summary>
Thomas@1817
  1117
        public string ToggleButtonEnableProtection_GetLabel(Office.IRibbonControl control)
Thomas@1817
  1118
        {
Thomas@2264
  1119
            return Properties.Resources.Ribbon_EnableProtection;
Thomas@1817
  1120
        }
Thomas@1817
  1121
Thomas@1817
  1122
        /// <summary>
Thomas@1870
  1123
        /// Callback to get whether the ToggleButtonEnableProtection is pressed.
Thomas@1817
  1124
        /// </summary>
Thomas@1817
  1125
        public bool ToggleButtonEnableProtection_GetPressed(Office.IRibbonControl control)
Thomas@1817
  1126
        {
Thomas@2299
  1127
            return ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false);
Thomas@1817
  1128
        }
Thomas@1817
  1129
Thomas@1817
  1130
        /// <summary>
Thomas@1870
  1131
        /// Callback to get the supertip/description text for the ToggleButtonEnableProtection.
Thomas@1817
  1132
        /// </summary>
Thomas@1817
  1133
        public string ToggleButtonEnableProtection_GetSupertip(Office.IRibbonControl control)
Thomas@1817
  1134
        {
Thomas@1817
  1135
            return (Properties.Resources.Ribbon_EnableProtectionDesc);
Thomas@1817
  1136
        }
Thomas@1817
  1137
Thomas@1817
  1138
        /// <summary>
Thomas@1870
  1139
        /// Callback to get whether the ToggleButtonEnableProtection is visible.
Thomas@1817
  1140
        /// </summary>
Thomas@1817
  1141
        public bool ToggleButtonEnableProtection_GetVisible(Office.IRibbonControl control)
Thomas@1817
  1142
        {
Thomas@1870
  1143
            return ((Globals.RELEASE_MODE != Globals.ReleaseMode.Reader) &&
Thomas@2264
  1144
                    (this.GetIsPEPEnabled(control)) == false);
Thomas@1817
  1145
        }
Thomas@1817
  1146
Thomas@1817
  1147
        ///////////////////////////////////////////////////////////
Thomas@1817
  1148
        // ToggleButtonForceProtection
Thomas@1817
  1149
        ///////////////////////////////////////////////////////////
Thomas@1817
  1150
Thomas@1817
  1151
        /// <summary>
Thomas@2264
  1152
        /// Event handler for when the ToggleButtonForceProtection is clicked.
Thomas@2264
  1153
        /// </summary>
Thomas@2264
  1154
        public void ToggleButtonForceProtection_Click(Office.IRibbonControl control, bool isPressed)
Thomas@2264
  1155
        {
Thomas@2299
  1156
            this.SetForceProtection(control, isPressed);
Thomas@2299
  1157
Thomas@2299
  1158
            // If protection is disabled, disable also never unsecure
Thomas@2299
  1159
            if (isPressed == false)
Thomas@2299
  1160
            {
Thomas@2299
  1161
                this.SetNeverUnsecure(control, isPressed);
Thomas@2299
  1162
            }
Thomas@2299
  1163
Thomas@2409
  1164
            this.UpdateUI(control);
Thomas@2264
  1165
        }
Thomas@2264
  1166
Thomas@2264
  1167
        /// <summary>
Thomas@1820
  1168
        /// Callback to get whether the ToggleButtonForceProtection is enabled
Thomas@1820
  1169
        /// </summary>
Thomas@1820
  1170
        public bool ToggleButtonForceProtection_GetEnabled(Office.IRibbonControl control)
Thomas@1820
  1171
        {
Thomas@2264
  1172
            bool enabled = false;
Thomas@2264
  1173
Thomas@2299
  1174
            /* The button is enabled when:
Thomas@2299
  1175
             * 1. No S/MIME option is enabled
Thomas@2299
  1176
             * 2. Force Unencrypted is not enabled
Thomas@2299
  1177
             * 3. Rating is Unsecure
Thomas@2299
  1178
             */
Thomas@2299
  1179
            if ((this.GetIsSMIMEEnabled(control)) ||
Thomas@2299
  1180
                (this.GetDisableForceProtection(control)))
Thomas@2264
  1181
            {
Thomas@2264
  1182
                return false;
Thomas@2264
  1183
            }
Thomas@2264
  1184
Thomas@2264
  1185
            if (this.GetIsPEPEnabled(control))
Thomas@2264
  1186
            {
Thomas@2409
  1187
                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
Thomas@2305
  1188
                           (this.GetForceUnencrypted(control) == false));
Thomas@2264
  1189
            }
Thomas@2264
  1190
            else
Thomas@2264
  1191
            {
Thomas@2305
  1192
                enabled = ((this.GetRating(control) == pEpRating.pEpRatingUnencrypted) &&
Thomas@2305
  1193
                           ((this.GetProperty(control, MailItemExtensions.PEPProperty.EnableProtection) as bool?) ?? false));
Thomas@2264
  1194
            }
Thomas@2264
  1195
Thomas@2264
  1196
            return enabled;
Thomas@1817
  1197
        }
Thomas@1817
  1198
Thomas@1817
  1199
        /// <summary>
Thomas@1795
  1200
        /// Callback to get the label text for the ToggleButtonForceProtection.
Thomas@1795
  1201
        /// </summary>
Thomas@1795
  1202
        public string ToggleButtonForceProtection_GetLabel(Office.IRibbonControl control)
Thomas@1795
  1203
        {
Thomas@2264
  1204
            return Properties.Resources.Ribbon_ForceProtection;
Thomas@1795
  1205
        }
Thomas@1795
  1206
Thomas@1795
  1207
        /// <summary>
Thomas@1817
  1208
        /// Callback to get whether the ToggleButtonForceProtection is pressed.
Thomas@1795
  1209
        /// </summary>
Thomas@1795
  1210
        public bool ToggleButtonForceProtection_GetPressed(Office.IRibbonControl control)
Thomas@1795
  1211
        {
Thomas@2409
  1212
            return ((this.GetForceProtection(control)) &&
Thomas@2305
  1213
                    (this.GetDisableForceProtection(control) == false));
Thomas@1795
  1214
        }
Thomas@1795
  1215
Thomas@1795
  1216
        /// <summary>
Thomas@1817
  1217
        /// Callback to get the supertip/description text for the ToggleButtonForceProtection.
Thomas@1795
  1218
        /// </summary>
Thomas@1795
  1219
        public string ToggleButtonForceProtection_GetSupertip(Office.IRibbonControl control)
Thomas@1795
  1220
        {
Thomas@2264
  1221
            return Properties.Resources.Ribbon_ForceProtectionDesc;
Thomas@1795
  1222
        }
Thomas@1795
  1223
Thomas@1795
  1224
        /// <summary>
Thomas@1817
  1225
        /// Callback to get whether the ToggleButtonForceProtection is visible.
Thomas@1795
  1226
        /// </summary>
Thomas@1795
  1227
        public bool ToggleButtonForceProtection_GetVisible(Office.IRibbonControl control)
Thomas@1795
  1228
        {
Thomas@2672
  1229
            // Disabled for the moment
Thomas@2672
  1230
            return false;
Thomas@2672
  1231
Thomas@2264
  1232
            // Visible if not in Reader mode
Thomas@2672
  1233
            //return (Globals.RELEASE_MODE != Globals.ReleaseMode.Reader);
Dean@1130
  1234
        }
Dean@1130
  1235
Dean@1130
  1236
        ///////////////////////////////////////////////////////////
Dean@1104
  1237
        // ToggleButtonNeverUnsecure
Dean@1096
  1238
        ///////////////////////////////////////////////////////////
Dean@1096
  1239
Dean@1093
  1240
        /// <summary>
Thomas@2264
  1241
        /// Event handler for when the ToggleButtonNeverUnsecure is clicked.
Thomas@2264
  1242
        /// </summary>
Thomas@2264
  1243
        public void ToggleButtonNeverUnsecure_Click(Office.IRibbonControl control, bool isPressed)
Thomas@2264
  1244
        {
Thomas@2299
  1245
            this.SetNeverUnsecure(control, isPressed);
Thomas@2409
  1246
            this.UpdateUI(control);
Thomas@2264
  1247
        }
Thomas@2264
  1248
Thomas@2264
  1249
        /// <summary>
Dean@1104
  1250
        /// Callback to get whether the ToggleButtonNeverUnsecure is enabled.
Dean@1093
  1251
        /// </summary>
Dean@1104
  1252
        public bool ToggleButtonNeverUnsecure_GetEnabled(Office.IRibbonControl control)
Dean@1093
  1253
        {
Thomas@2299
  1254
            // Enabled if not forcefully unencrypted, rating >= Reliable (or force protection), no S/MIME enabled and no BCC recipients
Thomas@2409
  1255
            return (((this.GetRating(control) >= pEpRating.pEpRatingReliable) || (this.GetForceProtection(control)) && (this.ToggleButtonForceProtection_GetEnabled(control))) &&
Thomas@2409
  1256
                    (this.GetForceUnencrypted(control) == false) &&
Thomas@2409
  1257
                    (this.GetIsSMIMEEnabled(control) == false));
Dean@1093
  1258
        }
Dean@1093
  1259
Dean@1093
  1260
        /// <summary>
Dean@1104
  1261
        /// Callback to get the label text for the ToggleButtonNeverUnsecure.
Dean@1093
  1262
        /// </summary>
Dean@1104
  1263
        public string ToggleButtonNeverUnsecure_GetLabel(Office.IRibbonControl control)
Dean@1093
  1264
        {
Thomas@2264
  1265
            return Properties.Resources.Ribbon_NeverUnsecure;
Dean@1093
  1266
        }
Dean@1093
  1267
Dean@1093
  1268
        /// <summary>
Dean@1104
  1269
        /// Callback to get whether the ToggleButtonNeverUnsecure is pressed.
Dean@1093
  1270
        /// </summary>
Dean@1104
  1271
        public bool ToggleButtonNeverUnsecure_GetPressed(Office.IRibbonControl control)
Dean@1093
  1272
        {
Thomas@2299
  1273
            return this.GetNeverUnsecure(control);
Dean@1093
  1274
        }
Dean@1093
  1275
Dean@1093
  1276
        /// <summary>
Dean@1104
  1277
        /// Callback to get the supertip/description text for the ToggleButtonNeverUnsecure.
Dean@1093
  1278
        /// </summary>
Dean@1104
  1279
        public string ToggleButtonNeverUnsecure_GetSupertip(Office.IRibbonControl control)
Dean@1093
  1280
        {
Thomas@2264
  1281
            return Properties.Resources.Ribbon_NeverUnsecureDesc;
Dean@1093
  1282
        }
Dean@1093
  1283
Dean@1093
  1284
        /// <summary>
Dean@1104
  1285
        /// Callback to get whether the ToggleButtonNeverUnsecure is visible.
Dean@1093
  1286
        /// </summary>
Dean@1104
  1287
        public bool ToggleButtonNeverUnsecure_GetVisible(Office.IRibbonControl control)
Dean@1093
  1288
        {
Dean@1314
  1289
            return (Globals.ThisAddIn.Settings.IsNeverUnsecureOptionVisible &&
Dean@1314
  1290
                    (Globals.RELEASE_MODE != Globals.ReleaseMode.Reader));
Dean@1132
  1291
        }
Dean@1132
  1292
Dean@1132
  1293
        ///////////////////////////////////////////////////////////
Dean@1132
  1294
        // ButtonUpgradePEP
Dean@1132
  1295
        ///////////////////////////////////////////////////////////
Dean@1132
  1296
Dean@1132
  1297
        /// <summary>
Thomas@2264
  1298
        /// Event handler for when the Upgrade pEp button is clicked.
Thomas@2264
  1299
        /// </summary>
Thomas@2264
  1300
        public void ButtonUpgradePEP_Click(Office.IRibbonControl control)
Thomas@2264
  1301
        {
Thomas@2264
  1302
            try
Thomas@2264
  1303
            {
Thomas@2264
  1304
                Process.Start(Globals.PEP_WEBSITE_UPGRADE_LINK);
Thomas@2264
  1305
            }
Thomas@2264
  1306
            catch (Exception ex)
Thomas@2264
  1307
            {
Thomas@2264
  1308
                Log.Error("ButtonUpgradePEP_Click: Unable to open website link, " + ex.ToString());
Thomas@2264
  1309
            }
Thomas@2264
  1310
        }
Thomas@2264
  1311
Thomas@2264
  1312
        /// <summary>
Dean@1132
  1313
        /// Callback to get whether the ButtonUpgradePEP is enabled.
Dean@1132
  1314
        /// </summary>
Dean@1132
  1315
        public bool ButtonUpgradePEP_GetEnabled(Office.IRibbonControl control)
Dean@1132
  1316
        {
Dean@1132
  1317
            // Always true, as it has to be clickable while shown
Dean@1132
  1318
            return true;
Dean@1132
  1319
        }
Dean@1132
  1320
Dean@1132
  1321
        /// <summary>
Dean@1132
  1322
        /// Callback to get the image for the ButtonUpgradePEP.
Dean@1132
  1323
        /// </summary>
Dean@1132
  1324
        public System.Drawing.Bitmap ButtonUpgradePEP_GetImage(Office.IRibbonControl control)
Dean@1132
  1325
        {
Thomas@2264
  1326
            return Properties.Resources.ImageUpgradePEP;
Dean@1132
  1327
        }
Dean@1132
  1328
Dean@1132
  1329
        /// <summary>
Dean@1132
  1330
        /// Callback to get the label text for the ButtonUpgradePEP.
Dean@1132
  1331
        /// </summary>
Dean@1132
  1332
        public string ButtonUpgradePEP_GetLabel(Office.IRibbonControl control)
Dean@1132
  1333
        {
Thomas@2264
  1334
            return (Environment.NewLine + Properties.Resources.Ribbon_UpgradePEP);
Dean@1132
  1335
        }
Dean@1132
  1336
Dean@1132
  1337
        /// <summary>
Dean@1132
  1338
        /// Callback to get the supertip/description text for the ButtonUpgradePEP.
Dean@1132
  1339
        /// </summary>
Dean@1132
  1340
        public string ButtonUpgradePEP_GetSupertip(Office.IRibbonControl control)
Dean@1132
  1341
        {
Thomas@2264
  1342
            return Properties.Resources.Ribbon_UpgradePEPDesc;
Dean@1132
  1343
        }
Dean@1132
  1344
Dean@1132
  1345
        /// <summary>
Dean@1132
  1346
        /// Callback to get whether the ButtonUpgradePEP is visible.
Dean@1132
  1347
        /// </summary>
Dean@1132
  1348
        public bool ButtonUpgradePEP_GetVisible(Office.IRibbonControl control)
Dean@1132
  1349
        {
Dean@1132
  1350
            // Only visible in reader mode
Dean@1132
  1351
            return (Globals.RELEASE_MODE == Globals.ReleaseMode.Reader);
Dean@847
  1352
        }
Dean@847
  1353
Dean@1096
  1354
        ///////////////////////////////////////////////////////////
Dean@1096
  1355
        // Groups
Dean@1096
  1356
        ///////////////////////////////////////////////////////////
Dean@1096
  1357
Dean@859
  1358
        /// <summary>
Dean@1096
  1359
        /// Callback to get whether the GroupPEPNewMailMessage is visible.
Dean@859
  1360
        /// </summary>
Dean@1096
  1361
        public bool GroupPEPNewMailMessage_GetVisible(Office.IRibbonControl control)
Dean@859
  1362
        {
Thomas@1870
  1363
            // Always needed
Thomas@1870
  1364
            return true;
nikolaj@1791
  1365
        }
Thomas@1795
  1366
Dean@1096
  1367
        /**************************************************************
Dean@1132
  1368
         *
Dean@478
  1369
         * Callbacks (Contact Inspector Ribbon)
Dean@1132
  1370
         *
Dean@478
  1371
         *************************************************************/
Dean@478
  1372
Thomas@2264
  1373
        ///////////////////////////////////////////////////////////
Thomas@2264
  1374
        // ToggleButtonForceUnencryptedContact
Thomas@2264
  1375
        ///////////////////////////////////////////////////////////
Thomas@2264
  1376
Thomas@2264
  1377
        /// <summary>
Thomas@2264
  1378
        /// Event handler for when the ToggleButtonForceUnencryptedContact is clicked.
Thomas@2264
  1379
        /// </summary>
Thomas@2264
  1380
        public void ToggleButtonForceUnencryptedContact_Click(Office.IRibbonControl control, bool isPressed)
Thomas@2264
  1381
        {
Thomas@2264
  1382
            this.SetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted, isPressed);
Thomas@2409
  1383
            this.UpdateUI(control);
Thomas@2264
  1384
        }
Thomas@2264
  1385
Dean@623
  1386
        /// <summary>
Dean@623
  1387
        /// Callback to get the image for the ToggleButtonForceUnencryptedContact.
Dean@623
  1388
        /// </summary>
Dean@623
  1389
        public System.Drawing.Bitmap ToggleButtonForceUnencryptedContact_GetImage(Office.IRibbonControl control)
Dean@623
  1390
        {
Thomas@2264
  1391
            if ((bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted))
Dean@623
  1392
            {
Thomas@2264
  1393
                return Properties.Resources.ImageForceUnencOn;
Dean@623
  1394
            }
Dean@623
  1395
            else
Dean@623
  1396
            {
Thomas@2264
  1397
                return Properties.Resources.ImageForceUnencOff;
Dean@623
  1398
            }
Dean@623
  1399
        }
Dean@478
  1400
Dean@623
  1401
        /// <summary>
Dean@623
  1402
        /// Callback to get the label text for the ToggleButtonForceUnencryptedContact.
Dean@623
  1403
        /// </summary>
Dean@623
  1404
        public string ToggleButtonForceUnencryptedContact_GetLabel(Office.IRibbonControl control)
Dean@623
  1405
        {
Thomas@2264
  1406
            return Properties.Resources.Ribbon_ForceUnencrypted;
Dean@623
  1407
        }
Dean@623
  1408
Dean@859
  1409
        /// <summary>
Dean@859
  1410
        /// Callback to get whether the ToggleButtonForceUnencryptedContact is pressed.
Dean@859
  1411
        /// </summary>
Dean@859
  1412
        public bool ToggleButtonForceUnencryptedContact_GetPressed(Office.IRibbonControl control)
Dean@859
  1413
        {
Thomas@2264
  1414
            return (bool)this.GetProperty(control, MailItemExtensions.PEPProperty.ForceUnencrypted);
Dean@859
  1415
        }
Dean@859
  1416
Dean@623
  1417
        /// Callback to get the supertip/description text for the ToggleButtonForceUnencryptedContact.
Dean@623
  1418
        /// </summary>
Dean@623
  1419
        public string ToggleButtonForceUnencryptedContact_GetSupertip(Office.IRibbonControl control)
Dean@623
  1420
        {
Thomas@2264
  1421
            return Properties.Resources.Ribbon_ForceUnencryptedDesc;
Dean@623
  1422
        }
Dean@623
  1423
Dean@623
  1424
        /// <summary>
Dean@859
  1425
        /// Callback to get whether the ToggleButtonForceUnencryptedContact is visible.
Dean@623
  1426
        /// </summary>
Dean@859
  1427
        public bool ToggleButtonForceUnencryptedContact_GetVisible(Office.IRibbonControl control)
Dean@623
  1428
        {
Thomas@2264
  1429
            return true;
Dean@623
  1430
        }
Dean@478
  1431
Dean@832
  1432
        /// <summary>
Dean@832
  1433
        /// Callback to get whether the GroupPEPContact is visible.
Dean@832
  1434
        /// </summary>
Dean@832
  1435
        public bool GroupPEPContact_GetVisible(Office.IRibbonControl control)
Dean@832
  1436
        {
Dean@1090
  1437
            return (Globals.ThisAddIn.Settings.IsDisableProtectionForContactsEnabled &&
Dean@860
  1438
                    (Globals.RELEASE_MODE != Globals.ReleaseMode.Reader));
Dean@832
  1439
        }
Dean@832
  1440
Dean@478
  1441
        /**************************************************************
Dean@1132
  1442
         *
Dean@340
  1443
         * Callbacks (Backstage)
Dean@1132
  1444
         *
Dean@338
  1445
         *************************************************************/
Dean@338
  1446
Dean@338
  1447
        /// <summary>
Dean@338
  1448
        /// Callback to get the image for the ButtonAccounts.
Dean@338
  1449
        /// </summary>
Dean@340
  1450
        public System.Drawing.Bitmap ButtonAccounts_GetImage(Office.IRibbonControl control)
Dean@338
  1451
        {
Dean@433
  1452
            return (Properties.Resources.ImageBackstageAccounts);
Dean@338
  1453
        }
Dean@338
  1454
Dean@338
  1455
        /// <summary>
Dean@591
  1456
        /// Callback to get the image for the ButtonCompatibility.
Dean@338
  1457
        /// </summary>
Dean@591
  1458
        public System.Drawing.Bitmap ButtonCompatibility_GetImage(Office.IRibbonControl control)
Dean@338
  1459
        {
Dean@591
  1460
            return (Properties.Resources.ImageBackstageCompatibility);
Dean@338
  1461
        }
Dean@338
  1462
Dean@338
  1463
        /// <summary>
Thomas@2102
  1464
        /// Callback to get the image for the ButtonCompatibility.
Thomas@2102
  1465
        /// </summary>
Thomas@2102
  1466
        public System.Drawing.Bitmap ButtonSync_GetImage(Office.IRibbonControl control)
Thomas@2102
  1467
        {
Thomas@2102
  1468
            return (Properties.Resources.ImageBackstageCompatibility);
Thomas@2102
  1469
        }
Thomas@2102
  1470
Thomas@2102
  1471
        /// <summary>
Dean@338
  1472
        /// Callback to get the image for the ImageControlLogo.
Dean@338
  1473
        /// </summary>
Dean@340
  1474
        public System.Drawing.Bitmap ImageControlLogo_GetImage(Office.IRibbonControl control)
Dean@338
  1475
        {
Dean@338
  1476
            return (Properties.Resources.ImageLogoMedium);
Dean@338
  1477
        }
Dean@338
  1478
Dean@338
  1479
        /// <summary>
Dean@338
  1480
        /// Callback to get the helper text for the GroupAccounts.
Dean@338
  1481
        /// </summary>
Dean@340
  1482
        public string GroupAccounts_GetHelperText(Office.IRibbonControl control)
Dean@338
  1483
        {
Dean@345
  1484
            return (Properties.Resources.Ribbon_GroupAccountsHelperText);
Dean@338
  1485
        }
Dean@338
  1486
Dean@338
  1487
        /// <summary>
Dean@591
  1488
        /// Callback to get the helper text for the GroupCompatibility.
Dean@338
  1489
        /// </summary>
Dean@591
  1490
        public string GroupCompatibility_GetHelperText(Office.IRibbonControl control)
Dean@338
  1491
        {
Dean@591
  1492
            return (Properties.Resources.Ribbon_GroupCompatibilityHelperText);
Dean@338
  1493
        }
Dean@338
  1494
Dean@338
  1495
        /// <summary>
Dean@338
  1496
        /// Callback to get the label text for the GroupAccounts.
Dean@338
  1497
        /// </summary>
Dean@340
  1498
        public string GroupAccounts_GetLabel(Office.IRibbonControl control)
Dean@338
  1499
        {
Dean@345
  1500
            return (Properties.Resources.Ribbon_GroupAccountsLabel);
Dean@338
  1501
        }
Dean@338
  1502
Dean@338
  1503
        /// <summary>
Dean@591
  1504
        /// Callback to get the label text for the GroupCompatibility.
Dean@338
  1505
        /// </summary>
Dean@591
  1506
        public string GroupCompatibility_GetLabel(Office.IRibbonControl control)
Dean@338
  1507
        {
Dean@591
  1508
            return (Properties.Resources.Ribbon_GroupCompatibilityLabel);
Dean@338
  1509
        }
Dean@338
  1510
Dean@338
  1511
        /// <summary>
Thomas@2318
  1512
        /// Callback to get the visibility of the GroupPEPHome.
Thomas@2318
  1513
        /// </summary>
Thomas@2318
  1514
        public bool GroupPEPHome_GetVisible(Office.IRibbonControl control)
Thomas@2318
  1515
        {
Thomas@2318
  1516
            bool visible = true;
Thomas@2318
  1517
Thomas@2467
  1518
            /* In Outlook 2010, there is no inline response.
Thomas@2467
  1519
             * IMPORTANT: Never call Explorer.ActiveInlineResponse on Outlook 2010
Thomas@2467
  1520
             *            as this might lead to a crash of Outlook (even inside a
Thomas@2467
  1521
             *            try/catch block)
Thomas@2687
  1522
             */
Thomas@2467
  1523
            if (Globals.OutlookVersion != Globals.Version.Outlook2010)
Thomas@2323
  1524
            {
Thomas@2467
  1525
                Outlook.Explorer explorer = null;
Thomas@2467
  1526
                try
Thomas@2318
  1527
                {
Thomas@2467
  1528
                    // Show only if no inline response is open
Thomas@2467
  1529
                    explorer = control.Context as Outlook.Explorer;
Thomas@2467
  1530
                    if (explorer != null)
Thomas@2467
  1531
                    {
Thomas@2467
  1532
                        visible = (explorer.ActiveInlineResponse == null);
Thomas@2467
  1533
                    }
Thomas@2409
  1534
                }
Thomas@2467
  1535
                catch (Exception ex)
Thomas@2467
  1536
                {
Thomas@2467
  1537
                    Log.Error("GroupPEPHome_GetVisible: Error occured. " + ex.ToString());
Thomas@2467
  1538
                }
Thomas@2467
  1539
                finally
Thomas@2467
  1540
                {
Thomas@2467
  1541
                    explorer = null;
Thomas@2467
  1542
                }
Thomas@2318
  1543
            }
Thomas@2318
  1544
Thomas@2318
  1545
            return visible;
Thomas@2318
  1546
        }
Thomas@2318
  1547
Thomas@2318
  1548
        /// <summary>
Dean@338
  1549
        /// Callback to get the label text for the ButtonAccounts.
Dean@338
  1550
        /// </summary>
Dean@340
  1551
        public string ButtonAccounts_GetLabel(Office.IRibbonControl control)
Dean@338
  1552
        {
Dean@345
  1553
            return (Properties.Resources.Ribbon_ButtonAccountsLabel);
Dean@338
  1554
        }
Dean@338
  1555
Dean@338
  1556
        /// <summary>
Dean@591
  1557
        /// Callback to get the label text for the ButtonCompatibility.
Dean@338
  1558
        /// </summary>
Dean@591
  1559
        public string ButtonCompatibility_GetLabel(Office.IRibbonControl control)
Dean@338
  1560
        {
Dean@591
  1561
            return (Properties.Resources.Ribbon_ButtonCompatibilityLabel);
Dean@338
  1562
        }
Dean@338
  1563
Dean@338
  1564
        /// <summary>
Dean@338
  1565
        /// Callback to get the label text for the LabelControlName.
Dean@338
  1566
        /// </summary>
Dean@340
  1567
        public string LabelControlName_GetLabel(Office.IRibbonControl control)
Dean@338
  1568
        {
Dean@1132
  1569
            return (Globals.RELEASE_MODE == Globals.ReleaseMode.Reader ? Globals.PEP_DISPLAY_NAME_READER : Globals.PEP_DISPLAY_NAME);
Dean@338
  1570
        }
Dean@340
  1571
Dean@338
  1572
        /// <summary>
Dean@338
  1573
        /// Callback to get the label text for the LabelControlVersion.
Dean@338
  1574
        /// </summary>
Dean@340
  1575
        public string LabelControlVersion_GetLabel(Office.IRibbonControl control)
Dean@338
  1576
        {
Dean@1366
  1577
            return (Globals.GetPEPVersion());
Dean@338
  1578
        }
Dean@340
  1579
Dean@338
  1580
        /// <summary>
Dean@338
  1581
        /// Callback to get the label text for the LabelControlCopyright.
Dean@338
  1582
        /// </summary>
Dean@340
  1583
        public string LabelControlCopyright_GetLabel(Office.IRibbonControl control)
Dean@338
  1584
        {
Dean@878
  1585
            return (Globals.PEP_COPYRIGHT);
Dean@338
  1586
        }
Dean@338
  1587
Dean@338
  1588
        /**************************************************************
Dean@1132
  1589
         *
Dean@335
  1590
         * Event Handling
Dean@1132
  1591
         *
Dean@335
  1592
         *************************************************************/
Dean@340
  1593
Dean@338
  1594
        /// <summary>
Dean@1375
  1595
        /// Event handler for when the ribbon loads.
Dean@338
  1596
        /// </summary>
Dean@335
  1597
        public void Ribbon_Load(Office.IRibbonUI ribbonUI)
Dean@335
  1598
        {
Dean@1375
  1599
            RibbonCustomizations.ribbon = ribbonUI;
Dean@335
  1600
        }
Dean@335
  1601
Dean@340
  1602
        /**************************************************************
Dean@1132
  1603
         *
Thomas@2264
  1604
         * Event Handling (Context menu)
Dean@1132
  1605
         *
Dean@340
  1606
         *************************************************************/
Dean@340
  1607
Dean@340
  1608
        /// <summary>
Thomas@2172
  1609
        /// Event handler for when the key import context menu button is clicked.
Thomas@2172
  1610
        /// </summary>
Thomas@2177
  1611
        public void ContextMenuKeyImportButton_Click(Office.IRibbonControl control)
Thomas@2172
  1612
        {
Thomas@2172
  1613
            Outlook.Store store = null;
Thomas@2172
  1614
            PEPIdentity ownIdentity = null;
Thomas@2172
  1615
Thomas@2172
  1616
            try
Thomas@2172
  1617
            {
Thomas@2172
  1618
                // Get own pEp identity of this store
Thomas@2172
  1619
                store = control.Context as Outlook.Store;
Thomas@2513
  1620
                ownIdentity = store.GetPEPIdentity(true);
Thomas@2172
  1621
Thomas@2172
  1622
                // Open wizard if identity has been successfully retrieved.
Thomas@2172
  1623
                if (ownIdentity != null)
Thomas@2172
  1624
                {
Thomas@2177
  1625
                    // Get wizard type (event can be raised from different buttons)
Thomas@2177
  1626
                    var wizardType = (control?.Id.Equals("ContextMenuKeyImportButtonPGP") == true) ? KeySyncWizard.WizardType.PGP : KeySyncWizard.WizardType.pEp;
Thomas@2177
  1627
                    KeySyncWizard.Wizard = new KeySyncWizard(wizardType, true, ownIdentity);
Thomas@2172
  1628
                    KeySyncWizard.Wizard?.Show();
Thomas@2172
  1629
                }
Thomas@2172
  1630
                else
Thomas@2172
  1631
                {
Thomas@2172
  1632
                    Log.Error("ContextMenuKeyImport_Click: Error getting own identity.");
Thomas@2172
  1633
                }
Thomas@2172
  1634
            }
Thomas@2172
  1635
            catch (Exception ex)
Thomas@2172
  1636
            {
Thomas@2172
  1637
                Log.Error("ContextMenuKeyImport_Click: Error opening wizard. " + ex.ToString());
Thomas@2172
  1638
            }
Thomas@2172
  1639
            finally
Thomas@2172
  1640
            {
Thomas@2172
  1641
                store = null;
Thomas@2172
  1642
            }
Thomas@2172
  1643
        }
Thomas@2172
  1644
Thomas@2687
  1645
        /// <summary>
Thomas@2687
  1646
        /// Event handler for when the reset contact context menu button is clicked.
Thomas@2687
  1647
        /// </summary>
Thomas@2687
  1648
        public void ContextMenuResetContactTrustButton_Click(Office.IRibbonControl control)
Thomas@2687
  1649
        {
Thomas@2687
  1650
            Outlook.Selection selection;
Thomas@2687
  1651
            Outlook.ContactItem contact;
Thomas@2687
  1652
Thomas@2687
  1653
            try
Thomas@2687
  1654
            {
Thomas@2687
  1655
                // Get the selected contact(s) and reset their trust
Thomas@2687
  1656
                selection = control.Context as Outlook.Selection;
Thomas@2687
  1657
Thomas@2687
  1658
                for (int i = 1; i <= selection.Count; i++)
Thomas@2687
  1659
                {
Thomas@2687
  1660
                    contact = selection[i];
Thomas@2687
  1661
                    string id = contact.EntryID;
Thomas@2687
  1662
                    ThisAddIn.PEPEngine.KeyResetUser(id, null);
Thomas@2687
  1663
                    contact = null;
Thomas@2687
  1664
                }
Thomas@2687
  1665
            }
Thomas@2687
  1666
            catch (Exception ex)
Thomas@2687
  1667
            {
Thomas@2687
  1668
                Log.Error("ContextMenuResetContactTrustButton_Click: Error occured. " + ex.ToString());
Thomas@2687
  1669
            }
Thomas@2687
  1670
            finally
Thomas@2687
  1671
            {
Thomas@2687
  1672
                contact = null;
Thomas@2687
  1673
                selection = null;
Thomas@2687
  1674
            }
Thomas@2687
  1675
        }
Thomas@2687
  1676
Dean@340
  1677
        /**************************************************************
Dean@1132
  1678
         *
Dean@340
  1679
         * Event Handling (Backstage)
Dean@1132
  1680
         *
Dean@340
  1681
         *************************************************************/
Dean@340
  1682
Dean@335
  1683
        /// <summary>
Dean@335
  1684
        /// Event handler for when the accounts button is clicked.
Dean@335
  1685
        /// This will open the options form.
Dean@335
  1686
        /// </summary>
Dean@335
  1687
        public void ButtonAccounts_Click(Office.IRibbonControl control)
Dean@335
  1688
        {
Dean@1079
  1689
            this.ShowOptions(FormControlOptions.State.OptionPages.Accounts);
Dean@335
  1690
        }
Dean@335
  1691
Dean@335
  1692
        /// <summary>
Dean@591
  1693
        /// Event handler for when the compatiblity button is clicked.
Dean@335
  1694
        /// This will open the options form.
Dean@335
  1695
        /// </summary>
Dean@591
  1696
        public void ButtonCompatibility_Click(Office.IRibbonControl control)
Dean@335
  1697
        {
Dean@1079
  1698
            this.ShowOptions(FormControlOptions.State.OptionPages.Compatibility);
Dean@335
  1699
        }
Dean@335
  1700
Dean@335
  1701
        /// <summary>
Dean@335
  1702
        /// Event handler for when the about button is clicked.
Dean@335
  1703
        /// This will open the options form.
Dean@335
  1704
        /// </summary>
Dean@335
  1705
        public void ButtonAbout_Click(Office.IRibbonControl control)
Dean@335
  1706
        {
Dean@1079
  1707
            this.ShowOptions(FormControlOptions.State.OptionPages.About);
Dean@335
  1708
        }
Dean@340
  1709
Dean@326
  1710
        #region IRibbonExtensibility Members
Dean@326
  1711
Dean@326
  1712
        public string GetCustomUI(string ribbonID)
Thomas@1820
  1713
        {
Thomas@1820
  1714
            switch (ribbonID)
nikolaj@1711
  1715
            {
nikolaj@1711
  1716
                case "Microsoft.Outlook.Explorer":
Thomas@2409
  1717
                    if (Globals.OutlookVersion == Globals.Version.Outlook2010)
Thomas@2323
  1718
                    {
Thomas@2323
  1719
                        return GetResourceText("pEp.UI.RibbonCustomizationsExplorer2010.xml");
Thomas@2323
  1720
                    }
Thomas@2323
  1721
                    else
Thomas@2323
  1722
                    {
Thomas@2323
  1723
                        return GetResourceText("pEp.UI.RibbonCustomizationsExplorer.xml");
Thomas@2323
  1724
                    }
nikolaj@1711
  1725
                case "Microsoft.Outlook.Mail.Compose":
nikolaj@1711
  1726
                    return GetResourceText("pEp.UI.RibbonCustomizationsCompose.xml");
nikolaj@1711
  1727
                case "Microsoft.Outlook.Mail.Read":
nikolaj@1711
  1728
                    return GetResourceText("pEp.UI.RibbonCustomizationsRead.xml");
nikolaj@1711
  1729
                default:
nikolaj@1711
  1730
                    return GetResourceText("pEp.UI.RibbonCustomizations.xml");
nikolaj@1711
  1731
            }
Dean@326
  1732
        }
Dean@326
  1733
Dean@326
  1734
        #endregion
Dean@326
  1735
Dean@326
  1736
        #region Helpers
Dean@326
  1737
Dean@326
  1738
        private static string GetResourceText(string resourceName)
Dean@326
  1739
        {
Dean@326
  1740
            Assembly asm = Assembly.GetExecutingAssembly();
Dean@326
  1741
            string[] resourceNames = asm.GetManifestResourceNames();
Dean@326
  1742
            for (int i = 0; i < resourceNames.Length; ++i)
Dean@326
  1743
            {
Dean@326
  1744
                if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
Dean@326
  1745
                {
Dean@326
  1746
                    using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
Dean@326
  1747
                    {
Dean@326
  1748
                        if (resourceReader != null)
Dean@326
  1749
                        {
Dean@326
  1750
                            return resourceReader.ReadToEnd();
Dean@326
  1751
                        }
Dean@326
  1752
                    }
Dean@326
  1753
                }
Dean@326
  1754
            }
Dean@326
  1755
            return null;
Dean@326
  1756
        }
Dean@326
  1757
Dean@326
  1758
        #endregion
Dean@326
  1759
    }
Dean@326
  1760
}