2015-06-08 17:29:39 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2015-06-24 14:57:16 -04:00
|
|
|
|
using Filtration.ObjectModel;
|
2016-01-31 06:56:55 -05:00
|
|
|
|
using Filtration.Parser.Interface.Services;
|
2015-06-08 17:29:39 -04:00
|
|
|
|
|
2016-01-31 06:56:55 -05:00
|
|
|
|
namespace Filtration.Parser.Services
|
2015-06-08 17:29:39 -04:00
|
|
|
|
{
|
|
|
|
|
internal class BlockGroupHierarchyBuilder : IBlockGroupHierarchyBuilder
|
|
|
|
|
{
|
|
|
|
|
private ItemFilterBlockGroup _rootBlockGroup;
|
|
|
|
|
|
|
|
|
|
public void Initialise(ItemFilterBlockGroup rootBlockGroup)
|
|
|
|
|
{
|
|
|
|
|
_rootBlockGroup = rootBlockGroup;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-27 17:24:35 -04:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
_rootBlockGroup = null;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, bool show, bool enabled)
|
2015-06-08 17:29:39 -04:00
|
|
|
|
{
|
|
|
|
|
if (_rootBlockGroup == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("BlockGroupHierarchyBuilder must be initialised with root BlockGroup before use");
|
|
|
|
|
}
|
2018-09-06 06:54:54 -04:00
|
|
|
|
return IntegrateStringListIntoBlockGroupHierarchy(groupStrings, _rootBlockGroup, show, enabled);
|
2015-06-08 17:29:39 -04:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-06 06:54:54 -04:00
|
|
|
|
public ItemFilterBlockGroup IntegrateStringListIntoBlockGroupHierarchy(IEnumerable<string> groupStrings, ItemFilterBlockGroup startItemGroup, bool show, bool enabled)
|
2015-06-08 17:29:39 -04:00
|
|
|
|
{
|
|
|
|
|
var inputGroups = groupStrings.ToList();
|
|
|
|
|
var firstGroup = inputGroups.First().Trim();
|
2015-06-14 14:17:39 -04:00
|
|
|
|
if (firstGroup.StartsWith("~"))
|
|
|
|
|
{
|
|
|
|
|
firstGroup = firstGroup.Substring(1);
|
|
|
|
|
}
|
2015-06-08 17:29:39 -04:00
|
|
|
|
|
|
|
|
|
ItemFilterBlockGroup matchingChildItemGroup = null;
|
|
|
|
|
if (startItemGroup.ChildGroups.Count(g => g.GroupName == firstGroup) > 0)
|
|
|
|
|
{
|
|
|
|
|
matchingChildItemGroup = startItemGroup.ChildGroups.First(c => c.GroupName == firstGroup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (matchingChildItemGroup == null)
|
|
|
|
|
{
|
2015-06-14 14:17:39 -04:00
|
|
|
|
var newItemGroup = CreateBlockGroup(inputGroups.First().Trim(), startItemGroup);
|
2018-09-06 06:54:54 -04:00
|
|
|
|
newItemGroup.IsShowChecked = show;
|
|
|
|
|
newItemGroup.IsEnableChecked = enabled;
|
2015-06-08 17:29:39 -04:00
|
|
|
|
startItemGroup.ChildGroups.Add(newItemGroup);
|
|
|
|
|
inputGroups = inputGroups.Skip(1).ToList();
|
2018-09-06 06:54:54 -04:00
|
|
|
|
return inputGroups.Count > 0 ? IntegrateStringListIntoBlockGroupHierarchy(inputGroups, newItemGroup, show, enabled) : newItemGroup;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if(matchingChildItemGroup.IsShowChecked != show)
|
|
|
|
|
{
|
|
|
|
|
matchingChildItemGroup.IsShowChecked = null;
|
|
|
|
|
}
|
|
|
|
|
if (matchingChildItemGroup.IsEnableChecked != enabled)
|
|
|
|
|
{
|
|
|
|
|
matchingChildItemGroup.IsEnableChecked = null;
|
|
|
|
|
}
|
2015-06-08 17:29:39 -04:00
|
|
|
|
}
|
|
|
|
|
inputGroups = inputGroups.Skip(1).ToList();
|
2018-09-06 06:54:54 -04:00
|
|
|
|
if(inputGroups.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
return IntegrateStringListIntoBlockGroupHierarchy(inputGroups, matchingChildItemGroup, show, enabled);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var leafNode = new ItemFilterBlockGroup("", matchingChildItemGroup, false, true);
|
|
|
|
|
leafNode.IsShowChecked = show;
|
|
|
|
|
leafNode.IsEnableChecked = enabled;
|
|
|
|
|
matchingChildItemGroup.ChildGroups.Add(leafNode);
|
|
|
|
|
return leafNode;
|
|
|
|
|
}
|
2015-06-08 17:29:39 -04:00
|
|
|
|
}
|
2015-06-14 14:17:39 -04:00
|
|
|
|
|
|
|
|
|
private ItemFilterBlockGroup CreateBlockGroup(string groupNameString, ItemFilterBlockGroup parentGroup)
|
|
|
|
|
{
|
|
|
|
|
var advanced = false;
|
|
|
|
|
|
|
|
|
|
if (groupNameString.StartsWith("~"))
|
|
|
|
|
{
|
|
|
|
|
groupNameString = groupNameString.Substring(1);
|
|
|
|
|
advanced = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (parentGroup.Advanced)
|
|
|
|
|
{
|
|
|
|
|
advanced = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new ItemFilterBlockGroup(groupNameString, parentGroup, advanced);
|
|
|
|
|
}
|
2015-06-08 17:29:39 -04:00
|
|
|
|
}
|
|
|
|
|
}
|