葡京网上娱乐场定时器–Quartz.Net

这次由路之需求:什么定时发送邮件通知,定时筛选取消客户下单未出的订单

 
最近开gis系统发现而当flex加载wmf图片。我记忆flash的loader只能是png,gis,jpg。wmf格式居然是window出的,flash居然无支持我吗是醉了,没道,只能后台转格式,首先wmf是矢量的格式,我先想到的是svg。刚好java之batick包可以支持wmf

还捡起定时器,在网上翻来索去找到—-Quartz.Net老字号了并无意味其便着实老矣哦

转svg。 代码如下

github:https://github.com/quartznet/quartznet

 1 /**
 2      * 将wmf转换为svg
 3      * 
 4      * @param src
 5      * @param dest
 6      */
 7     public  String wmfToSvg(InputStream insrc) {
 8         boolean compatible = false;
 9         //String resultString="";
10         try {
11             //InputStream in = new FileInputStream(src);
12             WmfParser parser = new WmfParser();
13             final SvgGdi gdi = new SvgGdi(compatible);
14             parser.parse(insrc, gdi);    
15             org.w3c.dom.Document doc = gdi.getDocument();
16             StringWriter strwite=new StringWriter();
17         
18             output(doc, strwite);
19             return strwite.getBuffer().toString();
20             // return resultString;
21              //getBuffer().toString();
22         } catch (Exception e) {
23             return e.getMessage();
24         }
25     }
26     
27     private  void output(org.w3c.dom.Document doc, StringWriter out) throws Exception {
28         TransformerFactory factory = TransformerFactory.newInstance();
29         Transformer transformer = factory.newTransformer();
30         transformer.setOutputProperty(OutputKeys.METHOD, "xml");
31         transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
32         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
33         transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC,
34                 "-//W3C//DTD SVG 1.0//EN");
35         transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM,
36                 "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
37         transformer.transform(new javax.xml.transform.dom.DOMSource(doc), new StreamResult(out));
38         out.flush();
39         out.close();
40     }

当介绍的田园里文章很多跟官方文档https://www.quartz-scheduler.net介绍的且特别清楚的!用起十分省心!

 
Flex的svg包实在过多地方还生,as3svgrendererlib-master用的比多,github上得以搜的交。我测试了网上的wmf都得以无啥问题,但是系统wmf是楼房基底图,导出来图片被某些字会叠加至一个角落里,我去就怎么回事,搞了大半天也从不觉察什么问题

so!接下自己大概介绍一下Quartz.Net框架设计 
下图借用园友的应当不会见介意

止能够是优先用png,wmf格式难道种类多?之前flex
加载tiff的时节便发现tiff格式太多 作了。

葡京网上娱乐场 1

 这是反吧png的流淌输出

 

 1 BASE64Encoder encode=new BASE64Encoder();
 2 byte[] WMF= houserow.getBlob("WMF");                
 3                     if(WMF!=null&&WMF.length>0)
 4                     {
 5                         String contentString =bytetoString(WMF);
 6                         InputStream wmfStream=new StringBufferInputStream(contentString);
 7                         String svgstr=wmfToSvg(wmfStream);
 8                         ByteArrayOutputStream strwite=new ByteArrayOutputStream();     
 9                         convertToPng(svgstr,strwite);
10                         byte[]lens=strwite.toByteArray();
11                         String WMF_pic="";
12                         if(svgstr != null&&!svgstr.equals(""))
13                         {
14                             WMF_pic=encode.encode(lens);
15                         }    
16                         createKeyPairXML(ke12,"WMF","户型图",WMF_pic,"");    
17                         
18                     }
19 
20     
21     
22     /**
23      * 将svgCode转换成png文件,直接输出到流中
24      * 
25      * @param svgCode svg代码
26      * @param outputStream 输出流
27      * @throws TranscoderException 异常
28      * @throws IOException io异常
29      */
30     public  void convertToPng(String svgCode, OutputStream outputStream)
31             throws TranscoderException, IOException {
32         try {
33             byte[] bytes = svgCode.getBytes("ISO-8859-1");
34             PNGTranscoder t = new PNGTranscoder();     
35            
36             TranscoderInput input = new TranscoderInput(new ByteArrayInputStream(bytes));
37             TranscoderOutput output = new TranscoderOutput(outputStream);
38             t.transcode(input, output);
39             outputStream.flush();
40         } finally {
41             if (outputStream != null) {
42                 try {
43                     outputStream.close();
44                 } catch (IOException e) {
45                     e.printStackTrace();
46                 }
47             }
48         }
49     }
50     
51 
52     public static String bytetoString(byte[] in)throws Exception{
53         InputStream is =byteTOInputStream(in);
54         return InputStreamTOString(is);
55     }
56     public static InputStream byteTOInputStream(byte[] in)throws Exception{
57     
58         ByteArrayInputStream is =new ByteArrayInputStream(in);
59         return is;
60         
61     }
62     public static String InputStreamTOString(InputStream in)throws Exception{
63         ByteArrayOutputStream outstream=new ByteArrayOutputStream();
64         byte[] data = new byte[in.available()];
65         int count=in.read(data,0,data.length);
66         if((count !=-1))
67         {
68             outstream.write(data, 0, count);
69         }
70         data = null;
71         String test =new String(outstream.toByteArray(),"ISO-8859-1");
72         System.out.println(test);
73         return test;    
74     }
75     public static byte[] Stringtobyte(String in)throws Exception{
76         InputStream is =StringToInputStream(in);
77         return InputStreamToByte(is);
78     }
79     public static InputStream StringToInputStream(String in)throws Exception{
80         ByteArrayInputStream is =new ByteArrayInputStream(in.getBytes("ISO-8859-1"));
81         return is;
82     }
83     public static byte[] InputStreamToByte(InputStream in)throws Exception{
84         ByteArrayOutputStream outstream=new ByteArrayOutputStream();
85         byte[] data=new byte[size];
86         int count =-1;
87         while((count = in.read(data,0,size))!=-1)
88         {
89             outstream.write(data, 0, count);
90         }
91         data = null;
92         byte[] tt=outstream.toByteArray();
93         File file=new File("");
94         FileImageOutputStream pic_out= new FileImageOutputStream(file);
95         BufferedImage img=new BufferedImage(105,80,BufferedImage.TYPE_3BYTE_BGR); 
96         ImageIO.write(img, "jpg", outstream);
97         return outstream.toByteArray();
98         
99     }

