From 785ddbd5b2cffda04613d75aa155a3d2c3ca63a8 Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 10 Jan 2022 11:52:07 +0100 Subject: [PATCH 1/6] Implemented a few ToDo's - Check required fields before publishing - Allow cancelling of package downloading - Check for JsonConverter attribute - Improved read/unread message separator --- .../TapetiClassLibraryExampleGenerator.cs | 10 +-- PettingZoo.Tapeti/TypeToJObjectConverter.cs | 16 ++++- .../PackageProgressStrings.Designer.cs | 9 +++ .../PackageProgressStrings.resx | 7 +- .../PackageProgressWindow.xaml | 9 ++- .../PackageProgressWindow.xaml.cs | 19 ++++++ .../PackageSelectionViewModel.cs | 1 - PettingZoo/TODO.md | 2 +- .../UI/Tab/Publisher/PublisherViewModel.cs | 31 +++++++-- .../UI/Tab/Publisher/RawPublisherViewModel.cs | 7 +- .../Tab/Publisher/TapetiPublisherViewModel.cs | 22 +++++-- .../UI/Tab/Subscriber/SubscriberView.xaml | 53 ++++++++------- .../UI/Tab/Subscriber/SubscriberViewModel.cs | 65 ++++++++++++------- 13 files changed, 172 insertions(+), 79 deletions(-) diff --git a/PettingZoo.Tapeti/TapetiClassLibraryExampleGenerator.cs b/PettingZoo.Tapeti/TapetiClassLibraryExampleGenerator.cs index ef2b4e7..038daa3 100644 --- a/PettingZoo.Tapeti/TapetiClassLibraryExampleGenerator.cs +++ b/PettingZoo.Tapeti/TapetiClassLibraryExampleGenerator.cs @@ -54,12 +54,13 @@ namespace PettingZoo.Tapeti progressWindow.Top = windowBounds.Top + (windowBounds.Height - progressWindow.Height) / 2; progressWindow.Show(); + var cancellationToken = progressWindow.CancellationToken; + Task.Run(async () => { try { - // TODO allow cancelling (by closing the progress window and optionally a Cancel button) - var assemblies = await args.Assemblies.GetAssemblies(progressWindow, CancellationToken.None); + var assemblies = await args.Assemblies.GetAssemblies(progressWindow, cancellationToken); // var classes = var examples = LoadExamples(assemblies); @@ -94,10 +95,11 @@ namespace PettingZoo.Tapeti // ReSharper disable once ConstantConditionalAccessQualifier - if I remove it, there's a "Dereference of a possibly null reference" warning instead progressWindow?.Close(); - MessageBox.Show($"Error while loading assembly: {e.Message}", "Petting Zoo - Exception", MessageBoxButton.OK, MessageBoxImage.Error); + if (e is not OperationCanceledException) + MessageBox.Show($"Error while loading assembly: {e.Message}", "Petting Zoo - Exception", MessageBoxButton.OK, MessageBoxImage.Error); }); } - }); + }, CancellationToken.None); }); }; diff --git a/PettingZoo.Tapeti/TypeToJObjectConverter.cs b/PettingZoo.Tapeti/TypeToJObjectConverter.cs index 2bb652f..7efcd8e 100644 --- a/PettingZoo.Tapeti/TypeToJObjectConverter.cs +++ b/PettingZoo.Tapeti/TypeToJObjectConverter.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace PettingZoo.Tapeti @@ -59,7 +60,20 @@ namespace PettingZoo.Tapeti actualType = equivalentType; - // TODO check for JsonConverter attribute? doubt we'll be able to generate a nice value for it, but at least we can provide a placeholder + try + { + if (type.GetCustomAttribute() != null) + { + // This type uses custom Json conversion so there's no way to know how to provide an example. + // We could try to create an instance of the type and pass it through the converter, but for now we'll + // just output a placeholder. + return ""; + } + } + catch + { + // Move along + } // String is also a class if (actualType == typeof(string)) diff --git a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.Designer.cs b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.Designer.cs index e0b38ff..6a82b2a 100644 --- a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.Designer.cs +++ b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.Designer.cs @@ -60,6 +60,15 @@ namespace PettingZoo.Tapeti.UI.PackageProgress { } } + /// + /// Looks up a localized string similar to Cancel. + /// + public static string ButtonCancel { + get { + return ResourceManager.GetString("ButtonCancel", resourceCulture); + } + } + /// /// Looks up a localized string similar to Reading message classes.... /// diff --git a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.resx b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.resx index 1d6d493..eccbf8f 100644 --- a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.resx +++ b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressStrings.resx @@ -112,11 +112,14 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Cancel + Reading message classes... diff --git a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressWindow.xaml b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressWindow.xaml index 45ccb52..aef7232 100644 --- a/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressWindow.xaml +++ b/PettingZoo.Tapeti/UI/PackageProgress/PackageProgressWindow.xaml @@ -5,10 +5,13 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:packageProgress="clr-namespace:PettingZoo.Tapeti.UI.PackageProgress" mc:Ignorable="d" - Height="80" Width="400" Title="{x:Static packageProgress:PackageProgressStrings.WindowTitle}" ResizeMode="NoResize" - WindowStyle="ToolWindow"> - + WindowStyle="ToolWindow" + SizeToContent="Height"> + + + + +