Skip to content

Commit

Permalink
#94 - Handled SettingsPropertyNotFoundException throws on first time …
Browse files Browse the repository at this point in the history
…startup because the "KnownTags" propertry is not defined yet
  • Loading branch information
WetHat committed Apr 24, 2023
1 parent 1127c9c commit 916ce9e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions OneNoteTaggingKit/Connect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
using Microsoft.Office.Core;
using Microsoft.Office.Interop.OneNote;
using System;
using System.Configuration;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
using System.Threading.Tasks;
using WetHatLab.OneNote.TaggingKit.common;
using WetHatLab.OneNote.TaggingKit.common.ui;
using WetHatLab.OneNote.TaggingKit.edit;
Expand Down Expand Up @@ -49,11 +48,18 @@ public ConnectTaggingKitAddin() {
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());
try {
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());
}
}
catch (SettingsPropertyNotFoundException) {
// no tags known so far
TraceLogger.Log(TraceCategory.Info(), "No previously defined tags found! Starting with empty tag suggestion list");
}

}
switch (Properties.Settings.Default.DisplayLanguage) {
case 1:
Expand All @@ -69,7 +75,7 @@ public ConnectTaggingKitAddin() {
break;
}
} catch (Exception ex) {
TraceLogger.ShowGenericErrorBox("Tagging Kit Initialization faled!", ex);
TraceLogger.ShowGenericErrorBox("Tagging Kit Initialization failed!", ex);
}
}

Expand Down

0 comments on commit 916ce9e

Please sign in to comment.