-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
262 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
## [1.0.0] | ||
### Added | ||
- Created nuspec | ||
- Created readme | ||
- Created changelog | ||
- Added and refactored source code |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0"?> | ||
<package > | ||
<metadata> | ||
<id>$id$</id> | ||
<version>$version$</version> | ||
<title>$title$</title> | ||
<authors>$author$</authors> | ||
<owners>$author$</owners> | ||
<projectUrl>https://github.com/Geta/Geta.ScheduledParameterJob</projectUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>$description$</description> | ||
<releaseNotes>EPiServer Scheduled Job with parameters</releaseNotes> | ||
<copyright>Copyright Geta 2018</copyright> | ||
<iconUrl>http://cdn.geta.no/opensource/icons/icon-core-32x32.png</iconUrl> | ||
<dependencies> | ||
<dependency id="EPiServer.CMS.Core" version="[11.3.3, 12)" /> | ||
</dependencies> | ||
</metadata> | ||
</package> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,228 @@ | ||
# Scheduled job with parameters | ||
============================= | ||
|
||
## Description | ||
EPiServer scheduled job with parameters within the admin UI. | ||
|
||
## Features | ||
* Create a scheduled job with parameters to be used in the admin UI. | ||
* Create any parameter type that you wish and use it within your scheduled job. | ||
* Scheduled job will run like any other. | ||
|
||
## How to get started? | ||
* ``install-package Geta.ScheduledParameterJob`` *still not available* | ||
|
||
* Add an App_Browsers folder to your site root if there is none there already. | ||
Inside the folder you should create an AdapterMappings.browser file with the content inside: | ||
``` | ||
<browsers> | ||
<browser refID="Default"> | ||
<controlAdapters> | ||
<adapter controlType="EPiServer.UI.Admin.DatabaseJob" | ||
adapterType="Geta.ScheduledParameterJob.DatabaseJobAdapter" /> | ||
</controlAdapters> | ||
</browser> | ||
</browsers> | ||
``` | ||
|
||
* Create you scheduled job extending ScheduleJob. | ||
* Create your Definitions (parameters) class implementing IParameterDefinitions | ||
|
||
## Code | ||
Credits: [Mathias Kunto](https://blog.mathiaskunto.com/) | ||
|
||
### Example scheduled job | ||
|
||
Example includes definition class with all available parameter types. Use the appropriate ones that you need for your solution. | ||
Make sure that you refererce the correct DefinitionsClass and DefinitionsAssembly. It should match the class that you create with the parameters. | ||
|
||
```csharp | ||
public class DefinitionSample : IParameterDefinitions | ||
{ | ||
public IEnumerable<ParameterControlDto> GetParameterControls() | ||
{ | ||
return new List<ParameterControlDto> | ||
{ | ||
AddACheckBoxSample(), | ||
AddATextBoxSample(), | ||
AddAnInputPageReferenceSample(), | ||
AddACalendarSample(), | ||
AddADropDownListSample() | ||
}; | ||
} | ||
|
||
public void SetValue(Control control, object value) | ||
{ | ||
if (control is CheckBox) | ||
{ | ||
((CheckBox)control).Checked = (bool)value; | ||
} | ||
else if (control is TextBox) | ||
{ | ||
((TextBox)control).Text = (string)value; | ||
} | ||
else if (control is DropDownList) | ||
{ | ||
((DropDownList)control).SelectedValue = (string)value; | ||
} | ||
else if (control is InputPageReference) | ||
{ | ||
((InputPageReference)control).PageLink = (PageReference)value; | ||
} | ||
else if (control is System.Web.UI.WebControls.Calendar) | ||
{ | ||
((System.Web.UI.WebControls.Calendar)control).SelectedDate = (DateTime)value; | ||
} | ||
} | ||
|
||
public object GetValue(Control control) | ||
{ | ||
if (control is CheckBox) | ||
{ | ||
return ((CheckBox)control).Checked; | ||
} | ||
if (control is TextBox) | ||
{ | ||
return ((TextBox)control).Text; | ||
} | ||
if (control is DropDownList) | ||
{ | ||
return ((DropDownList)control).SelectedValue; | ||
} | ||
if (control is InputPageReference) | ||
{ | ||
return ((InputPageReference)control).PageLink; | ||
} | ||
if (control is System.Web.UI.WebControls.Calendar) | ||
{ | ||
return ((System.Web.UI.WebControls.Calendar)control).SelectedDate; | ||
} | ||
return null; | ||
} | ||
|
||
private static ParameterControlDto AddACheckBoxSample() | ||
{ | ||
return new ParameterControlDto | ||
{ | ||
// Omitting LabelText will render control without label | ||
Description = "Sample of a CheckBox control", | ||
Control = new CheckBox | ||
{ | ||
ID = "CheckBoxSample", | ||
Text = "CheckBox Sample" | ||
} | ||
}; | ||
} | ||
|
||
private static ParameterControlDto AddATextBoxSample() | ||
{ | ||
return new ParameterControlDto | ||
{ | ||
LabelText = "TextBox Sample", | ||
Description = "Sample of a TextBox control", | ||
Control = new TextBox { ID = "TextBoxSample" } | ||
}; | ||
} | ||
|
||
private static ParameterControlDto AddAnInputPageReferenceSample() | ||
{ | ||
return new ParameterControlDto | ||
{ | ||
LabelText = "InputPageReference Sample", | ||
Description = "Sample of an EPiServer Page Selector control; InputPageReference.", | ||
Control = new InputPageReference { ID = "InputPageReferenceSample" } | ||
}; | ||
} | ||
|
||
private static ParameterControlDto AddACalendarSample() | ||
{ | ||
return new ParameterControlDto | ||
{ | ||
LabelText = "Calendar Sample", | ||
Description = "Sample of a Calendar control", | ||
Control = new System.Web.UI.WebControls.Calendar { ID = "CalendarSample" } | ||
}; | ||
} | ||
|
||
private static ParameterControlDto AddADropDownListSample() | ||
{ | ||
return new ParameterControlDto | ||
{ | ||
LabelText = "DropDownList Sample", | ||
Description = "Sample of a DropDownList control", | ||
Control = new DropDownList | ||
{ | ||
ID = "DropDownListSample", | ||
DataTextField = "Text", | ||
DataValueField = "Value", | ||
DataSource = new List<ListItem> | ||
{ | ||
new ListItem | ||
{ | ||
Text = "The first sample item", | ||
Value = "1" | ||
}, | ||
new ListItem | ||
{ | ||
Text = "The second sample item", | ||
Value = "2" | ||
}, | ||
new ListItem | ||
{ | ||
Text = "The third sample item", | ||
Value = "3" | ||
}, | ||
new ListItem | ||
{ | ||
Text = "The fourth sample item", | ||
Value = "4" | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
} | ||
|
||
|
||
[ScheduledPlugInWithParameters( | ||
DisplayName = "Sample parameter job", | ||
Description = "Sample job with parameters", | ||
DefinitionsClass = "AlloyDemo.Business.ScheduledJobs.ScheduledJobWithParameters.DefinitionSample", | ||
DefinitionsAssembly = "AlloyDemo" | ||
)] | ||
public class SampleParameterJob : ScheduledJob | ||
{ | ||
public static string Execute() | ||
{ | ||
var descriptor = PlugInDescriptor.Load("AlloyDemo.Business.ScheduledJobs.ScheduledJobWithParameters.SampleParameterJob", "AlloyDemo"); | ||
var store = typeof(ScheduledJobParameters).GetStore(); | ||
var parameters = store.LoadPersistedValuesFor(descriptor.ID.ToString(CultureInfo.InvariantCulture)); | ||
|
||
var cbChecked = parameters.ContainsKey("CheckBoxSample") && (bool)parameters["CheckBoxSample"] ? "Aye!" : "Nay.."; | ||
var tbText = parameters.ContainsKey("TextBoxSample") ? parameters["TextBoxSample"] as string : string.Empty; | ||
var sampleReference = parameters.ContainsKey("InputPageReferenceSample") ? (PageReference)parameters["InputPageReferenceSample"] : PageReference.EmptyReference; | ||
var samplePageName = sampleReference != null && sampleReference != PageReference.EmptyReference ? DataFactory.Instance.GetPage(sampleReference).PageName : string.Empty; | ||
var cDateTime = parameters.ContainsKey("CalendarSample") ? (DateTime?)parameters["CalendarSample"] : null; | ||
var ddlSelectedValue = parameters.ContainsKey("DropDownListSample") ? parameters["DropDownListSample"] as string : string.Empty; | ||
|
||
var result = string.Empty; | ||
result += string.Format("CheckBoxSample checked: <b>{0}</b><br />", cbChecked); | ||
result += string.Format("TextBoxSample text: <b>{0}</b><br />", tbText); | ||
result += string.Format("InputPageReferenceSample page name: <b>{0}</b> (PageId: <b>{1}</b>)<br />", samplePageName, sampleReference); | ||
result += string.Format("CalendarSample date: <b>{0}</b><br />", cDateTime.ToString()); | ||
result += string.Format("DropDownListSample selected value: <b>{0}</b><br />", ddlSelectedValue); | ||
return result; | ||
} | ||
} | ||
``` | ||
|
||
## More info | ||
|
||
[Blog for 7.5 upgrade](https://blog.mathiaskunto.com/2014/03/21/scheduled-jobs-with-input-parameters-in-episerver-7-5/) | ||
[Blog for WebForms](https://blog.mathiaskunto.com/2012/02/13/supplying-episerver-scheduled-jobs-with-parameters-through-admin-mode/) | ||
|
||
## Package maintainer | ||
https://github.com/digintsys | ||
|
||
## Changelog | ||
[Changelog](CHANGELOG.md) |