-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
BagPartIndexHandler.cs
54 lines (46 loc) · 1.79 KB
/
BagPartIndexHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using OrchardCore.Flows.Models;
using OrchardCore.Indexing;
namespace OrchardCore.Flows.Indexing
{
public class BagPartIndexHandler : ContentPartIndexHandler<BagPart>
{
private readonly IServiceProvider _serviceProvider;
public BagPartIndexHandler(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public override async Task BuildIndexAsync(BagPart bagPart, BuildPartIndexContext context)
{
var options = context.Settings.ToOptions();
if (options == DocumentIndexOptions.None)
{
return;
}
if (bagPart.ContentItems.Count != 0)
{
// Lazy resolution to prevent cyclic dependency
var contentItemIndexHandlers = _serviceProvider.GetServices<IContentItemIndexHandler>();
foreach (var contentItemIndexHandler in contentItemIndexHandlers)
{
foreach (var contentItem in bagPart.ContentItems)
{
var keys = new List<string>
{
contentItem.ContentType,
};
foreach (var key in context.Keys)
{
keys.Add($"{key}.{contentItem.ContentType}");
}
var buildIndexContext = new BuildIndexContext(context.DocumentIndex, contentItem, keys, context.Settings);
await contentItemIndexHandler.BuildIndexAsync(buildIndexContext);
}
}
}
}
}
}