From 3e5821b5d7eb16162ccde1b99c804ac0e7edf68b Mon Sep 17 00:00:00 2001 From: WetHat Date: Mon, 6 Feb 2023 09:18:13 +0100 Subject: [PATCH] Issue #89 : Remove illegal access to Settings when logging is registered. Handling exceptions when add-in is connected to OneNote --- OneNoteTaggingKit/Connect.cs | 45 +++++++++++++++++++++--------------- OneNoteTaggingKit/Logger.cs | 7 +++--- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/OneNoteTaggingKit/Connect.cs b/OneNoteTaggingKit/Connect.cs index e13f7d83..c59b4d98 100644 --- a/OneNoteTaggingKit/Connect.cs +++ b/OneNoteTaggingKit/Connect.cs @@ -42,27 +42,34 @@ public class ConnectTaggingKitAddin : IDTExtensibility2, IRibbonExtensibility /// public ConnectTaggingKitAddin() { TraceLogger.Register(); - // Upgrade Settings if necessary. On new version the UpdateRequired flag is - // reset to default (true) - if (Properties.Settings.Default.UpdateRequired) { - Properties.Settings.Default.Upgrade(); - Properties.Settings.Default.UpdateRequired = false; + try { + // Upgrade Settings if necessary. On new version the UpdateRequired flag is + // reset to default (true) + if (Properties.Settings.Default.UpdateRequired) { + Properties.Settings.Default.Upgrade(); + Properties.Settings.Default.UpdateRequired = false; - string knownTags = Properties.Settings.Default.GetPreviousVersion("KnownTags") as string; - if (knownTags != null) { - var tags = new PageTagSet(knownTags, TagFormat.AsEntered); - Properties.Settings.Default.KnownTagsCollection.AddRange((from t in tags select t.ToString()).ToArray()); + string knownTags = Properties.Settings.Default.GetPreviousVersion("KnownTags") as string; + if (knownTags != null) { + var tags = new PageTagSet(knownTags, TagFormat.AsEntered); + Properties.Settings.Default.KnownTagsCollection.AddRange((from t in tags select t.ToString()).ToArray()); + } } - } - switch (Properties.Settings.Default.DisplayLanguage) { - case 1: - TraceLogger.Log(TraceCategory.Info(), "Setting Display Language to English"); - Properties.Resources.Culture = CultureInfo.GetCultureInfo("en"); // Englisch - break; - case 2: - TraceLogger.Log(TraceCategory.Info(), "Setting Display Language to English"); - Properties.Resources.Culture = CultureInfo.GetCultureInfo("zh"); // Chinese - break; + switch (Properties.Settings.Default.DisplayLanguage) { + case 1: + TraceLogger.Log(TraceCategory.Info(), "Setting Display Language to English"); + Properties.Resources.Culture = CultureInfo.GetCultureInfo("en"); // Englisch + break; + case 2: + TraceLogger.Log(TraceCategory.Info(), "Setting Display Language to English"); + Properties.Resources.Culture = CultureInfo.GetCultureInfo("zh"); // Chinese + break; + default: + TraceLogger.Log(TraceCategory.Info(), "Setting Display Language to System"); + break; + } + } catch (Exception ex) { + TraceLogger.ShowGenericErrorBox("Tagging Kit Initialization faled!", ex); } } diff --git a/OneNoteTaggingKit/Logger.cs b/OneNoteTaggingKit/Logger.cs index 88517ccd..5ad47bf8 100644 --- a/OneNoteTaggingKit/Logger.cs +++ b/OneNoteTaggingKit/Logger.cs @@ -176,14 +176,13 @@ internal static void Register() Trace.Listeners.Add(listener); #if DEBUG - string config = "Debug"; + const string config = "Debug"; #else - string config = "Release"; + const string config = "Release"; #endif Log(TraceCategory.Info(), - "{0} logging activated.\r\n\tAddin-Version: {1}\r\n\t.net Framework Version: {2}\r\n\tConfiguration: {3}", - Properties.Resources.TaggingKit_About_Appname, + "OneNote Tagging Kit logging activated.\r\n\tAddin-Version: {1}\r\n\t.net Framework Version: {2}\r\n\tConfiguration: {3}", Assembly.GetExecutingAssembly().GetName().Version, Environment.Version, config