From 7005b2138f9d4659c8108966f9c8f69b8673a05b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20P=C3=B6tzl?=
<115746022+josef-poetzl@users.noreply.github.com>
Date: Fri, 17 May 2024 15:52:17 +0200
Subject: [PATCH 1/5] + UserSettingDialog (import from old AccUnit version)
---
source/AccUnit/AccessCodeLib.AccUnit.csproj | 2 +
source/AccUnit/Integration/UserSettings.cs | 110 +++++++++
source/AccUnit/Properties/AssemblyInfo.cs | 4 +-
source/AccUnit/Tools/UserSettings.cs | 111 +++++++++
.../AccessCodeLib.AccUnit.VbeAddIn.csproj | 24 ++
vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs | 6 +-
.../Properties/AssemblyInfo.cs | 4 +-
.../UserSettingWindow/DialogManager.cs | 93 +++++++
.../SettingsPropertyWrapper.cs | 41 ++++
.../UserSettingWindow/SettingsViewModel.cs | 39 +++
.../UserSettingWindow/SettingsWindow.xaml | 23 ++
.../UserSettingWindow/SettingsWindow.xaml.cs | 29 +++
.../UserSettingDialog.Designer.cs | 75 ++++++
.../UserSettingWindow/UserSettingDialog.cs | 26 ++
.../UserSettingDialog.de.resx | 126 ++++++++++
.../UserSettingWindow/UserSettingDialog.resx | 228 ++++++++++++++++++
vbe-add-In/AccUnit.VbeAddIn/UserSettings.cs | 181 ++++++++++++++
17 files changed, 1116 insertions(+), 6 deletions(-)
create mode 100644 source/AccUnit/Integration/UserSettings.cs
create mode 100644 source/AccUnit/Tools/UserSettings.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettings.cs
diff --git a/source/AccUnit/AccessCodeLib.AccUnit.csproj b/source/AccUnit/AccessCodeLib.AccUnit.csproj
index 8d94471..60d52eb 100644
--- a/source/AccUnit/AccessCodeLib.AccUnit.csproj
+++ b/source/AccUnit/AccessCodeLib.AccUnit.csproj
@@ -146,6 +146,7 @@
+
@@ -250,6 +251,7 @@
Settings.settings
+
diff --git a/source/AccUnit/Integration/UserSettings.cs b/source/AccUnit/Integration/UserSettings.cs
new file mode 100644
index 0000000..865a4ca
--- /dev/null
+++ b/source/AccUnit/Integration/UserSettings.cs
@@ -0,0 +1,110 @@
+using AccessCodeLib.AccUnit.Properties;
+using AccessCodeLib.Common.Tools.Logging;
+using System;
+using System.ComponentModel;
+
+namespace AccessCodeLib.AccUnit
+{
+ public class UserSettings
+ {
+ #region Static members
+
+ ///
+ /// Unloads the previously loaded instance provided via property Current.
+ /// This method is mainly needed to support testing the singleton implementation in property Current.
+ ///
+ public static void UnloadCurrent()
+ {
+ _current = null;
+ }
+
+ private static UserSettings _current;
+ public static UserSettings Current
+ {
+ get
+ {
+ if (_current == null)
+ {
+ _current = new UserSettings();
+ _current.Load();
+ }
+ return _current;
+ }
+ set
+ {
+ _current = value ?? throw new ArgumentNullException();
+ }
+ }
+
+ #endregion
+
+ private UserSettings()
+ {
+ }
+
+ public UserSettings Clone()
+ {
+ var clone = new UserSettings
+ {
+ ImportExportFolder = ImportExportFolder,
+ SeparatorChar = SeparatorChar,
+ SeparatorMaxLength = SeparatorMaxLength
+ };
+ return clone;
+ }
+
+ #region Load/Save
+
+ private void Load()
+ {
+ using (new BlockLogger())
+ {
+ ImportExportFolder = Settings.Default.ImportExportFolder;
+ SeparatorMaxLength = Settings.Default.SeparatorMaxLength;
+ SeparatorChar = Settings.Default.SeparatorChar;
+ }
+ }
+
+ public void Save()
+ {
+ Settings.Default.ImportExportFolder = ImportExportFolder;
+ Settings.Default.SeparatorMaxLength = SeparatorMaxLength;
+ Settings.Default.SeparatorChar = SeparatorChar;
+ Settings.Default.Save();
+ }
+
+ #endregion
+
+ #region Setting Properties
+
+ private string _importExportFolder;
+ public string ImportExportFolder
+ {
+ get
+ {
+ return _importExportFolder;
+ }
+ set
+ {
+ _importExportFolder = value.TrimEnd('\\', ' ').TrimStart();
+ }
+ }
+
+ [Category("Text output")]
+ [DefaultValue(60)]
+ [Description("")]
+ // ReSharper disable MemberCanBePrivate.Global
+ public int SeparatorMaxLength { get; set; }
+ // ReSharper restore MemberCanBePrivate.Global
+
+ [Category("Text output")]
+ [DefaultValue('-')]
+ [Description("")]
+ // ReSharper disable MemberCanBePrivate.Global
+ public char SeparatorChar { get; set; }
+ // ReSharper restore MemberCanBePrivate.Global
+
+
+ #endregion
+ }
+}
diff --git a/source/AccUnit/Properties/AssemblyInfo.cs b/source/AccUnit/Properties/AssemblyInfo.cs
index 2ea2cd7..675753b 100644
--- a/source/AccUnit/Properties/AssemblyInfo.cs
+++ b/source/AccUnit/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.9.9.0")]
-[assembly: AssemblyFileVersion("0.9.9.0")]
+[assembly: AssemblyVersion("0.9.10.0")]
+[assembly: AssemblyFileVersion("0.9.10.0")]
diff --git a/source/AccUnit/Tools/UserSettings.cs b/source/AccUnit/Tools/UserSettings.cs
new file mode 100644
index 0000000..447683f
--- /dev/null
+++ b/source/AccUnit/Tools/UserSettings.cs
@@ -0,0 +1,111 @@
+using AccessCodeLib.AccUnit.Properties;
+using AccessCodeLib.AccUnit.Tools.Templates;
+using AccessCodeLib.Common.Tools.Logging;
+using System;
+
+namespace AccessCodeLib.AccUnit.Tools
+{
+ public class UserSettings
+ {
+ #region Static members
+
+ ///
+ /// Unloads the previously loaded instance provided via property Current.
+ /// This method is mainly needed to support testing the singleton implementation in property Current.
+ ///
+ public static void UnloadCurrent()
+ {
+ _current = null;
+ }
+
+ private static UserSettings _current;
+ public static UserSettings Current
+ {
+ get
+ {
+ if (_current == null)
+ {
+ _current = new UserSettings();
+ _current.Load();
+ }
+ return _current;
+ }
+ set
+ {
+ _current = value ?? throw new ArgumentNullException();
+ }
+ }
+
+ #endregion
+
+ private UserSettings()
+ {
+ }
+
+ public UserSettings Clone()
+ {
+ var clone = new UserSettings
+ {
+ TemplateFolder = TemplateFolder,
+ TestTemplates = TestTemplates,
+ UserDefinedTemplates = UserDefinedTemplates,
+ TestMethodTemplate = TestMethodTemplate
+ };
+ return clone;
+ }
+
+ #region Load/Save
+
+ private void Load()
+ {
+ using (new BlockLogger())
+ {
+ TemplateFolder = Settings.Default.TemplateFolder;
+ TestMethodTemplate = GetTestMethodTemplate();
+ TestTemplates = new TestTemplateCollection();
+ UserDefinedTemplates = new TestTemplateCollection(TestTemplates.UserDefinedTemplates);
+ }
+ }
+
+ private static string GetTestMethodTemplate()
+ {
+ var savedTemplate = Settings.Default.TestMethodTemplate;
+ return !string.IsNullOrEmpty(savedTemplate) ? savedTemplate : Resources.DefaultTestMethodTemplate;
+ }
+
+ public void Save()
+ {
+ using (new BlockLogger())
+ {
+ Settings.Default.TestMethodTemplate = TestMethodTemplate;
+ Settings.Default.TemplateFolder = TemplateFolder;
+ Settings.Default.Save();
+ UserDefinedTemplates.Save();
+ TestTemplates = new TestTemplateCollection();
+ }
+ }
+
+ #endregion
+
+ #region Setting Properties
+
+ private string _templateFolder;
+ public string TemplateFolder
+ {
+ get
+ {
+ return _templateFolder;
+ }
+ set
+ {
+ _templateFolder = value.TrimEnd('\\', ' ').TrimStart();
+ }
+ }
+
+ public TestTemplateCollection TestTemplates { get; private set; }
+ public TestTemplateCollection UserDefinedTemplates { get; private set; }
+ public string TestMethodTemplate { get; set; }
+
+ #endregion
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj b/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
index a3bb8af..0c0b630 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
+++ b/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
@@ -92,6 +92,7 @@
+
@@ -135,6 +136,8 @@
+
+
CheckableTreeView.xaml
@@ -223,6 +226,17 @@
+
+
+ SettingsWindow.xaml
+
+
+
+ Form
+
+
+ UserSettingDialog.cs
+
@@ -280,6 +294,12 @@
VbeCommandbars.Designer.cs
Designer
+
+ UserSettingDialog.cs
+
+
+ UserSettingDialog.cs
+
@@ -321,6 +341,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
index cd3b485..50fbec3 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
@@ -27,11 +27,12 @@ internal class AddInManager : IDisposable
private readonly TestStarter _testStarter = new TestStarter();
private readonly TestExplorerManager _testExplorerManager;
+ private readonly DialogManager _dialogManager = new DialogManager();
/*
private readonly TagListManager _tagListManager = new TagListManager();
- private readonly DialogManager _dialogManager = new DialogManager();
+
private readonly TestTemplateGenerator _testTemplateGenerator = new TestTemplateGenerator();
private AccSpecCommandBarAdapterClient _accSpecCommandBarAdapterClient;
private AccSpecManager _accSpecManager;
@@ -130,12 +131,13 @@ private void InitCommandBarsAdapter()
_commandBarsAdapter.AddClient(_testStarter);
_commandBarsAdapter.AddClient(_vbeIntegrationManager);
_commandBarsAdapter.AddClient(_testExplorerManager);
+ _commandBarsAdapter.AddClient(_dialogManager);
/*
_commandBarsAdapter.AddClient(_tagListManager);
_commandBarsAdapter.AddClient(_testTemplateGenerator);
- _commandBarsAdapter.AddClient(_dialogManager);
+
*/
/*
diff --git a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
index a57c307..2f45ad6 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.9.1.0")]
-[assembly: AssemblyFileVersion("0.9.1.0")]
+[assembly: AssemblyVersion("0.9.2.0")]
+[assembly: AssemblyFileVersion("0.9.2.0")]
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs
new file mode 100644
index 0000000..e6742b1
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs
@@ -0,0 +1,93 @@
+using System;
+using System.Windows.Forms;
+using AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow;
+using AccessCodeLib.Common.Tools.Logging;
+using AccessCodeLib.Common.VBIDETools.Commandbar;
+using Microsoft.Office.Core;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn
+{
+ class DialogManager : ICommandBarsAdapterClient
+ {
+
+ public event EventHandler RefreshTestTemplates;
+ /*
+ private static void ShowAboutDialog()
+ {
+ var aboutForm = new AboutForm(AddInManager.FileVersion, AddInManager.SimplyVbUnitVersion);
+ aboutForm.ShowDialog();
+ }
+ */
+
+ #region ICommandBarsAdapterClient support
+
+ public void SubscribeToCommandBarAdapter(VbeCommandBarAdapter commandBarAdapter)
+ {
+ using (new BlockLogger())
+ {
+ if (!(commandBarAdapter is AccUnitCommandBarAdapter accUnitCommandBarAdapter)) return;
+
+ var popUp = accUnitCommandBarAdapter.AccUnitSubMenu;
+ CreateCommandBarItems(commandBarAdapter, popUp);
+ }
+ }
+
+ private void CreateCommandBarItems(VbeCommandBarAdapter commandBarAdapter, CommandBarPopup popUp)
+ {
+ var buttonData = new CommandbarButtonData
+ {
+ Caption = Resources.VbeCommandbars.ToolsUserSettingFormCommandbarButtonCaption,
+ Description = string.Empty,
+ FaceId = 222,
+ BeginGroup = true
+ };
+ commandBarAdapter.AddCommandBarButton(popUp, buttonData, AccUnitMenuItemsShowUserSettingForm);
+ /*
+ buttonData = new CommandbarButtonData
+ {
+ Caption = Resources.VbeCommandbars.ToolsAboutCommandbarButtonCaption,
+ Description = string.Empty,
+ FaceId = 487,
+ BeginGroup = true
+ };
+ commandBarAdapter.AddCommandBarButton(popUp, buttonData, AccUnitMenuItemsShowAboutForm);
+ */
+ }
+
+ /*
+ static void AccUnitMenuItemsShowAboutForm(CommandBarButton ctrl, ref bool cancelDefault)
+ {
+ ShowAboutDialog();
+ }
+ */
+
+ void AccUnitMenuItemsShowUserSettingForm(CommandBarButton ctrl, ref bool cancelDefault)
+ {
+ try
+ {
+ /*
+ var dialog = new SettingsWindow(new SettingsViewModel());
+ dialog.ShowDialog();
+ */
+
+ using (var settingDialog = new UserSettingDialog())
+ {
+ settingDialog.Settings = UserSettings.Current.Clone();
+ if (settingDialog.ShowDialog() == DialogResult.OK)
+ {
+ UserSettings.Current = settingDialog.Settings as UserSettings;
+ UserSettings.Current?.Save();
+ RefreshTestTemplates?.Invoke(this, null);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ UITools.ShowException(ex);
+ }
+ }
+
+ #endregion
+
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
new file mode 100644
index 0000000..3493cf4
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
+{
+ internal class SettingsPropertyWrapper : INotifyPropertyChanged
+ {
+ private readonly PropertyInfo _propertyInfo;
+ private readonly Properties.Settings _settings;
+
+ public SettingsPropertyWrapper(PropertyInfo propertyInfo, Properties.Settings settings)
+ {
+ _propertyInfo = propertyInfo;
+ _settings = settings;
+ }
+
+ public string Name => _propertyInfo.Name;
+
+ public object Value
+ {
+ get { return _propertyInfo.GetValue(_settings); }
+ set
+ {
+ _propertyInfo.SetValue(_settings, value);
+ OnPropertyChanged(nameof(Value));
+ }
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ protected void OnPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
new file mode 100644
index 0000000..aff0542
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
+{
+ internal class SettingsViewModel
+ {
+ public ObservableCollection SettingsProperties { get; private set; }
+ public ICommand SaveCommand { get; private set; }
+
+ public SettingsViewModel()
+ {
+ SettingsProperties = new ObservableCollection();
+
+ foreach (PropertyInfo property in typeof(Properties.Settings).GetProperties(BindingFlags.Public | BindingFlags.Instance))
+ {
+ if (property.CanRead && property.CanWrite)
+ {
+ SettingsProperties.Add(new SettingsPropertyWrapper(property, Properties.Settings.Default));
+ }
+ }
+
+ SaveCommand = new RelayCommand(SaveSettings);
+ }
+
+ public void SaveSettings()
+ {
+ Properties.Settings.Default.Save();
+ }
+ }
+
+
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
new file mode 100644
index 0000000..c53b602
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
new file mode 100644
index 0000000..9e83e83
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
+{
+ ///
+ /// Interaction logic for SettingsWindow.xaml
+ ///
+ public partial class SettingsWindow : Window
+ {
+ internal SettingsWindow(SettingsViewModel dataContext)
+ {
+ DataContext = dataContext;
+ InitializeComponent();
+ }
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs
new file mode 100644
index 0000000..8fb37ce
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs
@@ -0,0 +1,75 @@
+namespace AccessCodeLib.AccUnit.VbeAddIn
+{
+ partial class UserSettingDialog
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserSettingDialog));
+ this.SettingPropertyGrid = new System.Windows.Forms.PropertyGrid();
+ this.OkBtn = new System.Windows.Forms.Button();
+ this.CancelBtn = new System.Windows.Forms.Button();
+ this.SuspendLayout();
+ //
+ // SettingPropertyGrid
+ //
+ resources.ApplyResources(this.SettingPropertyGrid, "SettingPropertyGrid");
+ this.SettingPropertyGrid.Name = "SettingPropertyGrid";
+ //
+ // OkBtn
+ //
+ resources.ApplyResources(this.OkBtn, "OkBtn");
+ this.OkBtn.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.OkBtn.Name = "OkBtn";
+ this.OkBtn.UseVisualStyleBackColor = true;
+ //
+ // CancelBtn
+ //
+ resources.ApplyResources(this.CancelBtn, "CancelBtn");
+ this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
+ this.CancelBtn.Name = "CancelBtn";
+ this.CancelBtn.UseVisualStyleBackColor = true;
+ //
+ // UserSettingDialog
+ //
+ this.AcceptButton = this.OkBtn;
+ resources.ApplyResources(this, "$this");
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.Controls.Add(this.CancelBtn);
+ this.Controls.Add(this.OkBtn);
+ this.Controls.Add(this.SettingPropertyGrid);
+ this.Name = "UserSettingDialog";
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private System.Windows.Forms.PropertyGrid SettingPropertyGrid;
+ protected System.Windows.Forms.Button CancelBtn;
+ private System.Windows.Forms.Button OkBtn;
+ }
+}
\ No newline at end of file
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs
new file mode 100644
index 0000000..dbb8020
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs
@@ -0,0 +1,26 @@
+using System.Windows.Forms;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn
+{
+ public partial class UserSettingDialog : Form
+ {
+ public UserSettingDialog()
+ {
+ InitializeComponent();
+ Icon = UITools.ConvertBitmapToIcon(Resources.Icons.settings);
+ }
+
+ public object Settings
+ {
+ get
+ {
+ return SettingPropertyGrid.SelectedObject;
+ }
+ set
+ {
+ SettingPropertyGrid.SelectedObject = value;
+ }
+ }
+
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx
new file mode 100644
index 0000000..b85b4eb
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx
@@ -0,0 +1,126 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ &Abbrechen
+
+
+ AccUnit Einstellungen
+
+
\ No newline at end of file
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx
new file mode 100644
index 0000000..93a3395
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx
@@ -0,0 +1,228 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+
+ Top, Bottom, Left, Right
+
+
+
+ 0, 0
+
+
+ 561, 449
+
+
+
+ 0
+
+
+ SettingPropertyGrid
+
+
+ System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ $this
+
+
+ 2
+
+
+ Bottom, Left
+
+
+ 15, 465
+
+
+ 114, 27
+
+
+ 1
+
+
+ &OK
+
+
+ OkBtn
+
+
+ System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ $this
+
+
+ 1
+
+
+ Bottom, Right
+
+
+ 433, 465
+
+
+ 114, 27
+
+
+ 2
+
+
+ &Cancel
+
+
+ CancelBtn
+
+
+ System.Windows.Forms.Button, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ $this
+
+
+ 0
+
+
+ True
+
+
+ 7, 15
+
+
+ GrowAndShrink
+
+
+ 561, 505
+
+
+ Segoe UI, 9pt
+
+
+ CenterParent
+
+
+ AccUnit Settings
+
+
+ UserSettingDialog
+
+
+ System.Windows.Forms.Form, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettings.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettings.cs
new file mode 100644
index 0000000..d93c51f
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/UserSettings.cs
@@ -0,0 +1,181 @@
+using AccessCodeLib.AccUnit.Tools.Templates;
+using AccessCodeLib.Common.Tools.Logging;
+using System;
+using System.ComponentModel;
+using System.ComponentModel.Design;
+using System.Drawing.Design;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn
+{
+ public class UserSettings
+ {
+ #region Static members
+
+ ///
+ /// Unloads the previously loaded instance provided via property Current.
+ /// This method is mainly needed to support testing the singleton implementation in property Current.
+ ///
+ public static void UnloadCurrent()
+ {
+ _current = null;
+ AccUnit.UserSettings.UnloadCurrent();
+ Tools.UserSettings.UnloadCurrent();
+ }
+
+ private static UserSettings _current;
+ public static UserSettings Current
+ {
+ get
+ {
+ if (_current == null)
+ {
+ _current = new UserSettings();
+ _current.Load();
+ }
+ return _current;
+ }
+ set
+ {
+ _current = value ?? throw new ArgumentNullException();
+ }
+ }
+
+ #endregion
+
+ private AccUnit.UserSettings _testSuiteUserSettings;
+ private Tools.UserSettings _toolsUserSettings;
+ //private AccSpec.Integration.UserSettings _accSpecUserSettings;
+
+ private UserSettings()
+ {
+ }
+
+ public UserSettings Clone()
+ {
+ using (new BlockLogger())
+ {
+ var clone = new UserSettings
+ {
+ _testSuiteUserSettings = AccUnit.UserSettings.Current.Clone(),
+ _toolsUserSettings = Tools.UserSettings.Current.Clone(),
+ //_accSpecUserSettings = AccSpec.Integration.UserSettings.Current.Clone(),
+ RestoreVbeWindowsStateOnLoad = RestoreVbeWindowsStateOnLoad,
+ TestClassNameFormat = Properties.Settings.Default.TestClassNameFormat
+ };
+ return clone;
+ }
+ }
+
+ #region Load/Save
+
+ private void Load()
+ {
+ using (new BlockLogger())
+ {
+ _testSuiteUserSettings = AccUnit.UserSettings.Current.Clone();
+ _toolsUserSettings = Tools.UserSettings.Current.Clone();
+ //_accSpecUserSettings = AccSpec.Integration.UserSettings.Current.Clone();
+ RestoreVbeWindowsStateOnLoad = Properties.Settings.Default.RestoreVbeWindowsStateOnLoad;
+ TestClassNameFormat = Properties.Settings.Default.TestClassNameFormat;
+ }
+ }
+
+ public void Save()
+ {
+ AccUnit.UserSettings.Current = _testSuiteUserSettings;
+ AccUnit.UserSettings.Current.Save();
+ Tools.UserSettings.Current = _toolsUserSettings;
+ Tools.UserSettings.Current.Save();
+ /*
+ * AccSpec.Integration.UserSettings.Current = _accSpecUserSettings;
+ AccSpec.Integration.UserSettings.Current.Save();
+ */
+ Properties.Settings.Default.RestoreVbeWindowsStateOnLoad = RestoreVbeWindowsStateOnLoad;
+ Properties.Settings.Default.TestClassNameFormat = TestClassNameFormat;
+ }
+
+ #endregion
+
+ #region Setting Properties
+
+ [Category("Add-in")]
+ [DefaultValue("%ModuleUnderTest%Tests")]
+ [Description("Naming convention for test classes. Example: %ModuleUnderTest%Tests")]
+ public string TestClassNameFormat { get; set; }
+
+ [Category("Add-in")]
+ [DefaultValue(false)]
+ [Description("Save last state of treeview window on unload and restore window on load (if visible)")]
+ // ReSharper disable MemberCanBePrivate.Global
+ public bool RestoreVbeWindowsStateOnLoad { get; set; }
+ // ReSharper restore MemberCanBePrivate.Global
+
+ #region Tools
+
+ [Category("Import/Export")]
+ [DefaultValue(@"%APPFOLDER%\Tests\%APPNAME%")]
+ [Description("Import and export folder for test classes\n%APPFOLDER% ... Path to current mdb/accdb\n%APPNAME% ... Filename of mdb/accdb")]
+ public string ImportExportFolder
+ {
+ get { return _testSuiteUserSettings.ImportExportFolder; }
+ set { _testSuiteUserSettings.ImportExportFolder = value.TrimEnd('\\', ' ').TrimStart(); }
+ }
+
+ [Category("Templates")]
+ [DefaultValue(@"%APPDATA%\AccessCodeLib\AccUnit\Templates")]
+ [Description("Location of template files")]
+ public string TemplateFolder
+ {
+ get { return _toolsUserSettings.TemplateFolder; }
+ set { _toolsUserSettings.TemplateFolder = value.TrimEnd('\\', ' ').TrimStart(); }
+ }
+
+ [Browsable(false)]
+ public TestTemplateCollection TestTemplates
+ {
+ get
+ {
+ using (new BlockLogger())
+ {
+ return _toolsUserSettings.TestTemplates;
+ }
+ }
+ }
+
+ [Category("Templates")]
+ [Description("Collection of test class templates")]
+ public TestTemplateCollection UserDefinedTemplates
+ {
+ get
+ {
+ using (new BlockLogger())
+ {
+ return _toolsUserSettings.UserDefinedTemplates;
+ }
+ }
+ }
+
+ [Category("Templates")]
+ [Description("Template for test methods")]
+ [DefaultValue(@"Public Sub {MethodUnderTest}_{StateUnderTest}_{ExpectedBehaviour}({Params})
+ ' Arrange
+ Err.Raise vbObjectError, ""{MethodUnderTest}_{StateUnderTest}_{ExpectedBehaviour}"", ""Test not implemented""
+ Const Expected As Variant = ""expected value""
+ Dim Actual As Variant
+ ' Act
+ Actual = ""actual value""
+ ' Assert
+ Assert.That Actual, Iz.EqualTo(Expected)
+End Sub")]
+ [Editor(typeof(MultilineStringEditor), typeof(UITypeEditor))]
+ public string TestMethodTemplate
+ {
+ get { return _toolsUserSettings.TestMethodTemplate; }
+ set { _toolsUserSettings.TestMethodTemplate = value; }
+ }
+
+ #endregion
+
+ #endregion
+ }
+}
From c0a7f67715d3c1ad0e40b30b2baffc20742355c0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20P=C3=B6tzl?=
Date: Sat, 18 May 2024 00:50:41 +0200
Subject: [PATCH 2/5] About dialog
---
source/AccUnit/Configuration/Configurator.cs | 11 +++
.../AccUnit.VbeAddIn/About/AboutDialog.xaml | 61 +++++++++++++++
.../About/AboutDialog.xaml.cs | 12 +++
.../AccUnit.VbeAddIn/About/AboutViewModel.cs | 77 +++++++++++++++++++
.../AccessCodeLib.AccUnit.VbeAddIn.csproj | 30 ++++----
.../{UserSettingWindow => }/DialogManager.cs | 12 +--
.../AccUnit.VbeAddIn/SimpleLinkLabel.cs | 30 ++++++++
.../UserSettingDialog.Designer.cs | 0
.../UserSettingDialog.cs | 0
.../UserSettingDialog.de.resx | 0
.../UserSettingDialog.resx | 0
.../SettingsPropertyWrapper.cs | 41 ----------
.../UserSettingWindow/SettingsViewModel.cs | 39 ----------
.../UserSettingWindow/SettingsWindow.xaml | 23 ------
.../UserSettingWindow/SettingsWindow.xaml.cs | 29 -------
15 files changed, 211 insertions(+), 154 deletions(-)
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml.cs
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
rename vbe-add-In/AccUnit.VbeAddIn/{UserSettingWindow => }/DialogManager.cs (92%)
create mode 100644 vbe-add-In/AccUnit.VbeAddIn/SimpleLinkLabel.cs
rename vbe-add-In/AccUnit.VbeAddIn/{UserSettingWindow => }/UserSettingDialog.Designer.cs (100%)
rename vbe-add-In/AccUnit.VbeAddIn/{UserSettingWindow => }/UserSettingDialog.cs (100%)
rename vbe-add-In/AccUnit.VbeAddIn/{UserSettingWindow => }/UserSettingDialog.de.resx (100%)
rename vbe-add-In/AccUnit.VbeAddIn/{UserSettingWindow => }/UserSettingDialog.resx (100%)
delete mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
delete mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
delete mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
delete mode 100644 vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
diff --git a/source/AccUnit/Configuration/Configurator.cs b/source/AccUnit/Configuration/Configurator.cs
index f89f56d..da79e21 100644
--- a/source/AccUnit/Configuration/Configurator.cs
+++ b/source/AccUnit/Configuration/Configurator.cs
@@ -2,6 +2,8 @@
using AccessCodeLib.Common.VBIDETools;
using Microsoft.Vbe.Interop;
using System;
+using System.Diagnostics;
+using System.Reflection;
using System.Runtime.InteropServices;
namespace AccessCodeLib.AccUnit.Configuration
@@ -156,6 +158,15 @@ public IUserSettings UserSettings
}
}
+ public static string FileVersion
+ {
+ get
+ {
+ var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
+ return version.FileVersion;
+ }
+ }
+
/*
public static void CheckAccUnitVBAReferences(VBProject vbProject)
{
diff --git a/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
new file mode 100644
index 0000000..2eb92e9
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
@@ -0,0 +1,61 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ access-codelib.net
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml.cs b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml.cs
new file mode 100644
index 0000000..d7383e4
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml.cs
@@ -0,0 +1,12 @@
+using System.Windows;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.About
+{
+ public partial class AboutDialog : Window
+ {
+ public AboutDialog()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs b/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
new file mode 100644
index 0000000..9491c08
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
@@ -0,0 +1,77 @@
+using AccessCodeLib.AccUnit.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Windows.Input;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn.About
+{
+ public class AboutViewModel
+ {
+ public ICommand NavigateCommand { get; }
+
+ public string AddInVersion => AddInManager.FileVersion;
+ public string FrameworkVersion => Configurator.FileVersion;
+
+ public AboutViewModel()
+ {
+ NavigateCommand = new RelayCommand(Navigate);
+ Contributors = new List
+ {
+ new Contributor("Josef Pötzl"),
+ new Contributor("Paul Rohorzka"),
+ new Contributor("Sten Schmidt")
+ };
+ }
+
+ private void Navigate(string url)
+ {
+ if (Uri.TryCreate(url, UriKind.Absolute, out var uri))
+ {
+ Process.Start(new ProcessStartInfo(uri.AbsoluteUri) { UseShellExecute = true });
+ }
+ }
+
+ public IEnumerable Contributors { get; }
+
+ }
+
+ public class RelayCommand : ICommand
+ {
+ private readonly Action _execute;
+ private readonly Predicate _canExecute;
+
+ public RelayCommand(Action execute, Predicate canExecute = null)
+ {
+ _execute = execute ?? throw new ArgumentNullException(nameof(execute));
+ _canExecute = canExecute;
+ }
+
+ public bool CanExecute(object parameter)
+ {
+ return _canExecute == null || _canExecute((T)parameter);
+ }
+
+ public void Execute(object parameter)
+ {
+ _execute((T)parameter);
+ }
+
+ public event EventHandler CanExecuteChanged
+ {
+ add => CommandManager.RequerySuggested += value;
+ remove => CommandManager.RequerySuggested -= value;
+ }
+ }
+
+ public class Contributor
+ {
+ public Contributor(string name)
+ {
+ Name = name;
+ }
+
+ public string Name { get; }
+ }
+
+}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj b/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
index 0c0b630..ce539f0 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
+++ b/vbe-add-In/AccUnit.VbeAddIn/AccessCodeLib.AccUnit.VbeAddIn.csproj
@@ -107,6 +107,10 @@
+
+ AboutDialog.xaml
+
+
@@ -136,8 +140,10 @@
-
-
+
+
+ Component
+
CheckableTreeView.xaml
@@ -226,15 +232,11 @@
-
-
- SettingsWindow.xaml
-
-
+
Form
-
+
UserSettingDialog.cs
@@ -294,10 +296,10 @@
VbeCommandbars.Designer.cs
Designer
-
+
UserSettingDialog.cs
-
+
UserSettingDialog.cs
@@ -305,6 +307,10 @@
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
@@ -341,10 +347,6 @@
Designer
MSBuild:Compile
-
- Designer
- MSBuild:Compile
-
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs b/vbe-add-In/AccUnit.VbeAddIn/DialogManager.cs
similarity index 92%
rename from vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs
rename to vbe-add-In/AccUnit.VbeAddIn/DialogManager.cs
index e6742b1..d58da4a 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/DialogManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/DialogManager.cs
@@ -1,6 +1,6 @@
using System;
using System.Windows.Forms;
-using AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow;
+using AccessCodeLib.AccUnit.VbeAddIn.About;
using AccessCodeLib.Common.Tools.Logging;
using AccessCodeLib.Common.VBIDETools.Commandbar;
using Microsoft.Office.Core;
@@ -11,13 +11,12 @@ class DialogManager : ICommandBarsAdapterClient
{
public event EventHandler RefreshTestTemplates;
- /*
+
private static void ShowAboutDialog()
{
- var aboutForm = new AboutForm(AddInManager.FileVersion, AddInManager.SimplyVbUnitVersion);
+ var aboutForm = new AboutDialog();
aboutForm.ShowDialog();
}
- */
#region ICommandBarsAdapterClient support
@@ -42,7 +41,7 @@ private void CreateCommandBarItems(VbeCommandBarAdapter commandBarAdapter, Comma
BeginGroup = true
};
commandBarAdapter.AddCommandBarButton(popUp, buttonData, AccUnitMenuItemsShowUserSettingForm);
- /*
+
buttonData = new CommandbarButtonData
{
Caption = Resources.VbeCommandbars.ToolsAboutCommandbarButtonCaption,
@@ -51,15 +50,12 @@ private void CreateCommandBarItems(VbeCommandBarAdapter commandBarAdapter, Comma
BeginGroup = true
};
commandBarAdapter.AddCommandBarButton(popUp, buttonData, AccUnitMenuItemsShowAboutForm);
- */
}
- /*
static void AccUnitMenuItemsShowAboutForm(CommandBarButton ctrl, ref bool cancelDefault)
{
ShowAboutDialog();
}
- */
void AccUnitMenuItemsShowUserSettingForm(CommandBarButton ctrl, ref bool cancelDefault)
{
diff --git a/vbe-add-In/AccUnit.VbeAddIn/SimpleLinkLabel.cs b/vbe-add-In/AccUnit.VbeAddIn/SimpleLinkLabel.cs
new file mode 100644
index 0000000..d989dac
--- /dev/null
+++ b/vbe-add-In/AccUnit.VbeAddIn/SimpleLinkLabel.cs
@@ -0,0 +1,30 @@
+using System.Diagnostics;
+using System.Windows.Forms;
+
+namespace AccessCodeLib.AccUnit.VbeAddIn
+{
+ public class SimpleLinkLabel : LinkLabel
+ {
+ public override string Text
+ {
+ get { return base.Text; }
+ set
+ {
+ base.Text = value;
+ var url = base.Text;
+ Links.Clear();
+ Links.Add(0, url.Length, url);
+ }
+ }
+
+ protected override void OnLinkClicked(LinkLabelLinkClickedEventArgs e)
+ {
+ base.OnLinkClicked(e);
+ var psi = new ProcessStartInfo {
+ UseShellExecute = true,
+ FileName = e.Link.LinkData.ToString()
+ };
+ Process.Start(psi);
+ }
+ }
+}
\ No newline at end of file
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.Designer.cs
similarity index 100%
rename from vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.Designer.cs
rename to vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.Designer.cs
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.cs
similarity index 100%
rename from vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.cs
rename to vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.cs
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx b/vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.de.resx
similarity index 100%
rename from vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.de.resx
rename to vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.de.resx
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx b/vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.resx
similarity index 100%
rename from vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/UserSettingDialog.resx
rename to vbe-add-In/AccUnit.VbeAddIn/UserSettingDialog.resx
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
deleted file mode 100644
index 3493cf4..0000000
--- a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsPropertyWrapper.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
-{
- internal class SettingsPropertyWrapper : INotifyPropertyChanged
- {
- private readonly PropertyInfo _propertyInfo;
- private readonly Properties.Settings _settings;
-
- public SettingsPropertyWrapper(PropertyInfo propertyInfo, Properties.Settings settings)
- {
- _propertyInfo = propertyInfo;
- _settings = settings;
- }
-
- public string Name => _propertyInfo.Name;
-
- public object Value
- {
- get { return _propertyInfo.GetValue(_settings); }
- set
- {
- _propertyInfo.SetValue(_settings, value);
- OnPropertyChanged(nameof(Value));
- }
- }
-
- public event PropertyChangedEventHandler PropertyChanged;
- protected void OnPropertyChanged(string propertyName)
- {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
- }
- }
-
-}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
deleted file mode 100644
index aff0542..0000000
--- a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsViewModel.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows.Input;
-
-namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
-{
- internal class SettingsViewModel
- {
- public ObservableCollection SettingsProperties { get; private set; }
- public ICommand SaveCommand { get; private set; }
-
- public SettingsViewModel()
- {
- SettingsProperties = new ObservableCollection();
-
- foreach (PropertyInfo property in typeof(Properties.Settings).GetProperties(BindingFlags.Public | BindingFlags.Instance))
- {
- if (property.CanRead && property.CanWrite)
- {
- SettingsProperties.Add(new SettingsPropertyWrapper(property, Properties.Settings.Default));
- }
- }
-
- SaveCommand = new RelayCommand(SaveSettings);
- }
-
- public void SaveSettings()
- {
- Properties.Settings.Default.Save();
- }
- }
-
-
-}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
deleted file mode 100644
index c53b602..0000000
--- a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs b/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
deleted file mode 100644
index 9e83e83..0000000
--- a/vbe-add-In/AccUnit.VbeAddIn/UserSettingWindow/SettingsWindow.xaml.cs
+++ /dev/null
@@ -1,29 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-
-namespace AccessCodeLib.AccUnit.VbeAddIn.UserSettingWindow
-{
- ///
- /// Interaction logic for SettingsWindow.xaml
- ///
- public partial class SettingsWindow : Window
- {
- internal SettingsWindow(SettingsViewModel dataContext)
- {
- DataContext = dataContext;
- InitializeComponent();
- }
- }
-}
From 736d54a67492c620dcf2d550788c997e96cd9de2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20P=C3=B6tzl?=
Date: Sat, 18 May 2024 10:26:17 +0200
Subject: [PATCH 3/5] AboutDialog update copyright, Contributor, code
refactoring
---
source/AccUnit/AccessCodeLib.AccUnit.csproj | 1 +
source/AccUnit/Configuration/AccUnitInfo.cs | 30 +++++++++++++++++++
source/AccUnit/Configuration/Configurator.cs | 9 ------
source/AccUnit/Properties/AssemblyInfo.cs | 2 +-
.../AccUnit.VbeAddIn/About/AboutDialog.xaml | 15 +++++-----
.../AccUnit.VbeAddIn/About/AboutViewModel.cs | 9 ++++--
vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs | 9 ++++++
.../Properties/AssemblyInfo.cs | 2 +-
8 files changed, 57 insertions(+), 20 deletions(-)
create mode 100644 source/AccUnit/Configuration/AccUnitInfo.cs
diff --git a/source/AccUnit/AccessCodeLib.AccUnit.csproj b/source/AccUnit/AccessCodeLib.AccUnit.csproj
index 60d52eb..ac1dc8d 100644
--- a/source/AccUnit/AccessCodeLib.AccUnit.csproj
+++ b/source/AccUnit/AccessCodeLib.AccUnit.csproj
@@ -144,6 +144,7 @@
+
diff --git a/source/AccUnit/Configuration/AccUnitInfo.cs b/source/AccUnit/Configuration/AccUnitInfo.cs
new file mode 100644
index 0000000..e00a307
--- /dev/null
+++ b/source/AccUnit/Configuration/AccUnitInfo.cs
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+
+namespace AccessCodeLib.AccUnit.Configuration
+{
+ public class AccUnitInfo
+ {
+ public static string FileVersion
+ {
+ get
+ {
+ var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
+ return version.FileVersion;
+ }
+ }
+
+ public static string Copyright
+ {
+ get
+ {
+ var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
+ return version.LegalCopyright;
+ }
+ }
+ }
+}
diff --git a/source/AccUnit/Configuration/Configurator.cs b/source/AccUnit/Configuration/Configurator.cs
index da79e21..9f8da14 100644
--- a/source/AccUnit/Configuration/Configurator.cs
+++ b/source/AccUnit/Configuration/Configurator.cs
@@ -158,15 +158,6 @@ public IUserSettings UserSettings
}
}
- public static string FileVersion
- {
- get
- {
- var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
- return version.FileVersion;
- }
- }
-
/*
public static void CheckAccUnitVBAReferences(VBProject vbProject)
{
diff --git a/source/AccUnit/Properties/AssemblyInfo.cs b/source/AccUnit/Properties/AssemblyInfo.cs
index 675753b..90e6cf6 100644
--- a/source/AccUnit/Properties/AssemblyInfo.cs
+++ b/source/AccUnit/Properties/AssemblyInfo.cs
@@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("access-codelib.net")]
[assembly: AssemblyProduct("AccUnit")]
-[assembly: AssemblyCopyright("Copyright © 2024")]
+[assembly: AssemblyCopyright("© 2010-2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
index 2eb92e9..11aee8f 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
+++ b/vbe-add-In/AccUnit.VbeAddIn/About/AboutDialog.xaml
@@ -26,25 +26,26 @@
+
-
+
+
-
-
-
+
+
+ CommandParameter="https://accunit.access-codelib.net">
access-codelib.net
diff --git a/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs b/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
index 9491c08..7f578f9 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/About/AboutViewModel.cs
@@ -11,7 +11,12 @@ public class AboutViewModel
public ICommand NavigateCommand { get; }
public string AddInVersion => AddInManager.FileVersion;
- public string FrameworkVersion => Configurator.FileVersion;
+ public string FrameworkVersion => AccUnitInfo.FileVersion;
+ public string AddInCopyright => AddInManager.Copyright;
+ public string FrameworkCopyright => AccUnitInfo.Copyright;
+ public string Copyright => AddInCopyright.CompareTo(FrameworkCopyright) >= 0
+ ? AddInManager.Copyright : FrameworkCopyright;
+
public AboutViewModel()
{
@@ -21,7 +26,7 @@ public AboutViewModel()
new Contributor("Josef Pötzl"),
new Contributor("Paul Rohorzka"),
new Contributor("Sten Schmidt")
- };
+ };
}
private void Navigate(string url)
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
index 50fbec3..03bfeb7 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
@@ -415,6 +415,15 @@ public static string FileVersion
}
}
+ public static string Copyright
+ {
+ get
+ {
+ var version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
+ return version.LegalCopyright;
+ }
+ }
+
private VBE VBE => AddIn.VBE;
private AddIn AddIn => _addIn;
diff --git a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
index 2f45ad6..94a6212 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/Properties/AssemblyInfo.cs
@@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("access-codelib.net")]
[assembly: AssemblyProduct("AccUnit VBE Add-in")]
-[assembly: AssemblyCopyright("Copyright © 2024")]
+[assembly: AssemblyCopyright("© 2010-2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
From f35ffdebe2203c13c04a69001eddac6fb9914dd8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20P=C3=B6tzl?=
Date: Sat, 18 May 2024 22:21:36 +0200
Subject: [PATCH 4/5] minor refactoring (dispose support)
---
.../Commandbar/VbeCommandBarAdapter.cs | 10 +-
.../Properties/AssemblyInfo.cs | 4 +-
vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs | 107 +++++-------------
vbe-add-In/AccUnit.VbeAddIn/Connect.cs | 14 ++-
.../TestExplorer/TestExplorerManager.cs | 49 +++++++-
5 files changed, 94 insertions(+), 90 deletions(-)
diff --git a/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs b/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
index 3b8a293..392ba44 100644
--- a/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
+++ b/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
@@ -15,7 +15,7 @@ public VbeCommandBarAdapter(VBE vbe)
VBE = vbe;
}
- public VBE VBE { get; }
+ public VBE VBE { get; private set; }
public CommandBar MenuBar
{
@@ -61,12 +61,10 @@ private CommandBar GetCommandBar(int index)
return foundControl.Index;
}
}
- // ReSharper disable EmptyGeneralCatchClause
catch
{
// Don't mind if the control could not be found.
}
- // ReSharper restore EmptyGeneralCatchClause
return null;
}
@@ -115,6 +113,9 @@ protected virtual void Dispose(bool disposing)
using (new BlockLogger())
{
DisposeUnManagedResources();
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ GC.Collect();
_disposed = true;
}
@@ -124,7 +125,8 @@ private void DisposeUnManagedResources()
{
using (new BlockLogger())
{
-
+ VBE = null;
+
// issue #77: (http://accunit.access-codelib.net/bugs/view.php?id=77)
return;
/*
diff --git a/source/Common/Common.VBIDETools/Properties/AssemblyInfo.cs b/source/Common/Common.VBIDETools/Properties/AssemblyInfo.cs
index 9b7983c..8bf0bd9 100644
--- a/source/Common/Common.VBIDETools/Properties/AssemblyInfo.cs
+++ b/source/Common/Common.VBIDETools/Properties/AssemblyInfo.cs
@@ -28,5 +28,5 @@
// Build Number
// Revision
//
-[assembly: AssemblyVersion("0.9.17.0")]
-[assembly: AssemblyFileVersion("0.9.17.0")]
+[assembly: AssemblyVersion("0.9.18.0")]
+[assembly: AssemblyFileVersion("0.9.18.0")]
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
index 03bfeb7..663d5be 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
@@ -17,7 +17,7 @@ namespace AccessCodeLib.AccUnit.VbeAddIn
internal class AddInManager : IDisposable
{
private AddIn _addIn;
- private Timer _startupTimer;
+ //private Timer _startupTimer;
private OfficeApplicationHelper _officeApplicationHelper;
private readonly VbeIntegrationManager _vbeIntegrationManager = new VbeIntegrationManager();
@@ -40,8 +40,6 @@ internal class AddInManager : IDisposable
*/
- //private VbaProgrammingTools _vbaProgrammingTools;
-
public AddInManager(AddIn addIn)
{
using (new BlockLogger())
@@ -51,12 +49,6 @@ public AddInManager(AddIn addIn)
/*
_tagListManager.AddIn = addIn;
_testListAndResultManager.AddIn = addIn;
-
-
- if (Settings.Default.VbaProgrammingToolsEnabled)
- {
- _vbaProgrammingTools = new VbaProgrammingTools();
- }
*/
InitOfficeApplicationHelper();
@@ -136,8 +128,6 @@ private void InitCommandBarsAdapter()
/*
_commandBarsAdapter.AddClient(_tagListManager);
_commandBarsAdapter.AddClient(_testTemplateGenerator);
-
-
*/
/*
@@ -145,25 +135,10 @@ private void InitCommandBarsAdapter()
{
_commandBarsAdapter.AddClient(_accSpecCommandBarAdapterClient);
}
-
- if (_vbaProgrammingTools != null)
- {
- AddVbaProgrammingToolsToCommandBar();
- }
*/
}
}
- /*
- private void AddVbaProgrammingToolsToCommandBar()
- {
- using (new BlockLogger())
- {
- _commandBarsAdapter.AddClient(_vbaProgrammingTools);
- }
- }
- */
-
private void InitTestSuiteManager()
{
using (new BlockLogger())
@@ -291,29 +266,15 @@ private void InitOfficeApplicationHelper(object hostApplication = null)
{
using (new BlockLogger())
{
+ // Note: if load RubberDuck, an instance of Access stay in memory after close
_officeApplicationHelper = HostApplicationTools.GetOfficeApplicationHelper(VBE, ref hostApplication);
_vbeIntegrationManager.OfficeApplicationHelper = _officeApplicationHelper;
_testSuiteManager.OfficeApplicationHelper = _officeApplicationHelper;
-
- /*
- if (_vbaProgrammingTools != null)
- {
- InitVbaProgrammingTools(_officeApplicationHelper);
- }
- */
}
}
#endregion
- /*
- private void InitVbaProgrammingTools(OfficeApplicationHelper officeApplicationHelper)
- {
- using (new BlockLogger())
- {
- _vbaProgrammingTools.OfficeApplicationHelper = officeApplicationHelper;
- }
- }
- */
+
#region ad VbeWindow
private void InitVbeWindows()
@@ -357,6 +318,7 @@ private void InitStartUpTimer(int interval, bool start)
}
*/
+ /*
private void DisposeStartUpTimer()
{
if (_startupTimer == null)
@@ -401,6 +363,7 @@ void StartupTimerTick(object sender, EventArgs e)
//_testListAndResultManager.AddTestClassListToTestListAndResultWindow();
DisposeStartUpTimer();
}
+ */
#endregion
@@ -477,52 +440,32 @@ private void DisposeManagedResources()
{
using (new BlockLogger())
{
- try
- {
- DisposeStartUpTimer();
- DisposeVbaProgrammingTools();
-
- _testStarter.Dispose();
-
- //_testTemplateGenerator.Dispose();
+ //DisposeStartUpTimer();
+ //_testTemplateGenerator.Dispose();
- _vbeIntegrationManager.Dispose();
+ DisposeManagedResource(_testStarter);
+ DisposeManagedResource(_testExplorerManager);
+ DisposeManagedResource(_vbeIntegrationManager);
+ DisposeManagedResource(_commandBarsAdapter);
+ DisposeManagedResource(_testSuiteManager);
- try
- {
- _commandBarsAdapter.Dispose();
- }
- catch (Exception ex)
- {
- Logger.Log(ex);
- }
-
- _testSuiteManager.Dispose();
-
- DisposeAddInManagerBridge();
-
- }
- catch (Exception ex)
- {
- Logger.Log(ex);
- }
+ DisposeAddInManagerBridge();
- try
- {
- _officeApplicationHelper.Dispose();
- _officeApplicationHelper = null;
- }
- catch (Exception ex)
- {
- Logger.Log(ex);
- }
+ DisposeManagedResource(_officeApplicationHelper);
+ _officeApplicationHelper = null;
}
}
- private void DisposeVbaProgrammingTools()
+ private void DisposeManagedResource(IDisposable disposable)
{
- //_vbaProgrammingTools?.Dispose();
- //_vbaProgrammingTools = null;
+ try
+ {
+ disposable.Dispose();
+ }
+ catch (Exception ex)
+ {
+ Logger.Log(ex);
+ }
}
private void DisposeAddInManagerBridge()
@@ -548,6 +491,8 @@ private void RemoveEventHandler(AddInManagerBridge addInManagerBridge)
{
addInManagerBridge.TestSuiteRequest -= AddInBridgeTestSuiteRequest;
addInManagerBridge.HostApplicationInitialized -= AddInBridgeHostApplicationInitialized;
+ addInManagerBridge.ConstraintBuilderRequest -= AddInBridgeConstraintBuilderRequest;
+ addInManagerBridge.AssertRequest -= AddInBridgeAssertRequest;
}
public void Dispose()
diff --git a/vbe-add-In/AccUnit.VbeAddIn/Connect.cs b/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
index 76819bc..5ed29da 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
@@ -131,7 +131,10 @@ public void OnBeginShutdown(ref Array custom)
{
try
{
- _addInInstance.Object = null;
+ if (!_disposed)
+ {
+ Dispose();
+ }
}
catch (Exception ex)
{
@@ -176,6 +179,15 @@ protected virtual void Dispose(bool disposing)
return;
}
+ try
+ {
+ _addInInstance.Object = null;
+ }
+ catch (Exception ex)
+ {
+ Logger.Log(ex);
+ }
+
if (disposing)
{
Logger.Log("disposing == true");
diff --git a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
index 352c994..088ce23 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
@@ -1,4 +1,5 @@
-using AccessCodeLib.AccUnit.Interfaces;
+using AccessCodeLib.AccUnit.Configuration;
+using AccessCodeLib.AccUnit.Interfaces;
using AccessCodeLib.Common.Tools.Logging;
using AccessCodeLib.Common.VBIDETools;
using AccessCodeLib.Common.VBIDETools.Commandbar;
@@ -7,7 +8,7 @@
namespace AccessCodeLib.AccUnit.VbeAddIn.TestExplorer
{
- internal class TestExplorerManager : ITestResultReporter, ICommandBarsAdapterClient
+ internal class TestExplorerManager : ITestResultReporter, ICommandBarsAdapterClient, IDisposable
{
private readonly VbeUserControl _vbeUserControl;
private readonly TestExplorerViewModel _viewModel;
@@ -143,5 +144,49 @@ private void FillTestsFromVbProject()
}
#endregion
+
+ #region IDisposable Support
+
+ bool _disposed;
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (_disposed) return;
+
+ if (disposing)
+ {
+ DisposeManagedResources();
+ }
+
+ DisposeUnmanagedResources();
+ _disposed = true;
+ }
+
+ private void DisposeUnmanagedResources()
+ {
+ _testResultCollector = null;
+ }
+
+ private void DisposeManagedResources()
+ {
+ _vbeUserControl.Dispose();
+ }
+
+ public void Dispose()
+ {
+ using (new BlockLogger())
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+ }
+
+ ~TestExplorerManager()
+ {
+ Dispose(false);
+ }
+
+ #endregion
+
}
}
From 6c047cd54de7f78d8546abfadf9735fb2d505828 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Josef=20P=C3=B6tzl?=
Date: Sun, 19 May 2024 00:41:22 +0200
Subject: [PATCH 5/5] + fix COM object release (MarshalReleaseComObject)
---
.../Commandbar/VbeCommandBarAdapter.cs | 10 ++++------
.../Common.VBIDETools/InvocationHelper.cs | 9 +++++++--
.../OfficeApplicationHelper.cs | 13 ++++++++++---
vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs | 16 ++++++++--------
vbe-add-In/AccUnit.VbeAddIn/Connect.cs | 12 ++++++++++--
.../TestExplorer/TestExplorerManager.cs | 3 +--
...ccessCodeLib.Common.VbeUserControlHost.dll | Bin 13824 -> 13824 bytes
7 files changed, 40 insertions(+), 23 deletions(-)
diff --git a/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs b/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
index 392ba44..8df5198 100644
--- a/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
+++ b/source/Common/Common.VBIDETools/Commandbar/VbeCommandBarAdapter.cs
@@ -3,6 +3,7 @@
using Microsoft.Vbe.Interop;
using System;
using System.Collections.Generic;
+using System.Runtime.InteropServices;
namespace AccessCodeLib.Common.VBIDETools.Commandbar
{
@@ -112,19 +113,16 @@ protected virtual void Dispose(bool disposing)
using (new BlockLogger())
{
- DisposeUnManagedResources();
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
-
+ DisposeUnmanagedResources();
_disposed = true;
}
}
- private void DisposeUnManagedResources()
+ private void DisposeUnmanagedResources()
{
using (new BlockLogger())
{
+ Marshal.ReleaseComObject(VBE);
VBE = null;
// issue #77: (http://accunit.access-codelib.net/bugs/view.php?id=77)
diff --git a/source/Common/Common.VBIDETools/InvocationHelper.cs b/source/Common/Common.VBIDETools/InvocationHelper.cs
index b6b4129..25d2647 100644
--- a/source/Common/Common.VBIDETools/InvocationHelper.cs
+++ b/source/Common/Common.VBIDETools/InvocationHelper.cs
@@ -45,17 +45,22 @@ protected virtual void Dispose(bool disposing)
try
{
- _target = null;
+ if (_target != null)
+ {
+ //Marshal.ReleaseComObject(_target); // --> RCW error ... Why?
+ _target = null;
+ }
}
catch (Exception ex)
{
Logger.Log(ex.Message);
}
- // GC-Bereinigung wegen unmanaged res:
+ // GC clean up (instead of Marshal.ReleaseComObject)
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
+ GC.WaitForPendingFinalizers();
_disposed = true;
}
diff --git a/source/Common/Common.VBIDETools/OfficeApplicationHelper.cs b/source/Common/Common.VBIDETools/OfficeApplicationHelper.cs
index 0592b05..b10ae06 100644
--- a/source/Common/Common.VBIDETools/OfficeApplicationHelper.cs
+++ b/source/Common/Common.VBIDETools/OfficeApplicationHelper.cs
@@ -3,6 +3,7 @@
using Microsoft.Vbe.Interop;
using System;
using System.Linq;
+using System.Runtime.InteropServices;
namespace AccessCodeLib.Common.VBIDETools
{
@@ -137,8 +138,12 @@ protected virtual void Dispose(bool disposing)
}
}
- _application = null;
-
+ if (_application != null)
+ {
+ Marshal.ReleaseComObject(_application);
+ _application = null;
+ }
+
}
catch (Exception ex)
{
@@ -146,10 +151,12 @@ protected virtual void Dispose(bool disposing)
}
// GC-Bereinigung wegen unmanaged res:
+ /*
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
-
+ GC.WaitForPendingFinalizers();
+ */
_disposed = true;
}
diff --git a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
index 663d5be..ff330f8 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/AddInManager.cs
@@ -10,6 +10,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
+using System.Runtime.InteropServices;
using Timer = System.Windows.Forms.Timer;
namespace AccessCodeLib.AccUnit.VbeAddIn
@@ -37,7 +38,6 @@ internal class AddInManager : IDisposable
private AccSpecCommandBarAdapterClient _accSpecCommandBarAdapterClient;
private AccSpecManager _accSpecManager;
-
*/
public AddInManager(AddIn addIn)
@@ -416,24 +416,24 @@ protected virtual void Dispose(bool disposing)
try
{
- DisposeUnManagedResources();
+ DisposeUnmanagedResources();
}
catch (Exception ex)
{
Logger.Log(ex);
}
- GC.Collect();
- GC.WaitForPendingFinalizers();
- GC.Collect();
-
_disposed = true;
}
}
- private void DisposeUnManagedResources()
+ private void DisposeUnmanagedResources()
{
- _addIn = null;
+ if (_addIn != null)
+ {
+ Marshal.ReleaseComObject(_addIn);
+ _addIn = null;
+ }
}
private void DisposeManagedResources()
diff --git a/vbe-add-In/AccUnit.VbeAddIn/Connect.cs b/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
index 5ed29da..000c725 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/Connect.cs
@@ -199,11 +199,19 @@ protected virtual void Dispose(bool disposing)
}
}
- _addInInstance = null;
-
+ if (_addInInstance != null)
+ {
+ Logger.Log("Start Marshal.ReleaseComObject(_addInInstance) ...");
+ Marshal.ReleaseComObject(_addInInstance);
+ _addInInstance = null;
+ }
+
+ /*
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
+ GC.WaitForPendingFinalizers();
+ */
_disposed = true;
diff --git a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
index 088ce23..a90cf51 100644
--- a/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
+++ b/vbe-add-In/AccUnit.VbeAddIn/TestExplorer/TestExplorerManager.cs
@@ -1,5 +1,4 @@
-using AccessCodeLib.AccUnit.Configuration;
-using AccessCodeLib.AccUnit.Interfaces;
+using AccessCodeLib.AccUnit.Interfaces;
using AccessCodeLib.Common.Tools.Logging;
using AccessCodeLib.Common.VBIDETools;
using AccessCodeLib.Common.VBIDETools.Commandbar;
diff --git a/vbe-add-In/lib/VbeUserControlHost/AccessCodeLib.Common.VbeUserControlHost.dll b/vbe-add-In/lib/VbeUserControlHost/AccessCodeLib.Common.VbeUserControlHost.dll
index 50a8b805a555ccebfeb17b486e09ad6ebc614d00..4aa530d1eb208737a3f1b79fae5fbb1fe7290a1e 100644
GIT binary patch
delta 4770
zcmb7GeQ;I96+gT8-hJ=g_Y#r-NeCpo5J+xbLI@uU;X@MwLI?K5uF;ZXce7+sZQfZZ5paL4y_a_VvRG5)DB}sEEPu!wSKjwj-CF_-iJurf4Xnp
zZ}}mS#h+Xu3M`sKG|AmqTSDceV&E*24^SV;#n+R_=x
zn6aG|k%6UxhQbMhC{?y+fx1r;4c$BtzS*i+sVF?PBQ&&B(&&VCpoB
zABGb%**m9@&5Z4e$du-GA6M;+P8vM0)ecN$J4JxvaO-|S8$4|k%T=uhAv?v;wP6+Z
z9a1^iQ%njURD=eWntW{J&4ab8;>^}Jc!($lRrPudX8@XZQEKbwTEWA5ls9v0x@3Dz
zW07zO$DzANu`)G0^e^E})QpL+1}ta{Tu37)+5MN98!Lt2lkI+9&{(vKi)1@5HBC6<
zAV$XnzGWsba}6`T?c5`Bi{V@gap-uQGOtM*&P2$Om9h=B+8%(BbS7~R2dAMTkI8n;
zNe73nq7!1=$ti<@5uMC9G&+R`fU^Tj4O)a66Cp;f>V-~iQ(iJ}A368^=&20Dqc8&eht~u@&1HxkT*+kHH&Bk&KN;R
zd9!M&uuHT7a;f_ZUqK;;B?LIZYeHlYPMmD~u^WVYMA$K12VBcv7F%Fp*H9F_X>|G&
z%`q8I%6i`b3L_pAU6R)+MR9|%LE~7H+u!JRx^AcF_J^_+eV^4hLo-FjiKCW<#P+PfBywkyc^qRF^dwfbU;UQjF)SloFD
zaeJY!->RhrxSKXT16R^$rti3!Lt6qOU{j}dw2|1+T&;cIf869foX>!aFKDMop)vkt
z{t7J}z)5``Sccs+AhV?GgcQ?aUqUINPN8Jtjs|CJNJn5=gJVe6x-Vck6ET}k2XOjl
ztxw=&kg~OODItZmR8OAHlNJR%X@u4d3V2cx#dw&3--;|9PjnnZ0--Tlexe@56k{of
zHSvXMqAW;;c8zd%bFR{bX%a1t@1suOAz&{3$|{HJd+n*fr)f2qpIe`aT#t#-PV*}W
zr|nCa?Qi~Xgi`D25IXO-gHS0;slHQFWVksykEeNyruFPs*
zsx)X65(OlGhm|b@G+IkL{dc?jf`zeVL4}ywqq$?EMh=GboM%D3h`%76N=PTPRE#`C
zbRL$ho2sQ_4uRaS
z{W>(nNC_-+Gm;97s9NY&Buy0c?$)GhjMuGIZg0{M<7<13+n+Qf23g{(0L9y@EfSvv
z35oX#89yQMUX73+fhbOXvy0Eyr+nwe5BdSc;4dg
z!23hEp9cL5YLmYilM8Q+;K31eSg`s8P|!nQB$ePp$Dj*H5+=>Zc?#;&Lp-bp{VtvX
zFX+^NO?lX)Fh~+%K}%dQpfJ`Fyu$PZL|D>3XbtL6B5cx1WrQsf))kw}_TKmsUj4t`
ze#G|{;r0v|6|43MN+phxAwZi7fhkBCjAa@tG*)R`sBx*r2H;?%9Jbu3ajV9i
z`U0FrJBvQh%q5^gx?;-!P*EySAUz}G!COu^
zhUjj4IV|UkmB3mt7|59`r0-~m_-;Om_*Jx2Tpw5uo@2Q|>@nM@N6*qMK2Y1JS?mtR
zVwhl9paXfHz3ZVLi2HzB#Xfo&Oc!u(@G0O$^LgB|zncQ>+5op#2Lv6Vcfj}P8@O8!
z-AfPpU!jfSN$7gXZyl%468w7eZ9F^|tkdA9`Q8VAn9lRn<;gmAw&|stZ1|2h)5g*_P0jY)YT8J~oU@im`KAEKQL#!scx1)M-X22MgxKTV~d
z0?VlnID-xWXCuJ;
z>hqwTYUN>XR|C7j6heEmS*f*^(B5WMiWn=Zpjd7;YDFUy2dqZjVV7ohf%&bqOEcY?
z=?3$a)h+sHxa!vYQOzIK{83C9Q%5y_PV?t9a}L_w>YU~c$u1fa>+e&Be1+aq`wd?A
zs~XP&3(T;|D_#LCGvmPN=6+zc`Km^;cs1p~VsU5rY`V=;}{!=G0~JTxK$gNan6z69~H_QcmYhWsnIXC==y4|
z3va{KcBvv2Z^6}Emhe7C6MdJlp8WXU=K8w>riy$#PXEbWhmG?JyLb+}pNic|Lmn6i
zikGdh
z5NS&lFg1SIgmNo0smrm9)c6sP*Hv2lH&$4RP{`x@z3OD&+L3QbF}81V!7YaSaO9Wi
zU+$}Vklp9?J%|6KIrta5Yl=q9&boc`xS2Kmm5)8$(>m(y;Ba1f<>a~<4V#+Q*DYv`
zu4!7ksj03qx~gez^UAu#E1PQCnp!KP>o>JVTV_YwHr2I7H@7x6)wv6^)7`&hr6$!y
zSFWi`tokyWmbPIPo|9^fohbR$ZccHQ%&hL7TrAw=k~jyA7a4tzlw1_>zN2&i7UAw4
WHxWYrxG6$Tn$nj#;ZxCB>iah-76%Fd
delta 4626
zcmb7HYj9Q76<&LvbN0RW+`MBRB!t|U*U6Lc%ma|bL?ID12ti|lf{|*_a%lo}G`-%7
zR1{H%c!sLbDm1k=FvT*l1x7QK0wRuR9W5h$AWD6WT9xWh?dbGd``myTr$0QI`|Z8H
zwbtHi@4faqC$U>&w{E`I{4&(FXYl@s@`kp-ol8WDD@3W)-bz&GHdR%+ouX9UT<+c_
z?ksL;BmK+=O0sBiF;Pn)k??4G1d4rds&Lz7R^cQf6%GN6BxPD@6s|%)GJ(jJ1B_YW
zV)s7zGg0go80DhKU0{?&F`z2HSUPaCt9&xcDL|)ur5v~rZKWtTDwT9Fqb;){OqCPm
z)(A?C2jC4HhDMzyniUye#F5(d!Oojn+Yveh9Q)Y${i0MQPqEzXW
zu$>W6M5Z(&K5hmW9ZaZfb!RE`jsvI+^=%il+S7&+pz3=XvQq|KKccYjkjkk*E1h&+
zBBj@u#JlOulLoFbyYEFFA`BlD)nhnG=-L&jeP^_ShxI6L=DtkH_L@#+OWr!|9!6j)
zKj9nUP1K8tEWMyggpfu~BGe^mLJdsBV$?tmuu~1>X(5+|sDs0@eR9AL$*D%avO*5<
zKBNg}GQ@BV;2blBnW@b9BJ5Fqo#9M_m^%%}#S4~(GaYjI4YGeG#7F=}(wV^?4klFP
zTjhY}q=VE@;V8V}3R~L<*D~gY>v#aHB)!I!b56Yz!VnFBuzsirP%ZSLM~d
zWcmh4py*3EQz?oWjLS7nF}eS>?q}+LitfK7SHgFf#um*~7(X`^Tnc_d+mtdrl+7zqYdT})27KH0;597Mk#u@{Tf#TGjVfDtsKg+zlL_R
z0{cmUi*HenOdJWQ~LoCqRQU4K>ckfCD68Kw(ikRrH^EYW}2hQmEKpoP^
zfXvcg$4U1@G1If^#5iaJW
zak>!h)somYx(B!qSU`KNMqsZ!8w>a~{Q&)))_Y=%S!aGI3ZnE|`xDIey8quosa3Qa
z&TH(mVoB^jiZR2-c+zBa{ESN_d0vS}&T3p#}2
z{3IlPc*6d`#c~3z)jD3LLJB;nrFR8yNDl2gCkdHLSw-x*jt0dba8MIUUXAIx=rW1AiN_$7-HgKvc@q5obIPc93*8
zZnHtZgVv-3_e4_JO@3`NDp-3IDClM|l1fmN4SEqJ#iT;yf}mY`gq5iAg1(K%!Q*Cq
zXU0*}+eHx))b92smqi5UES}v9b*J8A<`~!F+a45s{QxUxj
z&F#1~`$261_6D~BKQ@PG51lmy`jZ3PZwLrFK*zxk>$|#9550$0`}a_<_$BRyjo%uj
z&*J8NR=OAEm#e&vQMB5EX6YaufwsVk=zSX5VR05BWa;=7~>fhv--A
z{50MIduY0yf!CBt6GRfejur@soBTKQ3&8mCKG*`BPFsO>^f+)f{R-Gf!@w5W4V+IS
zzy-7q*iNIs#q=i;_2U(M1VT5x1YAb10&k?_q8jDz30%f>+6~O5W57Z>4y>TFz-d%t
zRMRY)32de-fS1t#aFOP_H1?1S<`xXl-+uuc-ZREiuKxbJ(vU5dd&=JW(drO){q#X3^ktnIVf~Uj~FPu-iPP`&sl4F^k?5bMTu>Z;2-Sn$e$!wiUn2
z=(M;T?Unc~1iuKsXb0eGdPj7E?1I5k3{pj%vNA7We`(DTrPI|BHgJ
z#sNumy&VJgio1cw)JA6L0pJ<`L%@h;dd0)&*UN3dFT{4dyiGDtxh(uiQtmSs1fvr%
zxQY3P8XNU^-K511SRpAA55jF1
zE1Fx~y_HpIb#2hbpR2eZ8Z5|^Ep0sI?I)+2iCr32$aP`LmVccDljA+~~
XQ)?j{n>tI#8yiMar+*>_YkdC$dsX6Z