Stop logging warnings when pEp root folder visiblity is set to false more than once.
authorDean
Thu, 08 Sep 2016 13:19:09 +0200
changeset 125225f1d6633620
parent 1251 4fe048bff67e
child 1256 612c4f87e17d
Stop logging warnings when pEp root folder visiblity is set to false more than once.
ThisAddIn.cs
     1.1 --- a/ThisAddIn.cs	Thu Sep 08 12:58:27 2016 +0200
     1.2 +++ b/ThisAddIn.cs	Thu Sep 08 13:19:09 2016 +0200
     1.3 @@ -7,7 +7,6 @@
     1.4  using System.Globalization;
     1.5  using System.IO;
     1.6  using System.Runtime.InteropServices;
     1.7 -using System.Text;
     1.8  using System.Threading;
     1.9  using System.Windows.Forms;
    1.10  using Office = Microsoft.Office.Core;
    1.11 @@ -1836,29 +1835,38 @@
    1.12                          }
    1.13                      }
    1.14  
    1.15 -                    // Attempt to add/remove the store from the session
    1.16 -                    try
    1.17 +                    // Attempt to add/remove the store from the session which set's visiblity
    1.18 +                    if (visible)
    1.19                      {
    1.20 -                        if (visible)
    1.21 +                        try
    1.22                          {
    1.23                              // Release the temp folder before attempting an open/re-open
    1.24                              Marshal.ReleaseComObject(this._PEPStoreRootFolder);
    1.25                              this._PEPStoreRootFolder = null;
    1.26  
    1.27 +                            // After opening it will always be visible
    1.28                              this.OpenPEPStoreRootFolder();
    1.29                          }
    1.30 -                        else
    1.31 +                        catch (Exception e)
    1.32                          {
    1.33 -                            /* Remove the store from the session
    1.34 -                             * Importantly, the pEp store's root folder reference is not released.
    1.35 -                             * This allows the application to continue to use the store.
    1.36 -                             */
    1.37 +                            Log.Warning("SetPEPStoreRootFolderVisibility: Failed to make pEp root folder visible. " + e.ToString());
    1.38 +                        }
    1.39 +                    }
    1.40 +                    else
    1.41 +                    {
    1.42 +                        /* Remove the store from the session which will also hide it in the navigation pane.
    1.43 +                         * Importantly, the pEp store's root folder reference is not released.
    1.44 +                         * This allows the application to continue to use the store.
    1.45 +                         * 
    1.46 +                         * Also note that this call to remove the store will fail if the store is already removed.
    1.47 +                         * This can happen when the visibility is set to false more than once.
    1.48 +                         * Therefore, just try to remove it although don't log any errors.
    1.49 +                         */
    1.50 +                        try
    1.51 +                        {
    1.52                              ns.RemoveStore(this._PEPStoreRootFolder);
    1.53                          }
    1.54 -                    }
    1.55 -                    catch (Exception e)
    1.56 -                    {
    1.57 -                        Log.Warning("SetPEPStoreRootFolderVisibility: Failed to add/remove pEp store. " + e.ToString());
    1.58 +                        catch { }
    1.59                      }
    1.60                  }
    1.61              }