-
Notifications
You must be signed in to change notification settings - Fork 0
/
EditScheduler.ascx.cs
176 lines (149 loc) · 6.98 KB
/
EditScheduler.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#region copyright
// bitboxx - http://www.bitboxx.net
// Copyright (c) 2012
// by bitboxx solutions Torsten Weggen
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
#endregion
// Some blog info about Scheduler
// http://kemmis.info/blog/archive/2008/05/20/programmatically-add-delete-and-update-scheduled-tasks.aspx
using System;
using System.Collections;
using System.Web.UI;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Localization;
using DotNetNuke.Services.Scheduling;
using DotNetNuke.UI.Skins;
using DotNetNuke.UI.Skins.Controls;
namespace Bitboxx.DNNModules.BBNews
{
public partial class EditScheduler : PortalModuleBase
{
#region Private Members
private BBNewsController _controller;
private ScheduleItem _scheduleItem;
#endregion
#region Properties
public BBNewsController Controller
{
get
{
if (_controller == null)
_controller = new BBNewsController();
return _controller;
}
}
public Control MainControl { get; set; }
#endregion
protected void Page_Load(object sender, EventArgs e)
{
ArrayList scheduleItems = SchedulingProvider.Instance().GetSchedule();
// find schedule item with matching TypeFullName
foreach (object item in scheduleItems)
{
if (((ScheduleItem)item).TypeFullName == "Bitboxx.DNNModules.BBNews.BBNewsScheduler, Bitboxx.DNNModules.BBNews")
{
_scheduleItem = (ScheduleItem)item;
break;
}
}
// If we have no scheduler Task we create one!
if (_scheduleItem == null)
{
_scheduleItem = new ScheduleItem();
_scheduleItem.FriendlyName = "Bitboxx BBNews Feed Schedule";
_scheduleItem.TypeFullName = "Bitboxx.DNNModules.BBNews.BBNewsScheduler, Bitboxx.DNNModules.BBNews";
_scheduleItem.TimeLapse = 1; // execution frequency
_scheduleItem.TimeLapseMeasurement = "m"; // "s" for seconds, "m" for minutes, "h" for hours, "d" for days
_scheduleItem.RetryTimeLapse = 10; // retry frequency
_scheduleItem.RetryTimeLapseMeasurement = "s"; // "s" for seconds, "m" for minutes, "h" for hours, "d" for days
_scheduleItem.RetainHistoryNum = 50;
_scheduleItem.AttachToEvent = "None"; //for instance "APPLICATION_START" or "None"
_scheduleItem.CatchUpEnabled = false;
_scheduleItem.Enabled = true;
_scheduleItem.ObjectDependencies = ""; //for example "SiteLog,Users,UsersOnline"
_scheduleItem.Servers = ""; // (Optional)
_scheduleItem.ScheduleID = SchedulingProvider.Instance().AddSchedule(_scheduleItem);
}
bool isAdmin = UserInfo.IsInRole(this.PortalSettings.AdministratorRoleName);
txtFriendlyName.Enabled = isAdmin;
chkEnabled.Enabled = isAdmin;
txtTimeLapse.Enabled = isAdmin;
txtRetryTimeLapse.Enabled = isAdmin;
ddlRetainHistoryNum.Enabled = isAdmin;
ddlTimeLapseMeasurement.Enabled = isAdmin;
ddlRetryTimeLapseMeasurement.Enabled = isAdmin;
cmdUpdate.Enabled = isAdmin;
txtFriendlyName.Text = _scheduleItem.FriendlyName;
chkEnabled.Checked = _scheduleItem.Enabled;
txtTimeLapse.Text = _scheduleItem.TimeLapse == Null.NullInteger ? "" : Convert.ToString(_scheduleItem.TimeLapse);
txtRetryTimeLapse.Text = _scheduleItem.RetryTimeLapse == Null.NullInteger ? "" : Convert.ToString(_scheduleItem.RetryTimeLapse);
if (ddlTimeLapseMeasurement.Items.FindByValue(_scheduleItem.TimeLapseMeasurement) != null)
ddlTimeLapseMeasurement.Items.FindByValue(_scheduleItem.TimeLapseMeasurement).Selected = true;
if (ddlRetryTimeLapseMeasurement.Items.FindByValue(_scheduleItem.RetryTimeLapseMeasurement) != null)
ddlRetryTimeLapseMeasurement.Items.FindByValue(_scheduleItem.RetryTimeLapseMeasurement).Selected = true;
if (ddlRetainHistoryNum.Items.FindByValue(Convert.ToString(_scheduleItem.RetainHistoryNum)) != null)
ddlRetainHistoryNum.Items.FindByValue(Convert.ToString(_scheduleItem.RetainHistoryNum)).Selected = true;
else
{
ddlRetainHistoryNum.Items.Add(_scheduleItem.RetainHistoryNum.ToString());
ddlRetainHistoryNum.Items.FindByValue(Convert.ToString(_scheduleItem.RetainHistoryNum)).Selected = true;
}
}
protected void OnRunClick(object sender, EventArgs e)
{
SchedulingProvider.Instance().RunScheduleItemNow(_scheduleItem);
var strMessage = Localization.GetString("RunNow", LocalResourceFile);
Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.GreenSuccess);
}
/// <summary>
/// cmdUpdate_Click runs when the Update Button is clicked
/// </summary>
/// <remarks>
/// </remarks>
/// <history>
/// [cnurse] 9/28/2004 Updated to reflect design changes for Help, 508 support and localisation
/// </history>
protected void OnUpdateClick(Object sender, EventArgs e)
{
_scheduleItem.FriendlyName = txtFriendlyName.Text;
if (String.IsNullOrEmpty(txtTimeLapse.Text) || txtTimeLapse.Text == "0" || txtTimeLapse.Text == "-1")
{
_scheduleItem.TimeLapse = Null.NullInteger;
}
else
{
_scheduleItem.TimeLapse = Convert.ToInt32(txtTimeLapse.Text);
}
_scheduleItem.TimeLapseMeasurement = ddlTimeLapseMeasurement.SelectedItem.Value;
if (String.IsNullOrEmpty(txtRetryTimeLapse.Text) || txtRetryTimeLapse.Text == "0" || txtRetryTimeLapse.Text == "-1")
{
_scheduleItem.RetryTimeLapse = Null.NullInteger;
}
else
{
_scheduleItem.RetryTimeLapse = Convert.ToInt32(txtRetryTimeLapse.Text);
}
_scheduleItem.RetryTimeLapseMeasurement = ddlRetryTimeLapseMeasurement.SelectedItem.Value;
_scheduleItem.RetainHistoryNum = Convert.ToInt32(ddlRetainHistoryNum.SelectedItem.Value);
_scheduleItem.Enabled = chkEnabled.Checked;
SchedulingProvider.Instance().UpdateSchedule(_scheduleItem);
var strMessage = Localization.GetString("UpdateSuccess", LocalResourceFile);
Skin.AddModuleMessage(this, strMessage, ModuleMessage.ModuleMessageType.GreenSuccess);
//Response.Redirect(Globals.NavigateURL(), true);
}
}
}