Refactor, using latest bovender framework.

This commit is contained in:
daniel 2016-09-03 23:18:43 +02:00
parent 812042d4bf
commit 63012281db
30 changed files with 797 additions and 357 deletions

View File

@ -44,6 +44,7 @@ namespace Tests.Controller.Elements
public void TearDown()
{
((_Document)_document).Close(WdSaveOptions.wdDoNotSaveChanges);
Bovender.ComHelpers.ReleaseComObject(_document);
}
[Test]

View File

@ -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]

View File

@ -41,8 +41,8 @@
<AssemblyOriginatorKeyFile>zaaReloaded2.pfx</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Bovender, Version=0.14.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<HintPath>..\packages\Bovender.0.14.1.0\lib\net40\Bovender.dll</HintPath>
<Reference Include="Bovender, Version=0.14.4.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<HintPath>..\packages\Bovender.0.14.4.0\lib\net40\Bovender.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Office.Interop.Word, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
@ -52,9 +52,9 @@
<HintPath>..\packages\NLog.4.3.7\lib\net40\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
<Reference Include="nunit.framework, Version=3.4.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.4.1\lib\net40\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
@ -70,8 +70,8 @@
<Reference Include="System.Xaml" />
<Reference Include="System.XML" />
<Reference Include="WindowsBase" />
<Reference Include="YamlDotNet, Version=3.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.3.9.0\lib\net35\YamlDotNet.dll</HintPath>
<Reference Include="YamlDotNet, Version=3.9.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.Signed.3.9.0\lib\net35\YamlDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
@ -115,6 +115,7 @@
<Compile Include="ViewModels\SettingsViewModelTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config" />
<None Include="Tests.licenseheader" />
<None Include="zaaReloaded2.pfx" />

29
Tests/app.config Executable file
View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
app.config
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.
-->
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="YamlDotNet" publicKeyToken="ec19458f3c15af5e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.9.0.0" newVersion="3.9.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Bovender" version="0.14.1.0" targetFramework="net40" />
<package id="Bovender" version="0.14.4.0" targetFramework="net40" />
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
<package id="NLog" version="4.3.7" targetFramework="net40" />
<package id="NUnit" version="2.6.4" targetFramework="net40" />
<package id="YamlDotNet" version="3.9.0" targetFramework="net40" />
<package id="NUnit" version="3.4.1" targetFramework="net40" />
<package id="YamlDotNet.Signed" version="3.9.0" targetFramework="net40" />
</packages>

View File

@ -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<SettingsRepositoryView>().ShowDialog();
}
@ -127,8 +126,8 @@ namespace zaaReloaded2
public static void ShowPreferences()
{
ViewModels.PreferencesViewModel.Default.InjectInto<Views.PreferencesView>()
.ShowDialog();
ViewModels.PreferencesViewModel vm = new PreferencesViewModel();
vm.InjectInto<Views.PreferencesView>().ShowDialog();
}
public static void ApplyDanielsStyle()
@ -149,11 +148,15 @@ 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.";
@ -163,20 +166,27 @@ namespace zaaReloaded2
}
}
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,13 +197,19 @@ 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.";
@ -201,43 +217,64 @@ namespace zaaReloaded2
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.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<ItemCommentView>().ShowDialog();
}
}
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -59,7 +59,7 @@ namespace zaaReloaded2.Controller
/// </remarks>
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

View File

@ -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
}
}

View File

