Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 81 additions & 31 deletions ScheduledParameterJob/DatabaseJobAdapter.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.Adapters;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using EPiServer.ClientScript;
using EPiServer.Data.Dynamic;
using EPiServer.DataAbstraction;
using EPiServer.PlugIn;
using EPiServer.UI;
using EPiServer.UI.Admin;
Expand All @@ -26,8 +29,8 @@ public class DatabaseJobAdapter : PageAdapter
private string PluginId { get { return _pluginId ?? (_pluginId = ((DatabaseJob) Control).Request.QueryString["pluginId"]); } }

private Dictionary<string, object> _persistedValues;
private Dictionary<string, object> PersistedValues { get { return _persistedValues ?? (_persistedValues = typeof(ScheduledJobParameters).GetStore().LoadPersistedValuesFor(PluginId)); } }
private Dictionary<string, object> PersistedValues { get { return _persistedValues ?? (_persistedValues = typeof(ScheduledJobParameters).GetStore().LoadPersistedValuesFor(PluginId)); } }

private ScheduledPlugInWithParametersAttribute _attribute;
private ScheduledPlugInWithParametersAttribute Attribute
{
Expand Down Expand Up @@ -68,27 +71,51 @@ public DatabaseJobAdapter()
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (string.IsNullOrWhiteSpace(Page.Request.QueryString["GetRunningState"]) &&
!Page.Request.ContentType.Contains("application/json"))
{
if (Attribute == null)
{
// Not a job with parameters
return;
}
Attribute.Validate();
Initialization();
}
}

if (Attribute == null)
protected override void OnLoad(EventArgs e)
{
if (!string.IsNullOrWhiteSpace(Page.Request.QueryString["GetRunningState"]) &&
Page.Request.ContentType.Contains("application/json"))
{
// Not a job with parameters
return;
string g = Page.Request.QueryString["GetRunningState"];
Page.Response.Clear();
Page.Response.ContentType = "application/json";
Page.Response.Write(GetJSONJobRunningState(new Guid(g)));
Page.Response.End();
}
else
{
base.OnLoad(e);
}
Attribute.Validate();
Initialization();
}

protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Attribute == null)
{
// Not a job with parameters
return;
}
foreach (var control in ParameterControls)
if (string.IsNullOrWhiteSpace(Page.Request.QueryString["GetRunningState"]) &&
!Page.Request.ContentType.Contains("application/json"))
{
control.DataBind();
if (Attribute == null)
{
// Not a job with parameters
return;
}
foreach (var control in ParameterControls)
{
control.DataBind();
}
}
}

Expand Down Expand Up @@ -143,36 +170,36 @@ private Control CreateFieldsetFor(IEnumerable<ParameterControlDTO> controls)
fieldset.Controls.Add(SaveAndResetValuesButtons());
return fieldset;
}

private Control SaveAndResetValuesButtons()
{
var container = new HtmlGenericControl("div");
container.Attributes.Add("class", "save-and-reset-button-container");

var resetButton = new Button
{
Text = "Reset values",
ToolTip = "Resets all parameters for this scheduled job to their default values.",
CssClass = "reset-button"
};
{
Text = "Reset values",
ToolTip = "Resets all parameters for this scheduled job to their default values.",
CssClass = "reset-button"
};
resetButton.Click += new EventHandler(ResetValues_Click);
var resetButtonOutline = new HtmlGenericControl("span");
resetButtonOutline.Attributes.Add("class", "epi-cmsButton");
resetButtonOutline.Controls.Add(resetButton);
container.Controls.Add(resetButtonOutline);

var saveButton = new Button
{
Text = "Save values",
ToolTip = "Saves all parameters for this scheduled job.",
CssClass = "epi-cmsButton-tools save-button"
};
{
Text = "Save values",
ToolTip = "Saves all parameters for this scheduled job.",
CssClass = "epi-cmsButton-tools save-button"
};
saveButton.Click += new EventHandler(SaveValues_Click);
var saveButtonOutline = new HtmlGenericControl("span");
saveButtonOutline.Attributes.Add("class", "epi-cmsButton");
saveButtonOutline.Controls.Add(saveButton);
container.Controls.Add(saveButtonOutline);

return container;
}

Expand Down Expand Up @@ -206,11 +233,11 @@ private static Control CreateRowFor(ParameterControlDTO parameterControlDto)
if(parameterControlDto.ShowLabel)
{
var label = new Label
{
AssociatedControlID = parameterControlDto.Id,
Text = parameterControlDto.LabelText,
ToolTip = parameterControlDto.Description
};
{
AssociatedControlID = parameterControlDto.Id,
Text = parameterControlDto.LabelText,
ToolTip = parameterControlDto.Description
};
rowContainer.Controls.Add(label);
}
else
Expand Down Expand Up @@ -247,5 +274,28 @@ private void AddStylesheet()
cssLink.Attributes.Add("media", "screen");
Page.Header.Controls.Add(cssLink);
}

private string GetJSONJobRunningState(Guid scheduledJobId)
{
var isRunning = false;
var statusMessage = string.Empty;
var scheduledJob = ScheduledJob.Load(scheduledJobId);
if (scheduledJob != null)
{
isRunning = scheduledJob.IsRunning;
statusMessage = scheduledJob.CurrentStatusMessage;
}
var stringBuilder = new StringBuilder();
stringBuilder.Append("{'IsRunning': ");
stringBuilder.Append(isRunning.ToString().ToLower());
if (!string.IsNullOrEmpty(statusMessage))
{
stringBuilder.Append(", 'CurrentStatusMessage': '");
stringBuilder.Append(ClientScriptUtility.ToScriptSafeString(statusMessage));
stringBuilder.Append("'");
}
stringBuilder.Append("}");
return stringBuilder.ToString();
}
}
}
22 changes: 22 additions & 0 deletions ScheduledParameterJob/ScheduledParameterJob.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.23107.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScheduledParameterJob", "ScheduledParameterJob.csproj", "{3F77F381-C6B8-4D01-8E2C-5C11EBE151C5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{3F77F381-C6B8-4D01-8E2C-5C11EBE151C5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3F77F381-C6B8-4D01-8E2C-5C11EBE151C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F77F381-C6B8-4D01-8E2C-5C11EBE151C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F77F381-C6B8-4D01-8E2C-5C11EBE151C5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Loading