I need to add a scheduled job with input parameters to my Episerver 8 CMS project.
I'm following Mathias Kunto:
https://blog.mathiaskunto.com/2012/02/13/supplying-episerver-scheduled-jobs-with-parameters-through-admin-mode/
So I've added the following code to my Episerver 8 CMS project:
Definitionssample.cs
using EPiServer.Core;using EPiServer.Web.WebControls;using ScheduledParameterJob;using System;using System.Collections.Generic;using System.Web.UI;using System.Web.UI.WebControls;using Calendar = System.Web.UI.WebControls.Calendar;namespace Project.Business.ScheduledJobs { public class DefinitionSample : IParameterDefinitions { public IEnumerable<ParameterControlDTO> GetParameterControls() { return new List<ParameterControlDTO> { //AddACheckBoxSample(), //AddATextBoxSample(), //AddAnInputPageReferenceSample(), //AddACalendarSample(), //AddADropDownListSample() SourceCountry(), SourceLanguage(), TargetCountry(), TargetLanguage() }; } 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 Calendar) { ((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 Calendar) { return ((Calendar)control).SelectedDate; } return null; } private static ParameterControlDTO SourceCountry() { return new ParameterControlDTO { LabelText = "Source Country", Description = "Source Country", Control = new TextBox { ID = "SourceCountry" } }; } private static ParameterControlDTO TargetCountry() { return new ParameterControlDTO { LabelText = "Target Country", Description = "Target Country", Control = new TextBox { ID = "TargetCountry" } }; } private static ParameterControlDTO SourceLanguage() { return new ParameterControlDTO { LabelText = "Source Language", Description = "Source Language", Control = new TextBox { ID = "SourceLanguage" } }; } private static ParameterControlDTO TargetLanguage() { return new ParameterControlDTO { LabelText = "Target Language", Description = "Target Language", Control = new TextBox { ID = "TargetLanguage" } }; } and my scheduled job:
Translatemanager.cs
using ScheduledParameterJob;using ScheduledParameterJob.Extensions;using System.Globalization;namespace Project.Business.ScheduledJobs { [ScheduledPlugInWithParameters( DisplayName = "Translate Manager", Description = "Translate pages from source culture to target culture", DefinitionsClass = "Project.Business.ScheduledJobs.DefinitionSample", DefinitionsAssembly = "Project" )] public class TranslateManager : ScheduledJob { public static string Execute() { var descriptor = PlugInDescriptor.Load("Project.Business.ScheduledJobs.TranslateManager", "Project.Business.ScheduledJobs"); var store = typeof(ScheduledJobParameters).GetStore(); var parameters = store.LoadPersistedValuesFor(descriptor.ID.ToString(CultureInfo.InvariantCulture)); var sourcecountry = parameters.ContainsKey("SourceCountry") ? parameters["SourceCountry"] as string : string.Empty; var sourcelanguage = parameters.ContainsKey("SourceLanguage") ? parameters["SourceLanguage"] as string : string.Empty; var targetcountry = parameters.ContainsKey("TargetCountry") ? parameters["TargetCountry"] as string : string.Empty; var targetlanguage = parameters.ContainsKey("TargetLanguage") ? parameters["TargetLanguage"] as string : string.Empty; var result = string.Empty; result += string.Format("SourceCountry: <b>{0}</b><br />", sourcecountry); result += string.Format("SourceLanguage: <b>{0}</b><br />", sourcelanguage); result += string.Format("TargetCountry: <b>{0}</b><br />", targetcountry); result += string.Format("TargetLanguage: <b>{0}</b><br />", targetlanguage);
return result; } } }
Both Definitionssample.cs and TranslateManager.cs are included in the folder Project.Business.ScheduledJobs
When I try to run the scheduled job, appears the following error:
Server Error in '/' Application.
Method not found: 'EPiServer.UI.SystemMessageContainer EPiServer.UI.SystemPageBase.get_SystemMessageContainer()'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: Method not found: 'EPiServer.UI.SystemMessageContainer EPiServer.UI.SystemPageBase.get_SystemMessageContainer()'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. |
Stack Trace:
[MissingMethodException: Method not found: 'EPiServer.UI.SystemMessageContainer EPiServer.UI.SystemPageBase.get_SystemMessageContainer()'.] ScheduledParameterJob.DatabaseJobAdapter.DisplaySystemMessage() +0 System.Web.UI.Control.InitRecursive(Control namingContainer) +12759480 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2098 |
Any suggestions on what's missing?
What's systemmessagecontainer?
Another idea, is it possible to read the parameters of a scheduled job from an external text or xml file??? In this case we've lost de ui interface, but maybe it could be a solution for myparticular case.
Regards