Example #1
0
 /// <summary>
 /// Creates and starts a Sitecore Job to run as a long running background task
 /// </summary>
 /// <param name="args">The UploadArgs</param>
 public void StartMediaProcessorJob(IEnumerable<Item> uploadedItems)
 {
     var args = new MediaProcessorArgs { UploadedItems = uploadedItems };
     var jobOptions = new Sitecore.Jobs.JobOptions("CloudMediaProcessor", "MediaProcessing",
                                                   Sitecore.Context.Site.Name,
                                                   this, "RunMediaProcessor", new object[] { args });
     Sitecore.Jobs.JobManager.Start(jobOptions);
 }
        /// <summary>
        /// Creates and starts a Sitecore Job to run as a long running background task
        /// </summary>
        /// <param name="args">The UploadArgs</param>
        public void StartMediaProcessorJob(IEnumerable <Item> uploadedItems)
        {
            var args = new MediaProcessorArgs {
                UploadedItems = uploadedItems
            };
            var jobOptions = new Sitecore.Jobs.JobOptions("CloudMediaProcessor", "MediaProcessing",
                                                          Sitecore.Context.Site.Name,
                                                          this, "RunMediaProcessor", new object[] { args });

            Sitecore.Jobs.JobManager.Start(jobOptions);
        }
        public void StartJob()
        {
            var jobOptions = new Sitecore.Jobs.JobOptions(
                "Import Items",
                "BulkImport",
                Sitecore.Context.Site.Name,
                this,
                "ProcessMethod",
                new object[] { "hi" });

            Sitecore.Jobs.JobManager.Start(jobOptions);
        }
Example #4
0
        protected void btnPostImport_Click(object sender, EventArgs e)
        {
            var jobOptions = new Sitecore.Jobs.JobOptions(
                "PostImport",
                "Post Import",
                Sitecore.Context.Site.Name,
                this,
                "HandlePostImport",
                new object[] { });

            Sitecore.Jobs.JobManager.Start(jobOptions);

            repJobs.DataSource = Jobs;
            repJobs.DataBind();
        }
Example #5
0
        protected void btnImport_Click(object sender, EventArgs e)
        {
            //check import item
            if (importItem == null)
            {
                Log("Error", "Import item is null");
                txtMessage.Text = log.ToString();
                return;
            }

            //check handler assembly
            TextField ha = importItem.Fields["Handler Assembly"];

            if (ha == null || string.IsNullOrEmpty(ha.Value))
            {
                Log("Error", "Import handler assembly is not defined");
                txtMessage.Text = log.ToString();
                return;
            }

            //check handler class
            TextField hc = importItem.Fields["Handler Class"];

            if (hc == null || string.IsNullOrEmpty(hc.Value))
            {
                Log("Error", "Import handler class is not defined");
                txtMessage.Text = log.ToString();
                return;
            }

            //check db
            if (currentDB == null)
            {
                Log("Error", "Database is null");
                txtMessage.Text = log.ToString();
                return;
            }

            //check conn str
            if (string.IsNullOrEmpty(ddlConnStr.SelectedValue))
            {
                Log("Error", "Connection string is empty");
                txtMessage.Text = log.ToString();
                return;
            }

            //try to instantiate object
            IDataMap      map = null;
            DefaultLogger l   = new DefaultLogger();

            try
            {
                map = (IDataMap)Sitecore.Reflection.ReflectionUtil.CreateObject(
                    ha.Value,
                    hc.Value,
                    new object[] { currentDB, ddlConnStr.SelectedValue, importItem, l }
                    );
            }
            catch (FileNotFoundException fnfe)
            {
                Log("Error", string.Format("the binary {0} could not be found", ha.Value));
                txtMessage.Text = log.ToString();
                return;
            }

            //run process
            if (map == null)
            {
                Log("Error", "the data map provided could not be instantiated");
                txtMessage.Text = log.ToString();
                return;
            }

            var jobOptions = new Sitecore.Jobs.JobOptions(
                "DataImport",
                importItem.DisplayName,
                Sitecore.Context.Site.Name,
                this,
                "HandleImport",
                new object[] { map, l });

            Sitecore.Jobs.JobManager.Start(jobOptions);

            repJobs.DataSource = Jobs;
            repJobs.DataBind();
        }
        public void StartJob()
        {
            var jobOptions = new Sitecore.Jobs.JobOptions(
              "Import Items",
              "BulkImport",
              Sitecore.Context.Site.Name,
              this,
              "ProcessMethod",
              new object[] { "hi" });

            Sitecore.Jobs.JobManager.Start(jobOptions);
        }
Example #7
0
        protected override void ActivePageChanged(string page, string oldPage)
        {
            base.ActivePageChanged(page, oldPage);

            // if the wizard has reached the page that invokes the agent
            if (page == "Running")
            {
                // the name attribute of the agent to invoke
                string agent = Sitecore.Context.ClientPage.ClientRequest.Form["SelectedAgent"];
                Sitecore.Diagnostics.Assert.IsNotNullOrEmpty(agent, "agent");

                // don't let the user do anything while the agent runs
                base.NextButton.Disabled   = true;
                base.BackButton.Disabled   = true;
                base.CancelButton.Disabled = true;

                // retrieve the agent definition from the Web.config file
                XmlNode node = Sitecore.Configuration.Factory.GetConfigNode(
                    "scheduling/agent[@name='" + agent + "']");
                Sitecore.Diagnostics.Assert.IsNotNull(node, "node");

                // create an object that represents the agent
                object toRun = Sitecore.Configuration.Factory.CreateObject(node, true);

                // invoke this method of the object that represents the agent
                string method = StringUtil.GetString(
                    new string[]
                {
                    Sitecore.Xml.XmlUtil.GetAttribute("method", node), "Execute"
                });

                // if a managed site named scheduler exists,
                // invoke the agent under that context site,
                // otherwise the currentcontext site
                string contextSite = Sitecore.Context.Site.Name;

                if (Sitecore.Configuration.Factory.GetSite("scheduler") != null)
                {
                    contextSite = "scheduler";
                }

                // specify the agent to invoke
                Sitecore.Jobs.JobOptions jobOptions = new Sitecore.Jobs.JobOptions(
                    agent,               /* job name */
                    "Interactive agent", /* job category*/
                    contextSite,         /* context site in which job runs */
                    toRun,               /* object containing method to invoke as a job */
                    method,              /* name of the method to invoke as a job */
                    new object[] {} /* arguments to pass to the method */)
                {
                    ContextUser = Sitecore.Context.User,
                    AfterLife   = TimeSpan.FromMinutes(5),
                    WriteToLog  = true,
                };

                Type   enumType      = typeof(System.Threading.ThreadPriority);
                object priorityValue = Enum.Parse(
                    typeof(System.Threading.ThreadPriority),
                    this.Priority.Value,
                    true /*ignore the character case of the string to parse*/);
                PropertyInfo priorityProperty =
                    jobOptions.GetType().GetProperty("Priority");
                priorityProperty.SetValue(
                    jobOptions,
                    priorityValue,
                    null /*index required only for indexed properties*/);

                // start the agent
                Sitecore.Jobs.Job job = Sitecore.Jobs.JobManager.Start(jobOptions);

                // store the handle of the job that invoked the agent
                this.JobHandle = job.Handle.ToString();

                // refresh the wizard UI for the Running page in 100ms
                Sitecore.Web.UI.Sheer.SheerResponse.Timer("CheckStatus", 100);
            }
        }