Finished initial implementation of filter processing core

This commit is contained in:
Ben Wallis
2015-12-29 22:03:07 +00:00
parent 1bdc8bf6fd
commit d159f0b262
18 changed files with 11872 additions and 35 deletions

View File

@@ -1,16 +1,7 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
namespace Filtration.ItemFilterPreview
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}

View File

@@ -36,6 +36,14 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Core.3.3.0\lib\net45\Castle.Core.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Castle.Windsor, Version=3.3.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<HintPath>..\packages\Castle.Windsor.3.3.0\lib\net45\Castle.Windsor.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
@@ -63,6 +71,7 @@
<Compile Include="UserControls\ItemSocketsControl.xaml.cs">
<DependentUpon>ItemSocketsControl.xaml</DependentUpon>
</Compile>
<Compile Include="WindsorInstallers\ServicesInstaller.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@@ -98,6 +107,7 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Filtration.ObjectModel;
using Filtration.ObjectModel.Enums;
@@ -54,8 +55,8 @@ namespace Filtration.ItemFilterPreview.Model
}
var evenSocketCount = socketCount % 2 == 0;
var maxSocketGroups = evenSocketCount ? socketCount / 2 : socketCount - 1;
var maxLinkedSocketGroups = evenSocketCount ? maxSocketGroups : maxSocketGroups - 1;
var maxSocketGroups = Math.Max(1, evenSocketCount ? socketCount / 2 : socketCount - 1);
var maxLinkedSocketGroups = Math.Max(1, evenSocketCount ? maxSocketGroups : maxSocketGroups - 1);
if (value.Count > maxSocketGroups)
{
@@ -69,7 +70,10 @@ namespace Filtration.ItemFilterPreview.Model
_socketGroups = value;
Sockets = socketCount;
LinkedSockets = value.Where(s => s.Linked).Max(s => s.Count);
var linkedSocketGroups = value.Where(s => s.Linked).ToList();
LinkedSockets = linkedSocketGroups.Any() ? linkedSocketGroups.Max(s => s.Count) : 0;
}
}
}

View File

@@ -17,9 +17,11 @@ namespace Filtration.ItemFilterPreview.Services
public bool ItemBlockMatch(IItemFilterBlock block, IItem item)
{
return block.BlockItems
var match = block.BlockItems
.Where(blockItem => !(blockItem is IAudioVisualBlockItem) && !(blockItem is ActionBlockItem))
.All(blockItem => ItemBlockItemMatch(blockItem, item));
return match;
}
public bool ItemBlockItemMatch(IItemFilterBlockItem blockItem, IItem item)

View File

@@ -3,11 +3,15 @@ using System.Diagnostics;
using System.Linq;
using Filtration.ItemFilterPreview.Model;
using Filtration.ObjectModel;
using Filtration.ObjectModel.BlockItemBaseTypes;
namespace Filtration.ItemFilterPreview.Services
{
internal class ItemFilterProcessor
internal interface IItemFilterProcessor
{
IReadOnlyDictionary<IItem, IItemFilterBlock> ProcessItemsAgainstItemFilterScript(IItemFilterScript itemFilterScript, IEnumerable<IItem> items);
}
internal class ItemFilterProcessor : IItemFilterProcessor
{
private readonly IBlockItemMatcher _blockItemMatcher;
@@ -18,6 +22,8 @@ namespace Filtration.ItemFilterPreview.Services
public IReadOnlyDictionary<IItem, IItemFilterBlock> ProcessItemsAgainstItemFilterScript(IItemFilterScript itemFilterScript, IEnumerable<IItem> items)
{
var overallsw = Stopwatch.StartNew();
var matchedItemBlockPairs = new Dictionary<IItem, IItemFilterBlock>();
var sw = Stopwatch.StartNew();
@@ -25,13 +31,18 @@ namespace Filtration.ItemFilterPreview.Services
{
sw.Restart();
var matchedBlock = itemFilterScript.ItemFilterBlocks.FirstOrDefault(block => _blockItemMatcher.ItemBlockMatch(block, item));
var matchedBlock = itemFilterScript.ItemFilterBlocks
.Where(b => !(b is ItemFilterSection))
.FirstOrDefault(block => _blockItemMatcher.ItemBlockMatch(block, item));
matchedItemBlockPairs.Add(item, matchedBlock);
Debug.WriteLine("Processed Item in {0}ms", sw.ElapsedMilliseconds);
}
sw.Stop();
overallsw.Stop();
Debug.WriteLine("Total processing time: {0}ms", overallsw.ElapsedMilliseconds);
return matchedItemBlockPairs;
}
}

View File

@@ -0,0 +1,23 @@
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Filtration.ItemFilterPreview.Services;
namespace Filtration.ItemFilterPreview.WindsorInstallers
{
public class ServicesInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(
Component.For<IBlockItemMatcher>()
.ImplementedBy<BlockItemMatcher>()
.LifeStyle.Singleton);
container.Register(
Component.For<IItemFilterProcessor>()
.ImplementedBy<ItemFilterProcessor>()
.LifeStyle.Singleton);
}
}
}

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="3.3.0" targetFramework="net461" />
<package id="Castle.Windsor" version="3.3.0" targetFramework="net461" />
</packages>