This repository has been archived by the owner on Mar 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EventHandlers.cs
59 lines (48 loc) · 1.98 KB
/
EventHandlers.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
55
56
57
58
59
using CMS;
using CMS.DataEngine;
using CMS.MediaLibrary;
using CMS.Search;
using MediaLibrarySearchIndex;
[assembly: RegisterModule(typeof(EventHandlers))]
namespace MediaLibrarySearchIndex
{
public class EventHandlers : Module
{
public EventHandlers() : base(nameof(MediaLibrarySearchIndex) + nameof(EventHandlers))
{
}
protected override void OnInit()
{
base.OnInit();
MediaFileInfo.TYPEINFO.Events.Delete.After += Delete_After;
MediaFileInfo.TYPEINFO.Events.Insert.After += Update_After;
MediaFileInfo.TYPEINFO.Events.Update.After += Update_After;
}
private void Delete_After(object sender, ObjectEventArgs e)
{
if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX))
return;
var fileInfo = e.Object as MediaFileInfo;
if (fileInfo == null)
return;
SearchTaskInfoProvider.CreateTask(SearchTaskTypeEnum.Delete, CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX, SearchFieldsConstants.ID, fileInfo.FileID.ToString(), 0);
}
private void Update_After(object sender, ObjectEventArgs e)
{
if (!SearchIndexInfoProvider.SearchEnabled || !SearchIndexInfoProvider.SearchTypeEnabled(CMS.Search.SearchHelper.CUSTOM_SEARCH_INDEX))
return;
var fileInfo = e.Object as MediaFileInfo;
if (fileInfo == null)
return;
var taskInfo = new SearchTaskInfo
{
SearchTaskObjectType = SearchHelper.INDEX_TYPE,
SearchTaskValue = fileInfo.FileID.ToString(),
SearchTaskPriority = 0,
SearchTaskType = SearchTaskTypeEnum.Update,
SearchTaskStatus = SearchTaskStatusEnum.Ready
};
SearchTaskInfoProvider.SetSearchTaskInfo(taskInfo);
}
}
}