Try our conversational search powered by Generative AI!

Scheduled Job with input parameters

Vote:
 

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: {0}", sourcecountry);
            result += string.Format("SourceLanguage: {0}", sourcelanguage);
            result += string.Format("TargetCountry: {0}", targetcountry);
            result += string.Format("TargetLanguage: {0}", 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

#141339
Nov 12, 2015 14:04
Sudheer Kumar K - Jun 20, 2023 10:04
Hello Antonio,

could you please post to us the solution that you used to fix the above error?

Thanks
Sudheer
Vote:
 

I usually keep my settings to a scheduled job either on the start page of the site under a SiteSettings tab or in the appsettings config file. You can access both from a scheduled job. If you have access restricted start page you might need to impersonate a system user though....Its one line of code though so no worries there

#143968
Feb 04, 2016 0:18
Vote:
 

Hi Antonio,

I believe you must have fixed this issue long back. I know it's quite old thread but thought if somebody in future faced same issue then it might be helpful. :) 

I had faced this issue recently and noticed that it fails to find "DatabaseJobAdapter" class. "SystemMessageContainer" method is exist in "DatabaseJobAdapter.cs" but if you see the error it is trying to find this method in "EpiServer.UI". Reason behind this was I had not given full name or absolute path for this class in ".browser" file.

Also, make sure you have added "ScheduledParameterJobAdapterMappings.browser" file added inside "App_Browsers" directory (at root) of your project. 

This file is available here..

#254816
Edited, May 14, 2021 12:00
Vote:
 

Hi,

https://github.com/Geta/Geta.ScheduledParameterJob should be compatible with CMS 11.x

#255425
May 24, 2021 21:17
Manoj Kumawat - Apr 24, 2023 13:19
Now you already know it Valdis, WebForms support no longer exists with core. Are you planning to update it to core anymore or you fed-up doing this :D
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.