@ -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<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -105,12 +105,14 @@ namespace zaaReloaded2.Importer.ZaaImporter
Match match;
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 +122,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,6 +139,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
{
if (match.Groups["limits"].Success)
{
Logger.Debug("ParseLimits: Has limits");
Match limitMatch = _limitRegex.Match(match.Groups["limits"].Value);
if (limitMatch.Groups["limit1"].Success && limitMatch.Groups["limit2"].Success)
{
@ -210,5 +218,13 @@ namespace zaaReloaded2.Importer.ZaaImporter
static readonly Regex _materialRegex = new Regex(@"\((?<material>(SU|PU))\)");
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -23,6 +23,7 @@ using System.Text;
using System.Text.RegularExpressions;
using zaaReloaded2.Thesaurus;
using zaaReloaded2.LabModel;
using Bovender.Extensions;
namespace zaaReloaded2.Importer.ZaaImporter
{
@ -112,6 +113,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
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 +129,8 @@ namespace zaaReloaded2.Importer.ZaaImporter
}
else
{
Logger.Info("Parse: Does not match Lauris paragraph format");
Logger.Info("Parse: {0}", OriginalParagraph.TruncateWithEllipsis(40));
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<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -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,6 +219,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
// the normal format of a paragraph generated from Lauris.
if (m.Groups["tail"].Success)
{
Logger.Debug("ParseParagraph: Time stamp has tail, adding dummy caption");
paragraph = "DUMMY CAPTION: " + m.Groups["tail"].Value;
}
else
@ -228,12 +230,14 @@ namespace zaaReloaded2.Importer.ZaaImporter
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<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -67,6 +67,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
/// <param name="text">ZAA-formatted Lauris output to import.</param>
public void Import(string text)
{
Logger.Info("Import");
string[] paragraphs = Helpers.SplitParagraphs(text);
LaurisTimePoint timePoint = null;
@ -76,6 +77,7 @@ namespace zaaReloaded2.Importer.ZaaImporter
// create a new time point.
if (LaurisTimePoint.IsTimeStampLine(paragraph))
{
Logger.Info("Import: Time stamp line: {0}", 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 +96,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 +104,11 @@ namespace zaaReloaded2.Importer.ZaaImporter
}
timePoint.AddParagraph(paragraph);
}
else
{
Logger.Debug("Import: Neither time line, nor Lauris paragraph");
Logger.Debug("Import: {0}", paragraph.TruncateWithEllipsis(30));
}
}
}
@ -123,5 +131,13 @@ namespace zaaReloaded2.Importer.ZaaImporter
Units _units;
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -28,6 +28,12 @@ namespace zaaReloaded2.LabModel
/// </summary>
public enum Material
{
[Description("Serum")]
/// Serum (default -- first declared)
S,
[Description("EDTA-Blut")]
/// EDTA blood
E,
[Description("Blut")]
/// Blood
B,

109
zaaReloaded2/LogFile.cs Executable file
View File

@ -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
{
/// <summary>
/// Provides logging to file and to the debug console; wraps
/// NLog configuration and targets.
/// </summary>
public class LogFile : Bovender.Logging.LogFile
{
#region Singleton
new public static LogFile Default { get { return _lazy.Value; } }
private static readonly Lazy<LogFile> _lazy = new Lazy<LogFile>(
() =>
{
LogFile logFile = new LogFile();
Bovender.Logging.LogFile.LogFileProvider = new Func<Bovender.Logging.LogFile>(() => logFile);
return logFile;
});
#endregion
#region Static properties
/// <summary>
/// Gets whether file logging is enabled, without initializing
/// the singleton instance if it isn't.
/// </summary>
new public static bool IsInitializedAndEnabled
{
get
{
return _lazy.IsValueCreated && Default.IsFileLoggingEnabled;
}
}
#endregion
#region Properties
/// <summary>
/// Gets the folder where log files are stored.
/// </summary>
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<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -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
{
/// <summary>
/// Holds user preferences.
/// </summary>
public class Preferences
{
#region Singleton
public static Preferences Default
{
get
{
return _instance;
}
}
static readonly Preferences _instance = new Preferences();
static Preferences() { }
#endregion
#region Properties
/// <summary>
/// Gets or sets whether the add-in should not ask for
/// item comments (i.e. typist mode).
/// </summary>
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
}
}

View File

@ -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")]
@ -89,17 +77,6 @@ namespace zaaReloaded2.Properties {
}
}
[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")]
@ -265,18 +194,6 @@ namespace zaaReloaded2.Properties {
}
}
[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"]));
}
}
}
}

View File

@ -2,9 +2,6 @@
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="zaaReloaded2.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="SettingsRepository" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="AddinName" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2</Value>
</Setting>
@ -23,9 +20,6 @@
<Setting Name="ExceptionPostUrl" Type="System.String" Scope="Application">
<Value Profile="(Default)">http://zaa.nephrowiki.de/postreport.php</Value>
</Setting>
<Setting Name="LastUpdateCheck" Type="System.DateTime" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="LicenseUrl" Type="System.Uri" Scope="Application">
<Value Profile="(Default)">http://www.apache.org/licenses/LICENSE-2.0</Value>
</Setting>
@ -35,9 +29,6 @@
<Setting Name="SettingsNameClinic" Type="System.String" Scope="Application">
<Value Profile="(Default)">Standard für NepA</Value>
</Setting>
<Setting Name="LastSettings" Type="System.Guid" Scope="User">
<Value Profile="(Default)">00000000-0000-0000-0000-000000000000</Value>
</Setting>
<Setting Name="StyleParagraph" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2-Laborwerte</Value>
</Setting>
@ -53,9 +44,6 @@
<Setting Name="SerializationVersion" Type="System.Int32" Scope="Application">
<Value Profile="(Default)">2</Value>
</Setting>
<Setting Name="ImportExportPath" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="StyleHeader" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2-Überschrift</Value>
</Setting>
@ -65,23 +53,23 @@
<Setting Name="AbnormalStyle" Type="zaaReloaded2.Formatter.AbnormalStyle" Scope="Application">
<Value Profile="(Default)">None</Value>
</Setting>
<Setting Name="SuppressItemCommentInteraction" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="FirstRunWizardShown" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="ManualCommentPrompt" Type="System.String" Scope="Application">
<Value Profile="(Default)">BITTE_ERGÄNZEN</Value>
</Setting>
<Setting Name="Repository" Type="System.String" Scope="Application">
<Value Profile="(Default)">http://git.bovender.de</Value>
</Setting>
<Setting Name="NeedUpgrade" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="DrugsParagraph" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2-Medikamente</Value>
</Setting>
<Setting Name="UserFolder" Type="System.String" Scope="Application">
<Value Profile="(Default)">user</Value>
</Setting>
<Setting Name="AppDataFolder" Type="System.String" Scope="Application">
<Value Profile="(Default)">zaaReloaded2</Value>
</Setting>
<Setting Name="UserSettingsFile" Type="System.String" Scope="Application">
<Value Profile="(Default)">settings.yml</Value>
</Setting>
</Settings>
</SettingsFile>

View File

@ -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
/// <summary>
/// Gets the subdirectory for addin data in the user profile directory.
/// </summary>
@ -42,44 +45,73 @@ 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.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<Views.FirstRunView>();
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 +141,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<ViewModelMessageContent> 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 +176,8 @@ namespace zaaReloaded2
#region Private fields
Ribbon _ribbon;
UpdaterViewModel _updaterVM;
string _oldCaption;
UpdaterViewModel _updaterVM;
#endregion
@ -163,5 +194,13 @@ namespace zaaReloaded2
}
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -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<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -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<SemanticVersion> _lazy =
new Lazy<SemanticVersion>(() => new Version());
#endregion
#region Public method
public string BrandName
{
get
{
return Properties.Settings.Default.AddinName + " " + ToString();
}
}
#endregion
#region Constructors
/// <summary>
/// Returns the current version of the XL Toolbox addin.
/// Creates an instance with the current zaaReloaded2 version
/// </summary>
/// <returns></returns>
new public static SemanticVersion CurrentVersion()
{
return Bovender.Versioning.SemanticVersion.CurrentVersion(
Assembly.GetExecutingAssembly()
);
}
private Version() : base(Assembly.GetExecutingAssembly()) { }
public Version(string version) : base(version) { }
#endregion
}