园子中找寻发现已出同学去实践了,这里引用一下各位大大的博文地址(应该无见面介意,嘻嘻),大家也得以参照学习:
http://www.cnblogs.com/knowledgesea/p/5145239.html Quartz.net持久化与集群部署开发详解
http://www.cnblogs.com/mushroom/p/4231642.html#3760225 Net作业调度(四)—quartz.net持久化和集群
http://www.cnblogs.com/lanxiaoke/p/6629481.html 任务调度之持久化(基于Quartz.net)
http://www.cnblogs.com/lanxiaoke/p/6637714.html 任务调度之集群(基于Quartz.net)
http://www.cnblogs.com/huangxincheng/p/6916246.html 运用sqlserver搭建高可用双机热备的Quartz集群部署【附源码】

 
 之后会补充一篇加载tiff和dwg的文章,这些格式都是gis系统经常以的,虽然拿FME来拍卖也没错,那东西正版要几十万,还是算了。

当此博主自己拿Quartz.net的所待类目做了一致不好做,大伙可以瞅瞅**

 

葡京网上娱乐场 2葡京网上娱乐场 3

 1 using Quartz;
 2 using Quartz.Impl;
 3 using System;
 4 using System.Collections.Generic;
 5 using System.Linq;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 using Wshelper.Caching;
 9 using Wshelper.Logging;
10 
11 namespace Commons.Helpers
12 {
13     public class QuartzHelper
14     {
15         /// <summary>
16         /// 时间间隔执行任务
17         /// </summary>
18         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
19         /// <param name="seconds">时间间隔(单位:毫秒)</param>
20         public static void ExecuteInterval<T>(int seconds) where T : IJob
21         {
22             ISchedulerFactory factory = new StdSchedulerFactory();
23             IScheduler scheduler = factory.GetScheduler();
24 
25             //IJobDetail job = JobBuilder.Create<T>().WithIdentity("job1", "group1").Build();
26             IJobDetail job = JobBuilder.Create<T>().Build();
27 
28             ITrigger trigger = TriggerBuilder.Create()
29                 .StartNow()
30                 .WithSimpleSchedule(x => x.WithIntervalInSeconds(seconds).RepeatForever())
31                 .Build();
32 
33             scheduler.ScheduleJob(job, trigger);
34 
35             scheduler.Start();
36         }
37         /// <summary>
38         /// 指定时间执行任务
39         /// </summary>
40         /// <typeparam name="T">任务类,必须实现IJob接口</typeparam>
41         /// <param name="cronExpression">cron表达式,即指定时间点的表达式</param>
42         public static void ExecuteByCron<T>(string cronExpression) where T : IJob
43         {
44             ISchedulerFactory factory = new StdSchedulerFactory();
45             IScheduler scheduler = factory.GetScheduler();
46 
47             IJobDetail job = JobBuilder.Create<T>().Build();
48 
49             //DateTimeOffset startTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddSeconds(1), 2);
50             //DateTimeOffset endTime = DateBuilder.NextGivenSecondDate(DateTime.Now.AddYears(2), 3);
51 
52             ICronTrigger trigger = (ICronTrigger)TriggerBuilder.Create()
53                 //.StartAt(startTime).EndAt(endTime)
54                 .WithCronSchedule(cronExpression)
55                 .Build();
56 
57             scheduler.ScheduleJob(job, trigger);
58 
59             scheduler.Start();
60 
61             //Thread.Sleep(TimeSpan.FromDays(2));
62             //scheduler.Shutdown();
63         }
64     }
65 
66     #region 任务执行例
67     public class MyJob : IJob
68     {
69         ILogger logger = LoggerFactory.CreateLog();
70         public void Execute(IJobExecutionContext context)
71         {
72             //向c:\Quartz.txt写入当前时间并换行
73             //System.IO.File.AppendAllText(@"c:\Quartz.txt", DateTime.Now + Environment.NewLine);
74             ICache cache = new MemoryCacheFactory().Create();
75             cache.Clear();
76             logger.Info("时间:" + DateTime.Now.ToString() + "---------系统自动更新缓存!");
77         }
78     }
79     #endregion
80 }

View Code

 

启动:

葡京网上娱乐场 4葡京网上娱乐场 5

1 public static void QuartzHelp()
2         {
3             //#region Quartz调度任务
4             string cronExpression = "1 0 0 * * ? ";  //这是指每天的0点执行任务
5             QuartzHelper.ExecuteByCron<MyJob>(cronExpression);  //这是调用Cron计划方法
6             //#endregion
7         }

View Code

 

 

Quartz.Net 作者都更新了支持.net standrad2.0了,就象征可以当.net
core平台使用了,下载地址:https://www.nuget.org/packages/Quartz/3.0.0-beta1,更新说明地点:https://www.quartz-scheduler.net/2017/10/08/quartznet-3.0-beta1-released.html,相信不久过后便见面发布release版本,届时.net
core框架开发就不怕没有定时器的支撑了,~( ̄▽ ̄~)(~ ̄▽ ̄)~