Skip to content

Commit

Permalink
Code quality changes, which do change the API slightly.
Browse files Browse the repository at this point in the history
[release]
  • Loading branch information
Lakritzator committed Apr 27, 2017
1 parent 56a2ee1 commit 6b3b8f2
Show file tree
Hide file tree
Showing 41 changed files with 508 additions and 264 deletions.
24 changes: 15 additions & 9 deletions Application.Demo.Addon/ViewModels/AddonSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 8 additions & 11 deletions Application.Demo.Addon/ViewModels/AdminConfigViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,21 @@
namespace Application.Demo.Addon.ViewModels
{
[Export(typeof(IConfigScreen))]
public sealed class AdminConfigViewModel : AuthenticatedConfigScreen<Visibility>, IPartImportsSatisfiedNotification
public sealed class AdminConfigViewModel : AuthenticatedConfigScreen<Visibility>
{
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));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro.IconPacks, Version=1.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.1.8.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
<Reference Include="MahApps.Metro.IconPacks, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.1.9.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
Expand Down
2 changes: 1 addition & 1 deletion Application.Demo.MetroAddon/packages.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<package id="Dapplo.Log" version="1.0.29" targetFramework="net452" />
<package id="Dapplo.Utils" version="1.0.132" targetFramework="net452" />
<package id="MahApps.Metro" version="1.5.0" targetFramework="net452" />
<package id="MahApps.Metro.IconPacks" version="1.8.0" targetFramework="net452" />
<package id="MahApps.Metro.IconPacks" version="1.9.0" targetFramework="net452" />
<package id="System.Reactive.Core" version="3.1.1" targetFramework="net45" />
<package id="System.Reactive.Interfaces" version="3.1.1" targetFramework="net45" />
<package id="System.Reactive.Linq" version="3.1.1" targetFramework="net45" />
Expand Down
22 changes: 12 additions & 10 deletions Application.Demo/Application.Demo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@
<HintPath>..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MahApps.Metro.IconPacks, Version=1.8.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.1.8.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
<Reference Include="MahApps.Metro.IconPacks, Version=1.9.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.IconPacks.1.9.0\lib\net45\MahApps.Metro.IconPacks.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand Down Expand Up @@ -269,16 +269,9 @@
</Page>
</ItemGroup>
<ItemGroup>
<Resource Include="FodyWeavers.xml" />
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.1.29.4\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets') And '$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.1.29.4\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.1.29.4\build\dotnet\Fody.targets'))" />
</Target>
<UsingTask TaskName="CosturaCleanup" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" TaskFactory="CodeTaskFactory">
<ParameterGroup>
<Config Output="false" Required="true" ParameterType="Microsoft.Build.Framework.ITaskItem" />
Expand Down Expand Up @@ -315,6 +308,15 @@ foreach (var item in filesToCleanup)
<Target Name="CleanReferenceCopyLocalPaths" AfterTargets="AfterBuild;NonWinFodyTarget" Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<CosturaCleanup Config="FodyWeavers.xml" Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')" />
</Target>
<Import Project="..\packages\Fody.2.0.6\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.6\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Fody.2.0.6\build\dotnet\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.0.6\build\dotnet\Fody.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets'))" />
</Target>
<Import Project="..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.4.0\build\Costura.Fody.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
4 changes: 2 additions & 2 deletions Application.Demo/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura CreateTemporaryAssemblies='true' />
<Costura />
</Weavers>
2 changes: 1 addition & 1 deletion Application.Demo/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public static void Main()
{
#if DEBUG
// Initialize a debug logger for Dapplo packages
LogSettings.RegisterDefaultLogger<DebugLogger>(LogLevels.Verbose);
LogSettings.RegisterDefaultLogger<DebugLogger>(LogLevels.Info);
#endif
var application = new Dapplication("Application.Demo", "f32dbad8-9904-473e-86e2-19275c2d06a5")
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ namespace Application.Demo.UseCases.Configuration.ViewModels
/// This is just a placeholder, doesn't have a view
/// </summary>
[Export(typeof(IConfigScreen))]
public sealed class AddonConfigNodeViewModel : ConfigScreen, IPartImportsSatisfiedNotification
{
[Import]
public IConfigTranslations ConfigTranslations { get; set; }

public void OnImportsSatisfied()
public sealed class AddonConfigNodeViewModel : ConfigScreen
{
[ImportingConstructor]
public AddonConfigNodeViewModel(IConfigTranslations configTranslations)
{
// automatically update the DisplayName
ConfigTranslations.CreateDisplayNameBinding(this, nameof(ConfigTranslations.Addons));
configTranslations.CreateDisplayNameBinding(this, nameof(IConfigTranslations.Addons));
CanActivate = false;
Id = nameof(ConfigIds.Addons);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,72 +44,74 @@ namespace Application.Demo.UseCases.Configuration.ViewModels
/// It is a conductor where one item is active.
/// </summary>
[Export]
public class ConfigViewModel : Config<IConfigScreen>, IPartImportsSatisfiedNotification
public sealed class ConfigViewModel : Config<IConfigScreen>
{
private static readonly LogSource Log = new LogSource();

/// <summary>
/// Get all settings controls, these are the items that are displayed.
/// </summary>
[ImportMany]
public override IEnumerable<Lazy<IConfigScreen>> ConfigScreens { get; set; }

[Import]
public IConfigTranslations ConfigTranslations { get; set; }

[Import]
public ICoreTranslations CoreTranslations { get; set; }

[Import]
private IDemoConfiguration DemoConfiguration { get; set; }

[Import]
private WizardExampleViewModel DemoDialogViewModel { get; set; }
private readonly WizardExampleViewModel _demoDialogViewModel;

/// <summary>
/// Used to make it possible to show a MahApps dialog
/// </summary>
[Import]
private IDialogCoordinator Dialogcoordinator { get; set; }
private readonly IDialogCoordinator _dialogcoordinator;

/// <summary>
/// Used to show a "normal" dialog
/// </summary>
[Import]
private IWindowManager WindowsManager { get; set; }
private readonly IWindowManager _windowsManager;

/// <summary>
/// Used to send events
/// Is used from View
/// </summary>
[Import]
private IEventAggregator EventAggregator { get; set; }
public IConfigTranslations ConfigTranslations { get; }

public void OnImportsSatisfied()
/// <summary>
/// Is used from View
/// </summary>
public ICoreTranslations CoreTranslations { get; }

[ImportingConstructor]
public ConfigViewModel(
[ImportMany] IEnumerable<Lazy<IConfigScreen>> configScreens,
IWindowManager windowsManager,
IConfigTranslations configTranslations,
ICoreTranslations coreTranslations,
IDialogCoordinator dialogcoordinator,
IDemoConfiguration demoConfiguration,
WizardExampleViewModel demoDialogViewModel)
{
ConfigScreens = configScreens;
ConfigTranslations = configTranslations;
CoreTranslations = coreTranslations;
_windowsManager = windowsManager;
_dialogcoordinator = dialogcoordinator;
_demoDialogViewModel = demoDialogViewModel;

// automatically update the DisplayName
CoreTranslations.CreateDisplayNameBinding(this, nameof(ICoreTranslations.Settings));

// Set the current language (this should update all registered OnPropertyChanged anyway, so it can run in the background
var lang = DemoConfiguration.Language;
var lang = demoConfiguration.Language;
Task.Run(async () => await LanguageLoader.Current.ChangeLanguageAsync(lang).ConfigureAwait(false));
}

/// <summary>
/// Show the credentials for the login
/// </summary>
// ReSharper disable once UnusedMember.Global
public void Login()
{
var result = WindowsManager.ShowDialog(DemoDialogViewModel);
var result = _windowsManager.ShowDialog(_demoDialogViewModel);
Log.Info().WriteLine($"Girl you know it's {result}");
}

/// <summary>
/// Show a MahApps dialog from the MVVM
/// </summary>
/// <returns></returns>
// ReSharper disable once UnusedMember.Global
public async Task Dialog()
{
await Dialogcoordinator.ShowMessageAsync(this, "Message from VM", "MVVM based dialogs!");
await _dialogcoordinator.ShowMessageAsync(this, "Message from VM", "MVVM based dialogs!");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public sealed class LanguageConfigViewModel : ConfigScreen
/// Here all disposables are registered, so we can clean the up
/// </summary>
private CompositeDisposable _disposables;
private readonly IEventAggregator _eventAggregator;


/// <summary>
/// Used from the View
/// </summary>
// ReSharper disable once UnusedMember.Global
public IDictionary<string, string> AvailableLanguages => LanguageLoader.Current.AvailableLanguages;

/// <summary>
Expand All @@ -52,20 +58,26 @@ public sealed class LanguageConfigViewModel : ConfigScreen
public bool CanChangeLanguage
=> !string.IsNullOrWhiteSpace(DemoConfiguration.Language) && DemoConfiguration.Language != LanguageLoader.Current.CurrentLanguage;

[Import]
public ICoreTranslations CoreTranslations { get; set; }
public ICoreTranslations CoreTranslations { get; }

[Import]
public IDemoConfiguration DemoConfiguration { get; set; }
public IDemoConfiguration DemoConfiguration { get;}

[Import]
private IEventAggregator EventAggregator { get; set; }
[ImportingConstructor]
public LanguageConfigViewModel(
ICoreTranslations coreTranslations,
IDemoConfiguration demoConfiguration,
IEventAggregator eventAggregator)
{
_eventAggregator = eventAggregator;
DemoConfiguration = demoConfiguration;
CoreTranslations = coreTranslations;
}

public override void Commit()
{
// Manually commit
DemoConfiguration.CommitTransaction();
EventAggregator.PublishOnUIThread($"Changing to language: {DemoConfiguration.Language}");
_eventAggregator.PublishOnUIThread($"Changing to language: {DemoConfiguration.Language}");
Execute.OnUIThread(async () => { await LanguageLoader.Current.ChangeLanguageAsync(DemoConfiguration.Language).ConfigureAwait(false); });

base.Commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@

namespace Application.Demo.UseCases.Configuration.ViewModels
{
/// <summary>
/// This represents a node in the config
/// </summary>
[Export(typeof(IConfigScreen))]
public sealed class UiConfigNodeViewModel : ConfigScreen, IPartImportsSatisfiedNotification
public sealed class UiConfigNodeViewModel : ConfigScreen
{
[Import]
public IConfigTranslations ConfigTranslations { get; set; }
public IConfigTranslations ConfigTranslations { get; }

public void OnImportsSatisfied()
[ImportingConstructor]
public UiConfigNodeViewModel(IConfigTranslations configTranslations)
{
ConfigTranslations = configTranslations;

// automatically update the DisplayName
ConfigTranslations.CreateDisplayNameBinding(this, nameof(IConfigTranslations.Ui));

Expand Down
Loading

0 comments on commit 6b3b8f2

Please sign in to comment.