protected override void StartJob(JobInfo info, JobSegment segment)
        {
            var options = new DefaultJobOptions("ExperienceGenerator-" + info.Id + "/" + segment.Id, "ExperienceGenerator", Context.Site.Name, this, "Run",
                                                new object[] { segment });

            JobManager.Start(options);
        }
        public void UpdateAsync()
        {
            var jobCategory = typeof(UpdateLocalDatasourceReferenceService).Name;
            var siteName    = Context.Site == null ? "No Site Context" : Context.Site.Name;
            var jobOptions  = new DefaultJobOptions(this.GetJobName(), jobCategory, siteName, this, nameof(this.Update));

            JobManager.Start(jobOptions);
        }
Esempio n. 3
0
        public Job StartCreateListJob(ListSettings settings)
        {
            _activeJob   = new Job();
            settings.Job = _activeJob;
            var options = new DefaultJobOptions("ExperienceGeneratorExmLists-" + _activeJob.Id, "ExperienceGenerator", Context.Site.Name, this, "GenerateList", new object[] { settings });

            Sitecore.Jobs.JobManager.Start(options);
            return(_activeJob);
        }
Esempio n. 4
0
        public override void Process(PublishContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            try
            {
                var options = new DefaultJobOptions("Send Teams Notification", "Notifications", Context.Site.Name, this, "Run", new object[] { context });
                JobManager.Start(options);
                PowerShellLog.Info($"Job started: Send Teams Notification");
            }
            catch (Exception ex)
            {
                PowerShellLog.Error($"Error while invoking Send Teams Notification job from Publish pipeline.", ex);
            }
        }
Esempio n. 5
0
        private string StartWarmupSiteJob(WarmupSiteSetting siteSetting)
        {
            siteSetting.WarmingUp = true;
            siteSetting.WarmedUp  = false;

            var options = new DefaultJobOptions(JobName + " - " + siteSetting.Sitename,
                                                JobName,
                                                siteSetting.Sitename,
                                                this,
                                                "WarmupSiteStart",
                                                new object[] { siteSetting });

            JobManager.Start(options);
            return(JobName);
        }
