From 6b3b8f250bc19e0b0fa0914bdc0b1b58918c6446 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 27 Apr 2017 15:41:24 +0200 Subject: [PATCH] Code quality changes, which do change the API slightly. [release] --- .../ViewModels/AddonSettingsViewModel.cs | 24 ++-- .../ViewModels/AdminConfigViewModel.cs | 19 ++- .../NotSelectableConfigViewModel.cs | 15 +-- .../Application.Demo.MetroAddon.csproj | 4 +- Application.Demo.MetroAddon/packages.config | 2 +- Application.Demo/Application.Demo.csproj | 22 ++-- Application.Demo/FodyWeavers.xml | 4 +- Application.Demo/Startup.cs | 2 +- .../ViewModels/AddonConfigNodeViewModel.cs | 12 +- .../ViewModels/ConfigViewModel.cs | 62 +++++----- .../ViewModels/LanguageConfigViewModel.cs | 26 ++-- .../ViewModels/UiConfigNodeViewModel.cs | 13 +- .../UseCases/ContextMenu/ConfigMenuItem.cs | 23 ++-- .../UseCases/ContextMenu/ExitMenuItem.cs | 20 ++-- .../ContextMenu/SomeWindowMenuItems.cs | 53 ++++----- .../UseCases/ContextMenu/TitleMenuItem.cs | 10 +- .../ViewModels/DemoTrayIconViewModel.cs | 4 +- .../ContextMenu/WithChildrenMenuItem.cs | 1 + .../UseCases/ContextMenu/WizardMenuItem.cs | 36 ++---- .../UseCases/Menu/SaveAsMenuItem.cs | 1 + .../ViewModels/WizardExampleViewModel.cs | 26 ++-- Application.Demo/packages.config | 6 +- Dapplo.Caliburn.Tests/BasicTests.cs | 54 +++++++++ .../Dapplo.Caliburn.Tests.csproj | 111 ++++++++++++++++++ .../Properties/AssemblyInfo.cs | 36 ++++++ Dapplo.Caliburn.Tests/packages.config | 12 ++ Dapplo.CaliburnMicro.Configuration/Config.cs | 4 +- .../ConfigurationStartup.cs | 16 ++- .../Extensions/IniSectionExtensions.cs | 4 - .../CaliburnMicroBootstrapper.cs | 50 +++++--- .../Dapplo.CaliburnMicro.Dapp.csproj | 1 - .../TreeNodeExtensions.cs | 37 +++--- .../MetroWindowManager.cs | 6 +- .../ITrayIconViewModel.cs | 2 +- .../TrayIconManager.cs | 24 +++- .../ViewModels/TrayIconViewModel.cs | 10 +- .../LanguageChangedExtensions.cs | 1 - Dapplo.CaliburnMicro.sln | 6 + .../CaliburnLogger.cs | 6 +- .../Dapplo.CaliburnMicro.csproj | 5 +- Dapplo.CaliburnMicro/packages.config | 2 +- 41 files changed, 508 insertions(+), 264 deletions(-) create mode 100644 Dapplo.Caliburn.Tests/BasicTests.cs create mode 100644 Dapplo.Caliburn.Tests/Dapplo.Caliburn.Tests.csproj create mode 100644 Dapplo.Caliburn.Tests/Properties/AssemblyInfo.cs create mode 100644 Dapplo.Caliburn.Tests/packages.config rename {Dapplo.CaliburnMicro.Dapp => Dapplo.CaliburnMicro}/CaliburnLogger.cs (92%) diff --git a/Application.Demo.Addon/ViewModels/AddonSettingsViewModel.cs b/Application.Demo.Addon/ViewModels/AddonSettingsViewModel.cs index 6728ef37..8a8f5745 100644 --- a/Application.Demo.Addon/ViewModels/AddonSettingsViewModel.cs +++ b/Application.Demo.Addon/ViewModels/AddonSettingsViewModel.cs @@ -34,40 +34,46 @@ namespace Application.Demo.Addon.ViewModels { [Export(typeof(IConfigScreen))] - public sealed class AddonSettingsViewModel : ConfigScreen, IPartImportsSatisfiedNotification + public sealed class AddonSettingsViewModel : ConfigScreen { public AddonSettingsViewModel() { ParentId = nameof(ConfigIds.Addons); } - [Import] - public IAddonTranslations AddonTranslations { get; set; } + public IAddonTranslations AddonTranslations { get; } + private IAuthenticationProvider AuthenticationProvider { get; } - [Import] - private IAuthenticationProvider AuthenticationProvider { get; set; } + private IEventAggregator EventAggregator { get; } - [Import] - private IEventAggregator EventAggregator { get; set; } - - public void OnImportsSatisfied() + [ImportingConstructor] + public AddonSettingsViewModel( + IAddonTranslations addonTranslations, + IAuthenticationProvider authenticationProvider, + IEventAggregator eventAggregator) { + AddonTranslations = addonTranslations; + EventAggregator = eventAggregator; + AuthenticationProvider = authenticationProvider; // automatically update the DisplayName AddonTranslations.CreateDisplayNameBinding(this, nameof(IAddonTranslations.Addon)); } + // ReSharper disable once UnusedMember.Global public void AddAdmin() { var authenticationProvider = AuthenticationProvider as SimpleAuthenticationProvider; authenticationProvider?.AddPermission("Admin"); } + // ReSharper disable once UnusedMember.Global public void DoSomething() { EventAggregator.PublishOnUIThread("Addon button clicked"); } + // ReSharper disable once UnusedMember.Global public void RemoveAdmin() { var authenticationProvider = AuthenticationProvider as SimpleAuthenticationProvider; diff --git a/Application.Demo.Addon/ViewModels/AdminConfigViewModel.cs b/Application.Demo.Addon/ViewModels/AdminConfigViewModel.cs index 68d4e659..f55413e3 100644 --- a/Application.Demo.Addon/ViewModels/AdminConfigViewModel.cs +++ b/Application.Demo.Addon/ViewModels/AdminConfigViewModel.cs @@ -34,24 +34,21 @@ namespace Application.Demo.Addon.ViewModels { [Export(typeof(IConfigScreen))] - public sealed class AdminConfigViewModel : AuthenticatedConfigScreen, IPartImportsSatisfiedNotification + public sealed class AdminConfigViewModel : AuthenticatedConfigScreen { - public AdminConfigViewModel() + public IAddonTranslations AddonTranslations { get; } + + [ImportingConstructor] + public AdminConfigViewModel(IAddonTranslations addonTranslations) { + AddonTranslations = addonTranslations; + ParentId = nameof(ConfigIds.Addons); this.VisibleOnPermissions("Admin"); - } - - [Import] - public IAddonTranslations AddonTranslations { get; set; } - [Import] - private IAuthenticationProvider AuthenticationProvider { get; set; } - - public void OnImportsSatisfied() - { // automatically update the DisplayName AddonTranslations.CreateDisplayNameBinding(this, nameof(IAddonTranslations.Admin)); } + } } \ No newline at end of file diff --git a/Application.Demo.Addon/ViewModels/NotSelectableConfigViewModel.cs b/Application.Demo.Addon/ViewModels/NotSelectableConfigViewModel.cs index 8a6bbb7a..7709e19b 100644 --- a/Application.Demo.Addon/ViewModels/NotSelectableConfigViewModel.cs +++ b/Application.Demo.Addon/ViewModels/NotSelectableConfigViewModel.cs @@ -32,18 +32,15 @@ namespace Application.Demo.Addon.ViewModels { [Export(typeof(IConfigScreen))] - public sealed class NotSelectableConfigViewModel : ConfigScreen, IPartImportsSatisfiedNotification + public sealed class NotSelectableConfigViewModel : ConfigScreen { - public NotSelectableConfigViewModel() - { - ParentId = nameof(ConfigIds.Addons); - } + public IAddonTranslations AddonTranslations { get; } - [Import] - public IAddonTranslations AddonTranslations { get; set; } - - public void OnImportsSatisfied() + [ImportingConstructor] + public NotSelectableConfigViewModel(IAddonTranslations addonTranslations) { + AddonTranslations = addonTranslations; + ParentId = nameof(ConfigIds.Addons); IsEnabled = false; // automatically update the DisplayName AddonTranslations.CreateDisplayNameBinding(this, nameof(IAddonTranslations.NotSelectableAddon)); diff --git a/Application.Demo.MetroAddon/Application.Demo.MetroAddon.csproj b/Application.Demo.MetroAddon/Application.Demo.MetroAddon.csproj index e92aa417..ca895d39 100644 --- a/Application.Demo.MetroAddon/Application.Demo.MetroAddon.csproj +++ b/Application.Demo.MetroAddon/Application.Demo.MetroAddon.csproj @@ -71,8 +71,8 @@ ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll True - - ..\packages\MahApps.Metro.IconPacks.1.8.0\lib\net45\MahApps.Metro.IconPacks.dll + + ..\packages\MahApps.Metro.IconPacks.1.9.0\lib\net45\MahApps.Metro.IconPacks.dll True diff --git a/Application.Demo.MetroAddon/packages.config b/Application.Demo.MetroAddon/packages.config index d6b8cdf5..66e734ce 100644 --- a/Application.Demo.MetroAddon/packages.config +++ b/Application.Demo.MetroAddon/packages.config @@ -9,7 +9,7 @@ - + diff --git a/Application.Demo/Application.Demo.csproj b/Application.Demo/Application.Demo.csproj index 0e6293c8..03f00aa7 100644 --- a/Application.Demo/Application.Demo.csproj +++ b/Application.Demo/Application.Demo.csproj @@ -95,8 +95,8 @@ ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll True - - ..\packages\MahApps.Metro.IconPacks.1.8.0\lib\net45\MahApps.Metro.IconPacks.dll + + ..\packages\MahApps.Metro.IconPacks.1.9.0\lib\net45\MahApps.Metro.IconPacks.dll True @@ -269,16 +269,9 @@ - + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - @@ -315,6 +308,15 @@ foreach (var item in filesToCleanup) + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + \ No newline at end of file diff --git a/Dapplo.Caliburn.Tests/Properties/AssemblyInfo.cs b/Dapplo.Caliburn.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..e77999a3 --- /dev/null +++ b/Dapplo.Caliburn.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Dapplo.Caliburn.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Dapplo")] +[assembly: AssemblyProduct("Dapplo.Caliburn.Tests")] +[assembly: AssemblyCopyright("Copyright © Dapplo 2017")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("c62cc807-6929-4dde-9b30-ea3483e46d41")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Dapplo.Caliburn.Tests/packages.config b/Dapplo.Caliburn.Tests/packages.config new file mode 100644 index 00000000..bfb86f8e --- /dev/null +++ b/Dapplo.Caliburn.Tests/packages.config @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Dapplo.CaliburnMicro.Configuration/Config.cs b/Dapplo.CaliburnMicro.Configuration/Config.cs index 3bf1cbed..3d2ceaa2 100644 --- a/Dapplo.CaliburnMicro.Configuration/Config.cs +++ b/Dapplo.CaliburnMicro.Configuration/Config.cs @@ -24,6 +24,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using Caliburn.Micro; using Dapplo.CaliburnMicro.Menu; @@ -55,7 +56,7 @@ public virtual string Filter set { _filter = value; - NotifyOfPropertyChange(_filter); + NotifyOfPropertyChange(); TreeItems.Clear(); // Rebuild a tree for the ConfigScreens @@ -236,6 +237,7 @@ public virtual void ActivateChildView(TConfigScreen configScreen) /// Activates the specified config screen, and sends notify property changed events. /// /// The TConfigScreen to activate. + [SuppressMessage("Sonar Code Smell", "S3236:Caller information arguments should not be provided explicitly", Justification = "Notification of a different property is triggered.")] public override void ActivateItem(TConfigScreen configScreen) { if (configScreen != null && !configScreen.CanActivate) diff --git a/Dapplo.CaliburnMicro.Configuration/ConfigurationStartup.cs b/Dapplo.CaliburnMicro.Configuration/ConfigurationStartup.cs index a5c4e851..f9562144 100644 --- a/Dapplo.CaliburnMicro.Configuration/ConfigurationStartup.cs +++ b/Dapplo.CaliburnMicro.Configuration/ConfigurationStartup.cs @@ -38,9 +38,17 @@ namespace Dapplo.CaliburnMicro.Configuration [StartupAction(StartupOrder = int.MinValue)] public class ConfigurationStartup : IAsyncStartupAction { - [Import] - private IApplicationBootstrapper ApplicationBootstrapper { get; set; } + private readonly IApplicationBootstrapper _applicationBootstrapper; + /// + /// Create the ConfigurationStartup + /// + /// IApplicationBootstrapper + [ImportingConstructor] + public ConfigurationStartup(IApplicationBootstrapper applicationBootstrapper) + { + _applicationBootstrapper = applicationBootstrapper; + } /// /// async Start of the IniConfig /// @@ -51,10 +59,10 @@ public class ConfigurationStartup : IAsyncStartupAction var iniConfig = IniConfig.Current; if (iniConfig == null) { - iniConfig = new IniConfig(ApplicationBootstrapper.ApplicationName, ApplicationBootstrapper.ApplicationName); + iniConfig = new IniConfig(_applicationBootstrapper.ApplicationName, _applicationBootstrapper.ApplicationName); await iniConfig.LoadIfNeededAsync(cancellationToken); } - ApplicationBootstrapper.Export(iniConfig); + _applicationBootstrapper.Export(iniConfig); } } } \ No newline at end of file diff --git a/Dapplo.CaliburnMicro.Configuration/Extensions/IniSectionExtensions.cs b/Dapplo.CaliburnMicro.Configuration/Extensions/IniSectionExtensions.cs index 5902388f..3cd15f1c 100644 --- a/Dapplo.CaliburnMicro.Configuration/Extensions/IniSectionExtensions.cs +++ b/Dapplo.CaliburnMicro.Configuration/Extensions/IniSectionExtensions.cs @@ -38,7 +38,6 @@ public static class IniSectionExtensions /// /// Automatically call the update action when the Loaded fires /// If the is called on a DI object, make sure it's available. - /// When using MEF, it would be best to call this from IPartImportsSatisfiedNotification.OnImportsSatisfied /// /// IIniSection /// Action to call on events, argument is the IniSectionEventArgs @@ -60,7 +59,6 @@ public static IDisposable OnLoaded(this IIniSection iniSection, Action /// Automatically call the update action when the Reset fires /// If the is called on a DI object, make sure it's available. - /// When using MEF, it would be best to call this from IPartImportsSatisfiedNotification.OnImportsSatisfied /// /// IIniSection /// Action to call on events, argument is the IniSectionEventArgs @@ -82,7 +80,6 @@ public static IDisposable OnReset(this IIniSection iniSection, Action /// Automatically call the update action when the Saved fires /// If the is called on a DI object, make sure it's available. - /// When using MEF, it would be best to call this from IPartImportsSatisfiedNotification.OnImportsSatisfied /// /// IIniSection /// Action to call on events, argument is the IniSectionEventArgs @@ -104,7 +101,6 @@ public static IDisposable OnSaved(this IIniSection iniSection, Action /// Automatically call the update action when the Saving fires /// If the is called on a DI object, make sure it's available. - /// When using MEF, it would be best to call this from IPartImportsSatisfiedNotification.OnImportsSatisfied /// /// IIniSection /// Action to call on events, argument is the IniSectionEventArgs diff --git a/Dapplo.CaliburnMicro.Dapp/CaliburnMicroBootstrapper.cs b/Dapplo.CaliburnMicro.Dapp/CaliburnMicroBootstrapper.cs index 57e6b3cb..73a010d9 100644 --- a/Dapplo.CaliburnMicro.Dapp/CaliburnMicroBootstrapper.cs +++ b/Dapplo.CaliburnMicro.Dapp/CaliburnMicroBootstrapper.cs @@ -33,6 +33,7 @@ using Dapplo.Addons; using Dapplo.Log; using Dapplo.Utils.Resolving; +using System.Diagnostics.CodeAnalysis; #endregion @@ -47,16 +48,27 @@ namespace Dapplo.CaliburnMicro.Dapp public class CaliburnMicroBootstrapper : BootstrapperBase, IAsyncShutdownAction { private static readonly LogSource Log = new LogSource(); + private readonly IServiceExporter _serviceExporter; + private readonly IServiceLocator _serviceLocator; + private readonly IServiceRepository _serviceRepository; - [Import] - private IServiceExporter ServiceExporter { get; set; } - - [Import] - private IServiceLocator ServiceLocator { get; set; } - - [Import] - private IServiceRepository ServiceRepository { get; set; } - + /// + /// CaliburnMicroBootstrapper + /// + /// Used to export + /// Used to locate + /// Used to add assemblies + [ImportingConstructor] + public CaliburnMicroBootstrapper( + IServiceExporter serviceExporter, + IServiceLocator serviceLocator, + IServiceRepository serviceRepository + ) + { + _serviceExporter = serviceExporter; + _serviceLocator = serviceLocator; + _serviceRepository = serviceRepository; + } /// /// Shutdown Caliburn /// @@ -75,35 +87,36 @@ public class CaliburnMicroBootstrapper : BootstrapperBase, IAsyncShutdownAction /// some object to fill protected override void BuildUp(object instance) { - ServiceLocator.FillImports(instance); + _serviceLocator.FillImports(instance); } /// /// Configure the Dapplo.Addon.Bootstrapper with the AssemblySource.Instance values /// + [SuppressMessage("Sonar Code Smell", "S2696:Instance members should not write to static fields", Justification = "This is the only location where it makes sense.")] protected override void Configure() { LogManager.GetLog = type => new CaliburnLogger(type); foreach (var assembly in AssemblySource.Instance) { - ServiceRepository.Add(assembly); + _serviceRepository.Add(assembly); } ConfigureViewLocator(); // Test if there is a IWindowManager available, if not use the default - var windowManagers = ServiceLocator.GetExports(); + var windowManagers = _serviceLocator.GetExports(); if (!windowManagers.Any()) { - ServiceExporter.Export(new DapploWindowManager()); + _serviceExporter.Export(new DapploWindowManager()); } // Test if there is a IEventAggregator available, if not use the default - var eventAggregators = ServiceLocator.GetExports(); + var eventAggregators = _serviceLocator.GetExports(); if (!eventAggregators.Any()) { - ServiceExporter.Export(new EventAggregator()); + _serviceExporter.Export(new EventAggregator()); } // TODO: Documentation @@ -120,6 +133,7 @@ protected override void Configure() /// /// Add logic to find the base viewtype if the default locator can't find a view. /// + [SuppressMessage("Sonar Code Smell", "S2696:Instance members should not write to static fields", Justification = "This is the only location where it makes sense.")] private void ConfigureViewLocator() { var defaultLocator = ViewLocator.LocateTypeForModelType; @@ -153,7 +167,7 @@ private void ConfigureViewLocator() /// protected override IEnumerable GetAllInstances(Type serviceType) { - return ServiceLocator.GetExports(serviceType).Select(x => x.Value); + return _serviceLocator.GetExports(serviceType).Select(x => x.Value); } /// @@ -165,7 +179,7 @@ protected override IEnumerable GetAllInstances(Type serviceType) protected override object GetInstance(Type serviceType, string key) { var contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key; - return ServiceLocator.GetExport(serviceType, contract); + return _serviceLocator.GetExport(serviceType, contract); } /// @@ -179,7 +193,7 @@ protected override void OnStartup(object sender, StartupEventArgs e) base.OnStartup(sender, e); // Inform when no IShell export is found - var shells = ServiceLocator.GetExports(); + var shells = _serviceLocator.GetExports(); if (shells.Any()) { // Display the IShell ViewModel diff --git a/Dapplo.CaliburnMicro.Dapp/Dapplo.CaliburnMicro.Dapp.csproj b/Dapplo.CaliburnMicro.Dapp/Dapplo.CaliburnMicro.Dapp.csproj index f298a8f6..14d89e48 100644 --- a/Dapplo.CaliburnMicro.Dapp/Dapplo.CaliburnMicro.Dapp.csproj +++ b/Dapplo.CaliburnMicro.Dapp/Dapplo.CaliburnMicro.Dapp.csproj @@ -85,7 +85,6 @@ - diff --git a/Dapplo.CaliburnMicro.Menu/TreeNodeExtensions.cs b/Dapplo.CaliburnMicro.Menu/TreeNodeExtensions.cs index 4abe902d..d5f180fb 100644 --- a/Dapplo.CaliburnMicro.Menu/TreeNodeExtensions.cs +++ b/Dapplo.CaliburnMicro.Menu/TreeNodeExtensions.cs @@ -78,27 +78,28 @@ public static IEnumerable> CreateTree(th } } - if (predicate != null) + if (predicate == null) { - // Filter out the ones which don't match the predicate - foreach (var treeNodeItem in treeNodes) + return rootItems; + } + // Filter out the ones which don't match the predicate + foreach (var treeNodeItem in treeNodes) + { + if (treeNodeItem.ChildNodes.Any()) + { + continue; + } + if (predicate(treeNodeItem)) + { + continue; + } + // should not be shown, removed it from it's parent or the root + treeNodeItem.ParentNode?.ChildNodes.Remove(treeNodeItem); + if (treeNodeItem.ParentNode?.ChildNodes != null && !treeNodeItem.ParentNode.ChildNodes.Any()) { - if (treeNodeItem.ChildNodes.Any()) - { - continue; - } - if (predicate(treeNodeItem)) - { - continue; - } - // should not be shown, removed it from it's parent or the root - treeNodeItem.ParentNode?.ChildNodes.Remove(treeNodeItem); - if (treeNodeItem.ParentNode?.ChildNodes != null && !treeNodeItem.ParentNode.ChildNodes.Any()) - { - rootItems.Remove(treeNodeItem.ParentNode); - } - rootItems.Remove(treeNodeItem); + rootItems.Remove(treeNodeItem.ParentNode); } + rootItems.Remove(treeNodeItem); } return rootItems; } diff --git a/Dapplo.CaliburnMicro.Metro/MetroWindowManager.cs b/Dapplo.CaliburnMicro.Metro/MetroWindowManager.cs index c73afcf9..d1c9adc6 100644 --- a/Dapplo.CaliburnMicro.Metro/MetroWindowManager.cs +++ b/Dapplo.CaliburnMicro.Metro/MetroWindowManager.cs @@ -47,7 +47,7 @@ namespace Dapplo.CaliburnMicro.Metro /// here /// [Export(typeof(IWindowManager))] - public sealed class MetroWindowManager : DapploWindowManager, IPartImportsSatisfiedNotification + public sealed class MetroWindowManager : DapploWindowManager { private static readonly LogSource Log = new LogSource(); @@ -73,9 +73,9 @@ public sealed class MetroWindowManager : DapploWindowManager, IPartImportsSatisf public ThemeAccents ThemeAccent { get; private set; } /// - /// Called when a part's imports have been satisfied and it is safe to use. + /// Default constructor taking care of initialization /// - public void OnImportsSatisfied() + public MetroWindowManager() { foreach (var style in Styles) { diff --git a/Dapplo.CaliburnMicro.NotifyIconWpf/ITrayIconViewModel.cs b/Dapplo.CaliburnMicro.NotifyIconWpf/ITrayIconViewModel.cs index 5ce0971f..effffea7 100644 --- a/Dapplo.CaliburnMicro.NotifyIconWpf/ITrayIconViewModel.cs +++ b/Dapplo.CaliburnMicro.NotifyIconWpf/ITrayIconViewModel.cs @@ -40,7 +40,7 @@ public interface ITrayIconViewModel : IViewAware /// /// Gives write access to the "underlying" TrayIcon.Icon via a FrameworkElement /// - FrameworkElement Icon { set; } + void SetIcon(FrameworkElement icon); /// /// The ITrayIcon for the ViewModel diff --git a/Dapplo.CaliburnMicro.NotifyIconWpf/TrayIconManager.cs b/Dapplo.CaliburnMicro.NotifyIconWpf/TrayIconManager.cs index 6087c137..a417cc97 100644 --- a/Dapplo.CaliburnMicro.NotifyIconWpf/TrayIconManager.cs +++ b/Dapplo.CaliburnMicro.NotifyIconWpf/TrayIconManager.cs @@ -46,6 +46,8 @@ namespace Dapplo.CaliburnMicro.NotifyIconWpf public class TrayIconManager : IAsyncStartupAction, IAsyncShutdownAction, ITrayIconManager { private static readonly LogSource Log = new LogSource(); + private readonly IEnumerable> _trayIconViewModels; + private readonly IWindowManager _windowsManager; /// /// Cache for the created tray icons @@ -53,11 +55,21 @@ public class TrayIconManager : IAsyncStartupAction, IAsyncShutdownAction, ITrayI private readonly IDictionary, WeakReference> _trayIcons = new Dictionary, WeakReference>(); - [ImportMany] - private IEnumerable> TrayIconViewModels { get; set; } - [Import] - private IWindowManager WindowsManager { get; set; } + /// + /// Default constructor + /// + /// IEnumerable with laze trayicon ViewModels + /// IWindowManager + [ImportingConstructor] + public TrayIconManager( + [ImportMany]IEnumerable> trayIconViewModels, + IWindowManager windowsManager + ) + { + _windowsManager = windowsManager; + _trayIconViewModels = trayIconViewModels; + } /// /// Hide all trayicons to prevent them hanging useless in the system tray @@ -103,7 +115,7 @@ await Execute.OnUIThreadAsync(() => { await Execute.OnUIThreadAsync(() => { - foreach (var trayIconViewModel in TrayIconViewModels.Select(x => x.Value)) + foreach (var trayIconViewModel in _trayIconViewModels.Select(x => x.Value)) { // Get the view, to store it as ITrayIcon trayIconViewModel.ViewAttached += (sender, e) => @@ -113,7 +125,7 @@ await Execute.OnUIThreadAsync(() => var trayIcon = popup?.Child as ITrayIcon ?? contentControl?.Content as ITrayIcon ?? e.View as ITrayIcon; _trayIcons.Add(new WeakReference(trayIconViewModel), new WeakReference(trayIcon)); }; - WindowsManager.ShowPopup(trayIconViewModel); + _windowsManager.ShowPopup(trayIconViewModel); } }); } diff --git a/Dapplo.CaliburnMicro.NotifyIconWpf/ViewModels/TrayIconViewModel.cs b/Dapplo.CaliburnMicro.NotifyIconWpf/ViewModels/TrayIconViewModel.cs index fa681b34..5229f4cb 100644 --- a/Dapplo.CaliburnMicro.NotifyIconWpf/ViewModels/TrayIconViewModel.cs +++ b/Dapplo.CaliburnMicro.NotifyIconWpf/ViewModels/TrayIconViewModel.cs @@ -28,7 +28,6 @@ using System.Windows; using Caliburn.Micro; using Dapplo.CaliburnMicro.Behaviors; -using Dapplo.CaliburnMicro.Extensions; using Dapplo.CaliburnMicro.Menu; using Dapplo.Log; @@ -78,13 +77,10 @@ public virtual void Hide() /// /// Set the Icon to the underlying TrayIcon.Icon /// - public FrameworkElement Icon + public void SetIcon(FrameworkElement value) { - set - { - var taskbarIcon = TrayIcon as FrameworkElement; - taskbarIcon?.SetCurrentValue(FrameworkElementIcon.ValueProperty, value); - } + var taskbarIcon = TrayIcon as FrameworkElement; + taskbarIcon?.SetCurrentValue(FrameworkElementIcon.ValueProperty, value); } /// diff --git a/Dapplo.CaliburnMicro.Translations/LanguageChangedExtensions.cs b/Dapplo.CaliburnMicro.Translations/LanguageChangedExtensions.cs index 45dd27bb..6c0c7bcf 100644 --- a/Dapplo.CaliburnMicro.Translations/LanguageChangedExtensions.cs +++ b/Dapplo.CaliburnMicro.Translations/LanguageChangedExtensions.cs @@ -37,7 +37,6 @@ public static class LanguageChangedExtensions /// /// Automatically call the update action when the LanguageChanged fires /// If the is called on a DI object, make sure it's available. - /// When using MEF, it would be best to call this from IPartImportsSatisfiedNotification.OnImportsSatisfied /// /// ILanguage /// Action to call on active and update, the argument is the property name diff --git a/Dapplo.CaliburnMicro.sln b/Dapplo.CaliburnMicro.sln index 6791b328..207f449c 100644 --- a/Dapplo.CaliburnMicro.sln +++ b/Dapplo.CaliburnMicro.sln @@ -29,6 +29,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapplo.CaliburnMicro.Transl EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapplo.CaliburnMicro.Security.ActiveDirectory", "Dapplo.CaliburnMicro.Security.ActiveDirectory\Dapplo.CaliburnMicro.Security.ActiveDirectory.csproj", "{294B4089-CF38-4F09-ADAC-C85C481C2EF1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dapplo.Caliburn.Tests", "Dapplo.Caliburn.Tests\Dapplo.Caliburn.Tests.csproj", "{C62CC807-6929-4DDE-9B30-EA3483E46D41}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -87,6 +89,10 @@ Global {294B4089-CF38-4F09-ADAC-C85C481C2EF1}.Debug|Any CPU.Build.0 = Debug|Any CPU {294B4089-CF38-4F09-ADAC-C85C481C2EF1}.Release|Any CPU.ActiveCfg = Release|Any CPU {294B4089-CF38-4F09-ADAC-C85C481C2EF1}.Release|Any CPU.Build.0 = Release|Any CPU + {C62CC807-6929-4DDE-9B30-EA3483E46D41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C62CC807-6929-4DDE-9B30-EA3483E46D41}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C62CC807-6929-4DDE-9B30-EA3483E46D41}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C62CC807-6929-4DDE-9B30-EA3483E46D41}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Dapplo.CaliburnMicro.Dapp/CaliburnLogger.cs b/Dapplo.CaliburnMicro/CaliburnLogger.cs similarity index 92% rename from Dapplo.CaliburnMicro.Dapp/CaliburnLogger.cs rename to Dapplo.CaliburnMicro/CaliburnLogger.cs index 8e67797a..5e5d29fa 100644 --- a/Dapplo.CaliburnMicro.Dapp/CaliburnLogger.cs +++ b/Dapplo.CaliburnMicro/CaliburnLogger.cs @@ -27,7 +27,7 @@ #endregion -namespace Dapplo.CaliburnMicro.Dapp +namespace Dapplo.CaliburnMicro { /// /// A logger for Caliburn @@ -55,14 +55,14 @@ public void Error(Exception exception) } /// - /// Log information + /// Log information, this is actually reduced to the Dapplo-Level debug as Caliburn speaks a lot! /// /// /// public void Info(string format, params object[] args) { // Pre-format the message, otherwise we get problems with dependency objects etc - _log.Info().WriteLine(format, args); + _log.Debug().WriteLine(format, args); } /// diff --git a/Dapplo.CaliburnMicro/Dapplo.CaliburnMicro.csproj b/Dapplo.CaliburnMicro/Dapplo.CaliburnMicro.csproj index 8571bf4a..e2c552b3 100644 --- a/Dapplo.CaliburnMicro/Dapplo.CaliburnMicro.csproj +++ b/Dapplo.CaliburnMicro/Dapplo.CaliburnMicro.csproj @@ -55,8 +55,8 @@ ..\packages\Dapplo.Log.1.0.29\lib\net45\Dapplo.Log.dll True - - ..\packages\Dapplo.Windows.0.3.36\lib\net45\Dapplo.Windows.dll + + ..\packages\Dapplo.Windows.0.3.37\lib\net45\Dapplo.Windows.dll True @@ -89,6 +89,7 @@ + diff --git a/Dapplo.CaliburnMicro/packages.config b/Dapplo.CaliburnMicro/packages.config index ed794d96..3fae900d 100644 --- a/Dapplo.CaliburnMicro/packages.config +++ b/Dapplo.CaliburnMicro/packages.config @@ -4,7 +4,7 @@ - +