Index: Application/Ringtoets/src/Application.Ringtoets/App.xaml.cs =================================================================== diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Application/Ringtoets/src/Application.Ringtoets/App.xaml.cs (.../App.xaml.cs) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c) +++ Application/Ringtoets/src/Application.Ringtoets/App.xaml.cs (.../App.xaml.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -43,6 +43,7 @@ using Core.Plugins.Map; using Core.Plugins.ProjectExplorer; using log4net; +using log4net.Appender; using Ringtoets.GrassCoverErosionInwards.Plugin; using Ringtoets.HeightStructures.Plugin; using Ringtoets.Integration.Data; @@ -79,7 +80,7 @@ { SetLanguage(); - log.Info(Core.Common.Gui.Properties.Resources.App_Starting_Ringtoets); + log.Info(string.Format(Core.Common.Gui.Properties.Resources.App_Starting_Ringtoets_version_0, SettingsHelper.ApplicationVersion)); } /// @@ -184,7 +185,11 @@ /// private void DeleteOldLogFiles() { - string settingsDirectory = SettingsHelper.GetApplicationLocalUserSettingsDirectory(); + string settingsDirectory = GetLogFileDirectory(); + if (string.IsNullOrWhiteSpace(settingsDirectory)) + { + return; + } foreach (string logFile in Directory.GetFiles(settingsDirectory, "*.log")) { if ((DateTime.Now - File.GetCreationTime(logFile)).TotalDays > numberOfDaysToKeepLogFiles) @@ -194,6 +199,31 @@ } } + private string GetLogFileDirectory() + { + var fileAppender = LogManager.GetAllRepositories() + .SelectMany(r => r.GetAppenders()) + .OfType() + .FirstOrDefault(); + if (fileAppender == null) + { + return string.Empty; + } + + try + { + return Path.GetDirectoryName(fileAppender.File); + } + catch (Exception exception) + { + if (exception is ArgumentException || exception is PathTooLongException) + { + return string.Empty; + } + throw; + } + } + private bool ShutdownIfNotFirstInstance() { var hasMutex = false; @@ -318,14 +348,12 @@ } } }) - { if (exceptionDialog.ShowDialog() == DialogResult.OK) { Restart(); return; } - } } Environment.Exit(1); Index: Application/Ringtoets/src/Application.Ringtoets/app.config =================================================================== diff -u -r9061a3986829cbc8d619a8d9f7a0ea61a67b3dd3 -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Application/Ringtoets/src/Application.Ringtoets/app.config (.../app.config) (revision 9061a3986829cbc8d619a8d9f7a0ea61a67b3dd3) +++ Application/Ringtoets/src/Application.Ringtoets/app.config (.../app.config) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -50,8 +50,8 @@ - - + + Index: Core/Common/src/Core.Common.Gui/Appenders/RingtoetsUserDataFolderConverter.cs =================================================================== diff -u -r4512af7782ee31b36941bb280b54d9da2953dd71 -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Appenders/RingtoetsUserDataFolderConverter.cs (.../RingtoetsUserDataFolderConverter.cs) (revision 4512af7782ee31b36941bb280b54d9da2953dd71) +++ Core/Common/src/Core.Common.Gui/Appenders/RingtoetsUserDataFolderConverter.cs (.../RingtoetsUserDataFolderConverter.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -20,9 +20,7 @@ // All rights reserved. using System.IO; - using Core.Common.Gui.Settings; - using log4net.Util; namespace Core.Common.Gui.Appenders @@ -34,7 +32,7 @@ { protected override void Convert(TextWriter writer, object state) { - var settingsDirectory = SettingsHelper.GetApplicationLocalUserSettingsDirectory(); + var settingsDirectory = SettingsHelper.GetApplicationLocalUserSettingsDirectory(Option); writer.Write(settingsDirectory); } } Index: Core/Common/src/Core.Common.Gui/Commands/ApplicationFeatureCommandHandler.cs =================================================================== diff -u -rb78b6d08e4be8dfe938718d5e65085aa8bd72dcc -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Commands/ApplicationFeatureCommandHandler.cs (.../ApplicationFeatureCommandHandler.cs) (revision b78b6d08e4be8dfe938718d5e65085aa8bd72dcc) +++ Core/Common/src/Core.Common.Gui/Commands/ApplicationFeatureCommandHandler.cs (.../ApplicationFeatureCommandHandler.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -25,12 +25,9 @@ using System.IO; using System.Linq; using System.Windows.Forms; - using Core.Common.Gui.Forms.MainWindow; using Core.Common.Gui.Forms.PropertyGridView; using Core.Common.Gui.Properties; -using Core.Common.Gui.Settings; - using log4net; using log4net.Appender; @@ -68,30 +65,38 @@ public void OpenLogFileExternal() { + var fileAppender = LogManager.GetAllRepositories() + .SelectMany(r => r.GetAppenders()) + .OfType() + .FirstOrDefault(); + if (fileAppender == null || string.IsNullOrWhiteSpace(fileAppender.File)) + { + return; + } + + TryOpenLogFileExternal(fileAppender.File); + } + + private void TryOpenLogFileExternal(string logFile) + { + var logFolderPath = Path.GetDirectoryName(logFile); + try { - var fileAppender = LogManager.GetAllRepositories() - .SelectMany(r => r.GetAppenders()) - .OfType() - .FirstOrDefault(); - if (fileAppender != null) - { - var logFile = fileAppender.File; - Process.Start(logFile); - } + Process.Start(logFile); } catch (Exception e) { - if (e is Win32Exception || e is ObjectDisposedException || e is FileNotFoundException) + if (!string.IsNullOrWhiteSpace(logFolderPath) && (e is Win32Exception || e is ObjectDisposedException || e is FileNotFoundException)) { - MessageBox.Show(Resources.ApplicationFeatureiCommandHandler_OpenLogFileExternal_Unable_to_open_log_file_Opening_log_file_directory_instead, Resources.ApplicationFeatureCommandHandler_OpenLogFileExternal_Unable_to_open_log_file); - Process.Start(SettingsHelper.GetApplicationLocalUserSettingsDirectory()); + MessageBox.Show(Resources.ApplicationFeatureiCommandHandler_OpenLogFileExternal_Unable_to_open_log_file_Opening_log_file_directory_instead, + Resources.ApplicationFeatureCommandHandler_OpenLogFileExternal_Unable_to_open_log_file); + Process.Start(logFolderPath); + return; } - else - { - // Undocumented exception -> Fail Fast! - throw; - } + + // Undocumented exception -> Fail Fast! + throw; } } } Index: Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs =================================================================== diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -107,11 +107,11 @@ } /// - /// Looks up a localized string similar to Ringtoets wordt gestart.... + /// Looks up a localized string similar to Ringtoets versie {0} wordt gestart.... /// - public static string App_Starting_Ringtoets { + public static string App_Starting_Ringtoets_version_0 { get { - return ResourceManager.GetString("App_Starting_Ringtoets", resourceCulture); + return ResourceManager.GetString("App_Starting_Ringtoets_version_0", resourceCulture); } } Index: Core/Common/src/Core.Common.Gui/Properties/Resources.resx =================================================================== diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c) +++ Core/Common/src/Core.Common.Gui/Properties/Resources.resx (.../Resources.resx) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -214,8 +214,8 @@ Help - - Ringtoets wordt gestart... + + Ringtoets versie {0} wordt gestart... Berichten Index: Core/Common/src/Core.Common.Gui/Settings/GuiCoreSettings.cs =================================================================== diff -u -ra5a1a727ccd295ebb9f22e661eaba874e025718c -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Settings/GuiCoreSettings.cs (.../GuiCoreSettings.cs) (revision a5a1a727ccd295ebb9f22e661eaba874e025718c) +++ Core/Common/src/Core.Common.Gui/Settings/GuiCoreSettings.cs (.../GuiCoreSettings.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -46,4 +46,4 @@ /// public string ManualFilePath { get; set; } } -} +} \ No newline at end of file Index: Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs =================================================================== diff -u -r37235d0863116292cc4b095dcf2d19cf6d14c6b2 -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision 37235d0863116292cc4b095dcf2d19cf6d14c6b2) +++ Core/Common/src/Core.Common.Gui/Settings/SettingsHelper.cs (.../SettingsHelper.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -21,7 +21,6 @@ using System; using System.IO; -using System.Reflection; using Core.Common.Utils.Reflection; namespace Core.Common.Gui.Settings @@ -40,7 +39,6 @@ var info = AssemblyUtils.GetExecutingAssemblyInfo(); ApplicationName = info.Product; ApplicationVersion = info.Version; - ApplicationCompany = info.Company; } /// @@ -54,23 +52,15 @@ public static string ApplicationVersion { get; private set; } /// - /// Gets the company that released the application. - /// - public static string ApplicationCompany { get; private set; } - - /// /// Gets the application local user settings directory. /// + /// The postfix path to use after the local application data folder (if any). /// Directory path where the user settings can be found. - public static string GetApplicationLocalUserSettingsDirectory() + public static string GetApplicationLocalUserSettingsDirectory(string postfix) { var localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - var executingAssembly = Assembly.GetExecutingAssembly(); - var assemblyInfo = AssemblyUtils.GetAssemblyInfo(executingAssembly); - var companySettingsDirectoryPath = Path.Combine(localSettingsDirectoryPath, assemblyInfo.Company); + var appSettingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) ? localSettingsDirectoryPath : Path.Combine(localSettingsDirectoryPath, postfix); - var appSettingsDirectoryPath = Path.Combine(companySettingsDirectoryPath, ApplicationName + " " + ApplicationVersion); - if (!Directory.Exists(appSettingsDirectoryPath)) { Directory.CreateDirectory(appSettingsDirectoryPath); Index: Core/Common/test/Core.Common.Gui.Test/Appenders/RingtoetsUserDataFolderConverterTest.cs =================================================================== diff -u -r151bab16a7ebc1bffc0621ab56c6dc219db1e90f -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/test/Core.Common.Gui.Test/Appenders/RingtoetsUserDataFolderConverterTest.cs (.../RingtoetsUserDataFolderConverterTest.cs) (revision 151bab16a7ebc1bffc0621ab56c6dc219db1e90f) +++ Core/Common/test/Core.Common.Gui.Test/Appenders/RingtoetsUserDataFolderConverterTest.cs (.../RingtoetsUserDataFolderConverterTest.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -20,14 +20,10 @@ // All rights reserved. using System.IO; - using Core.Common.Gui.Appenders; using Core.Common.Gui.Settings; - using log4net.Util; - using NUnit.Framework; - using Rhino.Mocks; namespace Core.Common.Gui.Test.Appenders @@ -49,17 +45,24 @@ } [Test] - public void Convert_Always_WriteLocalUserDataDirectory() + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + [TestCase("some string")] + public void Convert_Always_WriteLocalUserDataDirectory(string infix) { // Setup - var settingsDirectory = SettingsHelper.GetApplicationLocalUserSettingsDirectory(); + var settingsDirectory = SettingsHelper.GetApplicationLocalUserSettingsDirectory(infix); var mocks = new MockRepository(); var textWriter = mocks.StrictMock(); textWriter.Expect(w => w.Write(settingsDirectory)); mocks.ReplayAll(); - var converter = new RingtoetsUserDataFolderConverter(); + var converter = new RingtoetsUserDataFolderConverter + { + Option = infix + }; // Call converter.Format(textWriter, null); Index: Core/Common/test/Core.Common.Gui.Test/Commands/ApplicationFeatureCommandHandlerTest.cs =================================================================== diff -u -rb78b6d08e4be8dfe938718d5e65085aa8bd72dcc -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/test/Core.Common.Gui.Test/Commands/ApplicationFeatureCommandHandlerTest.cs (.../ApplicationFeatureCommandHandlerTest.cs) (revision b78b6d08e4be8dfe938718d5e65085aa8bd72dcc) +++ Core/Common/test/Core.Common.Gui.Test/Commands/ApplicationFeatureCommandHandlerTest.cs (.../ApplicationFeatureCommandHandlerTest.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -24,9 +24,7 @@ using Core.Common.Gui.Forms.PropertyGridView; using Core.Common.Gui.PropertyBag; using Core.Common.Gui.Selection; - using NUnit.Framework; - using Rhino.Mocks; namespace Core.Common.Gui.Test.Commands @@ -44,7 +42,6 @@ var propertyResolver = mocks.Stub(); var mainWindow = mocks.Stub(); mainWindow.Expect(w => w.InitPropertiesWindowAndActivate()); - var applicationSelection = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new ApplicationFeatureCommandHandler(propertyResolver, mainWindow); @@ -67,7 +64,6 @@ propertyResolver.Expect(r => r.GetObjectProperties(target)) .Return(mocks.Stub()); var mainWindow = mocks.Stub(); - var applicationSelection = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new ApplicationFeatureCommandHandler(propertyResolver, mainWindow); @@ -91,7 +87,6 @@ propertyResolver.Expect(r => r.GetObjectProperties(target)) .Return(null); var mainWindow = mocks.Stub(); - var applicationSelection = mocks.Stub(); mocks.ReplayAll(); var commandHandler = new ApplicationFeatureCommandHandler(propertyResolver, mainWindow); Index: Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs =================================================================== diff -u -r37235d0863116292cc4b095dcf2d19cf6d14c6b2 -r82b94cbd467ad3e7e5adb525d57b7233a963a726 --- Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision 37235d0863116292cc4b095dcf2d19cf6d14c6b2) +++ Core/Common/test/Core.Common.Gui.Test/Settings/SettingsHelperTest.cs (.../SettingsHelperTest.cs) (revision 82b94cbd467ad3e7e5adb525d57b7233a963a726) @@ -41,7 +41,7 @@ } [Test] - public void ApplicationVersion_RetursnVersionOfExecutingAssembly() + public void ApplicationVersion_ReturnsVersionOfExecutingAssembly() { // Call var settings = SettingsHelper.ApplicationVersion; @@ -51,25 +51,18 @@ } [Test] - public void ApplicationCompany_ReturnsCompanyOfExecutingAssembly() + [TestCase(null)] + [TestCase("")] + [TestCase(" ")] + [TestCase("some directory name")] + public void GetApplicationLocalUserSettingsDirectory_VariousInfixes_ReturnsApplicationLocalUserSettingsDirectory(string postfix) { - // Call - var settings = SettingsHelper.ApplicationCompany; - - // Assert - Assert.AreEqual(AssemblyUtils.GetExecutingAssemblyInfo().Company, settings); - } - - [Test] - public void GetApplicationLocalUserSettingsDirectory_ReturnsApplicationLocalUserSettingsDirectory() - { // Setup var localSettingsDirectoryPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); - var companySettingsDirectoryPath = Path.Combine(localSettingsDirectoryPath, SettingsHelper.ApplicationCompany); - var appSettingsDirectoryPath = Path.Combine(companySettingsDirectoryPath, SettingsHelper.ApplicationName + " " + SettingsHelper.ApplicationVersion); + var appSettingsDirectoryPath = string.IsNullOrWhiteSpace(postfix) ? localSettingsDirectoryPath : Path.Combine(localSettingsDirectoryPath, postfix); // Call - var pathFromSettings = SettingsHelper.GetApplicationLocalUserSettingsDirectory(); + var pathFromSettings = SettingsHelper.GetApplicationLocalUserSettingsDirectory(postfix); // Assert Assert.AreEqual(appSettingsDirectoryPath, pathFromSettings);