Esempio n. 6
0
        Task IJob.Execute(IJobExecutionContext context)
        {
            //simple type and method call without params
            try
            {
                //get job parameters
                JobDataMap dataMap = context.JobDetail.JobDataMap;                                   //get the datamap from the Quartz job
                var        job     = (SitecronJob)dataMap[SitecronConstants.ParamNames.SitecronJob]; //get the SitecronJob from the job definition
                if (job == null)
                {
                    throw new Exception("Unable to load SiteCron Job Definition");
                }

                Type type = Type.GetType(job.SitecoreJobType);
                if (type == null)
                {
                    throw new Exception("Unable to resolve the Sitecore Job Type specified: " + job.SitecoreJobType);
                }

                object instance = Activator.CreateInstance(type);
                if (instance == null)
                {
                    throw new Exception("Unable to instantiate the Sitecore Job Type specified: " + job.SitecoreJobType);
                }

                DefaultJobOptions options = new DefaultJobOptions(job.SitecoreJobName, job.SitecoreJobCategory, job.SitecoreJobSiteName, instance, job.SitecoreJobMethod);

                ThreadPriority jobPriority;
                if (Enum.TryParse <ThreadPriority>(job.SitecoreJobPriority, out jobPriority))
                {
                    options.Priority = jobPriority;
                }
                else
                {
                    options.Priority = ThreadPriority.Normal;
                }

                JobManager.Start(options);

                context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, "Sitecron: RunAsSitecoreJob: Done");
            }
            catch (Exception ex)
            {
                Log.Error("SiteCron: RunAsSitecoreJob: ERROR something went wrong - " + ex.Message, ex, this);
                context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, "Sitecron: RunAsSitecoreJob: ERROR something went wrong - " + ex.Message);
            }
            return(Task.FromResult <object>(null));
        }
        public ActionResult RunImport(string id, string db, string importType)
        {
            var currentDB = (!string.IsNullOrWhiteSpace(db))
                ? Configuration.Factory.GetDatabase(db)
                : Context.ContentDatabase;

            Item importItem = null;

            if (ID.IsID(id))
            {
                importItem = currentDB.GetItem(ID.Parse(id));
            }

            //check import item
            if (importItem == null)
            {
                return(GetResult("", "Import item is null"));
            }

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

            if (ha == null || string.IsNullOrWhiteSpace(ha.Value))
            {
                return(GetResult("", "Import handler assembly is not defined"));
            }

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

            if (hc == null || string.IsNullOrWhiteSpace(hc.Value))
            {
                return(GetResult("", "Import handler class is not defined"));
            }

            //check db
            if (currentDB == null)
            {
                return(GetResult("", "Database is null"));
            }

            //check conn str
            Field connStrField = importItem.Fields["Connection String Name"];

            if (connStrField == null)
            {
                return(GetResult("", "Connection String Name is not set"));
            }

            var connStr  = "";
            var connName = connStrField.Value;

            if (string.IsNullOrWhiteSpace(connName))
            {
                return(GetResult("", "Connection String Name is empty"));
            }

            foreach (ConnectionStringSettings c in ConfigurationManager.ConnectionStrings)
            {
                if (!c.Name.ToLower().Equals(connName.ToLower()))
                {
                    continue;
                }

                connStr = c.ConnectionString;
                break;
            }

            if (string.IsNullOrWhiteSpace(connStr))
            {
                return(GetResult("", "Connection string is empty"));
            }

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

            try
            {
                map = (IDataMap)Reflection.ReflectionUtil.CreateObject(
                    ha.Value,
                    hc.Value,
                    new object[] { currentDB, connStr, importItem, l }
                    );
            }
            catch (FileNotFoundException fnfe)
            {
                var n = fnfe.Message;
                return(GetResult("", $"the binary {ha.Value} could not be found"));
            }

            //run process
            if (map == null)
            {
                var dbName         = currentDB?.Name;
                var importItemName = importItem?.Name;
                var loggerType     = l.GetType().ToString();

                return(GetResult("", $"the data map provided could not be instantiated. Database:{dbName}, Connection String: {connStr}, Import Item: {importItemName}, Logger: {loggerType}"));
            }

            string handleName = $"{importType}Import-{DateTime.UtcNow:yyyy/MM/dd-hh:mm}";

            var importService = new ImportProcessor(map, l);

            var jobOptions = new DefaultJobOptions(
                handleName,
                importItem.DisplayName,
                Context.Site.Name,
                importService,
                "Process",
                new object[] { });

            JobManager.Start(jobOptions);

            return(GetResult(handleName, ""));
        }
        Task IJob.Execute(IJobExecutionContext context)
        {
            try
            {
                //get job parameters
                JobDataMap dataMap = context.JobDetail.JobDataMap;                        //get the datamap from the Quartz job

                var job = (SitecronJob)dataMap[SitecronConstants.ParamNames.SitecronJob]; //get the SitecronJob from the job definition
                if (job == null)
                {
                    throw new Exception("Unable to load SiteCron Job Definition");
                }

                string   contextDbName = Settings.GetSetting(SitecronConstants.SettingsNames.SiteCronContextDB, "master");
                Database contextDb     = Factory.GetDatabase(contextDbName);

                Item jobItem = contextDb.GetItem(new ID(job.SitecoreScheduleJob));
                if (jobItem == null)
                {
                    throw new Exception("Unable to load Sitecore Schedule Job Item: " + job.SitecoreScheduleJob);
                }

                ScheduleItem scheduleItem = new ScheduleItem(jobItem);
                if (scheduleItem == null)
                {
                    throw new Exception("Invalid Sitecore Job item specified: " + job.SitecoreJobType);
                }

                Type type = Type.GetType(scheduleItem.CommandItem.InnerItem[SitecronConstants.FieldNames.Type]);
                if (type == null)
                {
                    throw new Exception("Unable to resolve the Sitecore Job Type specified: " + job.SitecoreJobType);
                }

                object instance = Activator.CreateInstance(type);
                if (instance == null)
                {
                    throw new Exception("Unable to instantiate the Sitecore Job Type specified: " + job.SitecoreJobType);
                }

                DefaultJobOptions options = new DefaultJobOptions(job.SitecoreJobName, job.SitecoreJobCategory, job.SitecoreJobSiteName, instance, scheduleItem.CommandItem.InnerItem[SitecronConstants.FieldNames.Method], new object[] { scheduleItem.Items, scheduleItem.CommandItem, scheduleItem });

                ThreadPriority jobPriority;
                if (Enum.TryParse <ThreadPriority>(job.SitecoreJobPriority, out jobPriority))
                {
                    options.Priority = jobPriority;
                }
                else
                {
                    options.Priority = ThreadPriority.Normal;
                }

                JobManager.Start(options);

                context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, "Sitecron: RunAsSitecoreJob: Done");
            }
            catch (Exception ex)
            {
                Log.Error("SiteCron: SitecoreScheduleCommandJob: ERROR something went wrong - " + ex.Message, ex, this);
                context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, "Sitecron: SitecoreScheduleCommandJob: ERROR something went wrong - " + ex.Message);
            }

            return(Task.FromResult <object>(null));
        }