Beispiel #1
0
 /// <summary>
 /// 创建作业实例
 /// (写入数据库及添加至作业调度池中)
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public PMS.Model.Message.IBaseResponse AddJobInfo(J_JobInfo model, IJobData jobData=null)
 {
     //1 创建与UserInfo的关系
        var user= this.CurrentDBSession.UserInfoDAL.GetListBy(u => u.ID == model.UID).FirstOrDefault();
     //12月9日
     //注意此处不要将user转成中间变量,否则会创建一个新的user对象该userInfo表中
     //model.UserInfoes.Add(user.ToMiddleModel());
     model.UserInfoes.Add(user);
     //2 创建J_JobInfo对象
     // 1 添加作业至调度池中
     if(jobData==null) jobData = new PMS.Model.JobDataModel.SendJobDataModel();
     model.JobState = (int)(PMS.Model.Enum.JobState_Enum.WAITING);
     base.Create(model);
     //var response = ijobService.AddScheduleJob(model, jobData);
     var response = client_quartzProxy.AddScheduleJob(model, jobData as PMS.Model.JobDataModel.SendJobDataModel);
     //object response_wcf= jobServiceClient.AddScheduleJob(model.ToMiddleModel(), jobData);
     //var response= response_wcf as Model.Message.IBaseResponse;
     //client.AddScheduleJob(model.ToMiddleModel(), jobData);
     //2 写入jobInfo表作业的状态
     if (response.Success)
     {
         model.JobState = (int)(PMS.Model.Enum.JobState_Enum.WAITING);
         base.Update(model);
     }
     //2 根据传入的JobInfo创建指定的作业
     //if (response.Success == true)
     //{
     //    base.Create(model);
     //}
     //if (base.Create(model))
     //{
     //    return true;
     //}
     return response;
 }
Beispiel #2
0
        static void Main(string[] args)
        {
            //方式一:直接调用服务
            #region 直接调用服务
            //ServiceReference_QuartzService.IJobService jobSer = new ServiceReference_QuartzService.JobServiceClient();
            //J_JobInfo job = new J_JobInfo()
            //{
            //    JobName = "1234",
            //    JobGroup = "quartz",
            //    JobClassName = "QueryJob",
            //    StartRunTime = DateTime.Now.AddSeconds(2),
            //    EndRunTime = DateTime.Now.AddSeconds(3),
            //    UID = 3
            //};

            //QuartzJobFactory.IJobService jobClass = new QuartzJobFactory.JobService();
            //ServiceReference_QuartzService.JobServiceClient client = new ServiceReference_QuartzService.JobServiceClient();
            //client.AddScheduleJob(job, new PMS.Model.JobDataModel.SendJobDataModel());
            //jobClass.AddScheduleJob(job, null);
            //jobSer.AddScheduleJob(job, new PMS.Model.JobDataModel.SendJobDataModel());
            #endregion

            //方式二:使用代理类的方式
            QuartzProxy.QuartzServiceFacade quartzService = new QuartzProxy.QuartzServiceFacade(new QuartzProxy.QuartzServiceClientProxy());
            J_JobInfo jobInstance = new J_JobInfo()
            {
                JobName = "1234",
                JobGroup = "quartz",
                JobClassName = "QueryJob",
                StartRunTime = DateTime.Now.AddSeconds(2),
                EndRunTime = DateTime.Now.AddSeconds(3),
                UID = 3
            };

            PMS.Model.JobDataModel.SendJobDataModel jobData = new PMS.Model.JobDataModel.SendJobDataModel()
            {
                JobDataValue = new PMS.Model.CombineModel.SendAndMessage_Model()
                {
                    Model_Send = new SMSModel_Send()
                    { },

                    Model_Message = new PMS.Model.ViewModel.ViewModel_Message()
                    { }
                }
            };

            var response_base = quartzService.AddScheduleJob(jobInstance, jobData);
        }
