Skip to content

Commit

Permalink
added changelog, readme and nuspec
Browse files Browse the repository at this point in the history
  • Loading branch information
ruifrvaz committed Jun 19, 2018
1 parent a644005 commit e064f8d
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 5 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
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
19 changes: 19 additions & 0 deletions Geta.ScheduledParameterJob.nuspec
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>
4 changes: 2 additions & 2 deletions Geta.ScheduledParameterJob/Parameters/ParameterControlDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ namespace Geta.ScheduledParameterJob.Parameters
{
public class ParameterControlDto
{
public string Id { get { return Control.ID; } }
public bool ShowLabel { get { return !string.IsNullOrEmpty(LabelText); } }
public string Id => Control.ID;
public bool ShowLabel => !string.IsNullOrEmpty(LabelText);

public string LabelText { get; set; }
public string Description { get; set; }
Expand Down
6 changes: 3 additions & 3 deletions Geta.ScheduledParameterJob/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Geta.ScheduledParameterJob")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyDescription("This package allows the creation of scheduled Job with parameters")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyCompany("Geta Digital©")]
[assembly: AssemblyProduct("Geta.ScheduledParameterJob")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyCopyright("Copyright Geta Digital© 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
228 changes: 228 additions & 0 deletions README.md
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)

0 comments on commit e064f8d

Please sign in to comment.