Created
March 31, 2011 15:59
-
-
Save sclarson/896644 to your computer and use it in GitHub Desktop.
Stoppable EPiServer Schedule Job Example
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
using System.Linq; | |
using EPiServer; | |
using EPiServer.BaseLibrary.Scheduling; | |
using EPiServer.Core; | |
using EPiServer.PlugIn; | |
namespace BlendInteractive.AppCode.Plugins | |
{ | |
[ScheduledPlugIn(DisplayName = "Delete Unpublished Faculty and Staff")] | |
public class DeleteUnpublishedPeople : JobBase | |
{ | |
public DeleteUnpublishedPeople() | |
{ | |
this.IsStoppable = true; | |
this.staffPages = 0; | |
this.facultyPages = 0; | |
this.stopped = false; | |
} | |
private int staffPages; | |
private int facultyPages; | |
private bool stopped; | |
public override void Stop() | |
{ | |
this.stopped = true; | |
base.Stop(); | |
} | |
public override string Execute() | |
{ | |
var facultyList = Utilities.GetFilteredPageCollection(PageReference.RootPage, "Faculty Page").Where(p => p.Status != VersionStatus.Published); | |
var stafflist = Utilities.GetFilteredPageCollection(PageReference.RootPage, "Staff Page").Where(p => p.Status != VersionStatus.Published); | |
foreach (var person in facultyList) | |
{ | |
DataFactory.Instance.MoveToWastebasket(person.PageLink); | |
facultyPages++; | |
this.OnStatusChanged(); | |
if(stopped) | |
{ | |
return Status(); | |
} | |
} | |
foreach (var person in stafflist) | |
{ | |
DataFactory.Instance.MoveToWastebasket(person.PageLink); | |
staffPages++; | |
this.OnStatusChanged(); | |
if(stopped) | |
{ | |
return Status(); | |
} | |
} | |
this.OnStatusChanged(); | |
return Status(); | |
} | |
protected void OnStatusChanged() | |
{ | |
this.OnStatusChanged("Deleted Pages: " + facultyPages + "Deleted Staff Pages: " + staffPages); | |
} | |
private string Status() | |
{ | |
return "Deleted Pages: " + facultyPages + "<br />Deleted Staff Pages: " + staffPages + "<br />"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Will when running
base.Stop();
, will the iteration be allowed to finish before the job is terminated?