{"id":3193,"date":"2015-10-17T11:00:28","date_gmt":"2015-10-17T11:00:28","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=3193"},"modified":"2015-10-17T11:03:52","modified_gmt":"2015-10-17T11:03:52","slug":"quarztopself%e5%ae%9e%e7%8e%b0%e8%b0%83%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2015\/10\/17\/quarztopself%e5%ae%9e%e7%8e%b0%e8%b0%83%e5%ba%a6\/","title":{"rendered":"quarz+topself\u5b9e\u73b0\u8c03\u5ea6"},"content":{"rendered":"<p>quarz:\u7528\u6765\u7075\u6d3b\u7684\u8c03\u5ea6\u7a0b\u5e8f\u7684\u6267\u884c<br \/>\ntopself:\u7528\u6765\u5c06\u5e94\u7528\u63d0\u5347\u4e3a\u670d\u52a1<\/p>\n<div>\n\t<span style=\"color: rgb(34, 51, 85);\">\u4e00\uff0c\u5efa\u7acb\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\uff0c\u5f15\u7528\u53f3\u952e\u6dfb\u52a0\uff1aquarz.net\uff0ctopself,<\/span><span style=\"color: rgb(34, 51, 85);\">topself.log4Net<\/span><\/div>\n<div>\n\t<span style=\"color: rgb(34, 51, 85);\">\u4e8c\uff0cmain\u4e2d\u6dfb\u52a0\u4ee3\u7801\uff0c\u7528topself\u627f\u63a5\u7a0b\u5e8f\u7684\u7ba1\u7406<\/span><\/p>\n<div>\n<div>\n<pre class=\"brush:csharp;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\nusing System\r\nusing Quartz;\r\nusing Topshelf;\r\nusing System.IO;\r\n\r\nnamespace Quarz\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            try\r\n            {\r\n                log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(AppDomain.CurrentDomain.BaseDirectory + &quot;log4net.config&quot;));\r\n                HostFactory.Run(x =&gt;\r\n                {\r\n                    x.UseLog4Net();\/\/\u8bb0\u5f55topself\u81ea\u5df1\u4ea7\u751f\u7684\u65e5\u5fd7\r\n\r\n                    x.Service&lt;ServiceRunner&gt;(); \/\/ServiceRunner\u662fquarz\u7684\u8c03\u5ea6\u7a0b\u5e8f\uff0c\u4ee5\u6b64\u6765\u8c03\u7528\r\n\r\n                    x.SetDescription(&quot;\u81ea\u5df1\u7684WindowsService\u8c03\u5ea6\u4e2d\u5fc3&quot;);\r\n                    x.SetDisplayName(&quot;CedarQuarz&quot;);\r\n                    x.SetServiceName(&quot;CedarQuarz&quot;);\r\n\r\n                    x.EnablePauseAndContinue();\r\n                });\r\n\r\n            }\r\n            catch (SchedulerException se)\r\n            {\r\n                Console.WriteLine(se);\r\n            }\r\n        }\r\n    }\r\n}\r\n\r\n\/\/ServiceRunner.cs\u5982\u4e0b\r\nusing Quartz;\r\nusing Quartz.Impl;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing System.Threading.Tasks;\r\nusing Topshelf;\r\n\r\nnamespace Quarz\r\n{\r\n    public sealed class ServiceRunner : ServiceControl, ServiceSuspend\r\n    {\r\n        private readonly IScheduler scheduler;\r\n\r\n        public ServiceRunner()\r\n        {\r\n            scheduler = StdSchedulerFactory.GetDefaultScheduler();\/\/\u8c03\u7528\u8c03\u5ea6\u8ba1\u5212,\u5728quarz_job.xml\u914d\u7f6e\u8981\u6267\u884c\u7684job\r\n        }\r\n\r\n        public bool Start(HostControl hostControl)\r\n        {\r\n            scheduler.Start();\r\n            return true;\r\n        }\r\n\r\n        public bool Stop(HostControl hostControl)\r\n        {\r\n            scheduler.Shutdown(false);\r\n            return true;\r\n        }\r\n\r\n        public bool Continue(HostControl hostControl)\r\n        {\r\n            scheduler.ResumeAll();\r\n            return true;\r\n        }\r\n\r\n        public bool Pause(HostControl hostControl)\r\n        {\r\n            scheduler.PauseAll();\r\n            return true;\r\n        }\r\n\r\n\r\n    }\r\n}\r\n\/\/\u81ea\u5df1\u5199\u7684job\u5b9e\u73b0ijob\u5373\u53ef\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Text;\r\nusing Quartz;\r\nusing System.Threading.Tasks;\r\nusing RTXSAPILib;\r\nusing System.Configuration;\r\nusing System.Data;\r\nusing System.Data.SqlClient;\r\n\r\n\r\nnamespace Quarz\r\n{\r\n    class RtxSendMsg : IJob\r\n    {\r\n        private static RTXSAPILib.IRTXSAPIRootObj _RootObj;\r\n        public static RTXSAPILib.IRTXSAPIRootObj RootObj {\r\n            get {\r\n                if (_RootObj == null) {\r\n                    _RootObj = new RTXSAPIRootObj();\r\n                }\r\n                return _RootObj;\r\n            }\r\n        }\r\n\r\n        public static string ServerIP= ConfigurationSettings.AppSettings[&quot;RtxServerIP&quot;];\r\n        public static short ServerPort = short.Parse(ConfigurationSettings.AppSettings[&quot;RtxServerPort&quot;]);\r\n        public static string ConnString = ConfigurationSettings.AppSettings[&quot;constring&quot;];\r\n        public static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);\r\n\r\n        public void Execute(IJobExecutionContext context)\r\n        {\r\n            log.Info(&quot;\u5f00\u59cb&quot;);\r\n            \/\/\u521d\u59cb\u5316\u670d\u52a1\u5668\u5c5e\u6027\r\n            try\r\n            {\r\n                RootObj.ServerIP =   ServerIP;\r\n                RootObj.ServerPort = ServerPort; \/\/\u8bbe\u7f6e\u670d\u52a1\u5668\u7aef\u53e3\r\n                DataTable dt = GetWaitNotifyInfo();\r\n                if (dt == null || dt.Rows.Count == 0) return;\r\n                foreach (DataRow dr in dt.Rows)\r\n                {\r\n                    SendNotify(StringHelper.FormatObjToString(dr[&quot;receiverAccount&quot;]),\r\n                        StringHelper.FormatObjToString(dr[&quot;CustomerID&quot;]),\r\n                        StringHelper.FormatObjToString(dr[&quot;CustomerName&quot;]),\r\n                        StringHelper.FormatObjToString(dr[&quot;D_StartTime&quot;]),\r\n                        StringHelper.FormatObjToString(dr[&quot;title&quot;]), StringHelper.FormatObjToInt(dr[&quot;holdtime&quot;]), StringHelper.FormatObjToString(dr[&quot;content&quot;]));\r\n                }\r\n            }\r\n            catch (Exception e) {\r\n                log.Error(e.StackTrace.ToString());\r\n            }\r\n            log.Info(&quot;\u7ed3\u675f&quot;);\r\n            \/\/SendNotify(&quot;zhengxuesong&quot;, &quot;hello&quot;, &quot;&quot;, &quot;\u3010\u672a\u63a5\u6765\u7535\u3011\u5ba2\u623765871\u4e8e2015-10-16 14\uff1a10\u6253\u6765\u7535\u8bdd\uff0c\u8bf7\u53ca\u65f6\u8ddf\u8fdb&quot;);\r\n        }\r\n\r\n        public DataTable GetWaitNotifyInfo() {\r\n            SqlParameter[] storedParams =\r\n             {\r\n                new SqlParameter(&quot;@Code&quot;,&quot;&quot;),\r\n                new SqlParameter(&quot;@UserID&quot;,&quot;&quot;)\r\n            };\r\n            IDataReader idr = Share.Data.SqlHelper.ExecuteReader(ConnString,\r\n                  CommandType.StoredProcedure,\r\n                  &quot;GetWaitNotifyInfo&quot;,\r\n                  storedParams);\r\n            DataTable dt = new DataTable();\r\n            dt.Load(idr);\r\n            return dt;\r\n        }\r\n\r\n        public static void SendNotify(string receiverAccount, string CustomerID, string CustomerName, string D_StartTime,  string title, int holdtime, string content)\r\n        {\r\n\r\n            try\r\n            {\r\n                if (!RootObj.UserManager.IsUserExist(receiverAccount)) {\r\n                    log.Warn(string.Format(&quot;{0}\u5728\u817e\u8baf\u901a\u91cc\u4e0d\u5b58\u5728\uff01&quot;, receiverAccount));\r\n                    return ;\r\n                };\r\n                RootObj.SendNotify(receiverAccount, title, holdtime, content); \/\/\u83b7\u53d6\u7248\u672c\u4fe1\u606f\r\n                log.Info(string.Format(&quot;{0},{1},{2},{3},{4},{5},{6}&quot;, receiverAccount, CustomerID, CustomerName, D_StartTime, title, holdtime, content));\r\n            }\r\n            catch (Exception xe)\r\n            {\r\n                log.Error(xe.StackTrace.ToString());\r\n\r\n            }\r\n\r\n        }\r\n\r\n    }\r\n}\r\n<\/pre>\n<\/p><\/div>\n<div>\n<div>\n<div>\n\t\t\t\t\t&nbsp;<\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/div>\n<div>\n\t<span style=\"color: rgb(34, 51, 85);\">\u4e09\uff0c\u5728app.config\u4e2d\u6307\u5b9ajob\u914d\u7f6e\u7684xml\u6587\u4ef6\uff0c\u89e6\u53d1\u5668\u7684\u89c4\u683c\u89c1<a href=\"http:\/\/www.quartz-scheduler.net\/documentation\/quartz-2.x\/tutorial\/crontrigger.html\">\u6587\u6863<\/a> <\/span><\/p>\n<pre class=\"brush:xml;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n  &lt;quartz&gt;\r\n    &lt;add key=&quot;quartz.scheduler.instanceName&quot; value=&quot;ExampleDefaultQuartzScheduler&quot;\/&gt;\r\n    &lt;add key=&quot;quartz.threadPool.type&quot; value=&quot;Quartz.Simpl.SimpleThreadPool, Quartz&quot;\/&gt;\r\n    &lt;add key=&quot;quartz.threadPool.threadCount&quot; value=&quot;10&quot;\/&gt;\r\n    &lt;add key=&quot;quartz.threadPool.threadPriority&quot; value=&quot;2&quot;\/&gt;\r\n    &lt;add key=&quot;quartz.jobStore.misfireThreshold&quot; value=&quot;60000&quot;\/&gt;\r\n    &lt;add key=&quot;quartz.jobStore.type&quot; value=&quot;Quartz.Simpl.RAMJobStore, Quartz&quot;\/&gt;\r\n    &lt;!--******************************Plugin\u914d\u7f6e********************************************* --&gt;\r\n    &lt;add key=&quot;quartz.plugin.xml.type&quot; value=&quot;Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz&quot; \/&gt;\r\n    &lt;add key=&quot;quartz.plugin.xml.fileNames&quot; value=&quot;~\/quartz_jobs.xml&quot;\/&gt;\r\n  &lt;\/quartz&gt;\r\n<\/pre>\n<\/div>\n<p>\u56db\uff0cquartz_jobs.xml\u5982\u4e0b<\/p>\n<pre class=\"brush:xml;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n\r\n&lt;!-- This file contains job definitions in schema version 2.0 format --&gt;\r\n\r\n&lt;job-scheduling-data xmlns=&quot;http:\/\/quartznet.sourceforge.net\/JobSchedulingData&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; version=&quot;2.0&quot;&gt;\r\n\r\n  &lt;processing-directives&gt;\r\n    &lt;overwrite-existing-data&gt;true&lt;\/overwrite-existing-data&gt;\r\n  &lt;\/processing-directives&gt;\r\n\r\n  &lt;schedule&gt;\r\n\r\n    &lt;!--TestJob\u6d4b\u8bd5 \u4efb\u52a1\u914d\u7f6e--&gt;\r\n    &lt;job&gt;\r\n      &lt;name&gt;RtxSendMsg&lt;\/name&gt;\r\n      &lt;group&gt;Rtx&lt;\/group&gt;\r\n      &lt;description&gt;\u5411rtx\u53d1\u9001\u63d0\u9192&lt;\/description&gt;\r\n      &lt;job-type&gt;Quarz.RtxSendMsg,Quarz&lt;\/job-type&gt;\r\n      &lt;durable&gt;true&lt;\/durable&gt;\r\n      &lt;recover&gt;false&lt;\/recover&gt;\r\n    &lt;\/job&gt;\r\n    &lt;trigger&gt;\r\n      &lt;cron&gt;\r\n        &lt;name&gt;\u5411rtx\u53d1\u9001\u63d0\u9192\u6bcf10\u5206\u949f&lt;\/name&gt;\r\n        &lt;group&gt;Rtx&lt;\/group&gt;\r\n        &lt;job-name&gt;RtxSendMsg&lt;\/job-name&gt;\r\n        &lt;job-group&gt;Rtx&lt;\/job-group&gt;\r\n        &lt;start-time&gt;2015-01-22T00:00:00+08:00&lt;\/start-time&gt;\r\n        &lt;cron-expression&gt;0 0\/10 * * * ?&lt;\/cron-expression&gt;\r\n      &lt;\/cron&gt;\r\n    &lt;\/trigger&gt;\r\n\r\n  &lt;\/schedule&gt;\r\n&lt;\/job-scheduling-data&gt;\r\n\r\n<\/pre>\n<p>\u4e94\uff0c\u6ce8\u518c\u670d\u52a1\u5728bin\u4e0b\u6267\u884c<\/p>\n<pre class=\"brush:ps;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n myapp.exe install\r\n myapp.exe start\r\n myapp.exe stop\r\n myapp.exe uninstall\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>quarz:\u7528\u6765\u7075\u6d3b\u7684\u8c03\u5ea6\u7a0b\u5e8f\u7684\u6267\u884c topself:\u7528\u6765\u5c06\u5e94\u7528\u63d0\u5347\u4e3a\u670d\u52a1 \u4e00\uff0c\u5efa\u7acb\u63a7\u5236\u53f0\u5e94\u7528\u7a0b\u5e8f\uff0c\u5f15\u7528\u53f3\u952e\u6dfb [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3193","post","type-post","status-publish","format-standard","hentry","category-1"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/3193","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=3193"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/3193\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=3193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=3193"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=3193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}