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-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);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|