198
zaaReloaded2/UserSettings.cs Executable file
View File

@ -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<UserSettings> _lazy = new Lazy<UserSettings>(() =>
{
// Logger.Info("Initializing singleton instance");
UserSettings s = FromFileOrDefault<UserSettings>(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
/// <summary>
/// Creates a new instance. This should never be called directly, use
/// the singleton factory instead. The constructor must be public to
/// enable deserialization.
/// </summary>
public UserSettings() { }
#endregion
#region Class logger
private static NLog.Logger Logger { get { return _logger.Value; } }
private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
#endregion
}
}

View File

@ -67,7 +67,7 @@ namespace zaaReloaded2.ViewModels
{
get
{
return zaaReloaded2.Updater.Version.CurrentVersion().ToString();
return zaaReloaded2.Updater.Version.Current.ToString();
}
}

View File

@ -40,7 +40,7 @@ namespace zaaReloaded2.ViewModels
public static void InjectIntoIfNeeded<T>()
where T: System.Windows.Window, new()
{
if (!Properties.Settings.Default.FirstRunWizardShown)
if (UserSettings.Default.FirstRun)
{
FirstRunViewModel vm = new FirstRunViewModel();
vm.InjectInto<T>().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
/// <summary>
/// Sets the FirstRunWizardShown property of the assembly properties
/// to true and calls the base function to close the associated view.
/// </summary>
protected override void DoCloseView()
{
Properties.Settings.Default.FirstRunWizardShown = true;
Properties.Settings.Default.Save();
base.DoCloseView();
}
#endregion
#region Implementation of ViewModelBase
public override object RevealModelObject()

View File

@ -29,25 +29,47 @@ namespace zaaReloaded2.ViewModels
/// </summary>
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

View File

@ -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);

View File

@ -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"
>
<Window.Resources>
<ResourceDictionary Source="/Bovender;component/Style.xaml" />
</Window.Resources>
<DockPanel Margin="10">
<DockPanel Margin="20">
<UniformGrid DockPanel.Dock="Bottom" Columns="2" Rows="1"
HorizontalAlignment="Right" Margin="0 10 0 0">
HorizontalAlignment="Right" Margin="0 20 0 0">
<Button Command="{Binding SaveCommand}" Content="OK" IsDefault="True" Margin="0 0 5 0" />
<Button Command="{Binding CloseViewCommand}" Content="Abbrechen" IsCancel="True" Margin="5 0 0 0" />
</UniformGrid>
<GroupBox Header="Sekretariatsmodus" Padding="10">
<CheckBox IsChecked="{Binding SuppressItemCommentInteraction}" Content="Keine Interaktion für _Kommentare">
</CheckBox>
</GroupBox>
<StackPanel>
<GroupBox Header="Sekretariatsmodus" Margin="0 0 0 5" Padding="10">
<StackPanel>
<CheckBox IsChecked="{Binding SuppressItemCommentInteraction}" Content="Keine Interaktion für _Kommentare" />
</StackPanel>
</GroupBox>
<GroupBox Header="Debugging" Margin="0 5 0 0" Padding="10">
<StackPanel>
<CheckBox IsChecked="{Binding EnableLogging}" Content="_Logfile aktivieren" />
<TextBlock Margin="0 10 0 0">
<Hyperlink Command="{Binding OpenLogFolderCommand}">
<TextBlock Text="{Binding LogFolder}" />
</Hyperlink>
</TextBlock>
</StackPanel>
</GroupBox>
</StackPanel>
</DockPanel>
</Window>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<!--
app.config
@ -20,12 +20,9 @@
-->
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="zaaReloaded2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="zaaReloaded2.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<zaaReloaded2.Properties.Settings>
@ -59,9 +56,6 @@
<setting name="StyleParagraph" serializeAs="String">
<value>zaaReloaded2-Laborwerte</value>
</setting>
<setting name="ReferenceStyle" serializeAs="String">
<value>IfSpecialOrAbnormal</value>
</setting>
<setting name="FormatElementLabel" serializeAs="String">
<value>Ausgabe-Elemente</value>
</setting>
@ -77,9 +71,6 @@
<setting name="StyleAbnormal" serializeAs="String">
<value>zaaReloaded2-Pathologisch</value>
</setting>
<setting name="AbnormalStyle" serializeAs="String">
<value>None</value>
</setting>
<setting name="ManualCommentPrompt" serializeAs="String">
<value>BITTE_ERGÄNZEN</value>
</setting>
@ -89,31 +80,23 @@
<setting name="DrugsParagraph" serializeAs="String">
<value>zaaReloaded2-Medikamente</value>
</setting>
<setting name="UserFolder" serializeAs="String">
<value>user</value>
</setting>
<setting name="AppDataFolder" serializeAs="String">
<value>zaaReloaded2</value>
</setting>
<setting name="UserSettingsFile" serializeAs="String">
<value>settings.yml</value>
</setting>
</zaaReloaded2.Properties.Settings>
</applicationSettings>
<userSettings>
<zaaReloaded2.Properties.Settings>
<setting name="SettingsRepository" serializeAs="String">
<value />
</setting>
<setting name="LastUpdateCheck" serializeAs="String">
<value />
</setting>
<setting name="LastSettings" serializeAs="String">
<value>00000000-0000-0000-0000-000000000000</value>
</setting>
<setting name="ImportExportPath" serializeAs="String">
<value />
</setting>
<setting name="SuppressItemCommentInteraction" serializeAs="String">
<value>False</value>
</setting>
<setting name="FirstRunWizardShown" serializeAs="String">
<value>False</value>
</setting>
<setting name="NeedUpgrade" serializeAs="String">
<value>True</value>
</setting>
</zaaReloaded2.Properties.Settings>
</userSettings>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="YamlDotNet" publicKeyToken="ec19458f3c15af5e" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.9.0.0" newVersion="3.9.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -19,8 +19,8 @@
limitations under the License.
-->
<packages>
<package id="Bovender" version="0.14.1.0" targetFramework="net40" />
<package id="Bovender" version="0.14.4.0" targetFramework="net40" />
<package id="Expression.Blend.Sdk" version="1.0.2" targetFramework="net40" />
<package id="NLog" version="4.3.7" targetFramework="net40" />
<package id="YamlDotNet" version="3.9.0" targetFramework="net40" />
<package id="YamlDotNet.Signed" version="3.9.0" targetFramework="net40" />
</packages>

View File

@ -134,8 +134,8 @@
-->
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="Bovender, Version=0.14.1.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<HintPath>..\packages\Bovender.0.14.1.0\lib\net40\Bovender.dll</HintPath>
<Reference Include="Bovender, Version=0.14.4.0, Culture=neutral, PublicKeyToken=df1c15557d8b6df8, processorArchitecture=MSIL">
<HintPath>..\packages\Bovender.0.14.4.0\lib\net40\Bovender.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Expression.Interactions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
@ -146,6 +146,7 @@
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Serialization.Formatters.Soap" />
@ -160,8 +161,8 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="WindowsBase" />
<Reference Include="YamlDotNet, Version=3.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.3.9.0\lib\net35\YamlDotNet.dll</HintPath>
<Reference Include="YamlDotNet, Version=3.9.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.Signed.3.9.0\lib\net35\YamlDotNet.dll</HintPath>
<Private>True</Private>
</Reference>
</ItemGroup>
@ -230,10 +231,10 @@
<Compile Include="Formatter\DanielsStyle.cs" />
<Compile Include="Formatter\DocumentWriter.cs" />
<Compile Include="Formatter\NoLaboratoryDataException.cs" />
<Compile Include="LogFile.cs" />
<Compile Include="Medication\Formatter.cs" />
<Compile Include="Medication\Importer.cs" />
<Compile Include="Medication\Prescription.cs" />
<Compile Include="Preferences.cs" />
<Compile Include="Ribbon.cs" />
<Compile Include="Thesaurus\ThesaurusBase.cs" />
<Compile Include="Formatter\IItemFormatterDictionary.cs" />