diff --git a/Tests/Controller/Elements/ItemsTest.cs b/Tests/Controller/Elements/ItemsTest.cs index 4c602b4..aaed72f 100755 --- a/Tests/Controller/Elements/ItemsTest.cs +++ b/Tests/Controller/Elements/ItemsTest.cs @@ -44,6 +44,7 @@ namespace Tests.Controller.Elements public void TearDown() { ((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges); + Bovender.ComHelpers.ReleaseComObject(_document); } [Test] diff --git a/Tests/Controller/SettingsRepositoryTest.cs b/Tests/Controller/SettingsRepositoryTest.cs index 6e11358..80a02c4 100755 --- a/Tests/Controller/SettingsRepositoryTest.cs +++ b/Tests/Controller/SettingsRepositoryTest.cs @@ -32,14 +32,14 @@ namespace Tests.Controller [SetUp] public void SetUp() { - _savedSettings = zaaReloaded2.Properties.Settings.Default.SettingsRepository; + _savedSettings = zaaReloaded2.UserSettings.Default.SettingsRepository; } [TearDown] public void TearDown() { - zaaReloaded2.Properties.Settings.Default.SettingsRepository = _savedSettings; - zaaReloaded2.Properties.Settings.Default.Save(); + zaaReloaded2.UserSettings.Default.SettingsRepository = _savedSettings; + zaaReloaded2.UserSettings.Default.Save(); } [Test] diff --git a/Tests/Importer/ZaaImporter/LaurisItemTest.cs b/Tests/Importer/ZaaImporter/LaurisItemTest.cs index 47383c9..3caee25 100755 --- a/Tests/Importer/ZaaImporter/LaurisItemTest.cs +++ b/Tests/Importer/ZaaImporter/LaurisItemTest.cs @@ -153,7 +153,7 @@ namespace Tests.Importer.ZaaImporter [TestCase("Albumin (SU)/die: 149.9 [<= 30] mg/d; ", Material.SU)] [TestCase("Gesamt-Eiweiss/Creatinin (PU): 281 [<= 70] mg/g Crea;", Material.U)] - [TestCase("Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; ", Material.B)] + [TestCase("Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; ", Material.S)] public void ParseLaurisMaterial(string laurisString, Material expectedMaterial) { LaurisItem i = new LaurisItem(laurisString); diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 91145c5..70fa036 100755 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -41,16 +41,20 @@ zaaReloaded2.pfx - - ..\packages\Bovender.0.5.0.0\lib\net40\Bovender.dll + + ..\packages\Bovender.0.14.5.0\lib\net40\Bovender.dll True True - - False - ..\packages\NUnit.2.6.4\lib\nunit.framework.dll + + ..\packages\NLog.4.3.7\lib\net40\NLog.dll + True + + + ..\packages\NUnit.3.4.1\lib\net40\nunit.framework.dll + True @@ -66,6 +70,10 @@ + + ..\packages\YamlDotNet.Signed.3.9.0\lib\net35\YamlDotNet.dll + True + @@ -107,6 +115,7 @@ + diff --git a/Tests/app.config b/Tests/app.config new file mode 100755 index 0000000..5974e15 --- /dev/null +++ b/Tests/app.config @@ -0,0 +1,29 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/packages.config b/Tests/packages.config index e347ad9..8e00340 100755 --- a/Tests/packages.config +++ b/Tests/packages.config @@ -1,6 +1,8 @@  - + - + + + \ No newline at end of file diff --git a/deploy/VstoAddinInstaller b/deploy/VstoAddinInstaller index 26f2dda..fba5721 160000 --- a/deploy/VstoAddinInstaller +++ b/deploy/VstoAddinInstaller @@ -1 +1 @@ -Subproject commit 26f2dda3892341a7eaf93df75b765edcf910ca71 +Subproject commit fba57212590cafd9cc650b0602dccb8b0dc39e5b diff --git a/deploy/make-installer.iss b/deploy/make-installer.iss old mode 100644 new mode 100755 index 8358f2c..ff3816b --- a/deploy/make-installer.iss +++ b/deploy/make-installer.iss @@ -8,7 +8,7 @@ #define ADDIN_NAME "zaaReloaded" #define COMPANY "Daniel Kraus (bovender)" #define DESCRIPTION "Word-Addin, das Lauris-Laborwerte in der Zentralen Arztbriefablage formatiert." -#define HOMEPAGE "http://zaa.nephrowiki.de" +#define HOMEPAGE "https://doktorkraus.de/zaareloaded" #define REGKEY "zaaReloaded2" #define SOURCEDIR "..\zaaReloaded2\bin\Release\" diff --git a/www/versioninfo.txt b/www/versioninfo.txt index 466cebf..d09b6f4 100644 --- a/www/versioninfo.txt +++ b/www/versioninfo.txt @@ -1,4 +1,4 @@ -2.2.3 -http://zaa.nephrowiki.de/downloads/zaaReloaded-$VERSION.exe -077df8d43cf97ef4082cda988393734a825b51cf0e023527cdc5752502c83f03 deploy/releases/zaaReloaded-2.2.3.exe +2.2.5 +https://doktorkraus.de/zaareloaded/downloads/zaaReloaded-$VERSION.exe +f5f348b5ffdc532240b63af8fbfd1983219adeee338b9decb3ac3df5f23965ca deploy/releases/zaaReloaded-2.2.5.exe diff --git a/zaaReloaded2/Commands.cs b/zaaReloaded2/Commands.cs index 4fbe14e..f800591 100755 --- a/zaaReloaded2/Commands.cs +++ b/zaaReloaded2/Commands.cs @@ -42,7 +42,7 @@ namespace zaaReloaded2 if (CanFormat()) { SettingsRepository repository = SettingsRepository.Load(); - Guid lastSettingsUid = Properties.Settings.Default.LastSettings; + Guid lastSettingsUid = UserSettings.Default.LastSettings; Settings lastSettings = repository.FindByGuid(lastSettingsUid); if (lastSettings != null) { @@ -72,8 +72,7 @@ namespace zaaReloaded2 SettingsViewModel settingsVM = args.Content.ViewModel as SettingsViewModel; Settings settings = settingsVM.RevealModelObject() as Settings; DoFormat(settings); - Properties.Settings.Default.LastSettings = settings.Uid; - Properties.Settings.Default.Save(); + UserSettings.Default.LastSettings = settings.Uid; }; vm.InjectInto().ShowDialog(); } @@ -108,7 +107,7 @@ namespace zaaReloaded2 + "wenn Word in der Zentralen Arztbriefablage ausgeführt wird.\r" + "Bitte Word als eigenständige Anwendung starten und dann " + "noch einmal versuchen."; - a.OkButtonLabel = "Schließen"; + a.OkButtonText = "Schließen"; a.Invoke(); } else @@ -127,8 +126,8 @@ namespace zaaReloaded2 public static void ShowPreferences() { - ViewModels.PreferencesViewModel.Default.InjectInto() - .ShowDialog(); + ViewModels.PreferencesViewModel vm = new PreferencesViewModel(); + vm.InjectInto().ShowDialog(); } public static void ApplyDanielsStyle() @@ -149,34 +148,45 @@ namespace zaaReloaded2 // (NB Technically, there is never _no_ selection in a document.) Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow; Word.Selection sel = activeWindow.Selection; - if (!(sel.Paragraphs.Count > 1 + Word.Paragraphs paragraphs = sel.Paragraphs; + Word.Document document = activeWindow.Document; + if (!(paragraphs.Count > 1 || (sel.Text.Length > 1 && sel.Text.EndsWith("\r")))) { - if (!Medication.Importer.AutoDetect(activeWindow.Document)) + Logger.Info("FormatDrugs: Attempting to auto-detect"); + if (!Medication.Importer.AutoDetect(document)) { + Logger.Info("FormatDrugs: Failed to auto-detect"); NotificationAction a = new NotificationAction(); a.Caption = "Formatieren nicht möglich"; a.Message = "Das Dokument scheint keine Medikationsliste zu enthalten."; - a.OkButtonLabel = "Schließen"; + a.OkButtonText = "Schließen"; a.Invoke(); return; } } - Medication.Importer importer = new Medication.Importer(activeWindow.Selection.Text); + Logger.Info("FormatDrugs: Importing"); + Medication.Importer importer = new Medication.Importer(sel.Text); Medication.Formatter formatter = new Medication.Formatter(importer.Prescriptions); + Logger.Info("FormatDrugs: Formatting"); switch (columns) { case 1: - formatter.FormatOneColumn(activeWindow.Document); + formatter.FormatOneColumn(document); break; case 2: - formatter.FormatTwoColumns(activeWindow.Document); + formatter.FormatTwoColumns(document); break; default: break; } + Logger.Info("FormatDrugs: Cleaning up"); + Bovender.ComHelpers.ReleaseComObject(document); + Bovender.ComHelpers.ReleaseComObject(paragraphs); + Bovender.ComHelpers.ReleaseComObject(sel); + Bovender.ComHelpers.ReleaseComObject(activeWindow); } #endregion @@ -187,57 +197,84 @@ namespace zaaReloaded2 { // If no "real" selection exists, attempt to auto-detect the lab data. // (NB Technically, there is never _no_ selection in a document.) - Word.Window activeWindow = Globals.ThisAddIn.Application.ActiveWindow; - Word.Selection sel = activeWindow.Selection; - if (!(sel.Paragraphs.Count > 1 - || (sel.Text.Length > 1 && sel.Text.EndsWith("\r")))) + Word.Application word = Globals.ThisAddIn.Application; + Word.Document activeDocument = word.ActiveDocument; + Word.Window activeWindow = word.ActiveWindow; + Word.Selection selection = activeWindow.Selection; + Word.Paragraphs paragraphs = selection.Paragraphs; + if (!(paragraphs.Count > 1 + || (selection.Text.Length > 1 && selection.Text.EndsWith("\r")))) { - if (!AutoDetect.Detect(activeWindow.Document)) + Logger.Info("DoFormat: Attempting to auto-detect"); + Word.Document doc = activeWindow.Document; + if (!AutoDetect.Detect(doc)) { + Logger.Info("DoFormat: Automatic detection failed"); NotificationAction a = new NotificationAction(); a.Caption = "Formatieren nicht möglich"; a.Message = "Das Dokument scheint keine Lauris-Labordaten zu enthalten."; - a.OkButtonLabel = "Schließen"; + a.OkButtonText = "Schließen"; a.Invoke(); return; } + // Don't release the COM object here + // Bovender.ComHelpers.ReleaseComObject(doc); } + Logger.Info("DoFormat: Importing"); ZaaImporter importer = new ZaaImporter(); - importer.Import(Globals.ThisAddIn.Application.ActiveWindow.Selection.Text); - Formatter.Formatter formatter = new Formatter.Formatter( - Globals.ThisAddIn.Application.ActiveDocument); + importer.Import(selection.Text); + Formatter.Formatter formatter = new Formatter.Formatter(activeDocument); + formatter.Settings = settings; formatter.Laboratory = importer.Laboratory; CommentPool.Default.Reset(); CommentPool.Default.FillInComment += CommentPool_FillInComment; try { + Logger.Info("DoFormat: Formatting"); formatter.Run(); } - catch (NoLaboratoryDataException) + catch (NoLaboratoryDataException e) { + Logger.Warn("DoFormat: No lab data?!"); + Logger.Warn(e); NotificationAction a = new NotificationAction(); a.Caption = "Formatieren nicht möglich"; a.Message = "Die aktuelle Markierung scheint keine Labordaten zu enthalten."; - a.OkButtonLabel = "Schließen"; + a.OkButtonText = "Schließen"; a.Invoke(); } + Bovender.ComHelpers.ReleaseComObject(paragraphs); + Bovender.ComHelpers.ReleaseComObject(selection); + Bovender.ComHelpers.ReleaseComObject(activeWindow); + Bovender.ComHelpers.ReleaseComObject(activeDocument); + Logger.Info("DoFormat: Finished"); } private static void CommentPool_FillInComment(object sender, ItemCommentEventArgs e) { - if (Preferences.Default.SuppressItemCommentInteraction) + if (UserSettings.Default.SuppressItemCommentInteraction) { + Logger.Info("CommentPool_FillInComment: Comment interaction is suppressed by user settings"); e.Comment.IsCancelled = true; } else { + Logger.Info("CommentPool_FillInComment: Requesting user interaction"); ItemCommentViewModel vm = new ItemCommentViewModel(e.Comment); vm.InjectInto().ShowDialog(); } } #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Controller/SettingsRepository.cs b/zaaReloaded2/Controller/SettingsRepository.cs index 5e57cc4..e59cd54 100755 --- a/zaaReloaded2/Controller/SettingsRepository.cs +++ b/zaaReloaded2/Controller/SettingsRepository.cs @@ -59,7 +59,7 @@ namespace zaaReloaded2.Controller /// public static SettingsRepository Load() { - string s = Properties.Settings.Default.SettingsRepository; + string s = UserSettings.Default.SettingsRepository; if (String.IsNullOrEmpty(s)) { return new SettingsRepository(); @@ -67,7 +67,7 @@ namespace zaaReloaded2.Controller else { MemoryStream stream = new MemoryStream(); - string encoded = Properties.Settings.Default.SettingsRepository; + string encoded = UserSettings.Default.SettingsRepository; byte[] bytes = Convert.FromBase64String(encoded); stream.Write(bytes, 0, bytes.Length); stream.Position = 0; @@ -94,8 +94,7 @@ namespace zaaReloaded2.Controller serializer.Serialize(stream, this); stream.Position = 0; string encoded = Convert.ToBase64String(stream.ToArray()); - Properties.Settings.Default.SettingsRepository = encoded; - Properties.Settings.Default.Save(); + UserSettings.Default.SettingsRepository = encoded; } #endregion diff --git a/zaaReloaded2/ExceptionHandler/ExceptionViewModel.cs b/zaaReloaded2/ExceptionHandler/ExceptionViewModel.cs index 02b9ae5..d65ef96 100755 --- a/zaaReloaded2/ExceptionHandler/ExceptionViewModel.cs +++ b/zaaReloaded2/ExceptionHandler/ExceptionViewModel.cs @@ -48,7 +48,7 @@ namespace zaaReloaded2.ExceptionHandler { get { - return zaaReloaded2.Updater.Version.CurrentVersion().ToString(); + return zaaReloaded2.Updater.Version.Current.ToString(); } } @@ -86,6 +86,11 @@ namespace zaaReloaded2.ExceptionHandler return @"x:\Code\zaaReloaded2\zaaReloaded2\"; } + protected override Bovender.UserSettings.UserSettingsBase UserSettings + { + get { return zaaReloaded2.UserSettings.Default; } + } + #endregion } } diff --git a/zaaReloaded2/Formatter/Formatter.cs b/zaaReloaded2/Formatter/Formatter.cs index 27c0c2b..b9f2ef7 100755 --- a/zaaReloaded2/Formatter/Formatter.cs +++ b/zaaReloaded2/Formatter/Formatter.cs @@ -272,15 +272,18 @@ namespace zaaReloaded2.Formatter { if (Document != null) { + Logger.Info("CreateStyles"); Style style; // Don't see a better way to check for the existence of a particular // paragraph style than by using a try...catch construction. try { style = Document.Styles[Properties.Settings.Default.StyleParagraph]; + Logger.Info("CreateStyles: Found paragraph style in document"); } catch { + Logger.Info("CreateStyles: Need to create paragraph style"); // Add default paragraph style for laboratory style = Document.Styles.Add(Properties.Settings.Default.StyleParagraph); style.Font.Size = 10; // pt @@ -293,13 +296,16 @@ namespace zaaReloaded2.Formatter style.ParagraphFormat.FirstLineIndent = -36; // pt style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify; } + Bovender.ComHelpers.ReleaseComObject(style); try { style = Document.Styles[Properties.Settings.Default.StyleHeader]; + Logger.Info("CreateStyles: Found header style in document"); } catch { + Logger.Info("CreateStyles: Need to create header style"); // Add header paragraph style for laboratory style = Document.Styles.Add(Properties.Settings.Default.StyleHeader); style.Font.Size = 10; // pt @@ -313,6 +319,7 @@ namespace zaaReloaded2.Formatter style.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphJustify; style.set_NextParagraphStyle(Document.Styles[Properties.Settings.Default.StyleParagraph]); } + Bovender.ComHelpers.ReleaseComObject(style); /* try @@ -422,5 +429,13 @@ namespace zaaReloaded2.Formatter Table _table; #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs index dec443e..e4ac164 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisItem.cs @@ -103,14 +103,17 @@ namespace zaaReloaded2.Importer.ZaaImporter // "HBs-Antigen: neg. ;" // "Erythrozyten (U): + [negativ]" Match match; + Logger.Debug("ParseLauris: {0}", LaurisText); if (_numericalRegex.IsMatch(LaurisText)) { + Logger.Debug("ParseLauris: Numerical match"); match = _numericalRegex.Match(LaurisText); ParseLimits(match); Value = match.Groups["value"].Value.Trim().Replace(',', '.'); } else { + Logger.Debug("ParseLauris: Not a numerical match"); match = _categoricalRegex.Match(LaurisText); Normal = match.Groups["normal"].Value.Trim(); Value = match.Groups["value"].Value.Trim(); @@ -120,6 +123,11 @@ namespace zaaReloaded2.Importer.ZaaImporter OriginalName = match.Groups["name"].Value.Trim(); Name = OriginalName; Unit = match.Groups["unit"].Value.Trim(); + Logger.Debug("ParseLauris: Match: {0}, {1}", Name, Unit); + } + else + { + Logger.Debug("ParseLauris: No match: \"{0}\"", LaurisText); } } @@ -132,9 +140,11 @@ namespace zaaReloaded2.Importer.ZaaImporter { if (match.Groups["limits"].Success) { + Logger.Debug("ParseLimits: Has limits: {0}", match.Groups["limits"].Value); Match limitMatch = _limitRegex.Match(match.Groups["limits"].Value); if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success) { + Logger.Debug("ParseLimits: Upper and lower limit detected"); // Use InvariantCulture because Lauris always outputs dots as decimal separator // Only in rare cases, a comma sneaks in... LowerLimit = Double.Parse(limitMatch.Groups["limit1"].Value.Replace(',', '.'), @@ -144,6 +154,7 @@ namespace zaaReloaded2.Importer.ZaaImporter } else { + Logger.Debug("ParseLimits: Single limit detected"); switch (limitMatch.Groups["operator"].Value.Trim()) { case "<=": @@ -159,9 +170,9 @@ namespace zaaReloaded2.Importer.ZaaImporter // Fixes exception ID 65ca8575. break; default: - throw new InvalidOperationException( - String.Format("Unknown operator in {0}", - match.Groups["limits"].Value)); + string unknown = match.Groups["limits"].Value; + Logger.Fatal("ParseLimits: Unknown operator \"{0}\"", unknown); + throw new InvalidOperationException(String.Format("Unknown operator in {0}",unknown)); } } } @@ -210,5 +221,13 @@ namespace zaaReloaded2.Importer.ZaaImporter static readonly Regex _materialRegex = new Regex(@"\((?(SU|PU))\)"); #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisParagraph.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisParagraph.cs index c81fb5d..54ad8c4 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisParagraph.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisParagraph.cs @@ -23,6 +23,7 @@ using System.Text; using System.Text.RegularExpressions; using zaaReloaded2.Thesaurus; using zaaReloaded2.LabModel; +using Bovender.Extensions; namespace zaaReloaded2.Importer.ZaaImporter { @@ -109,9 +110,11 @@ namespace zaaReloaded2.Importer.ZaaImporter /// void Parse() { + Logger.Info("Parse: \"{0}\"", OriginalParagraph.TruncateWithEllipsis(40)); Match m = _expectedFormat.Match(OriginalParagraph); if (m.Success) { + Logger.Info("Parse: Matches Lauris paragraph format"); Items = new ItemDictionary(); if (m.Groups["caption"].Success) { @@ -127,6 +130,7 @@ namespace zaaReloaded2.Importer.ZaaImporter } else { + Logger.Info("Parse: Does not match Lauris paragraph format"); IsLaurisParagraph = false; } } @@ -140,5 +144,13 @@ namespace zaaReloaded2.Importer.ZaaImporter Thesaurus.Units _unitDictionary; #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs index 06b9c6d..d2b59f9 100755 --- a/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs +++ b/zaaReloaded2/Importer/ZaaImporter/LaurisTimePoint.cs @@ -199,6 +199,7 @@ namespace zaaReloaded2.Importer.ZaaImporter Match m = _timeStampRegex.Match(paragraph); if (m.Success) { + Logger.Info("ParseParagraph: Matches time stamp"); DateTime dt; if (DateTime.TryParseExact( m.Groups["datetime"].Value, @@ -218,22 +219,25 @@ namespace zaaReloaded2.Importer.ZaaImporter // the normal format of a paragraph generated from Lauris. if (m.Groups["tail"].Success) { + Logger.Info("ParseParagraph: Time stamp has a tail -- putting it back with a dummy caption"); paragraph = "DUMMY CAPTION: " + m.Groups["tail"].Value; } else { - paragraph = String.Empty; + paragraph = null; } } if (!String.IsNullOrEmpty(paragraph)) { + Logger.Info("ParseParagraph: Not a time stamp"); LaurisParagraph lp = new LaurisParagraph( paragraph, _parameterDictionary, _unitDictionary); if (lp.IsLaurisParagraph) { + Logger.Debug("ParseParagraph: Merging Lauris paragraph"); Items.Merge(lp.Items); } } @@ -259,5 +263,13 @@ namespace zaaReloaded2.Importer.ZaaImporter Units _unitDictionary; #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs index 3377e3d..c2daefa 100755 --- a/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs +++ b/zaaReloaded2/Importer/ZaaImporter/ZaaImporter.cs @@ -67,15 +67,19 @@ namespace zaaReloaded2.Importer.ZaaImporter /// ZAA-formatted Lauris output to import. public void Import(string text) { + Logger.Info("Import: \"{0}\"", text.TruncateWithEllipsis(120)); string[] paragraphs = Helpers.SplitParagraphs(text); + Logger.Info("Import: {0} paragraph(s)", paragraphs.Length); LaurisTimePoint timePoint = null; foreach (string paragraph in paragraphs) { + Logger.Info("Import: \"{0}\"", paragraph.TruncateWithEllipsis(40)); // If the current paragraph looks like a Lauris time stamp, // create a new time point. if (LaurisTimePoint.IsTimeStampLine(paragraph)) { + Logger.Info("Import: Time stamp detected", paragraph); timePoint = new LaurisTimePoint(paragraph, _parameters, _units); // Add the time point to the laboratory only if none // with the same time stamp exists yet. @@ -94,6 +98,7 @@ namespace zaaReloaded2.Importer.ZaaImporter // if no time point exists yet, create one. else if (LaurisParagraph.ResemblesLaurisParagraph(paragraph)) { + Logger.Info("Import: Lauris paragraph detected"); if (timePoint == null) { timePoint = new LaurisTimePoint(_parameters, _units); @@ -101,6 +106,10 @@ namespace zaaReloaded2.Importer.ZaaImporter } timePoint.AddParagraph(paragraph); } + else + { + Logger.Debug("Import: Neither time stamp, nor Lauris paragraph"); + } } } @@ -123,5 +132,13 @@ namespace zaaReloaded2.Importer.ZaaImporter Units _units; #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/LabModel/LabItem.cs b/zaaReloaded2/LabModel/LabItem.cs index a95de4b..8e2ce7d 100755 --- a/zaaReloaded2/LabModel/LabItem.cs +++ b/zaaReloaded2/LabModel/LabItem.cs @@ -206,13 +206,14 @@ namespace zaaReloaded2.LabModel { get { - if (Material == LabModel.Material.B) + switch (Material) { - return Name; - } - else - { - return String.Format("{0}-{1}", Material.ToString(), Name); + case Material.S: + case Material.E: + case Material.B: + return Name; + default: + return String.Format("{0}-{1}", Material.ToString(), Name); } } } diff --git a/zaaReloaded2/LabModel/Material.cs b/zaaReloaded2/LabModel/Material.cs index c1bf1fe..1b3b2e3 100755 --- a/zaaReloaded2/LabModel/Material.cs +++ b/zaaReloaded2/LabModel/Material.cs @@ -28,6 +28,12 @@ namespace zaaReloaded2.LabModel /// public enum Material { + [Description("Serum")] + /// Serum (default -- first declared) + S, + [Description("EDTA-Blut")] + /// EDTA blood + E, [Description("Blut")] /// Blood B, diff --git a/zaaReloaded2/LogFile.cs b/zaaReloaded2/LogFile.cs new file mode 100755 index 0000000..9a14bb8 --- /dev/null +++ b/zaaReloaded2/LogFile.cs @@ -0,0 +1,109 @@ +/* LogFile.cs + * part of zaaReloaded2 + * + * Copyright 2016 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NLog; +using NLog.Config; +using NLog.Targets; +using NLog.Targets.Wrappers; + +namespace zaaReloaded2 +{ + /// + /// Provides logging to file and to the debug console; wraps + /// NLog configuration and targets. + /// + public class LogFile : Bovender.Logging.LogFile + { + #region Singleton + + new public static LogFile Default { get { return _lazy.Value; } } + + private static readonly Lazy _lazy = new Lazy( + () => + { + LogFile logFile = new LogFile(); + Bovender.Logging.LogFile.LogFileProvider = new Func(() => logFile); + return logFile; + }); + + #endregion + + #region Static properties + + /// + /// Gets whether file logging is enabled, without initializing + /// the singleton instance if it isn't. + /// + new public static bool IsInitializedAndEnabled + { + get + { + return _lazy.IsValueCreated && Default.IsFileLoggingEnabled; + } + } + + #endregion + + #region Properties + + /// + /// Gets the folder where log files are stored. + /// + public override string LogFolder + { + get + { + if (_logFolder == null) + { + _logFolder = System.IO.Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + Properties.Settings.Default.AppDataFolder, + Properties.Settings.Default.UserFolder); + } + return _logFolder; + } + } + + #endregion + + #region Constructor + + private LogFile() + : base() + { } + + #endregion + + #region Private fields + + string _logFolder; + + #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion + } +} diff --git a/zaaReloaded2/Preferences.cs b/zaaReloaded2/Preferences.cs deleted file mode 100755 index 87146fe..0000000 --- a/zaaReloaded2/Preferences.cs +++ /dev/null @@ -1,73 +0,0 @@ -/* Preferences.cs - * part of zaaReloaded2 - * - * Copyright 2015 Daniel Kraus - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace zaaReloaded2 -{ - /// - /// Holds user preferences. - /// - public class Preferences - { - #region Singleton - - public static Preferences Default - { - get - { - return _instance; - } - } - - static readonly Preferences _instance = new Preferences(); - - static Preferences() { } - - #endregion - - #region Properties - - /// - /// Gets or sets whether the add-in should not ask for - /// item comments (i.e. typist mode). - /// - public bool SuppressItemCommentInteraction - { - get - { - return Properties.Settings.Default.SuppressItemCommentInteraction; - } - set - { - Properties.Settings.Default.SuppressItemCommentInteraction = value; - Properties.Settings.Default.Save(); - } - } - - #endregion - - #region Constructors - - protected Preferences() { } - - #endregion - } -} diff --git a/zaaReloaded2/Properties/Settings.Designer.cs b/zaaReloaded2/Properties/Settings.Designer.cs index 31d49bd..8d190b3 100755 --- a/zaaReloaded2/Properties/Settings.Designer.cs +++ b/zaaReloaded2/Properties/Settings.Designer.cs @@ -23,18 +23,6 @@ namespace zaaReloaded2.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string SettingsRepository { - get { - return ((string)(this["SettingsRepository"])); - } - set { - this["SettingsRepository"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2")] @@ -64,7 +52,7 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("http://zaa.nephrowiki.de")] + [global::System.Configuration.DefaultSettingValueAttribute("https://doktorkraus.de/zaareloaded")] public global::System.Uri Homepage { get { return ((global::System.Uri)(this["Homepage"])); @@ -73,7 +61,7 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("http://zaa.nephrowiki.de/versioninfo.txt")] + [global::System.Configuration.DefaultSettingValueAttribute("https://doktorkraus.de/zaareloaded/versioninfo.txt")] public string VersionInfoFile { get { return ((string)(this["VersionInfoFile"])); @@ -82,24 +70,13 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("http://zaa.nephrowiki.de/postreport.php")] + [global::System.Configuration.DefaultSettingValueAttribute("https://doktorkraus.de/zaareloaded/postreport.php")] public string ExceptionPostUrl { get { return ((string)(this["ExceptionPostUrl"])); } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - public global::System.DateTime LastUpdateCheck { - get { - return ((global::System.DateTime)(this["LastUpdateCheck"])); - } - set { - this["LastUpdateCheck"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("http://www.apache.org/licenses/LICENSE-2.0")] @@ -127,18 +104,6 @@ namespace zaaReloaded2.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("00000000-0000-0000-0000-000000000000")] - public global::System.Guid LastSettings { - get { - return ((global::System.Guid)(this["LastSettings"])); - } - set { - this["LastSettings"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2-Laborwerte")] @@ -184,18 +149,6 @@ namespace zaaReloaded2.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string ImportExportPath { - get { - return ((string)(this["ImportExportPath"])); - } - set { - this["ImportExportPath"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2-Überschrift")] @@ -223,30 +176,6 @@ namespace zaaReloaded2.Properties { } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool SuppressItemCommentInteraction { - get { - return ((bool)(this["SuppressItemCommentInteraction"])); - } - set { - this["SuppressItemCommentInteraction"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("False")] - public bool FirstRunWizardShown { - get { - return ((bool)(this["FirstRunWizardShown"])); - } - set { - this["FirstRunWizardShown"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("BITTE_ERGÄNZEN")] @@ -258,25 +187,13 @@ namespace zaaReloaded2.Properties { [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("http://git.bovender.de")] + [global::System.Configuration.DefaultSettingValueAttribute("https://git.bovender.de")] public string Repository { get { return ((string)(this["Repository"])); } } - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool NeedUpgrade { - get { - return ((bool)(this["NeedUpgrade"])); - } - set { - this["NeedUpgrade"] = value; - } - } - [global::System.Configuration.ApplicationScopedSettingAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2-Medikamente")] @@ -285,5 +202,32 @@ namespace zaaReloaded2.Properties { return ((string)(this["DrugsParagraph"])); } } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("user")] + public string UserFolder { + get { + return ((string)(this["UserFolder"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("zaaReloaded2")] + public string AppDataFolder { + get { + return ((string)(this["AppDataFolder"])); + } + } + + [global::System.Configuration.ApplicationScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("settings.yml")] + public string UserSettingsFile { + get { + return ((string)(this["UserSettingsFile"])); + } + } } } diff --git a/zaaReloaded2/Properties/Settings.settings b/zaaReloaded2/Properties/Settings.settings index 3af0473..f5457a6 100755 --- a/zaaReloaded2/Properties/Settings.settings +++ b/zaaReloaded2/Properties/Settings.settings @@ -2,9 +2,6 @@ - - - zaaReloaded2 @@ -15,16 +12,13 @@ Daniel Kraus - http://zaa.nephrowiki.de + https://doktorkraus.de/zaareloaded - http://zaa.nephrowiki.de/versioninfo.txt + https://doktorkraus.de/zaareloaded/versioninfo.txt - http://zaa.nephrowiki.de/postreport.php - - - + https://doktorkraus.de/zaareloaded/postreport.php http://www.apache.org/licenses/LICENSE-2.0 @@ -35,9 +29,6 @@ Standard für NepA - - 00000000-0000-0000-0000-000000000000 - zaaReloaded2-Laborwerte @@ -53,9 +44,6 @@ 2 - - - zaaReloaded2-Überschrift @@ -65,23 +53,23 @@ None - - False - - - False - BITTE_ERGÄNZEN - http://git.bovender.de - - - True + https://git.bovender.de zaaReloaded2-Medikamente + + user + + + zaaReloaded2 + + + settings.yml + \ No newline at end of file diff --git a/zaaReloaded2/ThisAddIn.cs b/zaaReloaded2/ThisAddIn.cs index d901dfc..e434296 100755 --- a/zaaReloaded2/ThisAddIn.cs +++ b/zaaReloaded2/ThisAddIn.cs @@ -24,11 +24,14 @@ using System.Windows; using System.Windows.Input; using System.Windows.Controls; using System.Windows.Media; +using System.Configuration; namespace zaaReloaded2 { public partial class ThisAddIn { + #region Static property + /// /// Gets the subdirectory for addin data in the user profile directory. /// @@ -42,44 +45,77 @@ namespace zaaReloaded2 } } + #endregion + + #region Start up and shut down + private void ThisAddIn_Startup(object sender, System.EventArgs e) { - Bovender.ExceptionHandler.CentralHandler.ManageExceptionCallback += CentralHandler_ManageExceptionCallback; - Bovender.WpfHelpers.RegisterTextBoxSelectAll(); - - if (Properties.Settings.Default.NeedUpgrade) +#if DEBUG + Bovender.Logging.LogFile.Default.EnableDebugLogging(); +#endif + try { - Properties.Settings.Default.Upgrade(); - Properties.Settings.Default.NeedUpgrade = false; - Properties.Settings.Default.Save(); + Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); + if (System.IO.File.Exists(config.FilePath)) + { + System.IO.File.Delete(config.FilePath); + } + } + catch (Exception ex) + { + Logger.Warn("ThisAddIn_Startup: Unable to delete user config file"); + Logger.Warn(ex); } + Bovender.ExceptionHandler.CentralHandler.ManageExceptionCallback += CentralHandler_ManageExceptionCallback; + Bovender.Win32Window.MainWindowHandleProvider = () => + { + return IntPtr.Zero; + }; + Bovender.WpfHelpers.RegisterTextBoxSelectAll(); + UserSettings userSettings = UserSettings.Default; + CheckForUpdates(); - _oldCaption = Globals.ThisAddIn.Application.Caption; - Globals.ThisAddIn.Application.Caption = + Microsoft.Office.Interop.Word.Application word = Globals.ThisAddIn.Application; + _oldCaption = word.Caption; + word.Caption = String.Format( "{0} ({1} {2})", _oldCaption, Properties.Settings.Default.AddinName, - Updater.Version.CurrentVersion().ToString() + Updater.Version.Current.ToString() ); + ViewModels.FirstRunViewModel.InjectIntoIfNeeded(); + Logger.Info("ThisAddIn_Startup: Finished startup"); } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { - if (_updaterVM != null && _updaterVM.IsUpdatePending) + UserSettings.Default.LastVersionSeen = Updater.Version.Current.ToString(); + UserSettings.Default.Save(); + + if (_updaterVM != null && _updaterVM.InstallCommand.CanExecute(null)) { - if (_updaterVM.InstallUpdateCommand.CanExecute(null)) - _updaterVM.InstallUpdateCommand.Execute(null); + Logger.Info("ThisAddIn_Shutdown: Installing update"); + _updaterVM.InstallCommand.Execute(null); } try { + Logger.Info("ThisAddIn_Shutdown: Resetting application caption"); Globals.ThisAddIn.Application.Caption = _oldCaption; } - catch { } + catch (Exception ex) + { + Logger.Warn("ThisAddIn_Shutdown: Failed to reset application caption"); + Logger.Warn(ex); + } + Logger.Info("ThisAddIn_Shutdown: Finished shutdown"); } + #endregion + #region Properties public Ribbon Ribbon @@ -109,24 +145,23 @@ namespace zaaReloaded2 void CheckForUpdates() { - if (DateTime.Today == Properties.Settings.Default.LastUpdateCheck.Date) + // Check only once per day + if (DateTime.Today == UserSettings.Default.LastUpdateCheck.Date) return; - Properties.Settings.Default.LastUpdateCheck = DateTime.Today; - Properties.Settings.Default.Save(); - - _updaterVM = new UpdaterViewModel(new Updater.Updater()); - if (!_updaterVM.CanCheckForUpdate) return; - - _updaterVM.UpdateAvailableMessage.Sent += UpdateAvailableMessage_Sent; - _updaterVM.CheckForUpdateCommand.Execute(null); - } - - void UpdateAvailableMessage_Sent(object sender, MessageArgs e) - { - UpdaterViewModel uvm = e.Content.ViewModel as UpdaterViewModel; - uvm.DestinationFolder = System.IO.Path.GetTempPath(); - uvm.DownloadUpdateCommand.Execute(null); + Logger.Info("CheckForUpdates"); + UserSettings.Default.LastUpdateCheck = DateTime.Today; + ReleaseInfo releaseInfo = new ReleaseInfo(new Uri(Properties.Settings.Default.VersionInfoFile)); + ReleaseInfoViewModel releaseInfoVM = new ReleaseInfoViewModel(releaseInfo, Updater.Version.Current); + releaseInfoVM.UpdateAvailableMessage.Sent += (sender, args) => + { + Logger.Info("CheckForUpdates: Received update-available message"); + Updater.Updater updater = Updater.Updater.CreateDefault(releaseInfo); + updater.DestinationFolder = System.IO.Path.GetTempPath(); + _updaterVM = new UpdaterViewModel(updater); + _updaterVM.StartProcess(); + }; + releaseInfoVM.StartProcess(); } #endregion @@ -145,8 +180,8 @@ namespace zaaReloaded2 #region Private fields Ribbon _ribbon; - UpdaterViewModel _updaterVM; string _oldCaption; + UpdaterViewModel _updaterVM; #endregion @@ -163,5 +198,13 @@ namespace zaaReloaded2 } #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Updater/Updater.cs b/zaaReloaded2/Updater/Updater.cs index fcb4cab..6686100 100755 --- a/zaaReloaded2/Updater/Updater.cs +++ b/zaaReloaded2/Updater/Updater.cs @@ -1,4 +1,5 @@ -/* Updater.cs +using Bovender.Versioning; +/* Updater.cs * part of zaaReloaded2 * * Copyright 2015 Daniel Kraus @@ -24,23 +25,38 @@ namespace zaaReloaded2.Updater { class Updater : Bovender.Versioning.Updater { - protected override Bovender.Versioning.SemanticVersion GetCurrentVersion() + #region Static properties + + public static Updater Default { get; set; } + + #endregion + + #region Public static methods + + public static Updater CreateDefault(IReleaseInfo releaseInfo) { - return Version.CurrentVersion(); + Default = new Updater(releaseInfo); + return Default; } - protected override Uri GetVersionInfoUri() + #endregion + + #region Constructor + + public Updater(Bovender.Versioning.IReleaseInfo releaseInfo) + : base(releaseInfo) { - return new Uri(Properties.Settings.Default.VersionInfoFile); + CurrentVersion = Version.Current; } - protected override string BuildDestinationFileName() - { - return System.IO.Path.Combine( - DestinationFolder, - DownloadUri.ToString().Split('/').Last() - ); - } + #endregion + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion } } diff --git a/zaaReloaded2/Updater/Version.cs b/zaaReloaded2/Updater/Version.cs index f4a526e..9303fe4 100755 --- a/zaaReloaded2/Updater/Version.cs +++ b/zaaReloaded2/Updater/Version.cs @@ -26,18 +26,41 @@ namespace zaaReloaded2.Updater { class Version : SemanticVersion { - #region Static 'overrides' + #region Current version singleton + + public static SemanticVersion Current + { + get + { + return _lazy.Value; + } + } + + private static readonly Lazy _lazy = + new Lazy(() => new Version()); + + #endregion + + #region Public method + + public string BrandName + { + get + { + return Properties.Settings.Default.AddinName + " " + ToString(); + } + } + + #endregion + + #region Constructors /// - /// Returns the current version of the XL Toolbox addin. + /// Creates an instance with the current zaaReloaded2 version /// - /// - new public static SemanticVersion CurrentVersion() - { - return Bovender.Versioning.SemanticVersion.CurrentVersion( - Assembly.GetExecutingAssembly() - ); - } + private Version() : base(Assembly.GetExecutingAssembly()) { } + + public Version(string version) : base(version) { } #endregion } diff --git a/zaaReloaded2/UserSettings.cs b/zaaReloaded2/UserSettings.cs new file mode 100755 index 0000000..8b7e723 --- /dev/null +++ b/zaaReloaded2/UserSettings.cs @@ -0,0 +1,198 @@ +/* UserSettings.cs + * part of zaaReloaded2 + * + * Copyright 2016 Daniel Kraus + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace zaaReloaded2 +{ + [Serializable] + class UserSettings : Bovender.UserSettings.UserSettingsBase + { + #region Static property + + public static string UserSettingsFile + { + get + { + return Path.Combine( + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), + Properties.Settings.Default.AppDataFolder, + Properties.Settings.Default.UserFolder, + Properties.Settings.Default.UserSettingsFile); + } + } + + #endregion + + #region Singleton factory + + new public static UserSettings Default + { + get + { + return _lazy.Value; + } + } + + private static Lazy _lazy = new Lazy(() => + { + // Logger.Info("Initializing singleton instance"); + UserSettings s = FromFileOrDefault(UserSettingsFile); + Bovender.UserSettings.UserSettingsBase.Default = s; + return s; + }); + + #endregion + + #region User settings + + public DateTime LastUpdateCheck + { + get + { + if (_lastUpdateCheck == null) + { + _lastUpdateCheck = new DateTime(2016, 1, 1); + } + return _lastUpdateCheck; + } + set + { + _lastUpdateCheck = value; + } + } + + public string LastVersionSeen + { + get + { + if (_lastVersionSeen == null) + { + _lastVersionSeen = DEFAULT_VERSION; + } + return _lastVersionSeen; + } + set + { + _lastVersionSeen = value; + } + } + + public int UpdateCheckInterval + { + get + { + if (_updateCheckInterval <= 0) + { + _updateCheckInterval = 7; + } + return _updateCheckInterval; + } + set + { + _updateCheckInterval = value; + } + } + + public bool EnableLogging + { + get + { + return LogFile.IsInitializedAndEnabled; + } + set + { + if (value) + { + LogFile.Default.IsFileLoggingEnabled = true; + } + else if (LogFile.IsInitializedAndEnabled) + { + LogFile.Default.IsFileLoggingEnabled = true; + } + } + } + public string ImportExportPath { get; set; } + + public bool SuppressItemCommentInteraction { get; set; } + + public Guid LastSettings + { + get + { + if (_lastSettings == null) + { + _lastSettings = new Guid("00000000-0000-0000-0000-000000000000"); + } + return _lastSettings; + } + set + { + _lastSettings = value; + } + } + + public string SettingsRepository { get; set; } + + [YamlDotNet.Serialization.YamlIgnore] + public bool FirstRun { get { return LastVersionSeen == DEFAULT_VERSION; } } + + #endregion + + #region Private fields + + private DateTime _lastUpdateCheck; + private int _updateCheckInterval; + private string _lastVersionSeen; + private Guid _lastSettings; + private const string DEFAULT_VERSION = "0.0.0"; + + #endregion + + #region Overrides + + public override string GetSettingsFilePath() + { + return UserSettingsFile; + } + + #endregion + + #region Constructor + + /// + /// Creates a new instance. This should never be called directly, use + /// the singleton factory instead. The constructor must be public to + /// enable deserialization. + /// + public UserSettings() { } + + #endregion + + #region Class logger + + private static NLog.Logger Logger { get { return _logger.Value; } } + + private static readonly Lazy _logger = new Lazy(() => NLog.LogManager.GetCurrentClassLogger()); + + #endregion + } +} diff --git a/zaaReloaded2/VERSION b/zaaReloaded2/VERSION index 8d338d7..9a0975e 100755 --- a/zaaReloaded2/VERSION +++ b/zaaReloaded2/VERSION @@ -1,2 +1,2 @@ -2.2.4 -2.2.4.0 +2.2.5 +2.2.5.0 diff --git a/zaaReloaded2/ViewModels/AboutViewModel.cs b/zaaReloaded2/ViewModels/AboutViewModel.cs index 6403a19..dd7e6f7 100755 --- a/zaaReloaded2/ViewModels/AboutViewModel.cs +++ b/zaaReloaded2/ViewModels/AboutViewModel.cs @@ -67,7 +67,7 @@ namespace zaaReloaded2.ViewModels { get { - return zaaReloaded2.Updater.Version.CurrentVersion().ToString(); + return zaaReloaded2.Updater.Version.Current.ToString(); } } diff --git a/zaaReloaded2/ViewModels/FirstRunViewModel.cs b/zaaReloaded2/ViewModels/FirstRunViewModel.cs index 02b0f4b..5b141ce 100755 --- a/zaaReloaded2/ViewModels/FirstRunViewModel.cs +++ b/zaaReloaded2/ViewModels/FirstRunViewModel.cs @@ -40,7 +40,7 @@ namespace zaaReloaded2.ViewModels public static void InjectIntoIfNeeded() where T: System.Windows.Window, new() { - if (!Properties.Settings.Default.FirstRunWizardShown) + if (UserSettings.Default.FirstRun) { FirstRunViewModel vm = new FirstRunViewModel(); vm.InjectInto().Show(); @@ -93,34 +93,19 @@ namespace zaaReloaded2.ViewModels void DoSelectDoctorsMode() { // Properties will be saved by the DoCloseView override. - Properties.Settings.Default.SuppressItemCommentInteraction = false; + UserSettings.Default.SuppressItemCommentInteraction = false; CloseViewCommand.Execute(null); } void DoSelectTypistsMode() { // Properties will be saved by the DoCloseView override. - Properties.Settings.Default.SuppressItemCommentInteraction = true; + UserSettings.Default.SuppressItemCommentInteraction = true; CloseViewCommand.Execute(null); } #endregion - #region Overrides - - /// - /// Sets the FirstRunWizardShown property of the assembly properties - /// to true and calls the base function to close the associated view. - /// - protected override void DoCloseView() - { - Properties.Settings.Default.FirstRunWizardShown = true; - Properties.Settings.Default.Save(); - base.DoCloseView(); - } - - #endregion - #region Implementation of ViewModelBase public override object RevealModelObject() diff --git a/zaaReloaded2/ViewModels/PreferencesViewModel.cs b/zaaReloaded2/ViewModels/PreferencesViewModel.cs index 4242fd7..1de486c 100755 --- a/zaaReloaded2/ViewModels/PreferencesViewModel.cs +++ b/zaaReloaded2/ViewModels/PreferencesViewModel.cs @@ -29,25 +29,47 @@ namespace zaaReloaded2.ViewModels /// public class PreferencesViewModel : ViewModelBase { - #region Singleton + #region Properties - public static PreferencesViewModel Default + public bool SuppressItemCommentInteraction { get { - return _instance; + return _suppressCommentInteraction; + } + set + { + if (value != _suppressCommentInteraction) + { + _suppressCommentInteraction = value; + OnPropertyChanged("SuppressItemCommentInteraction"); + } } } - static PreferencesViewModel() { } + public bool EnableLogging + { + get + { + return _enableLogging; + } + set + { + if (value != _enableLogging) + { + _enableLogging = value; + OnPropertyChanged("EnableLogging"); + } + } + } - static readonly PreferencesViewModel _instance = new PreferencesViewModel(); - - #endregion - - #region Properties - - public bool SuppressItemCommentInteraction { get; set; } + public string LogFolder + { + get + { + return LogFile.Default.LogFolder; + } + } #endregion @@ -67,13 +89,32 @@ namespace zaaReloaded2.ViewModels } } + public DelegatingCommand OpenLogFolderCommand + { + get + { + if (_openLogFolderCommand == null) + { + _openLogFolderCommand = new DelegatingCommand( + param => DoOpenLogFolder(), + param => CanOpenLogFolder()); + } + return _openLogFolderCommand; + } + } + #endregion #region Constructor public PreferencesViewModel() { - SuppressItemCommentInteraction = Preferences.Default.SuppressItemCommentInteraction; + _suppressCommentInteraction = UserSettings.Default.SuppressItemCommentInteraction; + _enableLogging = UserSettings.Default.EnableLogging; + PropertyChanged += (sender, args) => + { + _dirty = true; + }; } #endregion @@ -82,20 +123,45 @@ namespace zaaReloaded2.ViewModels void DoSave() { - Preferences.Default.SuppressItemCommentInteraction = SuppressItemCommentInteraction; + if (_dirty) + { + UserSettings.Default.SuppressItemCommentInteraction = SuppressItemCommentInteraction; + UserSettings.Default.EnableLogging = EnableLogging; + } DoCloseView(); } bool CanSave() { - return true; + return _dirty; + } + + void DoOpenLogFolder() + { + if (CanOpenLogFolder()) + { + System.Diagnostics.Process.Start(LogFolder); + if (!_dirty) + { + CloseViewCommand.Execute(null); + } + } + } + + bool CanOpenLogFolder() + { + return !String.IsNullOrEmpty(LogFolder); } #endregion - #region Field + #region Fields DelegatingCommand _saveCommand; + DelegatingCommand _openLogFolderCommand; + bool _dirty; + bool _enableLogging; + bool _suppressCommentInteraction; #endregion @@ -103,7 +169,7 @@ namespace zaaReloaded2.ViewModels public override object RevealModelObject() { - throw new NotImplementedException(); + return UserSettings.Default; } #endregion diff --git a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs index 34ee606..ebfa517 100755 --- a/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs +++ b/zaaReloaded2/ViewModels/SettingsRepositoryViewModel.cs @@ -445,8 +445,7 @@ namespace zaaReloaded2.ViewModels { if (message.Confirmed) { - Properties.Settings.Default.ImportExportPath = message.Value; - Properties.Settings.Default.Save(); + UserSettings.Default.ImportExportPath = message.Value; Settings settings = LastSelected.RevealModelObject() as Settings; try { @@ -477,8 +476,7 @@ namespace zaaReloaded2.ViewModels { if (message.Confirmed) { - Properties.Settings.Default.ImportExportPath = message.Value; - Properties.Settings.Default.Save(); + UserSettings.Default.ImportExportPath = message.Value; try { Settings settings = Settings.LoadFromFile(message.Value); @@ -495,7 +493,7 @@ namespace zaaReloaded2.ViewModels string SuggestImportExportPath() { - string path = Properties.Settings.Default.ImportExportPath; + string path = UserSettings.Default.ImportExportPath; if (String.IsNullOrEmpty(path)) { return Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); diff --git a/zaaReloaded2/Views/AboutView.xaml b/zaaReloaded2/Views/AboutView.xaml index dab444c..6a46e07 100755 --- a/zaaReloaded2/Views/AboutView.xaml +++ b/zaaReloaded2/Views/AboutView.xaml @@ -38,7 +38,7 @@ Homepage: - + Quellcode: diff --git a/zaaReloaded2/Views/PreferencesView.xaml b/zaaReloaded2/Views/PreferencesView.xaml index 47bbd86..25473a7 100755 --- a/zaaReloaded2/Views/PreferencesView.xaml +++ b/zaaReloaded2/Views/PreferencesView.xaml @@ -23,22 +23,36 @@ xmlns:b="clr-namespace:Bovender.Mvvm.Views.Settings;assembly=Bovender" xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:action="clr-namespace:Bovender.Mvvm.Actions;assembly=Bovender" - SizeToContent="WidthAndHeight" ResizeMode="NoResize" ShowInTaskbar="False" + SizeToContent="WidthAndHeight" ResizeMode="NoResize" + ShowInTaskbar="False" Topmost="True" b:WindowState.CenterScreen="True" b:WindowState.Save="True" Title="Einstellungen" > - + + HorizontalAlignment="Right" Margin="0 20 0 0">