Skip to content

Commit

Permalink
Issue #89 : Remove illegal access to Settings when logging is registe…
Browse files Browse the repository at this point in the history
…red. Handling exceptions when add-in is connected to OneNote
  • Loading branch information
WetHat committed Feb 6, 2023
1 parent cba0c61 commit 3e5821b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
45 changes: 26 additions & 19 deletions OneNoteTaggingKit/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,34 @@ public class ConnectTaggingKitAddin : IDTExtensibility2, IRibbonExtensibility
/// </summary>
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);
}
}

Expand Down
7 changes: 3 additions & 4 deletions OneNoteTaggingKit/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e5821b

Please sign in to comment.