Beispiel #3
0
        /// <summary>
        /// 延时发送
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool SendMsgbyDelayed(PMS.Model.CombineModel.SendAndMessage_Model model,out  SMSModel_Receive response)
        {
            //response = new PMS.Model.Message.BaseResponse();
            //1 创建quartz父类客户端
            // 不使用服务因为此处需要通过反射的方式创建作业实例
            //Quartz_Service.JobServiceClient client = new Quartz_Service.JobServiceClient();
            //ServiceReference_QuartzService.JobServiceClient client = new ServiceReference_QuartzService.JobServiceClient();
            QuartzJobFactory.IJobService client = new QuartzJobFactory.JobService();
            //2 创建发送作业实例(非模板)
            /*此处需要实现:
                           1)向数据库写入创建的新的作业实例
                           2)创建该作业实例的关联表
            */
            //var jobTemplateInstance= jobTemplateBLL.GetListBy(t => t.JTID == 3);
            //jobInfoBLL.Create(new J_JobInfo() { JobName = "发送作业", JobClassName = "SendJob", NextRunTime=model.Model_Message.NextRunTime });
            //找到对应的作业模板(发送作业模板)
            //2.1 查找当前用户
            var user_current= userInfoBLL.GetListBy(u =>u.ID==  model.Model_Message.UID).FirstOrDefault();
            //2.2 根据当前用户找到指定类型(jobType)的作业模板
            var jobTemplate_target = (from t in user_current.J_JobTemplate
                                     where t.JobType == Convert.ToInt32(PMS.Model.Enum.JobType_Enum.sendJob)
                                     select t).FirstOrDefault();
            //2.3 根据作业模板创建作业实例
            //    调用J_JobInfoBLL中的AddJobInfo方法创建作业实例
            J_JobInfo jobInstance = new J_JobInfo()
            {
                UID = model.Model_Message.UID,
                CreateTime = DateTime.Now,
                EndRunTime = model.Model_Message.EndRunTime == DateTime.MinValue ? model.Model_Message.StartRunTime : model.Model_Message.EndRunTime,//此处加入判断,若EndRunTime时间为1/1/1/1这种情况先将起始时间赋给他
                NextRunTime = model.Model_Message.NextRunTime == DateTime.MinValue ? model.Model_Message.StartRunTime : model.Model_Message.NextRunTime,
                StartRunTime = model.Model_Message.StartRunTime,
                JobClassName = jobTemplate_target.JobClassName,
                JobName = jobTemplate_target.JTName,
                JobGroup = jobTemplate_target.JobGroup
            };
            //执行以下操作
            //var jobInstance = jobInfoBLL.GetListBy(j => j.JID == 27).FirstOrDefault();
            //3 创建JobData
            var jobData = new PMS.Model.JobDataModel.SendJobDataModel()
            {

                //4 将前台传入的model值赋给JobData中的JobValue
                JobDataValue=new PMS.Model.CombineModel.SendAndMessage_Model()
                {
                     Model_Send=new SMSModel_Send()
                     {
                         account = model.Model_Send.account,
                         content = model.Model_Send.content,
                         msgid = model.Model_Send.msgid,
                         password = model.Model_Send.password,
                         phones = model.Model_Send.phones,
                         sendtime = model.Model_Send.sendtime,
                         subcode = model.Model_Send.subcode

                     },

                    Model_Message =new PMS.Model.ViewModel.ViewModel_Message()
                    {
                        UID = model.Model_Message.UID,
                        Content=model.Model_Send.content,
                        SMSMissionID=model.Model_Message.SMSMissionID

                    }
                }
                //JobDataValue = new PMS.Model.SMSModel.SMSModel_Send()
                //{
                //    account = model.Model_Send.account,
                //    content = model.Model_Send.content,
                //    msgid = model.Model_Send.msgid,
                //    password = model.Model_Send.password,
                //    phones = model.Model_Send.phones,
                //    sendtime = model.Model_Send.sendtime,
                //    subcode = model.Model_Send.subcode
                //}
            };

            //5 将发送作业实例添加至计划任务中
            //注意此作业实例中需要含UID
            jobInfoBLL.AddJobInfo(jobInstance, jobData);

            //**** 11-16 创建jobInfo与其他的关联(以便在作业管理页面中显示)
            //在job的bll层中创建作业(同时写入数据库,并添加至调度池中)
            /*var response=*/
            //12-6
            //统一写在JobInfoBLL层中的AddJobInfo方法中
            //QuartzProxy.QuartzServiceFacade quartzService = new QuartzProxy.QuartzServiceFacade(new QuartzProxy.QuartzServiceClientProxy());
            //var response_base= quartzService.AddScheduleJob(jobInstance, jobData);
            //client.AddScheduleJob(jobInstance, jobData);
            response = new SMSModel_Receive() { result="0"};
            return true;
        }