-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathView.ascx.cs
123 lines (108 loc) · 4.41 KB
/
View.ascx.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#region Copyright
//
// Copyright (c) 2015
// by Satrabel
//
#endregion
#region Using Statements
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.FileSystem;
using DotNetNuke.Services.Scheduling;
using DotNetNuke.Services.Search.Internals;
using Satrabel.OpenFiles.Components;
using Satrabel.OpenFiles.Components.Lucene;
using System;
using System.Web.UI.WebControls;
#endregion
namespace Satrabel.OpenFiles
{
public partial class View : PortalModuleBase
{
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!Page.IsPostBack)
{
//bReindexAll.Visible = ModuleContext.PortalSettings.UserInfo.IsSuperUser;
bScheduleTask.Visible = ModuleContext.PortalSettings.UserInfo.IsSuperUser;
var fm = FolderManager.Instance;
var folders = fm.GetFolders(PortalId);
foreach (var folder in folders)
{
if (folder.FolderPath.ToLowerInvariant().StartsWith("files/"))
ddlFolders.Items.Add(new ListItem(folder.FolderPath.Trim('/'), folder.FolderPath));
}
}
}
protected void bReindexAll_Click(object sender, EventArgs e)
{
var searchEngine = LuceneController.Instance;
searchEngine.IndexAll();
}
protected void bScheduleTask_Click(object sender, EventArgs e)
{
var sc = SchedulingProvider.Instance();
var schedule = sc.GetSchedule("Satrabel.OpenFiles.Components.Lucene.SearchEngineScheduler, OpenFiles", "");
if (schedule == null)
{
schedule = CreateScheduleItem();
SchedulingProvider.Instance().AddSchedule(schedule);
}
}
private static ScheduleItem CreateScheduleItem()
{
var scheduleItem = new ScheduleItem();
scheduleItem.TypeFullName = "Satrabel.OpenFiles.Components.Lucene.SearchEngineScheduler, OpenFiles";
scheduleItem.FriendlyName = "OpenFiles.Search";
//DNN-4964 - values for time lapse and retry frequency can't be set to 0, -1 or left empty (client side validation has been added)
scheduleItem.TimeLapse = 30;
scheduleItem.TimeLapseMeasurement = "m";
scheduleItem.RetryTimeLapse = 30;
scheduleItem.RetryTimeLapseMeasurement = "m";
scheduleItem.RetainHistoryNum = 60;
scheduleItem.AttachToEvent = "";
scheduleItem.CatchUpEnabled = false;
scheduleItem.Enabled = true;
scheduleItem.ObjectDependencies = "SearchEngine";
scheduleItem.ScheduleStartDate = Null.NullDate;
scheduleItem.Servers = "";
return scheduleItem;
}
protected void bIndexFolder_Click(object sender, EventArgs e)
{
var searchEngine = LuceneController.Instance;
searchEngine.IndexFolder(PortalId, ddlFolders.SelectedValue);
}
protected void bUpdateIndex_Click(object sender, EventArgs e)
{
var sc = SchedulingProvider.Instance();
var schedule = sc.GetSchedule("Satrabel.OpenFiles.Components.Lucene.SearchEngineScheduler, OpenFiles", "");
if (schedule != null)
{
var startDate = DateTime.Now;
var lastSuccessFulDateTime = SearchHelper.Instance.GetLastSuccessfulIndexingDateTime(schedule.ScheduleID);
Log.Logger.Trace("Search: File Crawler - Starting. Content change start time " + lastSuccessFulDateTime.ToString("g"));
var searchEngine = LuceneController.Instance;
try
{
searchEngine.IndexContent(lastSuccessFulDateTime);
}
catch (Exception ex)
{
Log.Logger.ErrorFormat("Failed executing Scheduled Reindexing. Error: {0}", ex.Message);
}
finally
{
//searchEngine.Commit();
}
SearchHelper.Instance.SetLastSuccessfulIndexingDateTime(schedule.ScheduleID, startDate);
Log.Logger.Trace("Search: File Crawler - Indexing Successful");
}
}
}
}