using Core.AliyuService.AliYun; using CRM.Core.BLL.EventBus.EventHandlers; using CRM.Core.Common.EventBus; using Quartz; using Quartz.Xml; using System; using System.Collections; using System.Configuration; using System.IO; using System.ServiceProcess; using System.Threading; using WX.CRM.Common; namespace Core.AliyuService { public partial class CoreAliyunService : ServiceBase { public CoreAliyunService() { InitializeComponent(); } Thread _sms_send; protected override void OnStart(string[] args) { try { _sms_send = new Thread(new ThreadStart(GetScheduleJob)); _sms_send.Start(); LogHelper.Info("-----服务启动成功-----"); EventBus.Instance.Subscribe(new SoftAliyunSubEventHandler()); if (ConfigurationManager.AppSettings["AliyunSubOpen"] != null && ConfigurationManager.AppSettings["AliyunSubOpen"] == "1") { OnscSharp.CreatePushConsumer(); OnscSharp.StartPushConsumer(); LogHelper.Info("--阿里云订阅成功!"); } } catch (Exception e) { WX.CRM.Common.LogHelper.Error(e); } } protected override void OnStop() { try { LogHelper.Info("*******服务停止********"); if (ConfigurationManager.AppSettings["AliyunSubOpen"] != null && ConfigurationManager.AppSettings["AliyunSubOpen"] == "1") { //OnscSharp.ShutdownProducer(); OnscSharp.shutdownPushConsumer(); LogHelper.Info("**阿里云订阅关闭"); } } catch (Exception e) { WX.CRM.Common.LogHelper.Error(e); } } public void GetScheduleJob() { try { JobSchedulingDataProcessor processor = new JobSchedulingDataProcessor(true, true); ISchedulerFactory sf = new Quartz.Impl.StdSchedulerFactory(); IScheduler sched = sf.GetScheduler(); LogHelper.Info("------GetScheduleJob开始执行-----"); Stream s = new StreamReader(string.Concat(AppDomain.CurrentDomain.BaseDirectory, "XML/JobConfig.xml"), System.Text.Encoding.GetEncoding("UTF-8")).BaseStream; processor.ProcessStream(s, null); processor.ScheduleJobs(new Hashtable(), sched, false); sched.Start(); } catch (Exception ex) { WX.CRM.Common.LogHelper.Error(ex); } } } }