Exemple #1
0
        /// <summary>
        /// Builds a Quartz Job for a specified <see cref="Rock.Model.ServiceJob">Job</see>
        /// </summary>
        /// <param name="job">The <see cref="Rock.Model.ServiceJob"/> to create a Quarts Job for.</param>
        /// <returns>A object that implements the <see cref="Quartz.IJobDetail"/> interface</returns>
        public IJobDetail BuildQuartzJob(ServiceJob job)
        {
            // build the type object, will depend if the class is in an assembly or the App_Code folder
            Type type = null;

            if (job.Assembly == string.Empty || job.Assembly == null)
            {
                type = BuildManager.GetType(job.Class, false);
            }
            else
            {
                string thetype = string.Format("{0}, {1}", job.Class, job.Assembly);
                type = Type.GetType(thetype);
            }

            // load up job attributes (parameters)
            job.LoadAttributes();

            JobDataMap map = new JobDataMap();

            foreach (KeyValuePair <string, List <Rock.Model.AttributeValue> > attrib in job.AttributeValues)
            {
                map.Add(attrib.Key, attrib.Value[0].Value);
            }

            // create the quartz job object
            IJobDetail jobDetail = JobBuilder.Create(type)
                                   .WithDescription(job.Id.ToString())
                                   .WithIdentity(new Guid().ToString(), job.Name)
                                   .UsingJobData(map)
                                   .Build();

            return(jobDetail);
        }
Exemple #2
0
        /// <summary>
        /// Builds a Quartz Job for a specified <see cref="Rock.Model.ServiceJob">Job</see>
        /// </summary>
        /// <param name="job">The <see cref="Rock.Model.ServiceJob"/> to create a Quarts Job for.</param>
        /// <returns>A object that implements the <see cref="Quartz.IJobDetail"/> interface</returns>
        public IJobDetail BuildQuartzJob(ServiceJob job)
        {
            // build the type object, will depend if the class is in an assembly or the App_Code folder
            Type type = null;

            if (string.IsNullOrWhiteSpace(job.Assembly))
            {
                // first, if no assembly is known, look in all the dlls for it
                type = Rock.Reflection.FindType(typeof(Quartz.IJob), job.Class);

                if (type == null)
                {
                    // if it can't be found in dlls, look in App_Code using BuildManager
                    type = BuildManager.GetType(job.Class, false);
                }
            }
            else
            {
                // if an assembly is specified, load the type from that
                string thetype = string.Format("{0}, {1}", job.Class, job.Assembly);
                type = Type.GetType(thetype);
            }

            int?jobEntityTypeId = Rock.Web.Cache.EntityTypeCache.Get("Rock.Model.ServiceJob").Id;

            Rock.Attribute.Helper.UpdateAttributes(type, jobEntityTypeId, "Class", type.FullName);

            // load up job attributes (parameters)
            job.LoadAttributes();

            JobDataMap map = new JobDataMap();

            foreach (var attrib in job.AttributeValues)
            {
                map.Add(attrib.Key, attrib.Value.Value);
            }

            // create the quartz job object
            IJobDetail jobDetail = JobBuilder.Create(type)
                                   .WithDescription(job.Id.ToString())
                                   .WithIdentity(job.Guid.ToString(), job.Name)
                                   .UsingJobData(map)
                                   .Build();

            return(jobDetail);
        }
Exemple #3
0
        /// <summary>
        /// Builds a Quartz Job for a specified <see cref="Rock.Model.ServiceJob">Job</see>
        /// </summary>
        /// <param name="job">The <see cref="Rock.Model.ServiceJob"/> to create a Quarts Job for.</param>
        /// <returns>A object that implements the <see cref="Quartz.IJobDetail"/> interface</returns>
        public IJobDetail BuildQuartzJob(ServiceJob job)
        {
            // build the type object, will depend if the class is in an assembly or the App_Code folder
            Type type = null;

            if (string.IsNullOrWhiteSpace(job.Assembly))
            {
                // first try to load the job type from the App_Code folder
                type = BuildManager.GetType(job.Class, false);

                if (type == null)
                {
                    // if it couldn't be loaded from the app_code folder, look in Rock.dll
                    string thetype = string.Format("{0}, {1}", job.Class, this.GetType().Assembly.FullName);
                    type = Type.GetType(thetype);
                }
            }
            else
            {
                // if an assembly is specified, load the type from that
                string thetype = string.Format("{0}, {1}", job.Class, job.Assembly);
                type = Type.GetType(thetype);
            }

            // load up job attributes (parameters)
            job.LoadAttributes();

            JobDataMap map = new JobDataMap();

            foreach (var attrib in job.AttributeValues)
            {
                map.Add(attrib.Key, attrib.Value.Value);
            }

            // create the quartz job object
            IJobDetail jobDetail = JobBuilder.Create(type)
                                   .WithDescription(job.Id.ToString())
                                   .WithIdentity(job.Guid.ToString(), job.Name)
                                   .UsingJobData(map)
                                   .Build();

            return(jobDetail);
        }