2018-01-11 18:00:42 +11:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2018-01-09 15:49:19 +01:00
|
|
|
|
using System.Linq;
|
2018-01-12 09:23:40 +01:00
|
|
|
|
using System.Text.RegularExpressions;
|
2018-01-12 09:52:52 +01:00
|
|
|
|
using Umbraco.Core;
|
2018-01-11 18:00:42 +11:00
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.ObjectResolution;
|
|
|
|
|
|
using Umbraco.Web.Models;
|
2018-01-09 15:49:19 +01:00
|
|
|
|
|
2018-01-10 11:37:37 +01:00
|
|
|
|
namespace Umbraco.Web
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Allows for adding filters for tours during startup
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class TourFilterResolver : ManyObjectsResolverBase<TourFilterResolver, BackOfficeTourFilter>
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
public TourFilterResolver(IServiceProvider serviceProvider, ILogger logger) : base(serviceProvider, logger)
|
|
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private readonly HashSet<BackOfficeTourFilter> _instances = new HashSet<BackOfficeTourFilter>();
|
|
|
|
|
|
|
|
|
|
|
|
public IEnumerable<BackOfficeTourFilter> Filters
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Values; }
|
|
|
|
|
|
}
|
2018-01-09 15:49:19 +01:00
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Adds a filter instance
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filter"></param>
|
|
|
|
|
|
public void AddFilter(BackOfficeTourFilter filter)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.Add(filter);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-12 09:23:40 +01:00
|
|
|
|
/// <summary>
|
2018-01-12 09:52:52 +01:00
|
|
|
|
/// Helper method for adding a filter by exact plugin name
|
2018-01-12 09:23:40 +01:00
|
|
|
|
/// </summary>
|
2018-01-12 09:52:52 +01:00
|
|
|
|
/// <param name="pluginName">Regex string used for matching</param>
|
2018-01-12 09:23:40 +01:00
|
|
|
|
public void AddFilterByPlugin(string pluginName)
|
|
|
|
|
|
{
|
2018-01-12 09:52:52 +01:00
|
|
|
|
pluginName = pluginName.EnsureStartsWith("^").EnsureEndsWith("$");
|
2018-01-12 09:23:40 +01:00
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.Add(BackOfficeTourFilter.FilterPlugin(new Regex(pluginName, RegexOptions.IgnoreCase)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-01-12 09:52:52 +01:00
|
|
|
|
/// Helper method for adding a filter by exact file name
|
2018-01-12 09:23:40 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="file"></param>
|
|
|
|
|
|
public void AddFilterByFile(string file)
|
|
|
|
|
|
{
|
2018-01-12 09:52:52 +01:00
|
|
|
|
file = file.EnsureStartsWith("^").EnsureEndsWith("$");
|
2018-01-12 09:23:40 +01:00
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.Add(BackOfficeTourFilter.FilterFile(new Regex(file, RegexOptions.IgnoreCase)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-01-12 09:52:52 +01:00
|
|
|
|
/// Helper method for adding a filter by exact tour alias
|
2018-01-12 09:23:40 +01:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="alias"></param>
|
|
|
|
|
|
public void AddFilterByAlias(string alias)
|
|
|
|
|
|
{
|
2018-01-12 09:52:52 +01:00
|
|
|
|
alias = alias.EnsureStartsWith("^").EnsureEndsWith("$");
|
2018-01-12 09:23:40 +01:00
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.Add(BackOfficeTourFilter.FilterAlias(new Regex(alias, RegexOptions.IgnoreCase)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Removes a filter instance
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filter"></param>
|
|
|
|
|
|
public void RemoveFilter(BackOfficeTourFilter filter)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.Remove(filter);
|
|
|
|
|
|
}
|
2018-01-09 15:49:19 +01:00
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Removes a filter instance based on callback
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="filter"></param>
|
|
|
|
|
|
public void RemoveFilterWhere(Func<BackOfficeTourFilter, bool> filter)
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
using (Resolution.Configuration)
|
|
|
|
|
|
_instances.RemoveWhere(new Predicate<BackOfficeTourFilter>(filter));
|
2018-01-09 15:49:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Overridden to return the combined created instances based on the resolved Types and the Concrete values added with AddFilter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
protected override IEnumerable<BackOfficeTourFilter> CreateInstances()
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
var createdInstances = base.CreateInstances();
|
|
|
|
|
|
return createdInstances.Concat(_instances);
|
2018-01-09 15:49:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
public override void Clear()
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
base.Clear();
|
|
|
|
|
|
_instances.Clear();
|
2018-01-09 15:49:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-01-11 18:00:42 +11:00
|
|
|
|
internal override void ResetCollections()
|
2018-01-09 15:49:19 +01:00
|
|
|
|
{
|
2018-01-11 18:00:42 +11:00
|
|
|
|
base.ResetCollections();
|
|
|
|
|
|
_instances.Clear();
|
2018-01-09 15:49:19 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|