Skip to content

Commit

Permalink
It must be possible to start whatsON when plugin referenced in config…
Browse files Browse the repository at this point in the history
…uration is not available. Log error instead of throwing exception. Add special viewmodel to display the subject which can't be properly created.
  • Loading branch information
dominikgolda committed Apr 23, 2019
1 parent 4ec61eb commit 4925d9b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/Soloplan.WhatsON.GUI/Soloplan.WhatsON.GUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Config\ConfigResourcesHelper.cs" />
<Compile Include="Logging\ExceptionHandlingInitialization.cs" />
<Compile Include="Logging\LoggingConfiguration.cs" />
<Compile Include="SubjectTreeView\SubjectMissingViewModel.cs" />
<Compile Include="VisualConfig\GroupExpansionSettings.cs" />
<Compile Include="VisualConfig\MainWindowSettigns.cs" />
<Compile Include="NotificationsModel.cs" />
Expand Down Expand Up @@ -188,6 +189,10 @@
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Page Include="SubjectTreeView\SubjectMissingDataTemplate.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="SubjectTreeView\SubjectsTreeView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public void OnDoubleClick(object sender, MouseButtonEventArgs e)

private SubjectViewModel GetSubjectViewModel(Subject subject)
{
if (subject == null)
{
return new SubjectMissingViewModel();
}

var presentationPlugIn = PluginsManager.Instance.GetPresentationPlugIn(subject.GetType());
if (presentationPlugIn != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Soloplan.WhatsON.GUI.SubjectTreeView">

<ContextMenu x:Key="copyData">
<MenuItem Header="Copy data" Command="{Binding CopyData}" />
</ContextMenu>

<DataTemplate DataType="{x:Type local:SubjectMissingViewModel}">
<StackPanel Orientation="Horizontal" ContextMenu="{StaticResource copyData}">
<StackPanel.ToolTip>
<StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Identifier: " />
<TextBlock Text="{Binding Identifier, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Name: " />
<TextBlock Text="{Binding Name, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Description: " />
<TextBlock Text="{Binding Description, Mode=OneWay}" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Expected plugin type: " />
<TextBlock Text="{Binding ExpectedPluginType, Mode=OneWay}" />
</StackPanel>
</StackPanel>
</StackPanel.ToolTip>
<TextBlock FontWeight="Bold" Text="No plugIn found: " />
<TextBlock Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="SubjectMissingViewModel.cs" company="Soloplan GmbH">
// Copyright (c) Soloplan GmbH. All rights reserved.
// Licensed under the MIT License. See License-file in the project root for license information.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Soloplan.WhatsON.GUI.SubjectTreeView
{
using System.Text;
using System.Windows;
using System.Windows.Input;
using Microsoft.Expression.Interactivity.Core;

public class SubjectMissingViewModel : SubjectViewModel
{
public SubjectMissingViewModel()
{
void Act()
{
var builder = new StringBuilder();
builder.AppendLine($"Identifier: {this.Identifier}");
builder.AppendLine($"Name: {this.Name}");
builder.AppendLine($"Description: {this.Description}");
builder.AppendLine($"Expected plugin type: {this.ExpectedPluginType}");
Clipboard.SetText(builder.ToString());
}

this.CopyData = new ActionCommand(Act);
}

/// <summary>
/// Gets command for copying model data to clipboard.
/// </summary>
public ICommand CopyData { get; }

/// <summary>
/// Gets plugin type which was expected.
/// </summary>
public string ExpectedPluginType { get; private set; }

/// <summary>
/// Initializes viewmodel based on <paramref name="configuration"/>.
/// </summary>
/// <param name="configuration">Configuration of this subject.</param>
public override void Init(SubjectConfiguration configuration)
{
this.ExpectedPluginType = configuration.PluginTypeName;
base.Init(configuration);
}

/// <summary>
/// Doesn't do anything since <paramref name="changedSubject"/> is null.
/// </summary>
/// <param name="changedSubject">Subject which has changed - always null.</param>
public override void Update(Subject changedSubject)
{
return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
Fill="{Binding CurrentStatus.State, Mode=OneWay, Converter={StaticResource StatusToColorConverter}}" />
</StackPanel>
</DataTemplate>

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="SubjectMissingDataTemplate.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>

Expand Down
6 changes: 4 additions & 2 deletions src/Soloplan.WhatsON/PlugInsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ public Subject CreateNewSubject(SubjectConfiguration subjectConfiguration)
var plugin = this.SubjectPlugins.FirstOrDefault(p => p.GetType().FullName == subjectConfiguration.PluginTypeName);
if (plugin == null)
{
throw new InvalidOperationException($"Couldn't find plugin for a type: {subjectConfiguration.PluginTypeName}");
log.Error("Couldn't find plugin for a type: {pluginType}", subjectConfiguration.PluginTypeName);
return null;
}

var subject = plugin.CreateNew(subjectConfiguration);
Expand All @@ -156,7 +157,8 @@ public Subject GetSubject(SubjectConfiguration subjectConfiguration)
var plugin = this.SubjectPlugins.FirstOrDefault(p => p.GetType().FullName == subjectConfiguration.PluginTypeName);
if (plugin == null)
{
throw new InvalidOperationException($"Couldn't find plugin for a type: {subjectConfiguration.PluginTypeName}");
log.Error("Couldn't find plugin for a type: {pluginType}", subjectConfiguration.PluginTypeName);
return null;
}

return plugin.CreateNew(subjectConfiguration);
Expand Down

0 comments on commit 4925d9b

Please sign in to comment.