From 702c1187837dd5494f4ec545097f9909fcf15d87 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Mon, 8 May 2017 20:09:29 +0100 Subject: [PATCH 01/15] Added appveyor.yml --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..0de86f0 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,2 @@ +before_build: + - nuget restore \ No newline at end of file From 733c7d1757dc8222f4d2c1e2f2aa0de6bf574523 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Mon, 8 May 2017 20:12:24 +0100 Subject: [PATCH 02/15] Added [Ignore] to integration unit tests --- .../Repositories/TestItemSetRepository.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Filtration.ItemFilterPreview.Data.Tests/Repositories/TestItemSetRepository.cs b/Filtration.ItemFilterPreview.Data.Tests/Repositories/TestItemSetRepository.cs index 60db3ef..a593d1f 100644 --- a/Filtration.ItemFilterPreview.Data.Tests/Repositories/TestItemSetRepository.cs +++ b/Filtration.ItemFilterPreview.Data.Tests/Repositories/TestItemSetRepository.cs @@ -6,6 +6,7 @@ using NUnit.Framework; namespace Filtration.ItemFilterPreview.Data.Tests.Repositories { + [Ignore("integration test")] [TestFixture] public class TestItemSetRepository { From 3fe021949a14dd85f36644e1aa1e43336021056a Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Tue, 9 May 2017 21:41:51 +0100 Subject: [PATCH 03/15] Replaced AutoMapper usage for ItemFilterBlockGroup viewmodel mapping with constructor overload Updated NuGet packages --- .../Filtration.Common.Tests.csproj | 10 +- Filtration.Common.Tests/packages.config | 4 +- Filtration.Common/Filtration.Common.csproj | 4 +- Filtration.Common/packages.config | 2 +- ...ration.ItemFilterPreview.Data.Tests.csproj | 5 +- .../packages.config | 2 +- .../Filtration.ItemFilterPreview.Tests.csproj | 20 +- Filtration.ItemFilterPreview.Tests/app.config | 2 +- .../packages.config | 6 +- .../Filtration.ItemFilterPreview.csproj | 10 +- Filtration.ItemFilterPreview/packages.config | 4 +- .../Filtration.ObjectModel.Tests.csproj | 10 +- Filtration.ObjectModel.Tests/packages.config | 4 +- .../IItemFilterBlockItem.cs | 2 - .../Filtration.Parser.Tests.csproj | 20 +- Filtration.Parser.Tests/packages.config | 6 +- Filtration.Parser/Filtration.Parser.csproj | 5 +- Filtration.Parser/packages.config | 2 +- Filtration.Tests/Filtration.Tests.csproj | 20 +- Filtration.Tests/app.config | 2 +- Filtration.Tests/packages.config | 6 +- .../Filtration.ThemeEditor.Tests.csproj | 10 +- Filtration.ThemeEditor.Tests/packages.config | 4 +- .../Filtration.ThemeEditor.csproj | 12 +- Filtration.ThemeEditor/packages.config | 6 +- Filtration/App.config | 4 +- Filtration/App.xaml.cs | 34 +- Filtration/Filtration.csproj | 22 +- Filtration/NLog.xsd | 671 ++++++++++++++---- Filtration/Services/StaticDataService.cs | 2 - Filtration/Utilities/AutoMapperHelpers.cs | 32 - Filtration/Utilities/BlockGroupMapper.cs | 26 - .../ItemFilterBlockGroupViewModel.cs | 36 + .../ToolPanes/BlockGroupBrowserViewModel.cs | 18 +- .../WindsorInstallers/ServicesInstaller.cs | 6 - Filtration/packages.config | 10 +- 36 files changed, 676 insertions(+), 363 deletions(-) delete mode 100644 Filtration/Utilities/AutoMapperHelpers.cs delete mode 100644 Filtration/Utilities/BlockGroupMapper.cs diff --git a/Filtration.Common.Tests/Filtration.Common.Tests.csproj b/Filtration.Common.Tests/Filtration.Common.Tests.csproj index f5eaeec..4cef0e6 100644 --- a/Filtration.Common.Tests/Filtration.Common.Tests.csproj +++ b/Filtration.Common.Tests/Filtration.Common.Tests.csproj @@ -35,13 +35,11 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.Common.Tests/packages.config b/Filtration.Common.Tests/packages.config index c5d64ff..4b97194 100644 --- a/Filtration.Common.Tests/packages.config +++ b/Filtration.Common.Tests/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/Filtration.Common/Filtration.Common.csproj b/Filtration.Common/Filtration.Common.csproj index 3e0716c..13f3165 100644 --- a/Filtration.Common/Filtration.Common.csproj +++ b/Filtration.Common/Filtration.Common.csproj @@ -35,8 +35,8 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll diff --git a/Filtration.Common/packages.config b/Filtration.Common/packages.config index 088a524..0173a29 100644 --- a/Filtration.Common/packages.config +++ b/Filtration.Common/packages.config @@ -1,7 +1,7 @@  - + \ No newline at end of file diff --git a/Filtration.ItemFilterPreview.Data.Tests/Filtration.ItemFilterPreview.Data.Tests.csproj b/Filtration.ItemFilterPreview.Data.Tests/Filtration.ItemFilterPreview.Data.Tests.csproj index 5869c8a..30c7e22 100644 --- a/Filtration.ItemFilterPreview.Data.Tests/Filtration.ItemFilterPreview.Data.Tests.csproj +++ b/Filtration.ItemFilterPreview.Data.Tests/Filtration.ItemFilterPreview.Data.Tests.csproj @@ -46,9 +46,8 @@ ..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll True - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.ItemFilterPreview.Data.Tests/packages.config b/Filtration.ItemFilterPreview.Data.Tests/packages.config index 5229672..f051d19 100644 --- a/Filtration.ItemFilterPreview.Data.Tests/packages.config +++ b/Filtration.ItemFilterPreview.Data.Tests/packages.config @@ -1,7 +1,7 @@  - + diff --git a/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj b/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj index e6f2a41..e82122d 100644 --- a/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj +++ b/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj @@ -46,21 +46,17 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.Core.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.ItemFilterPreview.Tests/app.config b/Filtration.ItemFilterPreview.Tests/app.config index c1fa1bd..0c4712b 100644 --- a/Filtration.ItemFilterPreview.Tests/app.config +++ b/Filtration.ItemFilterPreview.Tests/app.config @@ -8,7 +8,7 @@ - + diff --git a/Filtration.ItemFilterPreview.Tests/packages.config b/Filtration.ItemFilterPreview.Tests/packages.config index a76be05..24885ed 100644 --- a/Filtration.ItemFilterPreview.Tests/packages.config +++ b/Filtration.ItemFilterPreview.Tests/packages.config @@ -1,8 +1,8 @@  - - - + + + \ No newline at end of file diff --git a/Filtration.ItemFilterPreview/Filtration.ItemFilterPreview.csproj b/Filtration.ItemFilterPreview/Filtration.ItemFilterPreview.csproj index f78f69b..88676a1 100644 --- a/Filtration.ItemFilterPreview/Filtration.ItemFilterPreview.csproj +++ b/Filtration.ItemFilterPreview/Filtration.ItemFilterPreview.csproj @@ -40,9 +40,8 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll - True + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll @@ -60,9 +59,8 @@ ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll True - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll diff --git a/Filtration.ItemFilterPreview/packages.config b/Filtration.ItemFilterPreview/packages.config index 7255210..500f87c 100644 --- a/Filtration.ItemFilterPreview/packages.config +++ b/Filtration.ItemFilterPreview/packages.config @@ -1,8 +1,8 @@  - + - + \ No newline at end of file diff --git a/Filtration.ObjectModel.Tests/Filtration.ObjectModel.Tests.csproj b/Filtration.ObjectModel.Tests/Filtration.ObjectModel.Tests.csproj index 0af02c0..69dd6ef 100644 --- a/Filtration.ObjectModel.Tests/Filtration.ObjectModel.Tests.csproj +++ b/Filtration.ObjectModel.Tests/Filtration.ObjectModel.Tests.csproj @@ -35,13 +35,11 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.ObjectModel.Tests/packages.config b/Filtration.ObjectModel.Tests/packages.config index c5d64ff..4b97194 100644 --- a/Filtration.ObjectModel.Tests/packages.config +++ b/Filtration.ObjectModel.Tests/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/Filtration.ObjectModel/IItemFilterBlockItem.cs b/Filtration.ObjectModel/IItemFilterBlockItem.cs index 021201e..ec693d0 100644 --- a/Filtration.ObjectModel/IItemFilterBlockItem.cs +++ b/Filtration.ObjectModel/IItemFilterBlockItem.cs @@ -5,8 +5,6 @@ namespace Filtration.ObjectModel { public interface IItemFilterBlockItem : INotifyPropertyChanged { - event PropertyChangedEventHandler PropertyChanged; - string PrefixText { get; } string OutputText { get; } string DisplayHeading { get; } diff --git a/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj b/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj index ee5be14..216294f 100644 --- a/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj +++ b/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj @@ -40,21 +40,17 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.Core.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.Parser.Tests/packages.config b/Filtration.Parser.Tests/packages.config index ded3f06..59fe830 100644 --- a/Filtration.Parser.Tests/packages.config +++ b/Filtration.Parser.Tests/packages.config @@ -1,7 +1,7 @@  - - - + + + \ No newline at end of file diff --git a/Filtration.Parser/Filtration.Parser.csproj b/Filtration.Parser/Filtration.Parser.csproj index c8291d2..2a8d160 100644 --- a/Filtration.Parser/Filtration.Parser.csproj +++ b/Filtration.Parser/Filtration.Parser.csproj @@ -35,9 +35,8 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll - True + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll diff --git a/Filtration.Parser/packages.config b/Filtration.Parser/packages.config index fce0733..89d6418 100644 --- a/Filtration.Parser/packages.config +++ b/Filtration.Parser/packages.config @@ -1,5 +1,5 @@  - + \ No newline at end of file diff --git a/Filtration.Tests/Filtration.Tests.csproj b/Filtration.Tests/Filtration.Tests.csproj index 0e6db22..4d15320 100644 --- a/Filtration.Tests/Filtration.Tests.csproj +++ b/Filtration.Tests/Filtration.Tests.csproj @@ -35,21 +35,17 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.dll - - ..\packages\FluentAssertions.4.13.1\lib\net45\FluentAssertions.Core.dll - True + + ..\packages\FluentAssertions.4.19.2\lib\net45\FluentAssertions.Core.dll - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.Tests/app.config b/Filtration.Tests/app.config index 576244b..15eab9e 100644 --- a/Filtration.Tests/app.config +++ b/Filtration.Tests/app.config @@ -8,7 +8,7 @@ - + diff --git a/Filtration.Tests/packages.config b/Filtration.Tests/packages.config index ded3f06..59fe830 100644 --- a/Filtration.Tests/packages.config +++ b/Filtration.Tests/packages.config @@ -1,7 +1,7 @@  - - - + + + \ No newline at end of file diff --git a/Filtration.ThemeEditor.Tests/Filtration.ThemeEditor.Tests.csproj b/Filtration.ThemeEditor.Tests/Filtration.ThemeEditor.Tests.csproj index da3c05f..88b49fc 100644 --- a/Filtration.ThemeEditor.Tests/Filtration.ThemeEditor.Tests.csproj +++ b/Filtration.ThemeEditor.Tests/Filtration.ThemeEditor.Tests.csproj @@ -35,13 +35,11 @@ ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Moq.4.5.21\lib\net45\Moq.dll - True + + ..\packages\Moq.4.5.30\lib\net45\Moq.dll - - ..\packages\NUnit.3.4.1\lib\net45\nunit.framework.dll - True + + ..\packages\NUnit.3.6.1\lib\net45\nunit.framework.dll diff --git a/Filtration.ThemeEditor.Tests/packages.config b/Filtration.ThemeEditor.Tests/packages.config index c5d64ff..4b97194 100644 --- a/Filtration.ThemeEditor.Tests/packages.config +++ b/Filtration.ThemeEditor.Tests/packages.config @@ -1,6 +1,6 @@  - - + + \ No newline at end of file diff --git a/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj b/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj index 7af0956..0cc1a04 100644 --- a/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj +++ b/Filtration.ThemeEditor/Filtration.ThemeEditor.csproj @@ -31,16 +31,15 @@ 4 - - ..\packages\AutoMapper.4.2.1\lib\net45\AutoMapper.dll - True + + ..\packages\AutoMapper.6.0.2\lib\net45\AutoMapper.dll ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll ..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll @@ -58,8 +57,7 @@ ..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll - ..\packages\NLog.4.3.7\lib\net45\NLog.dll - True + ..\packages\NLog.4.4.9\lib\net45\NLog.dll diff --git a/Filtration.ThemeEditor/packages.config b/Filtration.ThemeEditor/packages.config index 5f23e20..c5e8141 100644 --- a/Filtration.ThemeEditor/packages.config +++ b/Filtration.ThemeEditor/packages.config @@ -1,10 +1,10 @@  - + - + - + \ No newline at end of file diff --git a/Filtration/App.config b/Filtration/App.config index 9be4e10..ebcbc98 100644 --- a/Filtration/App.config +++ b/Filtration/App.config @@ -4,7 +4,7 @@
- +
@@ -41,7 +41,7 @@ - + diff --git a/Filtration/App.xaml.cs b/Filtration/App.xaml.cs index 19c8f2e..6690e58 100644 --- a/Filtration/App.xaml.cs +++ b/Filtration/App.xaml.cs @@ -36,34 +36,18 @@ namespace Filtration .Single(); _container.Kernel.ComponentModelBuilder.RemoveContributor(propInjector); - + _container.AddFacility(); _container.Install(FromAssembly.InThisApplication()); _container.Install(FromAssembly.Named("Filtration.Parser")); // Not directly referenced so manually call its installers - - Mapper.Configuration.ConstructServicesUsing(_container.Resolve); - - Mapper.CreateMap() - .ForMember(destination => destination.ChildGroups, options => options.ResolveUsing( - delegate(ResolutionResult resolutionResult) - { - var context = resolutionResult.Context; - var showAdvanced = (bool) context.Options.Items["showAdvanced"]; - var group = (ItemFilterBlockGroup) context.SourceValue; - if (showAdvanced) - return group.ChildGroups; - else - return group.ChildGroups.Where(c => c.Advanced == false); - })) - .ForMember(dest => dest.SourceBlockGroup, - opts => opts.MapFrom(from => from)) - .ForMember(dest => dest.IsExpanded, - opts => opts.UseValue(false)); - - Mapper.CreateMap().ConstructUsingServiceLocator(); - Mapper.CreateMap().ReverseMap(); - Mapper.CreateMap(); + Mapper.Initialize(cfg => + { + cfg.ConstructServicesUsing(_container.Resolve); + cfg.CreateMap().ConstructUsingServiceLocator(); + cfg.CreateMap().ReverseMap(); + cfg.CreateMap(); + }); Mapper.AssertConfigurationIsValid(); @@ -73,7 +57,7 @@ namespace Filtration var updateCheckService = _container.Resolve(); updateCheckService.CheckForUpdates(); } - + private static void OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { Logger.Fatal(e.Exception); diff --git a/Filtration/Filtration.csproj b/Filtration/Filtration.csproj index c056a2f..49144f9 100644 --- a/Filtration/Filtration.csproj +++ b/Filtration/Filtration.csproj @@ -42,20 +42,18 @@ Resources\filtration.ico - - ..\packages\AutoMapper.4.2.1\lib\net45\AutoMapper.dll - True + + ..\packages\AutoMapper.6.0.2\lib\net45\AutoMapper.dll ..\packages\Castle.Core.3.3.3\lib\net45\Castle.Core.dll True - - ..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll - - ..\packages\ControlzEx.2.1.2.3\lib\net45\ControlzEx.dll - True + + ..\packages\ControlzEx.2.2.0.4\lib\net45\ControlzEx.dll ..\packages\Fluent.Ribbon.4.0.3.394\lib\net45\Fluent.dll @@ -79,8 +77,7 @@ - ..\packages\NLog.4.3.7\lib\net45\NLog.dll - True + ..\packages\NLog.4.4.9\lib\net45\NLog.dll @@ -94,8 +91,7 @@ - ..\packages\ControlzEx.2.1.2.3\lib\net45\System.Windows.Interactivity.dll - True + ..\packages\ControlzEx.2.2.0.4\lib\net45\System.Windows.Interactivity.dll @@ -185,8 +181,6 @@ ThemeComponentSelectionControl.xaml - - diff --git a/Filtration/NLog.xsd b/Filtration/NLog.xsd index c489255..c9cbd05 100644 --- a/Filtration/NLog.xsd +++ b/Filtration/NLog.xsd @@ -42,12 +42,32 @@ - Pass NLog internal exceptions to the application. Default value is: false. + Throw an exception when there is an internal error. Default value is: false. + + + + + Throw an exception when there is a configuration error. If not set, determined by throwExceptions. + + + + + Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false. - Write internal NLog messages to the the System.Diagnostics.Trace. Default value is: false + Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false. + + + + + Write timestamps for internal NLog messages. Default value is: true. + + + + + Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false. @@ -174,7 +194,7 @@ - Name of the file to be included. The name is relative to the name of the current config file. + Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file. @@ -244,41 +264,17 @@ - - - - - - - - - - - Name of the target. - - - - - Layout used to format log messages. - - - - - Indicates whether to add <!-- --> comments around all written texts. - - - - - + + @@ -290,6 +286,11 @@ Number of log events that should be processed in a batch by the lazy writer thread. + + + Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch + + Action to be taken when the lazy writer thread request queue count exceeds the set limit. @@ -305,6 +306,11 @@ Time in milliseconds to sleep between batches. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -320,12 +326,30 @@ + + + Name of the target. + + + Delay the flush until the LogEvent has been confirmed as written + + + + + Condition expression. Log events who meet this condition will cause a flush on the wrapped target. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -337,6 +361,7 @@ + @@ -358,6 +383,11 @@ Indicates whether to use sliding timeout. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -368,23 +398,26 @@ + + - - - - - + + + + + + @@ -401,6 +434,11 @@ Instance of that is used to format log messages. + + + End of line value if a newline is appended at the end of log message . + + Maximum message size in bytes. @@ -421,6 +459,11 @@ Action that should be taken if the message is larger than maxMessageSize. + + + Maximum current connections. 0 = no maximum. + + Indicates whether to keep connection open whenever possible. @@ -431,11 +474,6 @@ Size of the connection cache (number of connections which are kept alive). - - - Maximum current connections. 0 = no maximum. - - Network address. @@ -446,19 +484,24 @@ Maximum queue size. + + + Indicates whether to include stack contents. + + Indicates whether to include source info (file name and line number) in the information sent over the network. - + - NDC item separator. + Indicates whether to include NLog-specific extensions to log4j schema. - + - Indicates whether to include stack contents. + Indicates whether to include dictionary contents. @@ -471,16 +514,21 @@ AppInfo field. By default it's the friendly name of the current AppDomain. - + - Indicates whether to include NLog-specific extensions to log4j schema. + NDC item separator. - + Indicates whether to include dictionary contents. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -525,8 +573,10 @@ + + @@ -553,6 +603,11 @@ Indicates whether to use default row highlighting rules. + + + Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + The encoding for writing messages to the . @@ -563,6 +618,11 @@ Indicates whether the error stream (stderr) should be used instead of the output stream (stdout). + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -664,7 +724,9 @@ + + @@ -691,11 +753,21 @@ Indicates whether to send the log messages to the standard error instead of the standard output. + + + Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App) + + The encoding for writing messages to the . + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -704,77 +776,83 @@ - - - - - - - - + + + + + + + + + + - Name of the target. - - - Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. - - - - - Name of the connection string (as specified in <connectionStrings> configuration section. - - - - - Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. - - - - - Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. - - - - - Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. - - - - - Name of the database provider. - - - - - Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. - - - - - Indicates whether to keep the database connection open between the log events. - - Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this. + + + Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string. + + + + + Name of the database provider. + + + + + Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string. + + + + + Indicates whether to keep the database connection open between the log events. + + + + + Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string. + + + + + Name of the connection string (as specified in <connectionStrings> configuration section. + + + + + Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase. + + + + + Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string. + + Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Text of the SQL command to be run on each log level. @@ -866,6 +944,7 @@ + @@ -887,6 +966,11 @@ Footer. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -896,6 +980,7 @@ + @@ -907,6 +992,11 @@ Layout used to format log messages. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -924,6 +1014,7 @@ + @@ -975,6 +1066,11 @@ Message length limit to write to the Event Log. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -991,6 +1087,7 @@ + @@ -1002,6 +1099,11 @@ Indicates whether to return to the first target after any successful write. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1022,7 +1124,12 @@ + + + + + @@ -1032,15 +1139,16 @@ - + + + - @@ -1104,7 +1212,12 @@ - Gets or set a value indicating whether a managed file stream is forced, instead of used the native implementation. + Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation. + + + + + Is the an absolute or relative path? @@ -1112,6 +1225,26 @@ Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong. + + + Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write + + + + + Is the an absolute or relative path? + + + + + Value indicationg whether file creation calls should be synchronized by a system global mutex. + + + + + Indicates whether the footer should be written only when the file is archived. + + Name of the file to write to. @@ -1157,9 +1290,9 @@ Indicates whether concurrent writes to the log file by multiple processes on the same host. - + - Delay in milliseconds to wait before attempting to write to the file again. + Indicates whether to keep log file open instead of opening and closing it on each logging event. @@ -1182,6 +1315,11 @@ Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Log file buffer size in bytes. @@ -1192,16 +1330,16 @@ Indicates whether to automatically flush the file buffers after each log message. + + + Delay in milliseconds to wait before attempting to write to the file again. + + Number of times the write is appended on the file before NLog discards the log message. - - - Indicates whether to keep log file open instead of opening and closing it on each logging event. - - @@ -1221,6 +1359,20 @@ + + + + + + + + + + + + + + @@ -1249,6 +1401,7 @@ + @@ -1260,6 +1413,11 @@ Condition expression. Log events who meet this condition will be forwarded to the wrapped target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1275,6 +1433,7 @@ + @@ -1316,6 +1475,11 @@ Username to change context to. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1342,6 +1506,38 @@ + + + + + + + + + + + + Name of the target. + + + + + Interval in which messages will be written up to the number of messages. + + + + + Maximum allowed number of messages written per . + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + + + + @@ -1354,6 +1550,7 @@ + @@ -1390,6 +1587,11 @@ Indicates whether to use binary message encoding. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1397,6 +1599,7 @@ + @@ -1409,11 +1612,16 @@ Name of the parameter. - + Type of the parameter. + + + Type of the parameter. Obsolete alias for + + @@ -1432,9 +1640,10 @@ - - + + + @@ -1510,9 +1719,9 @@ Sender's email address (e.g. joe@domain.com). - + - Indicates whether NewLine characters in the body should be replaced with tags. + Indicates the SMTP client timeout. @@ -1520,9 +1729,14 @@ Priority used for sending mails. - + - Indicates the SMTP client timeout. + Indicates whether NewLine characters in the body should be replaced with tags. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit @@ -1593,6 +1807,7 @@ + @@ -1604,6 +1819,11 @@ Layout used to format log messages. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1616,6 +1836,7 @@ + @@ -1646,6 +1867,11 @@ Indicates whether to check if a queue exists before writing to it. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Indicates whether to create the queue if it doesn't exists. @@ -1677,6 +1903,7 @@ + @@ -1693,6 +1920,11 @@ Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1703,6 +1935,7 @@ + @@ -1712,6 +1945,7 @@ + @@ -1728,6 +1962,11 @@ Encoding to be used. + + + End of line value if a newline is appended at the end of log message . + + Maximum message size in bytes. @@ -1773,6 +2012,11 @@ Maximum queue size. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1783,23 +2027,26 @@ + + - - - - - + + + + + + @@ -1816,6 +2063,11 @@ Instance of that is used to format log messages. + + + End of line value if a newline is appended at the end of log message . + + Maximum message size in bytes. @@ -1836,6 +2088,11 @@ Action that should be taken if the message is larger than maxMessageSize. + + + Maximum current connections. 0 = no maximum. + + Indicates whether to keep connection open whenever possible. @@ -1846,11 +2103,6 @@ Size of the connection cache (number of connections which are kept alive). - - - Maximum current connections. 0 = no maximum. - - Network address. @@ -1861,29 +2113,14 @@ Maximum queue size. - - - Indicates whether to include source info (file name and line number) in the information sent over the network. - - - - - NDC item separator. - - Indicates whether to include stack contents. - + - Indicates whether to include call site (class and method name) in the information sent over the network. - - - - - AppInfo field. By default it's the friendly name of the current AppDomain. + Indicates whether to include source info (file name and line number) in the information sent over the network. @@ -1896,6 +2133,31 @@ Indicates whether to include dictionary contents. + + + Indicates whether to include call site (class and method name) in the information sent over the network. + + + + + AppInfo field. By default it's the friendly name of the current AppDomain. + + + + + NDC item separator. + + + + + Indicates whether to include dictionary contents. + + + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1906,6 +2168,7 @@ + @@ -1922,6 +2185,11 @@ Indicates whether to perform layout calculation. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1931,6 +2199,7 @@ + @@ -1942,6 +2211,11 @@ Layout used to format log messages. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -1957,6 +2231,7 @@ + @@ -1998,6 +2273,11 @@ Performance counter instance name. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2040,6 +2320,7 @@ + @@ -2051,6 +2332,11 @@ Default filter to be applied when no specific rule matches. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2075,12 +2361,18 @@ + Name of the target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2089,6 +2381,7 @@ + @@ -2096,6 +2389,11 @@ Name of the target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Number of times to repeat each log message. @@ -2109,6 +2407,7 @@ + @@ -2117,6 +2416,11 @@ Name of the target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Number of retries that should be attempted on the wrapped target in case of a failure. @@ -2135,12 +2439,18 @@ + Name of the target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2149,12 +2459,18 @@ + Name of the target. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2164,6 +2480,7 @@ + @@ -2175,6 +2492,11 @@ Layout used to format log messages. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + @@ -2185,11 +2507,16 @@ + + + + + @@ -2201,11 +2528,26 @@ Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8. + + + Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit + + Encoding. + + + Value whether escaping be done according to the old NLog style (Very non-standard) + + + + + Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs) + + Web service method name. Only used with Soap. @@ -2226,6 +2568,16 @@ Web service URL. + + + Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ). + + + + + (optional) root namespace of the XML document, if POST of XML document chosen. (see and ). + + @@ -2235,6 +2587,8 @@ + + @@ -2345,9 +2699,21 @@ + + + + + List of property names to exclude when is true + + + + + Option to include all properties from the log events + + Option to render the empty object value {} @@ -2364,6 +2730,7 @@ + @@ -2372,6 +2739,11 @@ Determines wether or not this attribute will be Json encoded. + + + Indicates whether to escape non-ascii characters + + Layout that will be rendered as the attribute's value. @@ -2412,7 +2784,26 @@ - + + + + + + + + Option to include all properties from the log events + + + + + Indicates whether to include contents of the dictionary. + + + + + Indicates whether to include contents of the dictionary. + + diff --git a/Filtration/Services/StaticDataService.cs b/Filtration/Services/StaticDataService.cs index 36c5356..0d9467d 100644 --- a/Filtration/Services/StaticDataService.cs +++ b/Filtration/Services/StaticDataService.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Windows; using Filtration.Common.Services; using Filtration.Common.Utilities; -using Filtration.Utilities; namespace Filtration.Services { diff --git a/Filtration/Utilities/AutoMapperHelpers.cs b/Filtration/Utilities/AutoMapperHelpers.cs deleted file mode 100644 index 73b46e8..0000000 --- a/Filtration/Utilities/AutoMapperHelpers.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Linq; -using Filtration.ViewModels; - -namespace Filtration.Utilities -{ - internal class AutoMapperHelpers - { - public static void ItemFilterBlockGroupViewModelPostMap(ItemFilterBlockGroupViewModel viewModel) - { - foreach (var childViewModel in viewModel.ChildGroups) - { - ItemFilterBlockGroupViewModelPostMap(childViewModel); - } - - if (viewModel.ChildGroups.Count > 0) - { - if (viewModel.ChildGroups.All(g => g.IsChecked == true)) - { - viewModel.IsChecked = true; - } - else if (viewModel.ChildGroups.Any(g => g.IsChecked == true || g.IsChecked == null)) - { - viewModel.IsChecked = null; - } - else - { - viewModel.IsChecked = false; - } - } - } - } -} diff --git a/Filtration/Utilities/BlockGroupMapper.cs b/Filtration/Utilities/BlockGroupMapper.cs deleted file mode 100644 index 267f376..0000000 --- a/Filtration/Utilities/BlockGroupMapper.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Collections.ObjectModel; -using System.Linq; -using AutoMapper; -using Filtration.ObjectModel; -using Filtration.ViewModels; - -namespace Filtration.Utilities -{ - internal interface IBlockGroupMapper - { - ObservableCollection MapBlockGroupsToViewModels( - ObservableCollection blockGroups, bool showAdvanced); - } - - internal class BlockGroupMapper : IBlockGroupMapper - { - public ObservableCollection MapBlockGroupsToViewModels( - ObservableCollection blockGroups, bool showAdvanced) - { - - var mappedViewModels = Mapper.Map>(blockGroups, opts => opts.Items["showAdvanced"] = showAdvanced); - AutoMapperHelpers.ItemFilterBlockGroupViewModelPostMap(mappedViewModels.First()); - return mappedViewModels.First().ChildGroups; - } - } -} diff --git a/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs b/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs index b3c8132..54b7243 100644 --- a/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockGroupViewModel.cs @@ -18,6 +18,42 @@ namespace Filtration.ViewModels ChildGroups = new ObservableCollection(); } + public ItemFilterBlockGroupViewModel(ItemFilterBlockGroup itemFilterBlockGroup, bool showAdvanced, ItemFilterBlockGroupViewModel parent) + { + GroupName = itemFilterBlockGroup.GroupName; + ParentGroup = parent; + Advanced = itemFilterBlockGroup.Advanced; + SourceBlockGroup = itemFilterBlockGroup; + IsChecked = itemFilterBlockGroup.IsChecked; + + ChildGroups = new ObservableCollection(); + foreach (var childGroup in itemFilterBlockGroup.ChildGroups.Where(c => showAdvanced || !c.Advanced)) + { + ChildGroups.Add(new ItemFilterBlockGroupViewModel(childGroup, showAdvanced, this)); + } + + if (ChildGroups.Any()) + { + SetIsCheckedBasedOnChildGroups(); + } + } + + private void SetIsCheckedBasedOnChildGroups() + { + if (ChildGroups.All(g => g.IsChecked == true)) + { + IsChecked = true; + } + else if (ChildGroups.Any(g => g.IsChecked == true || g.IsChecked == null)) + { + IsChecked = null; + } + else + { + IsChecked = false; + } + } + public string GroupName { get; internal set; } public ItemFilterBlockGroupViewModel ParentGroup { get; internal set; } public ObservableCollection ChildGroups { get; internal set; } diff --git a/Filtration/ViewModels/ToolPanes/BlockGroupBrowserViewModel.cs b/Filtration/ViewModels/ToolPanes/BlockGroupBrowserViewModel.cs index 92d9152..a13f3c4 100644 --- a/Filtration/ViewModels/ToolPanes/BlockGroupBrowserViewModel.cs +++ b/Filtration/ViewModels/ToolPanes/BlockGroupBrowserViewModel.cs @@ -1,7 +1,7 @@ using System; using System.Collections.ObjectModel; +using System.Linq; using System.Windows.Media.Imaging; -using Filtration.Utilities; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Messaging; @@ -15,13 +15,11 @@ namespace Filtration.ViewModels.ToolPanes internal class BlockGroupBrowserViewModel : ToolViewModel, IBlockGroupBrowserViewModel { - private readonly IBlockGroupMapper _blockGroupMapper; private ObservableCollection _blockGroupViewModelViewModels; private ItemFilterBlockGroupViewModel _selectedBlockGroupViewModel; - public BlockGroupBrowserViewModel(IBlockGroupMapper blockGroupMapper) : base("Block Group Browser") + public BlockGroupBrowserViewModel() : base("Block Group Browser") { - _blockGroupMapper = blockGroupMapper; FilterToSelectedBlockGroupCommand = new RelayCommand(OnFilterToSelectedBlockGroupCommand, () => SelectedBlockGroupViewModel != null); ContentId = ToolContentId; @@ -60,7 +58,7 @@ namespace Filtration.ViewModels.ToolPanes public ItemFilterBlockGroupViewModel SelectedBlockGroupViewModel { - get { return _selectedBlockGroupViewModel; } + get => _selectedBlockGroupViewModel; set { _selectedBlockGroupViewModel = value; @@ -73,7 +71,7 @@ namespace Filtration.ViewModels.ToolPanes public ObservableCollection BlockGroupViewModels { - get { return _blockGroupViewModelViewModels; } + get => _blockGroupViewModelViewModels; private set { _blockGroupViewModelViewModels = value; @@ -94,9 +92,11 @@ namespace Filtration.ViewModels.ToolPanes private ObservableCollection RebuildBlockGroupViewModels(bool showAdvanced) { - return - _blockGroupMapper.MapBlockGroupsToViewModels( - AvalonDockWorkspaceViewModel.ActiveScriptViewModel.Script.ItemFilterBlockGroups, showAdvanced); + // This assumes that there will only ever be a single root node. + return new ObservableCollection + ( + new ItemFilterBlockGroupViewModel(AvalonDockWorkspaceViewModel.ActiveScriptViewModel.Script.ItemFilterBlockGroups.First(), showAdvanced, null).ChildGroups + ); } private void OnFilterToSelectedBlockGroupCommand() diff --git a/Filtration/WindsorInstallers/ServicesInstaller.cs b/Filtration/WindsorInstallers/ServicesInstaller.cs index ec3b2e4..d96e5a1 100644 --- a/Filtration/WindsorInstallers/ServicesInstaller.cs +++ b/Filtration/WindsorInstallers/ServicesInstaller.cs @@ -2,7 +2,6 @@ using Castle.MicroKernel.SubSystems.Configuration; using Castle.Windsor; using Filtration.Services; -using Filtration.Utilities; namespace Filtration.WindsorInstallers { @@ -20,11 +19,6 @@ namespace Filtration.WindsorInstallers .ImplementedBy() .LifeStyle.Singleton); - container.Register( - Component.For() - .ImplementedBy() - .LifeStyle.Singleton); - container.Register( Component.For() .ImplementedBy() diff --git a/Filtration/packages.config b/Filtration/packages.config index da3f499..d24e04a 100644 --- a/Filtration/packages.config +++ b/Filtration/packages.config @@ -1,17 +1,17 @@  - + - + - + - + - + \ No newline at end of file From 6277917ae67f3faad5867e35d250b20c7c5bf78a Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Tue, 9 May 2017 21:58:34 +0100 Subject: [PATCH 04/15] Updated Filtration.sln Visual Studio version from 14 to 15 --- Filtration.sln | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Filtration.sln b/Filtration.sln index 220be32..e7dc0d1 100644 --- a/Filtration.sln +++ b/Filtration.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +# Visual Studio 15 +VisualStudioVersion = 15.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Filtration", "Filtration\Filtration.csproj", "{55E0A34C-E039-43D7-A024-A4045401CDDA}" EndProject From 2d98f7de3656de9463fa68bf14daf7bcc5da2ab5 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Tue, 9 May 2017 22:03:24 +0100 Subject: [PATCH 05/15] Updated appveyor.yml --- appveyor.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 0de86f0..56a2d0c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,2 +1,7 @@ +version: 1.0.{build}-{branch} +image: Visual Studio 2017 before_build: - - nuget restore \ No newline at end of file + - nuget restore +build: + parallel: true + verbosity: minimal \ No newline at end of file From bb77138854005054d1167ea1650b213f02435a14 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sun, 14 May 2017 12:12:42 +0100 Subject: [PATCH 06/15] FIL-1 Changed Block Group Parsing to use " - " as delimiter instead of "-" --- .../Services/TestItemFilterBlockTranslator.cs | 29 +++++++++++++++++-- .../Services/ItemFilterBlockTranslator.cs | 7 +++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index 0ee32fb..b06b967 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -119,7 +119,7 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_NoBlockGroupComment_CallsBlockGroupHierarchyBuilder() + public void TranslateStringToItemFilterBlock_NoBlockGroupComment_DoesNotCallBlockGroupHierarchyBuilder() { // Arrange var inputString = "Show" + Environment.NewLine; @@ -139,7 +139,6 @@ namespace Filtration.Parser.Tests.Services var inputString = "Show #" + Environment.NewLine; // Act - _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Verifiable(); _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); // Assert @@ -154,7 +153,31 @@ namespace Filtration.Parser.Tests.Services var testBlockGroup = new ItemFilterBlockGroup("zzzzz", null); // Act - _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(testBlockGroup).Verifiable(); + _testUtility.MockBlockGroupHierarchyBuilder + .Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is>(s => s.Contains("Test Block Group") && s.Contains("Test Sub Block Group") && s.Contains("Test Another Block Group")))) + .Returns(testBlockGroup) + .Verifiable(); + + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + + // Assert + Assert.AreEqual(testBlockGroup, result.BlockGroup); + _testUtility.MockBlockGroupHierarchyBuilder.Verify(); + } + + [Test] + public void TranslateStringToItemFilterBlock_BlockGroupComment_NoSpacingAroundHyphens_SetsBlockItemGroupCorrectly() + { + // Arrange + var inputString = "Show # AAA-BBB-CCC" + Environment.NewLine; + var testBlockGroup = new ItemFilterBlockGroup("zzzzz", null); + + // Act + _testUtility.MockBlockGroupHierarchyBuilder + .Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.Is>(s => s.Contains("AAA-BBB-CCC")))) + .Returns(testBlockGroup) + .Verifiable(); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); // Assert diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index d2b9bcf..23553a9 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -56,7 +56,7 @@ namespace Filtration.Parser.Services } var adjustedLine = line.Replace("#", " # "); - var trimmedLine = adjustedLine.TrimStart(' ').TrimEnd(' '); + var trimmedLine = adjustedLine.Trim(); var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; @@ -395,7 +395,10 @@ namespace Filtration.Parser.Services if (blockGroupStart <= 0) return; var blockGroupText = inputString.Substring(blockGroupStart + 1); - var blockGroups = blockGroupText.Split('-').ToList(); + var blockGroups = blockGroupText.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries) + .Select(s => s.Trim()) + .ToList(); + if (blockGroups.Count(b => !string.IsNullOrEmpty(b.Trim())) > 0) { block.BlockGroup = _blockGroupHierarchyBuilder.IntegrateStringListIntoBlockGroupHierarchy(blockGroups); From ab7aefa8a6790a34aa79c04cfc6563e7215940f8 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sun, 14 May 2017 13:02:30 +0100 Subject: [PATCH 07/15] FIL-11 Added BlockGroupsEnabled flag to ItemFilterScript (encapsulated in new ItemFilterScriptSettings object) --- .../Filtration.ObjectModel.csproj | 1 + Filtration.ObjectModel/ItemFilterScript.cs | 5 + .../ItemFilterScriptSettings.cs | 21 +++ .../Services/IItemFilterBlockTranslator.cs | 4 +- .../Services/TestItemFilterBlockTranslator.cs | 148 ++++++++++-------- .../TestItemFilterScriptTranslator.cs | 7 +- .../Services/ItemFilterBlockTranslator.cs | 55 ++++--- .../Services/ItemFilterScriptTranslator.cs | 6 +- .../ViewModels/ItemFilterScriptViewModel.cs | 2 +- 9 files changed, 150 insertions(+), 99 deletions(-) create mode 100644 Filtration.ObjectModel/ItemFilterScriptSettings.cs diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj index 476cae3..b89826e 100644 --- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj +++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj @@ -84,6 +84,7 @@ + diff --git a/Filtration.ObjectModel/ItemFilterScript.cs b/Filtration.ObjectModel/ItemFilterScript.cs index 54d7cd6..6a730c2 100644 --- a/Filtration.ObjectModel/ItemFilterScript.cs +++ b/Filtration.ObjectModel/ItemFilterScript.cs @@ -15,6 +15,8 @@ namespace Filtration.ObjectModel string FilePath { get; set; } string Description { get; set; } DateTime DateModified { get; set; } + IItemFilterScriptSettings ItemFilterScriptSettings { get; } + List Validate(); void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet); } @@ -29,6 +31,7 @@ namespace Filtration.ObjectModel new ItemFilterBlockGroup("Root", null) }; ThemeComponents = new ThemeComponentCollection { IsMasterCollection = true}; + ItemFilterScriptSettings = new ItemFilterScriptSettings(ThemeComponents); } public ObservableCollection ItemFilterBlocks { get; } @@ -36,6 +39,8 @@ namespace Filtration.ObjectModel public ThemeComponentCollection ThemeComponents { get; set; } + public IItemFilterScriptSettings ItemFilterScriptSettings { get; } + public string FilePath { get; set; } public string Description { get; set; } public DateTime DateModified { get; set; } diff --git a/Filtration.ObjectModel/ItemFilterScriptSettings.cs b/Filtration.ObjectModel/ItemFilterScriptSettings.cs new file mode 100644 index 0000000..02cd23a --- /dev/null +++ b/Filtration.ObjectModel/ItemFilterScriptSettings.cs @@ -0,0 +1,21 @@ +using Filtration.ObjectModel.ThemeEditor; + +namespace Filtration.ObjectModel +{ + public interface IItemFilterScriptSettings + { + bool BlockGroupsEnabled { get; set; } + ThemeComponentCollection ThemeComponentCollection { get; } + } + + public class ItemFilterScriptSettings : IItemFilterScriptSettings + { + public ItemFilterScriptSettings(ThemeComponentCollection themeComponentCollection) + { + ThemeComponentCollection = themeComponentCollection; + } + + public bool BlockGroupsEnabled { get; set; } + public ThemeComponentCollection ThemeComponentCollection { get; } + } +} \ No newline at end of file diff --git a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs index 59d923e..54be87e 100644 --- a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs @@ -1,13 +1,11 @@ using System.Collections.ObjectModel; using Filtration.ObjectModel; -using Filtration.ObjectModel.ThemeEditor; namespace Filtration.Parser.Interface.Services { public interface IItemFilterBlockTranslator { - IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, - ThemeComponentCollection masterComponentCollection); + IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings); string TranslateItemFilterBlockToString(IItemFilterBlock block); void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString); } diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index b06b967..98d02be 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -34,7 +34,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(true, result.Enabled); @@ -48,7 +48,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(2, result.BlockItems.Count); @@ -64,7 +64,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ItemLevelBlockItem)); @@ -73,21 +73,6 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(FilterPredicateOperator.GreaterThanOrEqual, blockItem.FilterPredicate.PredicateOperator); } - [Test] - public void TranslateStringToItemFilterBlock_BlockGroupComment_CallsBlockGroupHierarchyBuilder() - { - // Arrange - var inputString = "Show # TestBlockGroup" + Environment.NewLine; - var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null); - - // Act - _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); - - // Assert - _testUtility.MockBlockGroupHierarchyBuilder.Verify(); - } - [Test] public void TranslateStringToItemFilterBlock_ShowBlock_SetsBlockGroupIsCheckedCorrectly() { @@ -97,7 +82,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(true, inputBlockGroup.IsChecked); @@ -112,41 +97,56 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(false, inputBlockGroup.IsChecked); } [Test] - public void TranslateStringToItemFilterBlock_NoBlockGroupComment_DoesNotCallBlockGroupHierarchyBuilder() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_BlockGroupComment_CallsBlockGroupHierarchyBuilder() + { + // Arrange + var inputString = "Show # TestBlockGroup" + Environment.NewLine; + var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null); + + // Act + _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + + // Assert + _testUtility.MockBlockGroupHierarchyBuilder.Verify(); + } + + [Test] + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_NoBlockGroupComment_DoesNotCallBlockGroupHierarchyBuilder() { // Arrange var inputString = "Show" + Environment.NewLine; // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert _testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>()), Times.Never); } [Test] - public void TranslateStringToItemFilterBlock_BlockGroupCommentWithNoGroups_DoesNotThrow() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_BlockGroupCommentWithNoGroups_DoesNotThrow() { // Arrange var inputString = "Show #" + Environment.NewLine; // Act - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert _testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>()), Times.Never); } [Test] - public void TranslateStringToItemFilterBlock_BlockGroupComment_SetsBlockItemGroupCorrectly() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_BlockGroupComment_SetsBlockItemGroupCorrectly() { // Arrange var inputString = "Show # Test Block Group - Test Sub Block Group - Test Another Block Group" + Environment.NewLine; @@ -158,7 +158,7 @@ namespace Filtration.Parser.Tests.Services .Returns(testBlockGroup) .Verifiable(); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert Assert.AreEqual(testBlockGroup, result.BlockGroup); @@ -166,7 +166,7 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_BlockGroupComment_NoSpacingAroundHyphens_SetsBlockItemGroupCorrectly() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_BlockGroupComment_NoSpacingAroundHyphens_SetsBlockItemGroupCorrectly() { // Arrange var inputString = "Show # AAA-BBB-CCC" + Environment.NewLine; @@ -178,13 +178,27 @@ namespace Filtration.Parser.Tests.Services .Returns(testBlockGroup) .Verifiable(); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert Assert.AreEqual(testBlockGroup, result.BlockGroup); _testUtility.MockBlockGroupHierarchyBuilder.Verify(); } + [Test] + public void TranslateStringToItemFilterBlock_BlockGroupsDisabled_BlockGroupComment_DoesNotCallBlockGroupHierarchyBuilder() + { + // Arrange + var inputString = "Show # AAA - BBB - CCC" + Environment.NewLine; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled == false)); + + // Assert + Assert.IsNull(result.BlockGroup); + _testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>()), Times.Never); + } + [Test] public void TranslateStringToItemFilterBlock_Hide_ReturnsCorrectObject() { @@ -192,7 +206,7 @@ namespace Filtration.Parser.Tests.Services var inputString = "Hide" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -208,7 +222,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual("This is a test Block", result.Description); @@ -228,7 +242,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual("Second Line", result.Description); @@ -246,7 +260,7 @@ namespace Filtration.Parser.Tests.Services " DropLevel = 40"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -264,7 +278,7 @@ namespace Filtration.Parser.Tests.Services " Corrupted True"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -281,7 +295,7 @@ namespace Filtration.Parser.Tests.Services " Identified True"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -298,7 +312,7 @@ namespace Filtration.Parser.Tests.Services " Quality < 18"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -316,7 +330,7 @@ namespace Filtration.Parser.Tests.Services " Rarity > Normal"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -334,7 +348,7 @@ namespace Filtration.Parser.Tests.Services " Rarity Normal"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); @@ -351,7 +365,7 @@ namespace Filtration.Parser.Tests.Services @" Class ""Test Class 1"" ""TestOneWordClassInQuotes"" TestOneWordClassNotInQuotes ""Test Class 2"""; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ClassBlockItem)); @@ -370,7 +384,7 @@ namespace Filtration.Parser.Tests.Services @" BaseType ""Test Base Type 1"" ""TestOneWordBaseTypeInQuotes"" TestOneWordBaseTypeNotInQuotes ""Test BaseType 2"""; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BaseTypeBlockItem)); @@ -389,7 +403,7 @@ namespace Filtration.Parser.Tests.Services " Sockets > 2"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -407,7 +421,7 @@ namespace Filtration.Parser.Tests.Services " LinkedSockets > 1"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -425,7 +439,7 @@ namespace Filtration.Parser.Tests.Services " Width = 1"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -443,7 +457,7 @@ namespace Filtration.Parser.Tests.Services " Height <= 3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert @@ -461,7 +475,7 @@ namespace Filtration.Parser.Tests.Services " Height <=3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is HeightBlockItem)); @@ -478,7 +492,7 @@ namespace Filtration.Parser.Tests.Services " SocketGroup RRGB"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SocketGroupBlockItem)); @@ -496,7 +510,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -514,7 +528,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 65 0 255 12"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -533,7 +547,7 @@ namespace Filtration.Parser.Tests.Services " SetBackgroundColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BackgroundColorBlockItem)); @@ -552,7 +566,7 @@ namespace Filtration.Parser.Tests.Services " SetBorderColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -571,8 +585,8 @@ namespace Filtration.Parser.Tests.Services // Act - Assert.DoesNotThrow(() => _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null)); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + Assert.DoesNotThrow(() => _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of())); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -590,9 +604,10 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100 # Rare Item Text"; var testComponent = new ThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { R = 255, G = 20, B = 100}); var testInputThemeComponentCollection = new ThemeComponentCollection { testComponent }; + var testInputItemFilterScriptSettings = Mock.Of(i => i.ThemeComponentCollection == testInputThemeComponentCollection); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, testInputThemeComponentCollection); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, testInputItemFilterScriptSettings); // Assert var blockItem = result.BlockItems.OfType().First(); @@ -610,7 +625,7 @@ namespace Filtration.Parser.Tests.Services " SetFontSize 15"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is FontSizeBlockItem)); @@ -627,7 +642,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 4"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -645,7 +660,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 2 95"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -662,7 +677,7 @@ namespace Filtration.Parser.Tests.Services var inputString = "# Section: " + testInputSectionDescription; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.IsInstanceOf(result); @@ -697,7 +712,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual("Test filter with everything", result.Description); @@ -785,7 +800,7 @@ namespace Filtration.Parser.Tests.Services " Quality < 17"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(2, result.BlockItems.Count(b => b is ItemLevelBlockItem)); @@ -814,7 +829,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -835,7 +850,7 @@ namespace Filtration.Parser.Tests.Services " SetFontSize 27" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is FontSizeBlockItem)); @@ -854,7 +869,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 2" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -872,7 +887,7 @@ namespace Filtration.Parser.Tests.Services " SetBackgroundColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BackgroundColorBlockItem)); @@ -891,7 +906,7 @@ namespace Filtration.Parser.Tests.Services " SetBorderColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -919,7 +934,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); @@ -946,7 +961,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -981,7 +996,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, null); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -1812,6 +1827,7 @@ namespace Filtration.Parser.Tests.Services // Assert } + private class ItemFilterBlockTranslatorTestUtility { public ItemFilterBlockTranslatorTestUtility() diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index bec3bd6..cb8000c 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -32,14 +32,12 @@ namespace Filtration.Parser.Tests.Services // Arrange var testInput = Resources.testscript; - _testUtility.MockItemFilterBlockTranslator.Setup(t => t.TranslateStringToItemFilterBlock(It.IsAny(), It.IsAny())).Verifiable(); - // Act var script = _testUtility.ScriptTranslator.TranslateStringToItemFilterScript(testInput); // Assert Assert.AreEqual(5, script.ItemFilterBlocks.Count); - _testUtility.MockItemFilterBlockTranslator.Verify(); + _testUtility.MockItemFilterBlockTranslator.Verify(t => t.TranslateStringToItemFilterBlock(It.IsAny(), It.IsAny())); } [Test] @@ -54,9 +52,6 @@ namespace Filtration.Parser.Tests.Services Environment.NewLine + "End Script Description"; - var mockItemFilterBlockTranslator = new Mock(); - mockItemFilterBlockTranslator.Setup(t => t.TranslateStringToItemFilterBlock(It.IsAny(), It.IsAny())).Verifiable(); - // Act var script = _testUtility.ScriptTranslator.TranslateStringToItemFilterScript(testInput); diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 23553a9..36409e3 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -31,9 +31,9 @@ namespace Filtration.Parser.Services // This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks // and reading ItemFilterScripts from a file. - public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, ThemeComponentCollection masterComponentCollection) + public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings) { - _masterComponentCollection = masterComponentCollection; + _masterComponentCollection = itemFilterScriptSettings.ThemeComponentCollection; var block = new ItemFilterBlock(); var showHideFound = false; @@ -63,30 +63,45 @@ namespace Filtration.Parser.Services var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos); switch (lineOption) { + + //case "Show": + // showHideFound = true; + // block.Action = BlockAction.Show; + // block.Enabled = true; + // AddBlockGroupToBlock(block, trimmedLine); + // break; + //case "Hide": + // showHideFound = true; + // block.Action = BlockAction.Hide; + // block.Enabled = true; + // AddBlockGroupToBlock(block, trimmedLine); + // break; + //case "ShowDisabled": + // showHideFound = true; + // block.Action = BlockAction.Show; + // block.Enabled = false; + // AddBlockGroupToBlock(block, trimmedLine); + // break; + //case "HideDisabled": + // showHideFound = true; + // block.Action = BlockAction.Hide; + // block.Enabled = false; + // AddBlockGroupToBlock(block, trimmedLine); + // break; case "Show": - showHideFound = true; - block.Action = BlockAction.Show; - block.Enabled = true; - AddBlockGroupToBlock(block, trimmedLine); - break; case "Hide": - showHideFound = true; - block.Action = BlockAction.Hide; - block.Enabled = true; - AddBlockGroupToBlock(block, trimmedLine); - break; case "ShowDisabled": - showHideFound = true; - block.Action = BlockAction.Show; - block.Enabled = false; - AddBlockGroupToBlock(block, trimmedLine); - break; case "HideDisabled": + { showHideFound = true; - block.Action = BlockAction.Hide; - block.Enabled = false; - AddBlockGroupToBlock(block, trimmedLine); + block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide; + block.Enabled = !lineOption.EndsWith("Disabled"); + if (itemFilterScriptSettings.BlockGroupsEnabled) + { + AddBlockGroupToBlock(block, trimmedLine); + } break; + } case "ItemLevel": { AddNumericFilterPredicateItemToBlockItems(block, trimmedLine); diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 03dccde..41173d0 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -22,7 +22,7 @@ namespace Filtration.Parser.Services _blockGroupHierarchyBuilder = blockGroupHierarchyBuilder; } - public string PreprocessDisabledBlocks(string inputString) + public static string PreprocessDisabledBlocks(string inputString) { bool inDisabledBlock = false; var showHideFound = false; @@ -120,7 +120,7 @@ namespace Filtration.Parser.Services var block = new string[end - begin]; Array.Copy(lines, begin, block, 0, end - begin); var blockString = string.Join("\r\n", block); - script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ThemeComponents)); + script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings)); } _blockGroupHierarchyBuilder.Cleanup(); @@ -136,7 +136,7 @@ namespace Filtration.Parser.Services foreach (var line in new LineReader(() => new StringReader(inputString))) { currentLine++; - var trimmedLine = line.TrimStart(' ').TrimEnd(' '); + var trimmedLine = line.Trim(' '); if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide") || trimmedLine.StartsWith("# Section:")) { diff --git a/Filtration/ViewModels/ItemFilterScriptViewModel.cs b/Filtration/ViewModels/ItemFilterScriptViewModel.cs index 3aa590a..c061b84 100644 --- a/Filtration/ViewModels/ItemFilterScriptViewModel.cs +++ b/Filtration/ViewModels/ItemFilterScriptViewModel.cs @@ -622,7 +622,7 @@ namespace Filtration.ViewModels if (string.IsNullOrEmpty(clipboardText)) return; _blockGroupHierarchyBuilder.Initialise(Script.ItemFilterBlockGroups.First()); - var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script.ThemeComponents); + var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script.ItemFilterScriptSettings); if (translatedBlock == null) return; var vm = _itemFilterBlockViewModelFactory.Create(); From 8e54cc3b4bf707986a3fb542d173a0e3148a469f Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sun, 14 May 2017 13:06:07 +0100 Subject: [PATCH 08/15] Fixed failing tests --- .../Services/TestItemFilterBlockTranslator.cs | 8 ++++---- .../Services/TestItemFilterScriptTranslator.cs | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index 98d02be..c638416 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -74,7 +74,7 @@ namespace Filtration.Parser.Tests.Services } [Test] - public void TranslateStringToItemFilterBlock_ShowBlock_SetsBlockGroupIsCheckedCorrectly() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ShowBlock_SetsBlockGroupIsCheckedCorrectly() { // Arrange var inputString = "Show # TestBlockGroup" + Environment.NewLine; @@ -82,14 +82,14 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert Assert.AreEqual(true, inputBlockGroup.IsChecked); } [Test] - public void TranslateStringToItemFilterBlock_HideBlock_SetsBlockGroupIsCheckedCorrectly() + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_HideBlock_SetsBlockGroupIsCheckedCorrectly() { // Arrange var inputString = "Hide # TestBlockGroup" + Environment.NewLine; @@ -97,7 +97,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); // Assert Assert.AreEqual(false, inputBlockGroup.IsChecked); diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index cb8000c..61657b4 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -348,6 +348,7 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual("This is a disabled block", secondBlock.Description); } + [Ignore("Ignored until toggling block group parsing can be controlled from the filter script input")] [Test] public void TranslateStringToItemFilterScript_DisabledBlockWithBlockGroup_ReturnsCorrectBlock() { @@ -363,6 +364,7 @@ namespace Filtration.Parser.Tests.Services "#Disabled Block End"; + var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object); _testUtility.MockBlockGroupHierarchyBuilder.Setup( b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())) From 797c911bb58587c272efa33a3c037851df8d6369 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sun, 14 May 2017 14:10:54 +0100 Subject: [PATCH 09/15] FIL-13 Comments on the Show/Hide line are now preserved if block groups are not enabled for the script --- .../BlockItemBaseTypes/ActionBlockItem.cs | 4 +- Filtration.ObjectModel/ItemFilterBlock.cs | 6 ++- .../Services/TestItemFilterBlockTranslator.cs | 51 ++++++++++++++++++ .../TestItemFilterScriptTranslator.cs | 1 + .../Services/ItemFilterBlockTranslator.cs | 53 ++++++++----------- 5 files changed, 81 insertions(+), 34 deletions(-) diff --git a/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs b/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs index d920d50..8660377 100644 --- a/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs +++ b/Filtration.ObjectModel/BlockItemBaseTypes/ActionBlockItem.cs @@ -15,7 +15,7 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes public BlockAction Action { - get { return _action; } + get => _action; set { _action = value; @@ -27,6 +27,8 @@ namespace Filtration.ObjectModel.BlockItemBaseTypes } } + public string Comment { get; set; } + public override string OutputText => Action.GetAttributeDescription(); public override string PrefixText => string.Empty; diff --git a/Filtration.ObjectModel/ItemFilterBlock.cs b/Filtration.ObjectModel/ItemFilterBlock.cs index cf80d76..f5bcff1 100644 --- a/Filtration.ObjectModel/ItemFilterBlock.cs +++ b/Filtration.ObjectModel/ItemFilterBlock.cs @@ -15,6 +15,7 @@ namespace Filtration.ObjectModel string Description { get; set; } ItemFilterBlockGroup BlockGroup { get; set; } BlockAction Action { get; set; } + ActionBlockItem ActionBlockItem { get; } ObservableCollection BlockItems { get; } Color DisplayBackgroundColor { get; } Color DisplayTextColor { get; } @@ -32,7 +33,8 @@ namespace Filtration.ObjectModel public ItemFilterBlock() { - BlockItems = new ObservableCollection {new ActionBlockItem(BlockAction.Show)}; + ActionBlockItem = new ActionBlockItem(BlockAction.Show); + BlockItems = new ObservableCollection {ActionBlockItem}; Enabled = true; } @@ -79,6 +81,8 @@ namespace Filtration.ObjectModel } } + public ActionBlockItem ActionBlockItem { get; } + public ObservableCollection BlockItems { get; } public int BlockCount(Type type) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index c638416..ec90142 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -26,6 +26,41 @@ namespace Filtration.Parser.Tests.Services _testUtility = new ItemFilterBlockTranslatorTestUtility(); } + [Test] + public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ActionBlockItemCommentIsNull() + { + + // Arrange + var inputString = "Show # Test - Test2 - Test3" + Environment.NewLine; + + var inputBlockGroup = new ItemFilterBlockGroup("TestBlockGroup", null); + _testUtility.MockBlockGroupHierarchyBuilder + .Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())) + .Returns(inputBlockGroup); + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + + //Assert + Assert.IsTrue(string.IsNullOrEmpty(result.ActionBlockItem.Comment)); + } + + [Test] + public void TranslateStringToItemFilterBlock_BlockGroupsDisabled_ActionBlockItemCommentIsSetCorrectly() + { + + // Arrange + var testInputExpectedComment = " this is a comment that should be preserved"; + + var inputString = $"Show #{testInputExpectedComment}" + Environment.NewLine; + + // Act + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled == false)); + + //Assert + Assert.AreEqual(testInputExpectedComment, result.ActionBlockItem.Comment); + } + [Test] public void TranslateStringToItemFilterBlock_NotDisabled_SetsBlockEnabledTrue() { @@ -1044,6 +1079,22 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(expectedResult, result); } + [Test] + public void TranslateItemFilterBlockToString_HasActionBlockComment_ReturnsCorrectString() + { + // Arrange + var testInputActionBlockComment = "this is a test"; + var expectedResult = $"Show #{testInputActionBlockComment}"; + + _testUtility.TestBlock.BlockItems.OfType().First().Comment = testInputActionBlockComment; + + // Act + var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); + + // Assert + Assert.AreEqual(expectedResult, result); + } + [Test] public void TranslateItemFilterBlockToString_FilterTypeHide_ReturnsCorrectString() { diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index 61657b4..fab162b 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -348,6 +348,7 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual("This is a disabled block", secondBlock.Description); } + // TODO: Reinstate this test [Ignore("Ignored until toggling block group parsing can be controlled from the filter script input")] [Test] public void TranslateStringToItemFilterScript_DisabledBlockWithBlockGroup_ReturnsCorrectBlock() diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 36409e3..27a78f0 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -55,39 +55,12 @@ namespace Filtration.Parser.Services continue; } - var adjustedLine = line.Replace("#", " # "); - var trimmedLine = adjustedLine.Trim(); - + var trimmedLine = line.Trim(); var spaceOrEndOfLinePos = trimmedLine.IndexOf(" ", StringComparison.Ordinal) > 0 ? trimmedLine.IndexOf(" ", StringComparison.Ordinal) : trimmedLine.Length; var lineOption = trimmedLine.Substring(0, spaceOrEndOfLinePos); switch (lineOption) { - - //case "Show": - // showHideFound = true; - // block.Action = BlockAction.Show; - // block.Enabled = true; - // AddBlockGroupToBlock(block, trimmedLine); - // break; - //case "Hide": - // showHideFound = true; - // block.Action = BlockAction.Hide; - // block.Enabled = true; - // AddBlockGroupToBlock(block, trimmedLine); - // break; - //case "ShowDisabled": - // showHideFound = true; - // block.Action = BlockAction.Show; - // block.Enabled = false; - // AddBlockGroupToBlock(block, trimmedLine); - // break; - //case "HideDisabled": - // showHideFound = true; - // block.Action = BlockAction.Hide; - // block.Enabled = false; - // AddBlockGroupToBlock(block, trimmedLine); - // break; case "Show": case "Hide": case "ShowDisabled": @@ -96,10 +69,17 @@ namespace Filtration.Parser.Services showHideFound = true; block.Action = lineOption.StartsWith("Show") ? BlockAction.Show : BlockAction.Hide; block.Enabled = !lineOption.EndsWith("Disabled"); + + // If block groups are enabled for this script, the comment after Show/Hide is parsed as a block + // group hierarchy, if block groups are disabled it is preserved as a simple text comment. if (itemFilterScriptSettings.BlockGroupsEnabled) { AddBlockGroupToBlock(block, trimmedLine); } + else + { + block.ActionBlockItem.Comment = GetTextAfterFirstComment(trimmedLine); + } break; } case "ItemLevel": @@ -406,10 +386,7 @@ namespace Filtration.Parser.Services private void AddBlockGroupToBlock(IItemFilterBlock block, string inputString) { - var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal); - if (blockGroupStart <= 0) return; - - var blockGroupText = inputString.Substring(blockGroupStart + 1); + var blockGroupText = GetTextAfterFirstComment(inputString); var blockGroups = blockGroupText.Split(new[] { " - " }, StringSplitOptions.RemoveEmptyEntries) .Select(s => s.Trim()) .ToList(); @@ -421,6 +398,14 @@ namespace Filtration.Parser.Services } } + private static string GetTextAfterFirstComment(string inputString) + { + var blockGroupStart = inputString.IndexOf("#", StringComparison.Ordinal); + if (blockGroupStart <= 0) return string.Empty; + + return inputString.Substring(blockGroupStart + 1); + } + private static Color GetColorFromString(string inputString) { var argbValues = Regex.Matches(inputString, @"\s+(\d+)"); @@ -474,6 +459,10 @@ namespace Filtration.Parser.Services { outputString += " # " + block.BlockGroup; } + else if (!string.IsNullOrEmpty(block.ActionBlockItem?.Comment)) + { + outputString += " #" + block.ActionBlockItem.Comment; + } // ReSharper disable once LoopCanBeConvertedToQuery foreach (var blockItem in block.BlockItems.Where(b => b.GetType() != typeof(ActionBlockItem)).OrderBy(b => b.SortOrder)) From 4def27c49dfc0cc39326931723134fa68cd4c501 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 20 May 2017 18:14:28 +0100 Subject: [PATCH 10/15] FIL-4 Refactored script parsing to retain isolated comments as a new ItemFilterBlockComment type - UI still needs reworking with new templates and such. --- Filtration.Common/Utilities/LineReader.cs | 8 ++ .../Services/TestItemFilterProcessor.cs | 4 +- .../Services/ItemFilterProcessor.cs | 1 + .../TestItemFilterBlock.cs | 17 ---- Filtration.ObjectModel/ItemFilterBlock.cs | 41 +++++--- Filtration.ObjectModel/ItemFilterScript.cs | 10 +- .../Services/IItemFilterBlockTranslator.cs | 1 + .../Filtration.Parser.Tests.csproj | 3 + .../Properties/Resources.Designer.cs | 31 ++++++ .../Properties/Resources.resx | 9 +- .../Resources/testscript2.txt | 31 ++++++ .../Services/TestItemFilterBlockTranslator.cs | 44 +++------ .../TestItemFilterScriptTranslator.cs | 46 +++++++-- .../Services/ItemFilterBlockTranslator.cs | 33 ++++--- .../Services/ItemFilterScriptTranslator.cs | 95 +++++++++++++++---- .../Services/ThemeService.cs | 2 +- .../ViewModels/ItemFilterBlockViewModel.cs | 1 - .../ViewModels/ItemFilterScriptViewModel.cs | 4 +- 18 files changed, 273 insertions(+), 108 deletions(-) create mode 100644 Filtration.Parser.Tests/Resources/testscript2.txt diff --git a/Filtration.Common/Utilities/LineReader.cs b/Filtration.Common/Utilities/LineReader.cs index 94dea54..1811195 100644 --- a/Filtration.Common/Utilities/LineReader.cs +++ b/Filtration.Common/Utilities/LineReader.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Diagnostics; using System.IO; using System.Text; @@ -21,6 +22,7 @@ namespace Filtration.Common.Utilities /// the stream into text. /// /// Data source + [DebuggerStepThrough] public LineReader(Func streamSource) : this(streamSource, Encoding.UTF8) { @@ -33,6 +35,7 @@ namespace Filtration.Common.Utilities /// Data source /// Encoding to use to decode the stream /// into text + [DebuggerStepThrough] public LineReader(Func streamSource, Encoding encoding) : this(() => new StreamReader(streamSource(), encoding)) { @@ -44,6 +47,7 @@ namespace Filtration.Common.Utilities /// UTF8 is used to decode the file into text. /// /// File to read from + [DebuggerStepThrough] public LineReader(string filename) : this(filename, Encoding.UTF8) { @@ -56,6 +60,7 @@ namespace Filtration.Common.Utilities /// File to read from /// Encoding to use to decode the file /// into text + [DebuggerStepThrough] public LineReader(string filename, Encoding encoding) : this(() => new StreamReader(filename, encoding)) { @@ -66,6 +71,7 @@ namespace Filtration.Common.Utilities /// is only called when the enumerator is fetched /// /// Data source + [DebuggerStepThrough] public LineReader(Func dataSource) { _dataSource = dataSource; @@ -74,6 +80,7 @@ namespace Filtration.Common.Utilities /// /// Enumerates the data source line by line. /// + [DebuggerStepThrough] public IEnumerator GetEnumerator() { using (TextReader reader = _dataSource()) @@ -89,6 +96,7 @@ namespace Filtration.Common.Utilities /// /// Enumerates the data source line by line. /// + [DebuggerStepThrough] IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); diff --git a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs index 28d1e66..17274f8 100644 --- a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs +++ b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs @@ -29,7 +29,7 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputItem = Mock.Of(); var testInputBlock = Mock.Of(); - var testInputScript = Mock.Of(s => s.ItemFilterBlocks == new ObservableCollection {testInputBlock}); + var testInputScript = Mock.Of(s => s.ItemFilterBlocks == new ObservableCollection {testInputBlock}); _testUtility.MockBlockItemMatcher .Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem)) @@ -50,7 +50,7 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputItem = Mock.Of(); var testInputBlock = Mock.Of(); - var testInputScript = Mock.Of(s => s.ItemFilterBlocks == new ObservableCollection { testInputBlock }); + var testInputScript = Mock.Of(s => s.ItemFilterBlocks == new ObservableCollection { testInputBlock }); _testUtility.MockBlockItemMatcher .Setup(b => b.ItemBlockMatch(testInputBlock, testInputItem)) diff --git a/Filtration.ItemFilterPreview/Services/ItemFilterProcessor.cs b/Filtration.ItemFilterPreview/Services/ItemFilterProcessor.cs index a680185..d385174 100644 --- a/Filtration.ItemFilterPreview/Services/ItemFilterProcessor.cs +++ b/Filtration.ItemFilterPreview/Services/ItemFilterProcessor.cs @@ -31,6 +31,7 @@ namespace Filtration.ItemFilterPreview.Services sw.Restart(); var matchedBlock = itemFilterScript.ItemFilterBlocks + .OfType() .Where(b => !(b is ItemFilterSection)) .FirstOrDefault(block => _blockItemMatcher.ItemBlockMatch(block, item)); diff --git a/Filtration.ObjectModel.Tests/TestItemFilterBlock.cs b/Filtration.ObjectModel.Tests/TestItemFilterBlock.cs index 8afd358..045db54 100644 --- a/Filtration.ObjectModel.Tests/TestItemFilterBlock.cs +++ b/Filtration.ObjectModel.Tests/TestItemFilterBlock.cs @@ -6,23 +6,6 @@ namespace Filtration.ObjectModel.Tests [TestFixture] public class TestItemFilterBlock { - [Test] - public void ItemFilterBlock_BlockCount_ReturnsCorrectNumber() - { - // Arrange - var block = new ItemFilterBlock(); - block.BlockItems.Add(new ItemLevelBlockItem()); - block.BlockItems.Add(new ItemLevelBlockItem()); - block.BlockItems.Add(new ItemLevelBlockItem()); - block.BlockItems.Add(new ItemLevelBlockItem()); - - // Act - var count = block.BlockCount(typeof (ItemLevelBlockItem)); - - // Assert - Assert.AreEqual(4, count); - } - [Test] public void ItemFilterBlock_AddBlockItemAllowed_LessThanMaximum_ReturnsTrue() { diff --git a/Filtration.ObjectModel/ItemFilterBlock.cs b/Filtration.ObjectModel/ItemFilterBlock.cs index f5bcff1..44a1094 100644 --- a/Filtration.ObjectModel/ItemFilterBlock.cs +++ b/Filtration.ObjectModel/ItemFilterBlock.cs @@ -9,7 +9,7 @@ using Filtration.ObjectModel.Extensions; namespace Filtration.ObjectModel { - public interface IItemFilterBlock + public interface IItemFilterBlock : IItemFilterBlockBase { bool Enabled { get; set; } string Description { get; set; } @@ -21,13 +21,32 @@ namespace Filtration.ObjectModel Color DisplayTextColor { get; } Color DisplayBorderColor { get; } double DisplayFontSize { get; } - int BlockCount(Type type); - bool AddBlockItemAllowed(Type type); bool HasBlockItemOfType(); bool HasBlockGroupInParentHierarchy(ItemFilterBlockGroup targetBlockGroup, ItemFilterBlockGroup startingBlockGroup); } - public class ItemFilterBlock : IItemFilterBlock + public interface IItemFilterBlockBase + { + } + + public class ItemFilterBlockBase : IItemFilterBlockBase + { + + } + + public interface IItemFilterCommentBlock : IItemFilterBlockBase + { + string Comment { get; set; } + bool IsSection { get; set; } + } + + public class ItemFilterCommentBlock : ItemFilterBlockBase, IItemFilterCommentBlock + { + public string Comment { get; set; } + public bool IsSection { get; set; } + } + + public class ItemFilterBlock : ItemFilterBlockBase, IItemFilterBlock { private ItemFilterBlockGroup _blockGroup; @@ -43,7 +62,7 @@ namespace Filtration.ObjectModel public ItemFilterBlockGroup BlockGroup { - get { return _blockGroup; } + get => _blockGroup; set { var oldBlockGroup = _blockGroup; @@ -85,15 +104,15 @@ namespace Filtration.ObjectModel public ObservableCollection BlockItems { get; } - public int BlockCount(Type type) - { - return BlockItems?.Count(b => b.GetType() == type) ?? 0; - } - public bool AddBlockItemAllowed(Type type) { + int BlockCount() + { + return BlockItems?.Count(b => b.GetType() == type) ?? 0; + } + var blockItem = (IItemFilterBlockItem)Activator.CreateInstance(type); - return BlockCount(type) < blockItem.MaximumAllowed; + return BlockCount() < blockItem.MaximumAllowed; } public bool HasBlockItemOfType() diff --git a/Filtration.ObjectModel/ItemFilterScript.cs b/Filtration.ObjectModel/ItemFilterScript.cs index 6a730c2..b6f79dd 100644 --- a/Filtration.ObjectModel/ItemFilterScript.cs +++ b/Filtration.ObjectModel/ItemFilterScript.cs @@ -9,7 +9,7 @@ namespace Filtration.ObjectModel { public interface IItemFilterScript { - ObservableCollection ItemFilterBlocks { get; } + ObservableCollection ItemFilterBlocks { get; } ObservableCollection ItemFilterBlockGroups { get; } ThemeComponentCollection ThemeComponents { get; set; } string FilePath { get; set; } @@ -25,7 +25,7 @@ namespace Filtration.ObjectModel { public ItemFilterScript() { - ItemFilterBlocks = new ObservableCollection(); + ItemFilterBlocks = new ObservableCollection(); ItemFilterBlockGroups = new ObservableCollection { new ItemFilterBlockGroup("Root", null) @@ -34,7 +34,7 @@ namespace Filtration.ObjectModel ItemFilterScriptSettings = new ItemFilterScriptSettings(ThemeComponents); } - public ObservableCollection ItemFilterBlocks { get; } + public ObservableCollection ItemFilterBlocks { get; } public ObservableCollection ItemFilterBlockGroups { get; } public ThemeComponentCollection ThemeComponents { get; set; } @@ -59,9 +59,7 @@ namespace Filtration.ObjectModel public void ReplaceColors(ReplaceColorsParameterSet replaceColorsParameterSet) { - foreach ( - var block in - ItemFilterBlocks.Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b))) + foreach (var block in ItemFilterBlocks.OfType().Where(b => BlockIsColorReplacementCandidate(replaceColorsParameterSet, b))) { if (replaceColorsParameterSet.ReplaceTextColor) { diff --git a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs index 54be87e..0d9a1d6 100644 --- a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs @@ -8,5 +8,6 @@ namespace Filtration.Parser.Interface.Services IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings); string TranslateItemFilterBlockToString(IItemFilterBlock block); void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString); + IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString); } } \ No newline at end of file diff --git a/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj b/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj index 216294f..26effd4 100644 --- a/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj +++ b/Filtration.Parser.Tests/Filtration.Parser.Tests.csproj @@ -109,6 +109,9 @@ + + + diff --git a/Filtration.Parser.Tests/Properties/Resources.Designer.cs b/Filtration.Parser.Tests/Properties/Resources.Designer.cs index b4a2cb0..4cd12a1 100644 --- a/Filtration.Parser.Tests/Properties/Resources.Designer.cs +++ b/Filtration.Parser.Tests/Properties/Resources.Designer.cs @@ -91,6 +91,37 @@ namespace Filtration.Parser.Tests.Properties { } } + /// + /// Looks up a localized string similar to #Script description + ///#Script description + ///#Script description + ///#Script description + /// + ///#Comment + ///#SomeComment + /// + ///#Blockdescription + ///Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal + /// Class "Life Flasks" "Mana Flasks" + /// Rarity Normal + /// DropLevel >= 60 + /// Quality >= 10 + /// SetFontSize 28 + /// SetTextColor 240 240 240 #Normal Item Highlight + /// + ///#commentymccommentface + /// + ///Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal + /// Class "Life Flasks" "Mana Flasks" + /// Rarity Normal + /// DropL [rest of string was truncated]";. + /// + public static string testscript2 { + get { + return ResourceManager.GetString("testscript2", resourceCulture); + } + } + /// /// Looks up a localized string similar to ###BETA VERSION 1.0.0.1-8 ///#Please test and let me know via pm on reddit /u/brute_force or @Thiole in game if i am online diff --git a/Filtration.Parser.Tests/Properties/Resources.resx b/Filtration.Parser.Tests/Properties/Resources.resx index 9797aeb..1e13abb 100644 --- a/Filtration.Parser.Tests/Properties/Resources.resx +++ b/Filtration.Parser.Tests/Properties/Resources.resx @@ -118,10 +118,13 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - ..\Resources\ThioleItemFilter.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 - ..\Resources\testscript.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + ..\Resources\testscript2.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + + + ..\Resources\ThioleItemFilter.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;Windows-1252 + \ No newline at end of file diff --git a/Filtration.Parser.Tests/Resources/testscript2.txt b/Filtration.Parser.Tests/Resources/testscript2.txt new file mode 100644 index 0000000..f9b3a9c --- /dev/null +++ b/Filtration.Parser.Tests/Resources/testscript2.txt @@ -0,0 +1,31 @@ +#Script description +#Script description +#Script description +#Script description + +#Blockdescription +Show #Flasks - Endgame - Life/Mana - Divine/Eternal - Q10+ - Normal + Class "Life Flasks" "Mana Flasks" + Rarity Normal + SetFontSize 28 + + + +# commentymccommentface + +Show + Class "Life Flasks" "Mana Flasks" + Rarity Normal + DropLevel >= 60 + +#commment +#morecomment +#blah + +#anothercomment + +#notpartofblockdescription +#blockdescription2 +Show #TestBlock + Class "Life Flasks" "Mana Flasks" + Rarity Normal \ No newline at end of file diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index ec90142..f2f3acd 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -26,6 +26,19 @@ namespace Filtration.Parser.Tests.Services _testUtility = new ItemFilterBlockTranslatorTestUtility(); } + [Test] + public void TranslateStringToItemFilterBlockComment_ReturnsItemFilterBlockCommentWithSpacesNotRemoved() + { + //Arrange + var testInputString = "# This is a comment\r\n# Line 2 \r\n # Test"; + + //Act + var result = _testUtility.Translator.TranslateStringToItemFilterCommentBlock(testInputString); + + //Assert + Assert.AreEqual(" This is a comment\r\n Line 2 \r\n Test", result.Comment); + } + [Test] public void TranslateStringToItemFilterBlock_BlockGroupsEnabled_ActionBlockItemCommentIsNull() { @@ -703,21 +716,6 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(2, blockItem.Value); Assert.AreEqual(95, blockItem.SecondValue); } - - [Test] - public void TranslateStringToItemFilterBlock_SectionComment_ReturnsItemFilterSectionObjectWithCorrectDescription() - { - // Arrange - const string testInputSectionDescription = "Wonderful items that you definitely won't want to miss!"; - var inputString = "# Section: " + testInputSectionDescription; - - // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); - - // Assert - Assert.IsInstanceOf(result); - Assert.AreEqual(testInputSectionDescription, result.Description); - } [Test] public void TranslateStringToItemFilterBlock_Everything_ReturnsCorrectObject() @@ -1571,22 +1569,6 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(expectedResult, result); } - [Test] - public void TranslateItemFilterBlockToString_Section_ReturnsCorrectString() - { - // Arrange - const string testInputSectionText = "Ermagerd it's a section!"; - var expectedResult = "# Section: " + testInputSectionText; - - _testUtility.TestBlock = new ItemFilterSection { Description = testInputSectionText }; - - // Act - var result = _testUtility.Translator.TranslateItemFilterBlockToString(_testUtility.TestBlock); - - // Assert - Assert.AreEqual(expectedResult, result); - } - [Test] public void TranslateItemFilterBlockToString_DisabledBlock_ReturnsCorrectString() { diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index fab162b..799ec2f 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using Filtration.ObjectModel; using Filtration.ObjectModel.BlockItemTypes; @@ -9,6 +10,7 @@ using Filtration.Parser.Interface.Services; using Filtration.Parser.Services; using Filtration.Parser.Tests.Properties; using Filtration.Properties; +using FluentAssertions; using Moq; using NUnit.Framework; @@ -75,6 +77,36 @@ namespace Filtration.Parser.Tests.Services // Not crashing out when loading a huge script means this integration test has passed! } + [Test] + public void TranslateStringToItemFilterScript_Blah() + { + // Arrange + var testInput = Resources.testscript2; + + var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object); + var translator = new ItemFilterScriptTranslator(blockTranslator, _testUtility.MockBlockGroupHierarchyBuilder.Object); + + // Act + var result = translator.TranslateStringToItemFilterScript(testInput); + + // Assert + var expectedResult = Mock.Of(s => s.ItemFilterBlocks == new ObservableCollection + { + Mock.Of(c => c.Description == "Blockdescription"), + Mock.Of(c => c.Comment == " commentymccommentface"), + Mock.Of(), + Mock.Of(c => c.Comment == "commment\r\nmorecomment\r\nblah"), + Mock.Of(c => c.Comment == "anothercomment"), + Mock.Of(c => c.Comment == "notpartofblockdescription "), + Mock.Of(c => c.Description == "blockdescription2") + } && s.ItemFilterBlockGroups == new ObservableCollection { new ItemFilterBlockGroup("Root", null, false) } + && s.ThemeComponents == new ThemeComponentCollection() + && s.ItemFilterScriptSettings == new ItemFilterScriptSettings(new ThemeComponentCollection()) + && s.Description == "Script description\r\nScript description\r\nScript description\r\nScript description"); + + result.ShouldBeEquivalentTo(expectedResult); + } + [Test] public void TranslateItemFilterScriptToString_OneBlock_CallsTranslator() { @@ -221,7 +253,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(2, result.ItemFilterBlocks.Count); - var block = result.ItemFilterBlocks.First(l => l.GetType() != typeof(ItemFilterSection)); + var block = result.ItemFilterBlocks.OfType().First(l => l.GetType() != typeof(ItemFilterSection)); Assert.AreEqual(4, block.BlockItems.Count); var baseTypeItem = block.BlockItems.OfType().First(); Assert.AreEqual(2, baseTypeItem.Items.Count); @@ -244,7 +276,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual("Script edited with Filtration - https://github.com/ben-wallis/Filtration", result.Description); - var firstBlock = result.ItemFilterBlocks.First(); + var firstBlock = result.ItemFilterBlocks.OfType().First(); Assert.IsNull(firstBlock.Description); } @@ -311,9 +343,9 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(3, result.ItemFilterBlocks.Count); - var firstBlock = result.ItemFilterBlocks.First(); - var secondBlock = result.ItemFilterBlocks.Skip(1).First(); - var thirdBlock = result.ItemFilterBlocks.Skip(2).First(); + var firstBlock = result.ItemFilterBlocks.OfType().First(); + var secondBlock = result.ItemFilterBlocks.OfType().Skip(1).First(); + var thirdBlock = result.ItemFilterBlocks.OfType().Skip(2).First(); Assert.AreEqual(3, firstBlock.BlockItems.Count); Assert.AreEqual(5, secondBlock.BlockItems.Count); @@ -344,7 +376,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(2, result.ItemFilterBlocks.Count); - var secondBlock = result.ItemFilterBlocks.Skip(1).First(); + var secondBlock = result.ItemFilterBlocks.OfType().Skip(1).First(); Assert.AreEqual("This is a disabled block", secondBlock.Description); } @@ -379,7 +411,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(2, result.ItemFilterBlocks.Count); - var secondBlock = result.ItemFilterBlocks.Skip(1).First(); + var secondBlock = result.ItemFilterBlocks.OfType().Skip(1).First(); Assert.AreEqual("This is a disabled block", secondBlock.Description); Assert.AreEqual("My Block Group", secondBlock.BlockGroup.GroupName); } diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 27a78f0..67d6181 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -29,6 +29,22 @@ namespace Filtration.Parser.Services _blockGroupHierarchyBuilder = blockGroupHierarchyBuilder; } + // Converts a string into an ItemFilterCommentBlock maintaining newlines and spaces but removing # characters + public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString) + { + var itemFilterCommentBlock = new ItemFilterCommentBlock(); + + foreach (var line in new LineReader(() => new StringReader(inputString))) + { + var trimmedLine = line.TrimStart(' ').TrimStart('#'); + itemFilterCommentBlock.Comment += trimmedLine + Environment.NewLine; + } + + itemFilterCommentBlock.Comment = itemFilterCommentBlock.Comment.TrimEnd('\r', '\n'); + + return itemFilterCommentBlock; + } + // This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks // and reading ItemFilterScripts from a file. public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings) @@ -39,16 +55,6 @@ namespace Filtration.Parser.Services foreach (var line in new LineReader(() => new StringReader(inputString))) { - - if (line.StartsWith(@"# Section:")) - { - var section = new ItemFilterSection - { - Description = line.Substring(line.IndexOf(":", StringComparison.Ordinal) + 1).Trim() - }; - return section; - } - if (line.StartsWith(@"#") && !showHideFound) { block.Description = line.TrimStart('#').TrimStart(' '); @@ -205,6 +211,7 @@ namespace Filtration.Parser.Services switch (matches.Count) { case 1: + { if (matches[0].Success) { var blockItemValue = new SoundBlockItem @@ -215,7 +222,9 @@ namespace Filtration.Parser.Services block.BlockItems.Add(blockItemValue); } break; + } case 2: + { if (matches[0].Success && matches[1].Success) { var blockItemValue = new SoundBlockItem @@ -226,6 +235,7 @@ namespace Filtration.Parser.Services block.BlockItems.Add(blockItemValue); } break; + } } break; } @@ -436,7 +446,8 @@ namespace Filtration.Parser.Services // to the clipboard, and when saving a ItemFilterScript. public string TranslateItemFilterBlockToString(IItemFilterBlock block) { - if (block.GetType() == typeof (ItemFilterSection)) + // TODO: fix + if (block.GetType() == typeof (ItemFilterCommentBlock)) { return "# Section: " + block.Description; } diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 41173d0..870f94d 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Text.RegularExpressions; using Filtration.Common.Utilities; using Filtration.ObjectModel; @@ -10,6 +11,26 @@ using Filtration.Properties; namespace Filtration.Parser.Services { + + internal class ItemFilterBlockBoundary + { + public ItemFilterBlockBoundary(int startLine, ItemFilterBlockBoundaryType itemFilterBlockBoundaryType) + { + StartLine = startLine; + BoundaryType = itemFilterBlockBoundaryType; + } + + public int StartLine { get; set; } + public ItemFilterBlockBoundaryType BoundaryType { get; set; } + + } + + internal enum ItemFilterBlockBoundaryType + { + ItemFilterBlock, + CommentBlock + } + internal class ItemFilterScriptTranslator : IItemFilterScriptTranslator { private readonly IItemFilterBlockTranslator _blockTranslator; @@ -98,12 +119,12 @@ namespace Filtration.Parser.Services var lines = Regex.Split(inputString, "\r\n|\r|\n"); // Process the script header - for (var i = 0; i < conditionBoundaries.First.Value; i++) + for (var i = 0; i < conditionBoundaries.First.Value.StartLine; i++) { if (lines[i].StartsWith("#")) { script.Description += lines[i].Substring(1).Trim(' ') + Environment.NewLine; - } + } } if (!string.IsNullOrEmpty(script.Description)) @@ -115,43 +136,85 @@ namespace Filtration.Parser.Services // and add that object to the ItemFilterBlocks list for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next) { - var begin = boundary.Value; - var end = boundary.Next?.Value ?? lines.Length; + var begin = boundary.Value.StartLine; + var end = boundary.Next?.Value.StartLine ?? lines.Length; var block = new string[end - begin]; Array.Copy(lines, begin, block, 0, end - begin); var blockString = string.Join("\r\n", block); - script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings)); + + if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) + { + script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings)); + } + else + { + script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString)); + } } _blockGroupHierarchyBuilder.Cleanup(); return script; } - - private static LinkedList IdentifyBlockBoundaries(string inputString) + + private static LinkedList IdentifyBlockBoundaries(string inputString) { - var blockBoundaries = new LinkedList(); + var blockBoundaries = new LinkedList(); var previousLine = string.Empty; - var currentLine = 0; + var currentLine = -1; + + var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(1, ItemFilterBlockBoundaryType.CommentBlock); foreach (var line in new LineReader(() => new StringReader(inputString))) { currentLine++; var trimmedLine = line.Trim(' '); - if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide") || - trimmedLine.StartsWith("# Section:")) + + if (string.IsNullOrWhiteSpace(trimmedLine)) + { + previousLine = line; + continue; + } + + // A line starting with a comment when we're inside a ItemFilterBlock boundary represents the end of that block + // as ItemFilterBlocks cannot have comment lines after the block description + if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary?.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) + { + blockBoundaries.AddLast(currentItemFilterBlockBoundary); + currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock); + } + // A line starting with a comment where the previous line was null represents the start of a new comment (unless we're on the first + // line in which case it's not a new comment). + else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentLine > 0) + { + if (blockBoundaries.Count > 0) + { + blockBoundaries.AddLast(currentItemFilterBlockBoundary); + } + currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock); + } + + else if (trimmedLine.StartsWith("Show") || trimmedLine.StartsWith("Hide")) { // If the line previous to the Show or Hide line is a comment then we should include that in the block // as it represents the block description. // currentLine > 2 caters for an edge case where the script description is a single line and the first // block has no description. This prevents the script description from being assigned to the first block's description. - blockBoundaries.AddLast(previousLine.StartsWith("#") && !previousLine.StartsWith("# Section:") && - currentLine > 2 - ? currentLine - 2 - : currentLine - 1); + if (!(currentItemFilterBlockBoundary.StartLine == currentLine - 1 && currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.CommentBlock)) + { + blockBoundaries.AddLast(currentItemFilterBlockBoundary); + } + currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(previousLine.StartsWith("#") && currentLine > 2 ? currentLine - 1 : currentLine, + ItemFilterBlockBoundaryType.ItemFilterBlock); } + previousLine = line; } + if (blockBoundaries.Last.Value != currentItemFilterBlockBoundary) + { + blockBoundaries.AddLast(currentItemFilterBlockBoundary); + } + return blockBoundaries; } @@ -178,7 +241,7 @@ namespace Filtration.Parser.Services // ReSharper disable once LoopCanBeConvertedToQuery foreach (var block in script.ItemFilterBlocks) { - outputString += _blockTranslator.TranslateItemFilterBlockToString(block) + Environment.NewLine; + outputString += _blockTranslator.TranslateItemFilterBlockToString(block as ItemFilterBlock) + Environment.NewLine; if (Settings.Default.ExtraLineBetweenBlocks) { diff --git a/Filtration.ThemeEditor/Services/ThemeService.cs b/Filtration.ThemeEditor/Services/ThemeService.cs index 95c22b9..360c24f 100644 --- a/Filtration.ThemeEditor/Services/ThemeService.cs +++ b/Filtration.ThemeEditor/Services/ThemeService.cs @@ -44,7 +44,7 @@ namespace Filtration.ThemeEditor.Services break; } - foreach (var block in script.ItemFilterBlocks) + foreach (var block in script.ItemFilterBlocks.OfType()) { foreach (var blockItem in block.BlockItems.Where(i => i.GetType() == targetType)) { diff --git a/Filtration/ViewModels/ItemFilterBlockViewModel.cs b/Filtration/ViewModels/ItemFilterBlockViewModel.cs index 250e4d7..6a07998 100644 --- a/Filtration/ViewModels/ItemFilterBlockViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockViewModel.cs @@ -4,7 +4,6 @@ using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Linq; using System.Windows.Media; -using Filtration.Common.ViewModels; using Filtration.ObjectModel; using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemTypes; diff --git a/Filtration/ViewModels/ItemFilterScriptViewModel.cs b/Filtration/ViewModels/ItemFilterScriptViewModel.cs index c061b84..2ba0149 100644 --- a/Filtration/ViewModels/ItemFilterScriptViewModel.cs +++ b/Filtration/ViewModels/ItemFilterScriptViewModel.cs @@ -320,7 +320,7 @@ namespace Filtration.ViewModels ItemFilterBlockViewModels.Clear(); Script = itemFilterScript; - foreach (var block in Script.ItemFilterBlocks) + foreach (var block in Script.ItemFilterBlocks.OfType()) { var vm = _itemFilterBlockViewModelFactory.Create(); vm.Initialise(block, this); @@ -426,7 +426,7 @@ namespace Filtration.ViewModels var unusedThemeComponents = Script.ThemeComponents.Where( t => - Script.ItemFilterBlocks.Count( + Script.ItemFilterBlocks.OfType().Count( b => b.BlockItems.OfType().Count(i => i.ThemeComponent == t) > 0) == 0).ToList(); if (unusedThemeComponents.Count <= 0) return true; From 43c61498321821f812bcd73271e5835fc1caa3e7 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 20 May 2017 18:34:45 +0100 Subject: [PATCH 11/15] Fixed failing tests --- .../TestItemFilterScriptTranslator.cs | 27 ------------------- .../Services/ItemFilterScriptTranslator.cs | 14 +++++++--- 2 files changed, 10 insertions(+), 31 deletions(-) diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index 799ec2f..9bca5bb 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -232,33 +232,6 @@ namespace Filtration.Parser.Tests.Services Assert.AreEqual(expectedOutput, result); } - [Test] - public void TranslateStringToItemFilterScript_SectionDirectlyBeforeBlockWithoutDescription_ReturnsCorrectObject() - { - // Arrange - var testInputScript = "# My Script" + Environment.NewLine + - Environment.NewLine + - "# Section: Chance Bases" + Environment.NewLine + - "Show" + Environment.NewLine + - " BaseType \"Lapis Amulet\" \"Amber Amulet\"" + Environment.NewLine + - " SetBorderColor 255 0 255" + Environment.NewLine + - " SetFontSize 25"; - - var blockTranslator = new ItemFilterBlockTranslator(_testUtility.MockBlockGroupHierarchyBuilder.Object); - var translator = new ItemFilterScriptTranslator(blockTranslator, - _testUtility.MockBlockGroupHierarchyBuilder.Object); - - // Act - var result = translator.TranslateStringToItemFilterScript(testInputScript); - - // Assert - Assert.AreEqual(2, result.ItemFilterBlocks.Count); - var block = result.ItemFilterBlocks.OfType().First(l => l.GetType() != typeof(ItemFilterSection)); - Assert.AreEqual(4, block.BlockItems.Count); - var baseTypeItem = block.BlockItems.OfType().First(); - Assert.AreEqual(2, baseTypeItem.Items.Count); - } - [Test] public void TranslateStringToItemFilterScript_OneLineDescriptionNoBlockDescriptionAddsDescriptionToScript() { diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 870f94d..e420c33 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -27,6 +27,7 @@ namespace Filtration.Parser.Services internal enum ItemFilterBlockBoundaryType { + ScriptDescription, ItemFilterBlock, CommentBlock } @@ -119,7 +120,7 @@ namespace Filtration.Parser.Services var lines = Regex.Split(inputString, "\r\n|\r|\n"); // Process the script header - for (var i = 0; i < conditionBoundaries.First.Value.StartLine; i++) + for (var i = 0; i < conditionBoundaries.Skip(1).First().StartLine; i++) { if (lines[i].StartsWith("#")) { @@ -136,6 +137,11 @@ namespace Filtration.Parser.Services // and add that object to the ItemFilterBlocks list for (var boundary = conditionBoundaries.First; boundary != null; boundary = boundary.Next) { + if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ScriptDescription) + { + continue; + } + var begin = boundary.Value.StartLine; var end = boundary.Next?.Value.StartLine ?? lines.Length; var block = new string[end - begin]; @@ -162,7 +168,7 @@ namespace Filtration.Parser.Services var previousLine = string.Empty; var currentLine = -1; - var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(1, ItemFilterBlockBoundaryType.CommentBlock); + var currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(0, ItemFilterBlockBoundaryType.ScriptDescription); foreach (var line in new LineReader(() => new StringReader(inputString))) { @@ -177,14 +183,14 @@ namespace Filtration.Parser.Services // A line starting with a comment when we're inside a ItemFilterBlock boundary represents the end of that block // as ItemFilterBlocks cannot have comment lines after the block description - if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary?.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) + if (trimmedLine.StartsWith("#") && currentItemFilterBlockBoundary.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) { blockBoundaries.AddLast(currentItemFilterBlockBoundary); currentItemFilterBlockBoundary = new ItemFilterBlockBoundary(currentLine, ItemFilterBlockBoundaryType.CommentBlock); } // A line starting with a comment where the previous line was null represents the start of a new comment (unless we're on the first // line in which case it's not a new comment). - else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentLine > 0) + else if (trimmedLine.StartsWith("#") && string.IsNullOrWhiteSpace(previousLine) && currentItemFilterBlockBoundary.BoundaryType != ItemFilterBlockBoundaryType.ScriptDescription) { if (blockBoundaries.Count > 0) { From b65fad0679f42dea8c9923b2beab30348732e918 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 17 Jun 2017 12:19:54 +0100 Subject: [PATCH 12/15] FIL-4 Completed refactoring of Sections to ItemFilterCommentBlocks --- .../Filtration.ItemFilterPreview.Tests.csproj | 1 - .../Services/serializationtest.cs | 4 +- .../Services/ItemFilterProcessor.cs | 5 +- .../Filtration.ObjectModel.csproj | 1 - Filtration.ObjectModel/ItemFilterBlock.cs | 2 - Filtration.ObjectModel/ItemFilterScript.cs | 12 +- Filtration.ObjectModel/ItemFilterSection.cs | 6 - .../Services/IItemFilterBlockTranslator.cs | 2 + .../Services/ItemFilterBlockTranslator.cs | 27 +- Filtration/App.xaml | 3 + Filtration/Filtration.csproj | 22 +- Filtration/Utility/RoutedCommandHandler.cs | 73 ++++++ Filtration/Utility/RoutedCommandHandlers.cs | 79 ++++++ .../AvalonDockWorkspaceViewModel.cs | 19 +- ...IItemFilterCommentBlockViewModelFactory.cs | 8 + .../ViewModels/ItemFilterBlockViewModel.cs | 122 ++++++--- .../ViewModels/ItemFilterScriptViewModel.cs | 245 +++++++++++------- Filtration/ViewModels/MainWindowViewModel.cs | 26 +- .../ToolPanes/BlockOutputPreviewViewModel.cs | 4 +- ...del.cs => CommentBlockBrowserViewModel.cs} | 30 +-- .../AvalonDock/AvalonDockWorkspaceView.xaml | 2 +- .../Views/AvalonDock/LayoutInitializer.cs | 2 +- .../Views/AvalonDock/PanesTemplateSelector.cs | 2 +- Filtration/Views/BlockTemplateSelector.cs | 26 -- ...w.xaml => ItemFilterCommentBlockView.xaml} | 6 +- ....cs => ItemFilterCommentBlockView.xaml.cs} | 4 +- Filtration/Views/ItemFilterScriptView.xaml | 24 +- Filtration/Views/MainWindow.xaml | 8 +- Filtration/Views/StartPageView.xaml | 2 +- ...View.xaml => CommentBlockBrowserView.xaml} | 10 +- ...aml.cs => CommentBlockBrowserView.xaml.cs} | 4 +- .../WindsorInstallers/ViewModelsInstaller.cs | 12 +- 32 files changed, 518 insertions(+), 275 deletions(-) delete mode 100644 Filtration.ObjectModel/ItemFilterSection.cs create mode 100644 Filtration/Utility/RoutedCommandHandler.cs create mode 100644 Filtration/Utility/RoutedCommandHandlers.cs create mode 100644 Filtration/ViewModels/IItemFilterCommentBlockViewModelFactory.cs rename Filtration/ViewModels/ToolPanes/{SectionBrowserViewModel.cs => CommentBlockBrowserViewModel.cs} (60%) delete mode 100644 Filtration/Views/BlockTemplateSelector.cs rename Filtration/Views/{ItemFilterSectionView.xaml => ItemFilterCommentBlockView.xaml} (91%) rename Filtration/Views/{ItemFilterSectionView.xaml.cs => ItemFilterCommentBlockView.xaml.cs} (51%) rename Filtration/Views/ToolPanes/{SectionBrowserView.xaml => CommentBlockBrowserView.xaml} (70%) rename Filtration/Views/ToolPanes/{SectionBrowserView.xaml.cs => CommentBlockBrowserView.xaml.cs} (55%) diff --git a/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj b/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj index e82122d..9f42fc4 100644 --- a/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj +++ b/Filtration.ItemFilterPreview.Tests/Filtration.ItemFilterPreview.Tests.csproj @@ -117,7 +117,6 @@ - - + - - - + + - @@ -36,14 +37,15 @@ - + + - + @@ -59,9 +61,9 @@ BorderThickness="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled" VirtualizingStackPanel.VirtualizationMode="Recycling" - ItemTemplateSelector="{StaticResource BlockTemplateSelector}" - attachedProperties:SelectingItemAttachedProperty.SelectingItem="{Binding SectionBrowserSelectedBlockViewModel}" - SelectedItem="{Binding SelectedBlockViewModel}" x:Name="BlocksListBox"> + attachedProperties:SelectingItemAttachedProperty.SelectingItem="{Binding CommentBlockBrowserBrowserSelectedBlockViewModel}" + SelectedItem="{Binding SelectedBlockViewModel}"> + diff --git a/Filtration/Views/MainWindow.xaml b/Filtration/Views/MainWindow.xaml index 46b6ac2..6e57bfe 100644 --- a/Filtration/Views/MainWindow.xaml +++ b/Filtration/Views/MainWindow.xaml @@ -9,15 +9,20 @@ xmlns:viewsAvalonDock="clr-namespace:Filtration.Views.AvalonDock" xmlns:views="clr-namespace:Filtration.Views" xmlns:gif="http://wpfanimatedgif.codeplex.com" + xmlns:utility="clr-namespace:Filtration.Utility" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=viewModels:MainWindowViewModel}" Title="{Binding WindowTitle}" Height="762" Width="1126" IsIconVisible="True" Closing="MainWindow_OnClosing" Drop="MainWindow_OnDrop" AllowDrop="True"> + + + + @@ -67,7 +72,7 @@ - + @@ -146,4 +151,5 @@ + \ No newline at end of file diff --git a/Filtration/Views/StartPageView.xaml b/Filtration/Views/StartPageView.xaml index 8e3793c..150334c 100644 --- a/Filtration/Views/StartPageView.xaml +++ b/Filtration/Views/StartPageView.xaml @@ -8,7 +8,7 @@ Welcome to Filtration, to get started either - create a new script or open an existing script + create a new script or open an existing script diff --git a/Filtration/Views/ToolPanes/SectionBrowserView.xaml b/Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml similarity index 70% rename from Filtration/Views/ToolPanes/SectionBrowserView.xaml rename to Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml index 5a34ece..13ec390 100644 --- a/Filtration/Views/ToolPanes/SectionBrowserView.xaml +++ b/Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml @@ -1,19 +1,19 @@ - - @@ -21,7 +21,7 @@ - + diff --git a/Filtration/Views/ToolPanes/SectionBrowserView.xaml.cs b/Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml.cs similarity index 55% rename from Filtration/Views/ToolPanes/SectionBrowserView.xaml.cs rename to Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml.cs index bd977be..5e9b6da 100644 --- a/Filtration/Views/ToolPanes/SectionBrowserView.xaml.cs +++ b/Filtration/Views/ToolPanes/CommentBlockBrowserView.xaml.cs @@ -1,8 +1,8 @@ namespace Filtration.Views.ToolPanes { - public partial class SectionBrowserView + public partial class CommentBlockBrowserView { - public SectionBrowserView() + public CommentBlockBrowserView() { InitializeComponent(); } diff --git a/Filtration/WindsorInstallers/ViewModelsInstaller.cs b/Filtration/WindsorInstallers/ViewModelsInstaller.cs index d002ac1..14d2c55 100644 --- a/Filtration/WindsorInstallers/ViewModelsInstaller.cs +++ b/Filtration/WindsorInstallers/ViewModelsInstaller.cs @@ -26,6 +26,11 @@ namespace Filtration.WindsorInstallers .ImplementedBy() .LifeStyle.Transient); + container.Register( + Component.For() + .ImplementedBy() + .LifeStyle.Transient); + container.Register( Component.For() .ImplementedBy() @@ -42,8 +47,8 @@ namespace Filtration.WindsorInstallers .LifeStyle.Singleton); container.Register( - Component.For() - .ImplementedBy() + Component.For() + .ImplementedBy() .LifeStyle.Singleton); container.Register( @@ -69,6 +74,9 @@ namespace Filtration.WindsorInstallers container.Register( Component.For().AsFactory()); + container.Register( + Component.For().AsFactory()); + container.Register( Component.For().AsFactory()); } From fee2a4dd99c03a39ed1074fb1502961e1c850621 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Sat, 17 Jun 2017 13:50:44 +0100 Subject: [PATCH 13/15] Initial refactoring to support CommandManager --- .../Services/TestItemFilterProcessor.cs | 14 +- .../Commands/CommandManager.cs | 62 ++++ Filtration.ObjectModel/Commands/ICommand.cs | 7 + .../Commands/IUndoableCommand.cs | 8 + .../Factories/IItemFilterScriptFactory.cs | 9 + .../Filtration.ObjectModel.csproj | 16 + Filtration.ObjectModel/ItemFilterScript.cs | 54 +++- .../Properties/Annotations.cs | 295 ++++++++++++------ .../Properties/AssemblyInfo.cs | 7 + .../WindsorInstallers/CommandsInstaller.cs | 21 ++ .../WindsorInstallers/ModelsInstaller.cs | 23 ++ Filtration.ObjectModel/packages.config | 5 + .../Services/IItemFilterScriptTranslator.cs | 4 +- .../TestItemFilterScriptTranslator.cs | 107 +++---- .../Services/ItemFilterScriptTranslator.cs | 16 +- .../TestItemFilterScriptRepository.cs | 27 +- .../Providers/ThemeProvider.cs | 8 +- .../Services/ThemeService.cs | 4 +- .../ViewModels/ThemeEditorViewModel.cs | 8 +- Filtration.sln.DotSettings | 1 + .../ItemFilterScriptRepository.cs | 6 +- .../Services/ItemFilterPersistenceService.cs | 10 +- .../ViewModels/ItemFilterScriptViewModel.cs | 8 +- .../ViewModels/ReplaceColorsViewModel.cs | 23 +- Filtration/Views/ItemFilterScriptView.xaml | 5 +- Filtration/Views/StartPageView.xaml | 2 +- 26 files changed, 549 insertions(+), 201 deletions(-) create mode 100644 Filtration.ObjectModel/Commands/CommandManager.cs create mode 100644 Filtration.ObjectModel/Commands/ICommand.cs create mode 100644 Filtration.ObjectModel/Commands/IUndoableCommand.cs create mode 100644 Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs create mode 100644 Filtration.ObjectModel/WindsorInstallers/CommandsInstaller.cs create mode 100644 Filtration.ObjectModel/WindsorInstallers/ModelsInstaller.cs create mode 100644 Filtration.ObjectModel/packages.config diff --git a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs index 17274f8..2a20555 100644 --- a/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs +++ b/Filtration.ItemFilterPreview.Tests/Services/TestItemFilterProcessor.cs @@ -6,6 +6,7 @@ using Filtration.ItemFilterPreview.Tests.Properties; using Filtration.ObjectModel; using Filtration.ObjectModel.BlockItemTypes; using Filtration.ObjectModel.Enums; +using Filtration.ObjectModel.Factories; using Filtration.Parser.Services; using Moq; using NUnit.Framework; @@ -71,7 +72,12 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputScriptFile = Resources.MuldiniFilterScript; var blockGroupHierarchyBuilder = new BlockGroupHierarchyBuilder(); - var scriptTranslator = new ItemFilterScriptTranslator(new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), blockGroupHierarchyBuilder); + var mockItemFilterScriptFactory = new Mock(); + mockItemFilterScriptFactory + .Setup(i => i.Create()) + .Returns(new ItemFilterScript()); + + var scriptTranslator = new ItemFilterScriptTranslator(blockGroupHierarchyBuilder, new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), mockItemFilterScriptFactory.Object); var script = scriptTranslator.TranslateStringToItemFilterScript(testInputScriptFile); var testInputItem = new Item @@ -101,7 +107,11 @@ namespace Filtration.ItemFilterPreview.Tests.Services //Arrange var testInputScriptFile = Resources.MuldiniFilterScript; var blockGroupHierarchyBuilder = new BlockGroupHierarchyBuilder(); - var scriptTranslator = new ItemFilterScriptTranslator(new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), blockGroupHierarchyBuilder); + var mockItemFilterScriptFactory = new Mock(); + mockItemFilterScriptFactory + .Setup(i => i.Create()) + .Returns(new ItemFilterScript()); + var scriptTranslator = new ItemFilterScriptTranslator(blockGroupHierarchyBuilder, new ItemFilterBlockTranslator(blockGroupHierarchyBuilder), mockItemFilterScriptFactory.Object); var script = scriptTranslator.TranslateStringToItemFilterScript(testInputScriptFile); var testInputItems = new List diff --git a/Filtration.ObjectModel/Commands/CommandManager.cs b/Filtration.ObjectModel/Commands/CommandManager.cs new file mode 100644 index 0000000..e8dc6f7 --- /dev/null +++ b/Filtration.ObjectModel/Commands/CommandManager.cs @@ -0,0 +1,62 @@ +using System.Collections.Generic; + +namespace Filtration.ObjectModel.Commands +{ + public interface ICommandManager + { + void ExecuteCommand(ICommand command); + void Undo(int undoLevels = 1); + void Redo(int redoLevels = 1); + } + + public interface ICommandManagerInternal : ICommandManager + { + void SetScript(IItemFilterScriptInternal layout); + } + + internal class CommandManager : ICommandManagerInternal + { + private readonly Stack _undoCommandStack = new Stack(); + private readonly Stack _redoCommandStack = new Stack(); + private IItemFilterScriptInternal _itemFilterScript; + + public void SetScript(IItemFilterScriptInternal itemFilterScript) + { + _itemFilterScript = itemFilterScript; + } + + public void ExecuteCommand(ICommand command) + { + command.Execute(); + var undoableCommand = command as IUndoableCommand; + if (undoableCommand != null) + { + _undoCommandStack.Push(undoableCommand); + _redoCommandStack.Clear(); + } + _itemFilterScript.SetIsDirty(true); + } + + public void Undo(int undoLevels = 1) + { + for (var index = undoLevels; _undoCommandStack.Count > 0 && index > 0; --index) + { + var undoableCommand = _undoCommandStack.Pop(); + undoableCommand.Undo(); + _redoCommandStack.Push(undoableCommand); + } + _itemFilterScript.SetIsDirty(true); + } + + public void Redo(int redoLevels = 1) + { + for (int index = redoLevels; _redoCommandStack.Count > 0 && index > 0; --index) + { + var undoableCommand = _redoCommandStack.Pop(); + undoableCommand.Redo(); + _undoCommandStack.Push(undoableCommand); + } + _itemFilterScript.SetIsDirty(true); + } + } +} diff --git a/Filtration.ObjectModel/Commands/ICommand.cs b/Filtration.ObjectModel/Commands/ICommand.cs new file mode 100644 index 0000000..84cfe3c --- /dev/null +++ b/Filtration.ObjectModel/Commands/ICommand.cs @@ -0,0 +1,7 @@ +namespace Filtration.ObjectModel.Commands +{ + public interface ICommand + { + void Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/IUndoableCommand.cs b/Filtration.ObjectModel/Commands/IUndoableCommand.cs new file mode 100644 index 0000000..9a9eb76 --- /dev/null +++ b/Filtration.ObjectModel/Commands/IUndoableCommand.cs @@ -0,0 +1,8 @@ +namespace Filtration.ObjectModel.Commands +{ + internal interface IUndoableCommand : ICommand + { + void Undo(); + void Redo(); + } +} diff --git a/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs b/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs new file mode 100644 index 0000000..2a5c0b2 --- /dev/null +++ b/Filtration.ObjectModel/Factories/IItemFilterScriptFactory.cs @@ -0,0 +1,9 @@ +namespace Filtration.ObjectModel.Factories +{ + public interface IItemFilterScriptFactory + { + IItemFilterScript Create(); + + void Release(IItemFilterScript itemFilterScript); + } +} diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj index 23e9171..17c34c7 100644 --- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj +++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj @@ -31,6 +31,12 @@ 4 + + ..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll + + + ..\packages\Castle.Windsor.3.4.0\lib\net45\Castle.Windsor.dll + @@ -68,6 +74,9 @@ + + + @@ -77,6 +86,7 @@ + @@ -97,6 +107,12 @@ + + + + + + @@ -42,7 +42,6 @@ - diff --git a/Filtration/Views/StartPageView.xaml b/Filtration/Views/StartPageView.xaml index 150334c..8e3793c 100644 --- a/Filtration/Views/StartPageView.xaml +++ b/Filtration/Views/StartPageView.xaml @@ -8,7 +8,7 @@ Welcome to Filtration, to get started either - create a new script or open an existing script + create a new script or open an existing script From d84b17ced31499ed187daf15572c04c367acc259 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Thu, 7 Dec 2017 18:14:47 +0000 Subject: [PATCH 14/15] Implemented script-level undo/redo (currently hidden in UI) --- .gitignore | 184 ++++++++-- .../Commands/CommandManager.cs | 3 +- .../ItemFilterScript/AddBlockCommand.cs | 37 ++ .../AddCommentBlockCommand.cs | 37 ++ .../ItemFilterScript/MoveBlockDownCommand.cs | 39 ++ .../MoveBlockToBottomCommand.cs | 30 ++ .../ItemFilterScript/MoveBlockToTopCommand.cs | 30 ++ .../ItemFilterScript/MoveBlockUpCommand.cs | 39 ++ .../ItemFilterScript/PasteBlockCommand.cs | 37 ++ .../ItemFilterScript/RemoveBlockCommand.cs | 29 ++ .../SetScriptDescriptionCommand.cs | 30 ++ .../Filtration.ObjectModel.csproj | 9 + Filtration.ObjectModel/ItemFilterBlock.cs | 37 +- Filtration.ObjectModel/ItemFilterScript.cs | 14 +- .../Services/IItemFilterBlockTranslator.cs | 5 +- .../Services/TestItemFilterBlockTranslator.cs | 106 +++--- .../TestItemFilterScriptTranslator.cs | 2 +- .../Services/ItemFilterBlockTranslator.cs | 17 +- .../Services/ItemFilterScriptTranslator.cs | 4 +- .../TestItemFilterScriptRepository.cs | 1 + Filtration/Filtration.csproj | 11 +- .../ItemFilterScriptRepository.cs | 1 + Filtration/Resources/Icons/redo_icon.png | Bin 0 -> 579 bytes Filtration/Resources/Icons/undo_icon.png | Bin 0 -> 339 bytes .../IItemFilterBlockViewModelFactory.cs | 2 +- ...IItemFilterCommentBlockViewModelFactory.cs | 2 +- .../IItemFilterScriptViewModelFactory.cs | 2 +- .../ItemFilterBlockBaseViewModelFactory.cs | 37 ++ .../ViewModels/ItemFilterBlockViewModel.cs | 71 +--- .../ItemFilterBlockViewModelBase.cs | 42 +++ .../ItemFilterCommentBlockViewModel.cs | 29 ++ .../ViewModels/ItemFilterScriptViewModel.cs | 343 +++++++----------- Filtration/ViewModels/MainWindowViewModel.cs | 22 +- Filtration/Views/IconsDictionary.xaml | 2 + Filtration/Views/MainWindow.xaml | 12 +- .../WindsorInstallers/ViewModelsInstaller.cs | 6 + 36 files changed, 888 insertions(+), 384 deletions(-) create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/AddCommentBlockCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockDownCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToBottomCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToTopCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockUpCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/PasteBlockCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockCommand.cs create mode 100644 Filtration.ObjectModel/Commands/ItemFilterScript/SetScriptDescriptionCommand.cs create mode 100644 Filtration/Resources/Icons/redo_icon.png create mode 100644 Filtration/Resources/Icons/undo_icon.png rename Filtration/ViewModels/{ => Factories}/IItemFilterBlockViewModelFactory.cs (80%) rename Filtration/ViewModels/{ => Factories}/IItemFilterCommentBlockViewModelFactory.cs (82%) rename Filtration/ViewModels/{ => Factories}/IItemFilterScriptViewModelFactory.cs (81%) create mode 100644 Filtration/ViewModels/Factories/ItemFilterBlockBaseViewModelFactory.cs create mode 100644 Filtration/ViewModels/ItemFilterBlockViewModelBase.cs create mode 100644 Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs diff --git a/.gitignore b/.gitignore index 7964536..bce8a85 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,42 @@ ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + # Build results [Dd]ebug/ [Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ x64/ -build/ +x86/ bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ -# Roslyn cache directories -*.ide/ +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* -#NUNIT +# NUNIT *.VisualState.xml TestResult.xml @@ -32,6 +45,19 @@ TestResult.xml [Rr]eleasePS/ dlldata.c +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio *_i.c *_p.c *_i.h @@ -64,14 +90,21 @@ _Chutzpah* ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx +*.sap + +# Visual Studio Trace Files +*.e2e # TFS 2012 Local Workspace $tf/ @@ -84,7 +117,7 @@ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user -# JustCode is a .NET coding addin-in +# JustCode is a .NET coding add-in .JustCode # TeamCity is a build add-in @@ -93,9 +126,18 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch _NCrunch_* .*crunch*.local.xml +nCrunchTemp_* # MightyMoose *.mm.* @@ -123,42 +165,63 @@ publish/ # Publish Web Output *.[Pp]ublish.xml *.azurePubxml -## TODO: Comment the next line if you want to checkin your -## web deploy settings but do note that will include unencrypted -## passwords -#*.pubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj -# NuGet Packages Directory -packages/* -## TODO: If the tool you use requires repositories.config -## uncomment the next line -#!packages/repositories.config +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ -# Enable "build/" folder in the NuGet Packages folder since -# NuGet packages use it for MSBuild targets. -# This line needs to be after the ignore of the build folder -# (and the packages folder if the line above has been uncommented) -!packages/build/ +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets -# Windows Azure Build Output +# Microsoft Azure Build Output csx/ *.build.csdef -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.dbproj.schemaview +*.jfm *.pfx *.publishsettings -node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ # RIA/Silverlight projects Generated_Code/ @@ -174,6 +237,7 @@ UpgradeLog*.htm # SQL Server files *.mdf *.ldf +*.ndf # Business Intelligence projects *.rdl.data @@ -183,7 +247,69 @@ UpgradeLog*.htm # Microsoft Fakes FakesAssemblies/ -# LightSwitch generated files -GeneratedArtifacts/ -_Pvt_Extensions/ -ModelManifest.xml \ No newline at end of file +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# TypeScript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ \ No newline at end of file diff --git a/Filtration.ObjectModel/Commands/CommandManager.cs b/Filtration.ObjectModel/Commands/CommandManager.cs index e8dc6f7..2f58cee 100644 --- a/Filtration.ObjectModel/Commands/CommandManager.cs +++ b/Filtration.ObjectModel/Commands/CommandManager.cs @@ -28,8 +28,7 @@ namespace Filtration.ObjectModel.Commands public void ExecuteCommand(ICommand command) { command.Execute(); - var undoableCommand = command as IUndoableCommand; - if (undoableCommand != null) + if (command is IUndoableCommand undoableCommand) { _undoCommandStack.Push(undoableCommand); _redoCommandStack.Clear(); diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockCommand.cs new file mode 100644 index 0000000..7aa9e85 --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/AddBlockCommand.cs @@ -0,0 +1,37 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class AddBlockCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _addAfterItemFilterBlock; + private IItemFilterBlock _newItemFilterBlock; + + public AddBlockCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase addAfterItemFilterBlock) + { + _itemFilterScript = itemFilterScript; + _addAfterItemFilterBlock = addAfterItemFilterBlock; + } + public void Execute() + { + _newItemFilterBlock = new ItemFilterBlock(_itemFilterScript); + if (_addAfterItemFilterBlock != null) + { + _itemFilterScript.ItemFilterBlocks.Insert(_itemFilterScript.ItemFilterBlocks.IndexOf(_addAfterItemFilterBlock) + 1, _newItemFilterBlock); + } + else + { + _itemFilterScript.ItemFilterBlocks.Add(_newItemFilterBlock); + } + + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_newItemFilterBlock); + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/AddCommentBlockCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/AddCommentBlockCommand.cs new file mode 100644 index 0000000..1c627df --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/AddCommentBlockCommand.cs @@ -0,0 +1,37 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class AddCommentBlockCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _addAfterItemFilterBlock; + private IItemFilterCommentBlock _newItemFilterBlock; + + public AddCommentBlockCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase addAfterItemFilterBlock) + { + _itemFilterScript = itemFilterScript; + _addAfterItemFilterBlock = addAfterItemFilterBlock; + } + public void Execute() + { + _newItemFilterBlock = new ItemFilterCommentBlock(_itemFilterScript); + if (_addAfterItemFilterBlock != null) + { + _itemFilterScript.ItemFilterBlocks.Insert(_itemFilterScript.ItemFilterBlocks.IndexOf(_addAfterItemFilterBlock) + 1, _newItemFilterBlock); + } + else + { + _itemFilterScript.ItemFilterBlocks.Add(_newItemFilterBlock); + } + + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_newItemFilterBlock); + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockDownCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockDownCommand.cs new file mode 100644 index 0000000..0f837e6 --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockDownCommand.cs @@ -0,0 +1,39 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class MoveBlockDownCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _blockToMove; + private int _indexMovedFrom; + + public MoveBlockDownCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase blockToMove) + { + _itemFilterScript = itemFilterScript; + _blockToMove = blockToMove; + } + + public void Execute() + { + _indexMovedFrom = _itemFilterScript.ItemFilterBlocks.IndexOf(_blockToMove); + + if (_indexMovedFrom >= _itemFilterScript.ItemFilterBlocks.Count) + { + throw new InvalidOperationException("Cannot move the bottom block down"); + } + + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom + 1, _blockToMove); + + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom, _blockToMove); + } + + public void Redo() => Execute(); + } +} \ No newline at end of file diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToBottomCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToBottomCommand.cs new file mode 100644 index 0000000..3b680a7 --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToBottomCommand.cs @@ -0,0 +1,30 @@ +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class MoveBlockToBottomCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _blockToMove; + private int _indexMovedFrom; + + public MoveBlockToBottomCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase blockToMove) + { + _itemFilterScript = itemFilterScript; + _blockToMove = blockToMove; + } + public void Execute() + { + _indexMovedFrom = _itemFilterScript.ItemFilterBlocks.IndexOf(_blockToMove); + + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Add(_blockToMove); + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom, _blockToMove); + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToTopCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToTopCommand.cs new file mode 100644 index 0000000..49ac04a --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockToTopCommand.cs @@ -0,0 +1,30 @@ +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class MoveBlockToTopCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _blockToMove; + private int _indexMovedFrom; + + public MoveBlockToTopCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase blockToMove) + { + _itemFilterScript = itemFilterScript; + _blockToMove = blockToMove; + } + public void Execute() + { + _indexMovedFrom = _itemFilterScript.ItemFilterBlocks.IndexOf(_blockToMove); + + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(0, _blockToMove); + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom, _blockToMove); + } + + public void Redo() => Execute(); + } +} \ No newline at end of file diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockUpCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockUpCommand.cs new file mode 100644 index 0000000..44b7fec --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/MoveBlockUpCommand.cs @@ -0,0 +1,39 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class MoveBlockUpCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _blockToMove; + private int _indexMovedFrom; + + public MoveBlockUpCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase blockToMove) + { + _itemFilterScript = itemFilterScript; + _blockToMove = blockToMove; + } + + public void Execute() + { + _indexMovedFrom = _itemFilterScript.ItemFilterBlocks.IndexOf(_blockToMove); + + if (_indexMovedFrom <= 0) + { + throw new InvalidOperationException("Cannot move the top block up"); + } + + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom-1, _blockToMove); + + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_blockToMove); + _itemFilterScript.ItemFilterBlocks.Insert(_indexMovedFrom, _blockToMove); + } + + public void Redo() => Execute(); + } +} \ No newline at end of file diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/PasteBlockCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/PasteBlockCommand.cs new file mode 100644 index 0000000..7d7c680 --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/PasteBlockCommand.cs @@ -0,0 +1,37 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class PasteBlockCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly IItemFilterBlockBase _pastedItemFilterBlock; + private readonly IItemFilterBlockBase _addAfterItemFilterBlock; + + public PasteBlockCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase pastedItemFilterBlock, IItemFilterBlockBase addAfterItemFilterBlock) + { + _itemFilterScript = itemFilterScript; + _pastedItemFilterBlock = pastedItemFilterBlock; + _addAfterItemFilterBlock = addAfterItemFilterBlock; + } + + public void Execute() + { + if (_addAfterItemFilterBlock != null) + { + _itemFilterScript.ItemFilterBlocks.Insert(_itemFilterScript.ItemFilterBlocks.IndexOf(_addAfterItemFilterBlock) + 1, _pastedItemFilterBlock); + } + else + { + _itemFilterScript.ItemFilterBlocks.Add(_pastedItemFilterBlock); + } + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Remove(_pastedItemFilterBlock); + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockCommand.cs new file mode 100644 index 0000000..07e61ac --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/RemoveBlockCommand.cs @@ -0,0 +1,29 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class RemoveBlockCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private IItemFilterBlockBase _removedItemFilterBlock; + private int _indexRemovedFrom; + + public RemoveBlockCommand(IItemFilterScript itemFilterScript, IItemFilterBlockBase itemFilterBlockBase) + { + _itemFilterScript = itemFilterScript; + _removedItemFilterBlock = itemFilterBlockBase; + } + public void Execute() + { + _indexRemovedFrom = _itemFilterScript.ItemFilterBlocks.IndexOf(_removedItemFilterBlock); + _itemFilterScript.ItemFilterBlocks.Remove(_removedItemFilterBlock); + } + + public void Undo() + { + _itemFilterScript.ItemFilterBlocks.Insert(_indexRemovedFrom, _removedItemFilterBlock); + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Commands/ItemFilterScript/SetScriptDescriptionCommand.cs b/Filtration.ObjectModel/Commands/ItemFilterScript/SetScriptDescriptionCommand.cs new file mode 100644 index 0000000..ec99154 --- /dev/null +++ b/Filtration.ObjectModel/Commands/ItemFilterScript/SetScriptDescriptionCommand.cs @@ -0,0 +1,30 @@ +using System; + +namespace Filtration.ObjectModel.Commands.ItemFilterScript +{ + public class SetScriptDescriptionCommand : IUndoableCommand + { + private readonly IItemFilterScript _itemFilterScript; + private readonly string _newDescription; + private string _oldDescription; + + public SetScriptDescriptionCommand(IItemFilterScript itemFilterScript, string newDescription) + { + _itemFilterScript = itemFilterScript; + _newDescription = newDescription; + } + + public void Execute() + { + _oldDescription = _itemFilterScript.Description; + _itemFilterScript.Description = _newDescription; + } + + public void Undo() + { + _itemFilterScript.Description = _oldDescription; + } + + public void Redo() => Execute(); + } +} diff --git a/Filtration.ObjectModel/Filtration.ObjectModel.csproj b/Filtration.ObjectModel/Filtration.ObjectModel.csproj index 17c34c7..e4a341c 100644 --- a/Filtration.ObjectModel/Filtration.ObjectModel.csproj +++ b/Filtration.ObjectModel/Filtration.ObjectModel.csproj @@ -76,6 +76,15 @@ + + + + + + + + + diff --git a/Filtration.ObjectModel/ItemFilterBlock.cs b/Filtration.ObjectModel/ItemFilterBlock.cs index d8cfcc1..92bd8ef 100644 --- a/Filtration.ObjectModel/ItemFilterBlock.cs +++ b/Filtration.ObjectModel/ItemFilterBlock.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Windows.Media; using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemTypes; +using Filtration.ObjectModel.Commands; using Filtration.ObjectModel.Enums; using Filtration.ObjectModel.Extensions; @@ -29,9 +30,20 @@ namespace Filtration.ObjectModel { } - public class ItemFilterBlockBase : IItemFilterBlockBase + public abstract class ItemFilterBlockBase : IItemFilterBlockBase { - + protected ItemFilterBlockBase() + { + } + + protected ItemFilterBlockBase(IItemFilterScript parentScript) + { + CommandManager = parentScript.CommandManager; + ParentScript = parentScript; + } + + public ICommandManager CommandManager { get; } + public IItemFilterScript ParentScript { get; set; } } public interface IItemFilterCommentBlock : IItemFilterBlockBase @@ -41,6 +53,10 @@ namespace Filtration.ObjectModel public class ItemFilterCommentBlock : ItemFilterBlockBase, IItemFilterCommentBlock { + public ItemFilterCommentBlock(IItemFilterScript parentScript) : base(parentScript) + { + } + public string Comment { get; set; } } @@ -48,14 +64,19 @@ namespace Filtration.ObjectModel { private ItemFilterBlockGroup _blockGroup; - public ItemFilterBlock() + internal ItemFilterBlock() { - ActionBlockItem = new ActionBlockItem(BlockAction.Show); - BlockItems = new ObservableCollection {ActionBlockItem}; - Enabled = true; + BlockItems = new ObservableCollection { ActionBlockItem }; } - public bool Enabled { get; set; } + public ItemFilterBlock(IItemFilterScript parentScript) : base(parentScript) + { + BlockItems = new ObservableCollection { ActionBlockItem }; + } + + public ICommandManager CommandManager { get; } + + public bool Enabled { get; set; } = true; public string Description { get; set; } public ItemFilterBlockGroup BlockGroup @@ -98,7 +119,7 @@ namespace Filtration.ObjectModel } } - public ActionBlockItem ActionBlockItem { get; } + public ActionBlockItem ActionBlockItem { get; } = new ActionBlockItem(BlockAction.Show); public ObservableCollection BlockItems { get; } diff --git a/Filtration.ObjectModel/ItemFilterScript.cs b/Filtration.ObjectModel/ItemFilterScript.cs index 9548e51..703ad6d 100644 --- a/Filtration.ObjectModel/ItemFilterScript.cs +++ b/Filtration.ObjectModel/ItemFilterScript.cs @@ -37,6 +37,7 @@ namespace Filtration.ObjectModel public class ItemFilterScript : IItemFilterScriptInternal { private bool _isDirty; + private string _description; internal ItemFilterScript() { @@ -65,7 +66,18 @@ namespace Filtration.ObjectModel public IItemFilterScriptSettings ItemFilterScriptSettings { get; } public string FilePath { get; set; } - public string Description { get; set; } + + public string Description + { + get => _description; + set + { + if (value == _description) return; + _description = value; + OnPropertyChanged(); + } + } + public DateTime DateModified { get; set; } public bool IsDirty diff --git a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs index 6704bb6..859e276 100644 --- a/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Interface/Services/IItemFilterBlockTranslator.cs @@ -5,10 +5,11 @@ namespace Filtration.Parser.Interface.Services { public interface IItemFilterBlockTranslator { - IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings); + IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScript parentItemFilterScript, bool initialiseBlockGroupHierarchyBuilder = false); + IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString, IItemFilterScript parentItemFilterScript); + string TranslateItemFilterBlockToString(IItemFilterBlock block); void ReplaceAudioVisualBlockItemsFromString(ObservableCollection blockItems, string inputString); - IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString); string TranslateItemFilterCommentBlockToString(IItemFilterCommentBlock itemFilterCommentBlock); string TranslateItemFilterBlockBaseToString(IItemFilterBlockBase itemFilterBlockBase); } diff --git a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs index f2f3acd..8c5dc7c 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterBlockTranslator.cs @@ -33,7 +33,7 @@ namespace Filtration.Parser.Tests.Services var testInputString = "# This is a comment\r\n# Line 2 \r\n # Test"; //Act - var result = _testUtility.Translator.TranslateStringToItemFilterCommentBlock(testInputString); + var result = _testUtility.Translator.TranslateStringToItemFilterCommentBlock(testInputString, Mock.Of()); //Assert Assert.AreEqual(" This is a comment\r\n Line 2 \r\n Test", result.Comment); @@ -52,7 +52,7 @@ namespace Filtration.Parser.Tests.Services .Returns(inputBlockGroup); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); //Assert Assert.IsTrue(string.IsNullOrEmpty(result.ActionBlockItem.Comment)); @@ -68,7 +68,7 @@ namespace Filtration.Parser.Tests.Services var inputString = $"Show #{testInputExpectedComment}" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled == false)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled == false)); //Assert Assert.AreEqual(testInputExpectedComment, result.ActionBlockItem.Comment); @@ -82,7 +82,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(true, result.Enabled); @@ -96,7 +96,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(2, result.BlockItems.Count); @@ -112,7 +112,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ItemLevelBlockItem)); @@ -130,7 +130,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert Assert.AreEqual(true, inputBlockGroup.IsChecked); @@ -145,7 +145,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert Assert.AreEqual(false, inputBlockGroup.IsChecked); @@ -160,7 +160,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Returns(inputBlockGroup).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert _testUtility.MockBlockGroupHierarchyBuilder.Verify(); @@ -174,7 +174,7 @@ namespace Filtration.Parser.Tests.Services // Act _testUtility.MockBlockGroupHierarchyBuilder.Setup(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>())).Verifiable(); - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert _testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>()), Times.Never); @@ -187,7 +187,7 @@ namespace Filtration.Parser.Tests.Services var inputString = "Show #" + Environment.NewLine; // Act - _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert _testUtility.MockBlockGroupHierarchyBuilder.Verify(b => b.IntegrateStringListIntoBlockGroupHierarchy(It.IsAny>()), Times.Never); @@ -206,7 +206,7 @@ namespace Filtration.Parser.Tests.Services .Returns(testBlockGroup) .Verifiable(); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert Assert.AreEqual(testBlockGroup, result.BlockGroup); @@ -226,7 +226,7 @@ namespace Filtration.Parser.Tests.Services .Returns(testBlockGroup) .Verifiable(); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled)); // Assert Assert.AreEqual(testBlockGroup, result.BlockGroup); @@ -240,7 +240,7 @@ namespace Filtration.Parser.Tests.Services var inputString = "Show # AAA - BBB - CCC" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.BlockGroupsEnabled == false)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.BlockGroupsEnabled == false)); // Assert Assert.IsNull(result.BlockGroup); @@ -254,7 +254,7 @@ namespace Filtration.Parser.Tests.Services var inputString = "Hide" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -270,7 +270,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual("This is a test Block", result.Description); @@ -290,7 +290,7 @@ namespace Filtration.Parser.Tests.Services " ItemLevel >= 55"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual("Second Line", result.Description); @@ -308,7 +308,7 @@ namespace Filtration.Parser.Tests.Services " DropLevel = 40"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -326,7 +326,7 @@ namespace Filtration.Parser.Tests.Services " Corrupted True"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -343,7 +343,7 @@ namespace Filtration.Parser.Tests.Services " Identified True"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -360,7 +360,7 @@ namespace Filtration.Parser.Tests.Services " Quality < 18"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -378,7 +378,7 @@ namespace Filtration.Parser.Tests.Services " Rarity > Normal"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -396,7 +396,7 @@ namespace Filtration.Parser.Tests.Services " Rarity Normal"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); @@ -413,7 +413,7 @@ namespace Filtration.Parser.Tests.Services @" Class ""Test Class 1"" ""TestOneWordClassInQuotes"" TestOneWordClassNotInQuotes ""Test Class 2"""; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ClassBlockItem)); @@ -432,7 +432,7 @@ namespace Filtration.Parser.Tests.Services @" BaseType ""Test Base Type 1"" ""TestOneWordBaseTypeInQuotes"" TestOneWordBaseTypeNotInQuotes ""Test BaseType 2"""; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BaseTypeBlockItem)); @@ -451,7 +451,7 @@ namespace Filtration.Parser.Tests.Services " Sockets > 2"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -469,7 +469,7 @@ namespace Filtration.Parser.Tests.Services " LinkedSockets > 1"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -487,7 +487,7 @@ namespace Filtration.Parser.Tests.Services " Width = 1"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -505,7 +505,7 @@ namespace Filtration.Parser.Tests.Services " Height <= 3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert @@ -523,7 +523,7 @@ namespace Filtration.Parser.Tests.Services " Height <=3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is HeightBlockItem)); @@ -540,7 +540,7 @@ namespace Filtration.Parser.Tests.Services " SocketGroup RRGB"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SocketGroupBlockItem)); @@ -558,7 +558,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -576,7 +576,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 65 0 255 12"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -595,7 +595,7 @@ namespace Filtration.Parser.Tests.Services " SetBackgroundColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BackgroundColorBlockItem)); @@ -614,7 +614,7 @@ namespace Filtration.Parser.Tests.Services " SetBorderColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -633,8 +633,8 @@ namespace Filtration.Parser.Tests.Services // Act - Assert.DoesNotThrow(() => _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of())); - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + Assert.DoesNotThrow(() => _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript)); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -652,10 +652,9 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100 # Rare Item Text"; var testComponent = new ThemeComponent(ThemeComponentType.TextColor, "Rare Item Text", new Color { R = 255, G = 20, B = 100}); var testInputThemeComponentCollection = new ThemeComponentCollection { testComponent }; - var testInputItemFilterScriptSettings = Mock.Of(i => i.ThemeComponentCollection == testInputThemeComponentCollection); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, testInputItemFilterScriptSettings); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of(i => i.ItemFilterScriptSettings.ThemeComponentCollection == testInputThemeComponentCollection)); // Assert var blockItem = result.BlockItems.OfType().First(); @@ -673,7 +672,7 @@ namespace Filtration.Parser.Tests.Services " SetFontSize 15"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is FontSizeBlockItem)); @@ -690,7 +689,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 4"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -708,7 +707,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 2 95"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -745,7 +744,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 3"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual("Test filter with everything", result.Description); @@ -833,7 +832,7 @@ namespace Filtration.Parser.Tests.Services " Quality < 17"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(2, result.BlockItems.Count(b => b is ItemLevelBlockItem)); @@ -862,7 +861,7 @@ namespace Filtration.Parser.Tests.Services " SetTextColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is TextColorBlockItem)); @@ -883,7 +882,7 @@ namespace Filtration.Parser.Tests.Services " SetFontSize 27" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is FontSizeBlockItem)); @@ -902,7 +901,7 @@ namespace Filtration.Parser.Tests.Services " PlayAlertSound 2" + Environment.NewLine; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is SoundBlockItem)); @@ -920,7 +919,7 @@ namespace Filtration.Parser.Tests.Services " SetBackgroundColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BackgroundColorBlockItem)); @@ -939,7 +938,7 @@ namespace Filtration.Parser.Tests.Services " SetBorderColor 255 20 100"; // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is BorderColorBlockItem)); @@ -967,7 +966,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is RarityBlockItem)); @@ -994,7 +993,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -1029,7 +1028,7 @@ namespace Filtration.Parser.Tests.Services _testUtility.TestBlock.BlockItems.Add(new WidthBlockItem(FilterPredicateOperator.Equal, 4)); // Act - var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, Mock.Of()); + var result = _testUtility.Translator.TranslateStringToItemFilterBlock(inputString, _testUtility.MockItemFilterScript); // Assert Assert.AreEqual(1, result.BlockItems.Count(b => b is ActionBlockItem)); @@ -1870,6 +1869,7 @@ namespace Filtration.Parser.Tests.Services // Mock setups MockBlockGroupHierarchyBuilder = new Mock(); + MockItemFilterScript = Mock.Of(i => i.ItemFilterScriptSettings.ThemeComponentCollection == new ThemeComponentCollection()); // Class under test instantiation Translator = new ItemFilterBlockTranslator(MockBlockGroupHierarchyBuilder.Object); @@ -1878,6 +1878,8 @@ namespace Filtration.Parser.Tests.Services public ItemFilterBlock TestBlock { get; set; } public Mock MockBlockGroupHierarchyBuilder { get; } public ItemFilterBlockTranslator Translator { get; } + + public IItemFilterScript MockItemFilterScript { get; } } } } diff --git a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs index 886102e..32ac065 100644 --- a/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs +++ b/Filtration.Parser.Tests/Services/TestItemFilterScriptTranslator.cs @@ -40,7 +40,7 @@ namespace Filtration.Parser.Tests.Services // Assert Assert.AreEqual(5, script.ItemFilterBlocks.Count); - mockItemFilterBlockTranslator.Verify(t => t.TranslateStringToItemFilterBlock(It.IsAny(), It.IsAny())); + mockItemFilterBlockTranslator.Verify(t => t.TranslateStringToItemFilterBlock(It.IsAny(), It.IsAny(), false)); } [Test] diff --git a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs index 485ccfd..b8b10a1 100644 --- a/Filtration.Parser/Services/ItemFilterBlockTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterBlockTranslator.cs @@ -30,9 +30,9 @@ namespace Filtration.Parser.Services } // Converts a string into an ItemFilterCommentBlock maintaining newlines and spaces but removing # characters - public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString) + public IItemFilterCommentBlock TranslateStringToItemFilterCommentBlock(string inputString, IItemFilterScript parentItemFilterScript) { - var itemFilterCommentBlock = new ItemFilterCommentBlock(); + var itemFilterCommentBlock = new ItemFilterCommentBlock(parentItemFilterScript); foreach (var line in new LineReader(() => new StringReader(inputString))) { @@ -47,10 +47,15 @@ namespace Filtration.Parser.Services // This method converts a string into a ItemFilterBlock. This is used for pasting ItemFilterBlocks // and reading ItemFilterScripts from a file. - public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScriptSettings itemFilterScriptSettings) + public IItemFilterBlock TranslateStringToItemFilterBlock(string inputString, IItemFilterScript parentItemFilterScript, bool initialiseBlockGroupHierarchyBuilder = false) { - _masterComponentCollection = itemFilterScriptSettings.ThemeComponentCollection; - var block = new ItemFilterBlock(); + if (initialiseBlockGroupHierarchyBuilder) + { + _blockGroupHierarchyBuilder.Initialise(parentItemFilterScript.ItemFilterBlockGroups.First()); + } + + _masterComponentCollection = parentItemFilterScript.ItemFilterScriptSettings.ThemeComponentCollection; + var block = new ItemFilterBlock(parentItemFilterScript); var showHideFound = false; foreach (var line in new LineReader(() => new StringReader(inputString))) @@ -78,7 +83,7 @@ namespace Filtration.Parser.Services // If block groups are enabled for this script, the comment after Show/Hide is parsed as a block // group hierarchy, if block groups are disabled it is preserved as a simple text comment. - if (itemFilterScriptSettings.BlockGroupsEnabled) + if (parentItemFilterScript.ItemFilterScriptSettings.BlockGroupsEnabled) { AddBlockGroupToBlock(block, trimmedLine); } diff --git a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs index 2e214a3..2c7d8b9 100644 --- a/Filtration.Parser/Services/ItemFilterScriptTranslator.cs +++ b/Filtration.Parser/Services/ItemFilterScriptTranslator.cs @@ -154,11 +154,11 @@ namespace Filtration.Parser.Services if (boundary.Value.BoundaryType == ItemFilterBlockBoundaryType.ItemFilterBlock) { - script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script.ItemFilterScriptSettings)); + script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterBlock(blockString, script)); } else { - script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString)); + script.ItemFilterBlocks.Add(_blockTranslator.TranslateStringToItemFilterCommentBlock(blockString, script)); } } diff --git a/Filtration.Tests/Repositories/TestItemFilterScriptRepository.cs b/Filtration.Tests/Repositories/TestItemFilterScriptRepository.cs index 4f6097a..12a911e 100644 --- a/Filtration.Tests/Repositories/TestItemFilterScriptRepository.cs +++ b/Filtration.Tests/Repositories/TestItemFilterScriptRepository.cs @@ -6,6 +6,7 @@ using Filtration.ObjectModel.Factories; using Filtration.Repositories; using Filtration.Services; using Filtration.ViewModels; +using Filtration.ViewModels.Factories; using FluentAssertions; using Moq; using NUnit.Framework; diff --git a/Filtration/Filtration.csproj b/Filtration/Filtration.csproj index 52cd482..b0a83bb 100644 --- a/Filtration/Filtration.csproj +++ b/Filtration/Filtration.csproj @@ -184,11 +184,14 @@ - + + + + - - + + @@ -443,6 +446,8 @@ + + diff --git a/Filtration/Repositories/ItemFilterScriptRepository.cs b/Filtration/Repositories/ItemFilterScriptRepository.cs index c50a9b2..2348b2a 100644 --- a/Filtration/Repositories/ItemFilterScriptRepository.cs +++ b/Filtration/Repositories/ItemFilterScriptRepository.cs @@ -3,6 +3,7 @@ using Filtration.ObjectModel; using Filtration.ObjectModel.Factories; using Filtration.Services; using Filtration.ViewModels; +using Filtration.ViewModels.Factories; namespace Filtration.Repositories { diff --git a/Filtration/Resources/Icons/redo_icon.png b/Filtration/Resources/Icons/redo_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8618cdb1e3c8f14652f03f9ea87daacb5469cfaf GIT binary patch literal 579 zcmV-J0=)f+P)ybOTd* ze&w)Q*u^=mJ>1vnq{tU*rNylF>e5O^_n=@f4iSOCi7>JqbUTBlE9LWpy<24fSby|E z_mxzi0Kh0zOKVrNd+A&Tzby}(a|9v5aYGEp9*7ZQA_m*EAjkH$Q0RpaqV8aBgYx%k zdS)T{<=Xm+F1-ltmW6hE*l_*G48aU7l`@2?B8WW9#p7^o2hM0{W|wmM(Ju>vK&31B ztWJ#M;PW@L)j8h!TD!A<5^cHo_L+9UeVNXs5s(jcLB+hT>4_u*05CPFY$miMejN4C z>Df=tE(5^#*SEJFIl3|E4ZtY|4?Yl!;2{J6h& z55tRqvF}4LJ^^?EGaMPfasA4)-PH#lbww!k%;H6Z#W@s4V2r?N5SjRCB_SzG)3yw7QNtZQ#@Hb(+>cO=pk1O3##F#5Vpl_*Z~6^vcJ!G`SF~ zGXc8qi>52(4uG380RSM3!tDq!mhQeYW&*U|6ii~YMMO_$adE2U`}O~R+U57o-u05U=~Rr}=kNNQy6Rt&-$s4fkFn>l#_Td_+@-(jaF*O+i`rL%-iD#z zS$xwrV$4r^+MTlFVT9Mn)$kYh`I`U$0FX&UK~xx(U5(okf-nq3lU}H$6hXX$Vyi9X z|9{X(pX$yelRcAcfWc3LODQee?5X!LMk#jB&=bH9d$(RRf|HO4x)4WenmXx@^S}Uo zE$T+n7540<9`QDJVZ?GARw1rSpw(P-r!;63p^Zf@x$W lxZg^Dz5FelPo;+=)fcW|2lh8{Ir;zq002ovPDHLkV1jEgqMQH# literal 0 HcmV?d00001 diff --git a/Filtration/ViewModels/IItemFilterBlockViewModelFactory.cs b/Filtration/ViewModels/Factories/IItemFilterBlockViewModelFactory.cs similarity index 80% rename from Filtration/ViewModels/IItemFilterBlockViewModelFactory.cs rename to Filtration/ViewModels/Factories/IItemFilterBlockViewModelFactory.cs index 349fd9b..9c43c78 100644 --- a/Filtration/ViewModels/IItemFilterBlockViewModelFactory.cs +++ b/Filtration/ViewModels/Factories/IItemFilterBlockViewModelFactory.cs @@ -1,4 +1,4 @@ -namespace Filtration.ViewModels +namespace Filtration.ViewModels.Factories { internal interface IItemFilterBlockViewModelFactory { diff --git a/Filtration/ViewModels/IItemFilterCommentBlockViewModelFactory.cs b/Filtration/ViewModels/Factories/IItemFilterCommentBlockViewModelFactory.cs similarity index 82% rename from Filtration/ViewModels/IItemFilterCommentBlockViewModelFactory.cs rename to Filtration/ViewModels/Factories/IItemFilterCommentBlockViewModelFactory.cs index 2323baf..947fd52 100644 --- a/Filtration/ViewModels/IItemFilterCommentBlockViewModelFactory.cs +++ b/Filtration/ViewModels/Factories/IItemFilterCommentBlockViewModelFactory.cs @@ -1,4 +1,4 @@ -namespace Filtration.ViewModels +namespace Filtration.ViewModels.Factories { internal interface IItemFilterCommentBlockViewModelFactory { diff --git a/Filtration/ViewModels/IItemFilterScriptViewModelFactory.cs b/Filtration/ViewModels/Factories/IItemFilterScriptViewModelFactory.cs similarity index 81% rename from Filtration/ViewModels/IItemFilterScriptViewModelFactory.cs rename to Filtration/ViewModels/Factories/IItemFilterScriptViewModelFactory.cs index f488b44..ddb0fd4 100644 --- a/Filtration/ViewModels/IItemFilterScriptViewModelFactory.cs +++ b/Filtration/ViewModels/Factories/IItemFilterScriptViewModelFactory.cs @@ -1,4 +1,4 @@ -namespace Filtration.ViewModels +namespace Filtration.ViewModels.Factories { internal interface IItemFilterScriptViewModelFactory { diff --git a/Filtration/ViewModels/Factories/ItemFilterBlockBaseViewModelFactory.cs b/Filtration/ViewModels/Factories/ItemFilterBlockBaseViewModelFactory.cs new file mode 100644 index 0000000..6e55a3d --- /dev/null +++ b/Filtration/ViewModels/Factories/ItemFilterBlockBaseViewModelFactory.cs @@ -0,0 +1,37 @@ +using System; +using Filtration.ObjectModel; + +namespace Filtration.ViewModels.Factories +{ + internal interface IItemFilterBlockBaseViewModelFactory + { + IItemFilterBlockViewModelBase Create(IItemFilterBlockBase itemFilterBlockBase); + } + + internal class ItemFilterBlockBaseViewModelFactory : IItemFilterBlockBaseViewModelFactory + { + private readonly IItemFilterBlockViewModelFactory _itemFilterBlockViewModelFactory; + private readonly IItemFilterCommentBlockViewModelFactory _itemFilterCommentBlockViewModelFactory; + + public ItemFilterBlockBaseViewModelFactory(IItemFilterBlockViewModelFactory itemFilterBlockViewModelFactory, + IItemFilterCommentBlockViewModelFactory itemFilterCommentBlockViewModelFactory) + { + _itemFilterBlockViewModelFactory = itemFilterBlockViewModelFactory; + _itemFilterCommentBlockViewModelFactory = itemFilterCommentBlockViewModelFactory; + } + + public IItemFilterBlockViewModelBase Create(IItemFilterBlockBase itemFilterBlockBase) + { + if (itemFilterBlockBase is IItemFilterBlock) + { + return _itemFilterBlockViewModelFactory.Create(); + } + if (itemFilterBlockBase is IItemFilterCommentBlock) + { + return _itemFilterCommentBlockViewModelFactory.Create(); + } + + throw new InvalidOperationException("Unknown IItemFilterBlockBase type"); + } + } +} diff --git a/Filtration/ViewModels/ItemFilterBlockViewModel.cs b/Filtration/ViewModels/ItemFilterBlockViewModel.cs index a009579..0a6c205 100644 --- a/Filtration/ViewModels/ItemFilterBlockViewModel.cs +++ b/Filtration/ViewModels/ItemFilterBlockViewModel.cs @@ -9,7 +9,6 @@ using Filtration.ObjectModel.BlockItemBaseTypes; using Filtration.ObjectModel.BlockItemTypes; using Filtration.Services; using Filtration.Views; -using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.CommandWpf; using Xceed.Wpf.Toolkit; @@ -17,7 +16,6 @@ namespace Filtration.ViewModels { internal interface IItemFilterBlockViewModel : IItemFilterBlockViewModelBase { - void Initialise(IItemFilterBlock itemFilterBlock, ItemFilterScriptViewModel parentScriptViewModel); bool IsExpanded { get; set; } IItemFilterBlock Block { get; } bool BlockEnabled { get; set; } @@ -25,72 +23,12 @@ namespace Filtration.ViewModels void RefreshBlockPreview(); } - internal interface IItemFilterBlockViewModelBase - { - IItemFilterBlockBase BaseBlock { get; } - bool IsDirty { get; set; } - event EventHandler BlockBecameDirty; - } - - internal abstract class ItemFilterBlockViewModelBase : ViewModelBase, IItemFilterBlockViewModelBase - { - private bool _isDirty; - - protected void Initialise(IItemFilterBlockBase itemfilterBlock) - { - BaseBlock = itemfilterBlock; - } - - - public event EventHandler BlockBecameDirty; - - public IItemFilterBlockBase BaseBlock { get; protected set; } - - public bool IsDirty - { - get => _isDirty; - set - { - if (value != _isDirty) - { - _isDirty = value; - RaisePropertyChanged(); - BlockBecameDirty?.Invoke(this, EventArgs.Empty); - } - } - } - } - - internal interface IItemFilterCommentBlockViewModel : IItemFilterBlockViewModelBase - { - void Initialise(IItemFilterCommentBlock itemFilterCommentBlock); - IItemFilterCommentBlock ItemFilterCommentBlock { get; } - string Comment { get; } - } - - internal class ItemFilterCommentBlockViewModel : ItemFilterBlockViewModelBase, IItemFilterCommentBlockViewModel - { - public ItemFilterCommentBlockViewModel() - { - } - - public void Initialise(IItemFilterCommentBlock itemFilterCommentBlock) - { - ItemFilterCommentBlock = itemFilterCommentBlock; - BaseBlock = itemFilterCommentBlock; - } - - public IItemFilterCommentBlock ItemFilterCommentBlock { get; private set; } - - public string Comment => ItemFilterCommentBlock.Comment; - } - internal class ItemFilterBlockViewModel : ItemFilterBlockViewModelBase, IItemFilterBlockViewModel { private readonly IStaticDataService _staticDataService; private readonly IReplaceColorsViewModel _replaceColorsViewModel; private readonly MediaPlayer _mediaPlayer = new MediaPlayer(); - private ItemFilterScriptViewModel _parentScriptViewModel; + private IItemFilterScriptViewModel _parentScriptViewModel; private bool _displaySettingsPopupOpen; private bool _isExpanded; @@ -120,8 +58,9 @@ namespace Filtration.ViewModels PlaySoundCommand = new RelayCommand(OnPlaySoundCommand, () => HasSound); } - public void Initialise(IItemFilterBlock itemFilterBlock, ItemFilterScriptViewModel parentScriptViewModel) + public override void Initialise(IItemFilterBlockBase itemFilterBlockBase, IItemFilterScriptViewModel parentScriptViewModel) { + var itemFilterBlock = itemFilterBlockBase as IItemFilterBlock; if (itemFilterBlock == null || parentScriptViewModel == null) { throw new ArgumentNullException(nameof(itemFilterBlock)); @@ -139,7 +78,7 @@ namespace Filtration.ViewModels } - base.Initialise(itemFilterBlock); + base.Initialise(itemFilterBlock, parentScriptViewModel); } public RelayCommand CopyBlockCommand { get; } @@ -350,7 +289,7 @@ namespace Filtration.ViewModels private void OnAddSectionCommand() { - _parentScriptViewModel.AddSection(this); + _parentScriptViewModel.AddCommentBlock(this); } private void OnDeleteBlockCommand() diff --git a/Filtration/ViewModels/ItemFilterBlockViewModelBase.cs b/Filtration/ViewModels/ItemFilterBlockViewModelBase.cs new file mode 100644 index 0000000..347da48 --- /dev/null +++ b/Filtration/ViewModels/ItemFilterBlockViewModelBase.cs @@ -0,0 +1,42 @@ +using System; +using Filtration.ObjectModel; +using GalaSoft.MvvmLight; + +namespace Filtration.ViewModels +{ + internal interface IItemFilterBlockViewModelBase + { + void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel); + IItemFilterBlockBase BaseBlock { get; } + bool IsDirty { get; set; } + event EventHandler BlockBecameDirty; + } + + internal abstract class ItemFilterBlockViewModelBase : ViewModelBase, IItemFilterBlockViewModelBase + { + private bool _isDirty; + + public virtual void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel) + { + BaseBlock = itemfilterBlock; + } + + public event EventHandler BlockBecameDirty; + + public IItemFilterBlockBase BaseBlock { get; protected set; } + + public bool IsDirty + { + get => _isDirty; + set + { + if (value != _isDirty) + { + _isDirty = value; + RaisePropertyChanged(); + BlockBecameDirty?.Invoke(this, EventArgs.Empty); + } + } + } + } +} \ No newline at end of file diff --git a/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs b/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs new file mode 100644 index 0000000..84b292c --- /dev/null +++ b/Filtration/ViewModels/ItemFilterCommentBlockViewModel.cs @@ -0,0 +1,29 @@ +using Filtration.ObjectModel; + +namespace Filtration.ViewModels +{ + internal interface IItemFilterCommentBlockViewModel : IItemFilterBlockViewModelBase + { + IItemFilterCommentBlock ItemFilterCommentBlock { get; } + string Comment { get; } + } + + internal class ItemFilterCommentBlockViewModel : ItemFilterBlockViewModelBase, IItemFilterCommentBlockViewModel + { + public ItemFilterCommentBlockViewModel() + { + } + + public override void Initialise(IItemFilterBlockBase itemfilterBlock, IItemFilterScriptViewModel itemFilterScriptViewModel) + { + ItemFilterCommentBlock = itemfilterBlock as IItemFilterCommentBlock; + BaseBlock = ItemFilterCommentBlock; + + base.Initialise(itemfilterBlock, itemFilterScriptViewModel); + } + + public IItemFilterCommentBlock ItemFilterCommentBlock { get; private set; } + + public string Comment => ItemFilterCommentBlock.Comment; + } +} \ No newline at end of file diff --git a/Filtration/ViewModels/ItemFilterScriptViewModel.cs b/Filtration/ViewModels/ItemFilterScriptViewModel.cs index 1435f70..e76f10f 100644 --- a/Filtration/ViewModels/ItemFilterScriptViewModel.cs +++ b/Filtration/ViewModels/ItemFilterScriptViewModel.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; +using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.IO; @@ -15,8 +16,11 @@ using Filtration.Common.ViewModels; using Filtration.Interface; using Filtration.ObjectModel; using Filtration.ObjectModel.BlockItemBaseTypes; +using Filtration.ObjectModel.Commands; +using Filtration.ObjectModel.Commands.ItemFilterScript; using Filtration.Parser.Interface.Services; using Filtration.Services; +using Filtration.ViewModels.Factories; using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.Messaging; using NLog; @@ -59,21 +63,25 @@ namespace Filtration.ViewModels RelayCommand ToggleShowAdvancedCommand { get; } RelayCommand ClearFilterCommand { get; } - void AddSection(IItemFilterBlockViewModelBase targetBlockViewModel); + void AddCommentBlock(IItemFilterBlockViewModelBase targetBlockViewModel); void AddBlock(IItemFilterBlockViewModelBase targetBlockViewModel); void CopyBlock(IItemFilterBlockViewModelBase targetBlockViewModel); void CopyBlockStyle(IItemFilterBlockViewModel targetBlockViewModel); void PasteBlock(IItemFilterBlockViewModelBase targetBlockViewModel); void PasteBlockStyle(IItemFilterBlockViewModel targetBlockViewModel); + void DeleteBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase); + void MoveBlockToTop(IItemFilterBlockViewModelBase targetBlockViewModelBase); + void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase); + void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase); + void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase); } internal class ItemFilterScriptViewModel : PaneViewModel, IItemFilterScriptViewModel { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private readonly IItemFilterBlockViewModelFactory _itemFilterBlockViewModelFactory; + private readonly IItemFilterBlockBaseViewModelFactory _itemFilterBlockBaseViewModelFactory; private readonly IItemFilterBlockTranslator _blockTranslator; - private readonly IItemFilterCommentBlockViewModelFactory _itemFilterCommentBlockViewModelFactory; private readonly IAvalonDockWorkspaceViewModel _avalonDockWorkspaceViewModel; private readonly IItemFilterPersistenceService _persistenceService; private readonly IMessageBoxService _messageBoxService; @@ -86,19 +94,18 @@ namespace Filtration.ViewModels private readonly ObservableCollection _itemFilterBlockViewModels; private ICollectionView _itemFilterBlockViewModelsCollectionView; private Predicate _blockFilterPredicate; + private ICommandManager _scriptCommandManager; - public ItemFilterScriptViewModel(IItemFilterBlockViewModelFactory itemFilterBlockViewModelFactory, + public ItemFilterScriptViewModel(IItemFilterBlockBaseViewModelFactory itemFilterBlockBaseViewModelFactory, IItemFilterBlockTranslator blockTranslator, - IItemFilterCommentBlockViewModelFactory itemFilterCommentBlockViewModelFactory, IAvalonDockWorkspaceViewModel avalonDockWorkspaceViewModel, IItemFilterPersistenceService persistenceService, IMessageBoxService messageBoxService, IClipboardService clipboardService, IBlockGroupHierarchyBuilder blockGroupHierarchyBuilder) { - _itemFilterBlockViewModelFactory = itemFilterBlockViewModelFactory; + _itemFilterBlockBaseViewModelFactory = itemFilterBlockBaseViewModelFactory; _blockTranslator = blockTranslator; - _itemFilterCommentBlockViewModelFactory = itemFilterCommentBlockViewModelFactory; _avalonDockWorkspaceViewModel = avalonDockWorkspaceViewModel; _avalonDockWorkspaceViewModel.ActiveDocumentChanged += OnActiveDocumentChanged; _persistenceService = persistenceService; @@ -116,12 +123,12 @@ namespace Filtration.ViewModels ClearFilterCommand = new RelayCommand(OnClearFilterCommand, () => BlockFilterPredicate != null); CloseCommand = new RelayCommand(async () => await OnCloseCommand()); DeleteBlockCommand = new RelayCommand(OnDeleteBlockCommand, () => SelectedBlockViewModel != null); - MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => SelectedBlockViewModel != null); - MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => SelectedBlockViewModel != null); - MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => SelectedBlockViewModel != null); - MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => SelectedBlockViewModel != null); + MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) > 0); + MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) > 0); + MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) < ItemFilterBlockViewModels.Count); + MoveBlockToBottomCommand = new RelayCommand(OnMoveBlockToBottomCommand, () => SelectedBlockViewModel != null && ItemFilterBlockViewModels.IndexOf(SelectedBlockViewModel) < ItemFilterBlockViewModels.Count); AddBlockCommand = new RelayCommand(OnAddBlockCommand); - AddSectionCommand = new RelayCommand(OnAddSectionCommand, () => SelectedBlockViewModel != null); + AddSectionCommand = new RelayCommand(OnAddCommentBlockCommand, () => SelectedBlockViewModel != null); DisableBlockCommand = new RelayCommand(OnDisableBlockCommand, HasSelectedEnabledBlock); EnableBlockCommand = new RelayCommand(OnEnableBlockCommand, HasSelectedDisabledBlock); CopyBlockCommand = new RelayCommand(OnCopyBlockCommand, () => SelectedBlockViewModel != null); @@ -138,6 +145,94 @@ namespace Filtration.ViewModels IconSource = icon; } + public void Initialise(IItemFilterScript itemFilterScript, bool newScript) + { + ItemFilterBlockViewModels.Clear(); + + Script = itemFilterScript; + _scriptCommandManager = Script.CommandManager; + AddItemFilterBlockViewModels(Script.ItemFilterBlocks, -1); + + Script.ItemFilterBlocks.CollectionChanged += ItemFilterBlocksOnCollectionChanged; + + _filenameIsFake = newScript; + + if (newScript) + { + Script.FilePath = "Untitled.filter"; + } + + Title = Filename; + ContentId = "ScriptContentId"; + } + + private void ItemFilterBlocksOnCollectionChanged(object sender, NotifyCollectionChangedEventArgs notifyCollectionChangedEventArgs) + { + switch (notifyCollectionChangedEventArgs.Action) + { + case NotifyCollectionChangedAction.Add: + { + AddItemFilterBlockViewModels(notifyCollectionChangedEventArgs.NewItems.Cast(), notifyCollectionChangedEventArgs.NewStartingIndex); + break; + } + case NotifyCollectionChangedAction.Remove: + { + RemoveItemFilterBlockviewModels(notifyCollectionChangedEventArgs.OldItems.Cast()); + break; + } + default: + { + Debugger.Break(); // Unhandled NotifyCollectionChangedAction + break; + } + } + } + + private void AddItemFilterBlockViewModels(IEnumerable itemFilterBlocks, int addAtIndex) + { + var firstNewViewModel = true; + + foreach (var itemFilterBlock in itemFilterBlocks) + { + var vm = _itemFilterBlockBaseViewModelFactory.Create(itemFilterBlock); + vm.Initialise(itemFilterBlock, this); + vm.BlockBecameDirty += OnBlockBecameDirty; + + if (addAtIndex == -1) + { + ItemFilterBlockViewModels.Add(vm); + } + else + { + ItemFilterBlockViewModels.Insert(addAtIndex, vm); + } + + if (firstNewViewModel) + { + SelectedBlockViewModel = vm; + firstNewViewModel = false; + } + } + } + + private void RemoveItemFilterBlockviewModels(IEnumerable itemFilterBlocks) + { + foreach (var itemFilterBlock in itemFilterBlocks) + { + var itemFilterBlockViewModel = ItemFilterBlockViewModels.FirstOrDefault(f => f.BaseBlock == itemFilterBlock); + if (itemFilterBlockViewModel == null) + { + throw new InvalidOperationException("Item Filter Block removed from model but does not exist in view model!"); + } + + ItemFilterBlockViewModels.Remove(itemFilterBlockViewModel); + if (SelectedBlockViewModel == itemFilterBlockViewModel) + { + SelectedBlockViewModel = null; + } + } + } + public RelayCommand ToggleShowAdvancedCommand { get; } public RelayCommand ClearFilterCommand { get; } public RelayCommand CloseCommand { get; } @@ -229,12 +324,7 @@ namespace Filtration.ViewModels public string Description { get => Script.Description; - set - { - Script.Description = value; - IsDirty = true; - RaisePropertyChanged(); - } + set => _scriptCommandManager.ExecuteCommand(new SetScriptDescriptionCommand(Script, value)); } public bool ShowAdvanced @@ -340,54 +430,7 @@ namespace Filtration.ViewModels private bool _filenameIsFake; private bool _showAdvanced; - - public void Initialise(IItemFilterScript itemFilterScript, bool newScript) - { - ItemFilterBlockViewModels.Clear(); - - Script = itemFilterScript; - - foreach (var block in Script.ItemFilterBlocks) - { - var itemFilterBlock = block as IItemFilterBlock; - if (itemFilterBlock != null) - { - var itemFilterBlockViewModel = _itemFilterBlockViewModelFactory.Create(); - itemFilterBlockViewModel.Initialise(itemFilterBlock, this); - itemFilterBlockViewModel.BlockBecameDirty += OnBlockBecameDirty; - ItemFilterBlockViewModels.Add(itemFilterBlockViewModel); - continue; - } - - var itemFilterCommentBlock = block as IItemFilterCommentBlock; - if (itemFilterCommentBlock == null) - { - throw new InvalidOperationException("Unknown item filter block type"); - } - - - var itemFilterCommentBlockViewModel = _itemFilterCommentBlockViewModelFactory.Create(); - itemFilterCommentBlockViewModel.Initialise(itemFilterCommentBlock); - itemFilterCommentBlockViewModel.BlockBecameDirty += OnBlockBecameDirty; - ItemFilterBlockViewModels.Add(itemFilterCommentBlockViewModel); - } - - _filenameIsFake = newScript; - - if (newScript) - { - Script.FilePath = "Untitled.filter"; - } - - if (ItemFilterBlockViewModels.Count > 0) - { - SelectedBlockViewModel = ItemFilterBlockViewModels.First(); - } - - Title = Filename; - ContentId = "ScriptContentId"; - } - + public async Task SaveAsync() { if (!ValidateScript()) return; @@ -602,8 +645,7 @@ namespace Filtration.ViewModels } catch { - _messageBoxService.Show("Clipboard Error", "Failed to access the clipboard, copy command not completed.", - MessageBoxButton.OK, MessageBoxImage.Error); + _messageBoxService.Show("Clipboard Error", "Failed to access the clipboard, copy command not completed.", MessageBoxButton.OK, MessageBoxImage.Error); } } @@ -671,39 +713,18 @@ namespace Filtration.ViewModels { var clipboardText = _clipboardService.GetClipboardText(); if (string.IsNullOrEmpty(clipboardText)) return; - _blockGroupHierarchyBuilder.Initialise(Script.ItemFilterBlockGroups.First()); - - var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script.ItemFilterScriptSettings); + + var translatedBlock = _blockTranslator.TranslateStringToItemFilterBlock(clipboardText, Script, true); // TODO: Doesn't handle pasting comment blocks? if (translatedBlock == null) return; - var vm = _itemFilterBlockViewModelFactory.Create(); - vm.Initialise(translatedBlock, this); - - if (ItemFilterBlockViewModels.Count > 0) - { - Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModelBase.BaseBlock) + 1, - translatedBlock); - ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase) + 1, vm); - } - else - { - Script.ItemFilterBlocks.Add(translatedBlock); - ItemFilterBlockViewModels.Add(vm); - } - - vm.BlockBecameDirty += OnBlockBecameDirty; - - SelectedBlockViewModel = vm; - IsDirty = true; + _scriptCommandManager.ExecuteCommand(new PasteBlockCommand(Script, translatedBlock, targetBlockViewModelBase.BaseBlock)); } catch (Exception e) { Logger.Error(e); var innerException = e.InnerException?.Message ?? string.Empty; - _messageBoxService.Show("Paste Error", - e.Message + Environment.NewLine + innerException, MessageBoxButton.OK, - MessageBoxImage.Error); + _messageBoxService.Show("Paste Error", e.Message + Environment.NewLine + innerException, MessageBoxButton.OK, MessageBoxImage.Error); } } @@ -712,21 +733,6 @@ namespace Filtration.ViewModels MoveBlockToTop(SelectedBlockViewModel); } - public void MoveBlockToTop(IItemFilterBlockViewModelBase targetBlockViewModelBase) - { - var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase); - - if (currentIndex > 0) - { - var block = targetBlockViewModelBase.BaseBlock; - Script.ItemFilterBlocks.Remove(block); - Script.ItemFilterBlocks.Insert(0, block); - ItemFilterBlockViewModels.Move(currentIndex, 0); - IsDirty = true; - RaisePropertyChanged(nameof(ItemFilterCommentBlockViewModels)); - } - } - private void OnMoveBlockUpCommand() { MoveBlockUp(SelectedBlockViewModel); @@ -734,18 +740,7 @@ namespace Filtration.ViewModels public void MoveBlockUp(IItemFilterBlockViewModelBase targetBlockViewModelBase) { - var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase); - - if (currentIndex > 0) - { - var block = targetBlockViewModelBase.BaseBlock; - var blockPos = Script.ItemFilterBlocks.IndexOf(block); - Script.ItemFilterBlocks.RemoveAt(blockPos); - Script.ItemFilterBlocks.Insert(blockPos - 1, block); - ItemFilterBlockViewModels.Move(currentIndex, currentIndex - 1); - IsDirty = true; - RaisePropertyChanged(nameof(ItemFilterCommentBlockViewModels)); - } + _scriptCommandManager.ExecuteCommand(new MoveBlockUpCommand(Script, targetBlockViewModelBase?.BaseBlock)); } private void OnMoveBlockDownCommand() @@ -755,18 +750,7 @@ namespace Filtration.ViewModels public void MoveBlockDown(IItemFilterBlockViewModelBase targetBlockViewModelBase) { - var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase); - - if (currentIndex < ItemFilterBlockViewModels.Count - 1) - { - var block = targetBlockViewModelBase.BaseBlock; - var blockPos = Script.ItemFilterBlocks.IndexOf(block); - Script.ItemFilterBlocks.RemoveAt(blockPos); - Script.ItemFilterBlocks.Insert(blockPos + 1, block); - ItemFilterBlockViewModels.Move(currentIndex, currentIndex + 1); - IsDirty = true; - RaisePropertyChanged(nameof(ItemFilterCommentBlockViewModels)); - } + _scriptCommandManager.ExecuteCommand(new MoveBlockDownCommand(Script, targetBlockViewModelBase?.BaseBlock)); } private void OnMoveBlockToBottomCommand() @@ -774,21 +758,6 @@ namespace Filtration.ViewModels MoveBlockToBottom(SelectedBlockViewModel); } - public void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase) - { - var currentIndex = ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase); - - if (currentIndex < ItemFilterBlockViewModels.Count - 1) - { - var block = targetBlockViewModelBase.BaseBlock; - Script.ItemFilterBlocks.Remove(block); - Script.ItemFilterBlocks.Add(block); - ItemFilterBlockViewModels.Move(currentIndex, ItemFilterBlockViewModels.Count - 1); - IsDirty = true; - RaisePropertyChanged(nameof(ItemFilterCommentBlockViewModels)); - } - } - private void OnAddBlockCommand() { AddBlock(SelectedBlockViewModel); @@ -796,25 +765,28 @@ namespace Filtration.ViewModels public void AddBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase) { - var vm = _itemFilterBlockViewModelFactory.Create(); - var newBlock = new ItemFilterBlock(); - vm.Initialise(newBlock, this); + _scriptCommandManager.ExecuteCommand(new AddBlockCommand(Script, targetBlockViewModelBase?.BaseBlock)); + // TODO: Expand new viewmodel + } - if (targetBlockViewModelBase != null) - { - Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModelBase.BaseBlock) + 1, newBlock); - ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase) + 1, vm); - } - else - { - Script.ItemFilterBlocks.Add(newBlock); - ItemFilterBlockViewModels.Add(vm); - } + public void AddCommentBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase) + { + _scriptCommandManager.ExecuteCommand(new AddCommentBlockCommand(Script, targetBlockViewModelBase.BaseBlock)); + } - vm.BlockBecameDirty += OnBlockBecameDirty; - SelectedBlockViewModel = vm; - vm.IsExpanded = true; - IsDirty = true; + public void DeleteBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase) + { + _scriptCommandManager.ExecuteCommand(new RemoveBlockCommand(Script, targetBlockViewModelBase.BaseBlock)); + } + + public void MoveBlockToBottom(IItemFilterBlockViewModelBase targetBlockViewModelBase) + { + _scriptCommandManager.ExecuteCommand(new MoveBlockToBottomCommand(Script, targetBlockViewModelBase.BaseBlock)); + } + + public void MoveBlockToTop(IItemFilterBlockViewModelBase targetBlockViewModelBase) + { + _scriptCommandManager.ExecuteCommand(new MoveBlockToTopCommand(Script, targetBlockViewModelBase.BaseBlock)); } private void OnBlockBecameDirty(object sender, EventArgs e) @@ -822,23 +794,9 @@ namespace Filtration.ViewModels SetDirtyFlag(); } - private void OnAddSectionCommand() + private void OnAddCommentBlockCommand() { - AddSection(SelectedBlockViewModel); - } - - public void AddSection(IItemFilterBlockViewModelBase targetBlockViewModelBase) - { - var vm = _itemFilterCommentBlockViewModelFactory.Create(); - var newSection = new ItemFilterCommentBlock { Comment = "New Comment Block" }; - vm.Initialise(newSection); - - Script.ItemFilterBlocks.Insert(Script.ItemFilterBlocks.IndexOf(targetBlockViewModelBase.BaseBlock), newSection); - ItemFilterBlockViewModels.Insert(ItemFilterBlockViewModels.IndexOf(targetBlockViewModelBase), vm); - IsDirty = true; - SelectedBlockViewModel = vm; - RaisePropertyChanged(nameof(ItemFilterCommentBlockViewModels)); - Messenger.Default.Send(new NotificationMessage("SectionsChanged")); + AddCommentBlock(SelectedBlockViewModel); } private void OnExpandAllBlocksCommand() @@ -862,31 +820,6 @@ namespace Filtration.ViewModels DeleteBlock(SelectedBlockViewModel); } - public void DeleteBlock(IItemFilterBlockViewModelBase targetBlockViewModelBase) - { - var result = _messageBoxService.Show("Delete Confirmation", "Are you sure you wish to delete this block?", - MessageBoxButton.YesNo, - MessageBoxImage.Question); - - if (result == MessageBoxResult.Yes) - { - var isSection = targetBlockViewModelBase.BaseBlock is ItemFilterCommentBlock; - - Script.ItemFilterBlocks.Remove(targetBlockViewModelBase.BaseBlock); - ItemFilterBlockViewModels.Remove(targetBlockViewModelBase); - IsDirty = true; - - targetBlockViewModelBase.BlockBecameDirty -= OnBlockBecameDirty; - - if (isSection) - { - Messenger.Default.Send(new NotificationMessage("SectionsChanged")); - } - - } - SelectedBlockViewModel = null; - } - private void OnDisableBlockCommand() { var selectedBlockViewModel = SelectedBlockViewModel as IItemFilterBlockViewModel; diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs index 962fa9b..105851d 100644 --- a/Filtration/ViewModels/MainWindowViewModel.cs +++ b/Filtration/ViewModels/MainWindowViewModel.cs @@ -85,6 +85,11 @@ namespace Filtration.ViewModels PasteCommand = new RelayCommand(OnPasteCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); PasteBlockStyleCommand = new RelayCommand(OnPasteBlockStyleCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); + // TODO: Only enabled if undo/redo available + UndoCommand = new RelayCommand(OnUndoCommand, () => ActiveDocumentIsScript); + RedoCommand = new RelayCommand(OnRedoCommand, () => ActiveDocumentIsScript); + + MoveBlockUpCommand = new RelayCommand(OnMoveBlockUpCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); MoveBlockDownCommand = new RelayCommand(OnMoveBlockDownCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); MoveBlockToTopCommand = new RelayCommand(OnMoveBlockToTopCommand, () => ActiveDocumentIsScript && ActiveScriptHasSelectedBlock); @@ -158,9 +163,7 @@ namespace Filtration.ViewModels } case "OpenScript": { -#pragma warning disable 4014 - Task.Run(OnOpenScriptCommand).GetAwaiter().GetResult(); -#pragma warning restore 4014 + OnOpenScriptCommand(); break; } case "ShowLoadingBanner": @@ -191,6 +194,9 @@ namespace Filtration.ViewModels public RelayCommand OpenAboutWindowCommand { get; } public RelayCommand ReplaceColorsCommand { get; } + public RelayCommand UndoCommand { get;} + public RelayCommand RedoCommand { get; } + public RelayCommand EditMasterThemeCommand { get; } public RelayCommand CreateThemeCommand { get; } public RelayCommand ApplyThemeToScriptCommand { get; } @@ -521,6 +527,16 @@ namespace Filtration.ViewModels _avalonDockWorkspaceViewModel.ActiveScriptViewModel.PasteBlockStyleCommand.Execute(null); } + private void OnUndoCommand() + { + _avalonDockWorkspaceViewModel.ActiveScriptViewModel.Script.CommandManager.Undo(); + } + + private void OnRedoCommand() + { + _avalonDockWorkspaceViewModel.ActiveScriptViewModel.Script.CommandManager.Redo(); + } + private void OnNewScriptCommand() { var newViewModel = _itemFilterScriptRepository.NewScript(); diff --git a/Filtration/Views/IconsDictionary.xaml b/Filtration/Views/IconsDictionary.xaml index 281fa83..e3e426c 100644 --- a/Filtration/Views/IconsDictionary.xaml +++ b/Filtration/Views/IconsDictionary.xaml @@ -30,6 +30,8 @@ + + diff --git a/Filtration/Views/MainWindow.xaml b/Filtration/Views/MainWindow.xaml index 6e57bfe..e914d0d 100644 --- a/Filtration/Views/MainWindow.xaml +++ b/Filtration/Views/MainWindow.xaml @@ -19,6 +19,10 @@ + + + @@ -32,7 +36,7 @@ - Recent Documents will go here in a future release. + Recent Documents will go here in a future release. @@ -85,6 +89,12 @@ + + + diff --git a/Filtration/WindsorInstallers/ViewModelsInstaller.cs b/Filtration/WindsorInstallers/ViewModelsInstaller.cs index 14d2c55..30afd6e 100644 --- a/Filtration/WindsorInstallers/ViewModelsInstaller.cs +++ b/Filtration/WindsorInstallers/ViewModelsInstaller.cs @@ -3,6 +3,7 @@ using Castle.MicroKernel.Registration; using Castle.MicroKernel.SubSystems.Configuration; using Castle.Windsor; using Filtration.ViewModels; +using Filtration.ViewModels.Factories; using Filtration.ViewModels.ToolPanes; namespace Filtration.WindsorInstallers @@ -79,6 +80,11 @@ namespace Filtration.WindsorInstallers container.Register( Component.For().AsFactory()); + + container.Register( + Component.For() + .ImplementedBy() + .LifeStyle.Singleton); } } } From d91f7e1ac3e6aca048847364e172a3b9e439f094 Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Thu, 7 Dec 2017 18:18:05 +0000 Subject: [PATCH 15/15] Fixed compile warnings --- Filtration.ObjectModel/ItemFilterBlock.cs | 2 -- Filtration/ViewModels/MainWindowViewModel.cs | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Filtration.ObjectModel/ItemFilterBlock.cs b/Filtration.ObjectModel/ItemFilterBlock.cs index 92bd8ef..6fd27c9 100644 --- a/Filtration.ObjectModel/ItemFilterBlock.cs +++ b/Filtration.ObjectModel/ItemFilterBlock.cs @@ -74,8 +74,6 @@ namespace Filtration.ObjectModel BlockItems = new ObservableCollection { ActionBlockItem }; } - public ICommandManager CommandManager { get; } - public bool Enabled { get; set; } = true; public string Description { get; set; } diff --git a/Filtration/ViewModels/MainWindowViewModel.cs b/Filtration/ViewModels/MainWindowViewModel.cs index 105851d..7fe247c 100644 --- a/Filtration/ViewModels/MainWindowViewModel.cs +++ b/Filtration/ViewModels/MainWindowViewModel.cs @@ -163,7 +163,9 @@ namespace Filtration.ViewModels } case "OpenScript": { +#pragma warning disable 4014 OnOpenScriptCommand(); +#pragma warning restore 4014 break; } case "ShowLoadingBanner":