Veronique 1 yıl önce
ebeveyn
işleme
acf9d8f6d3
1 değiştirilmiş dosya ile 49 ekleme ve 39 silme
  1. 49 39
      PDFMonitor_SVG/FormMain.cs

+ 49 - 39
PDFMonitor_SVG/FormMain.cs

@@ -77,45 +77,55 @@ namespace PDFMonitor_SVG {
 
         private void doConvertTask(object state) {
             SVGTaskInfo svgTaskInfo = (SVGTaskInfo)state;
-            context.Post(_ => {
-                memoLog.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
-                " 任务[" + svgTaskInfo.SvgFileName + "]开始");
-            }, null);
-            //传过来的是px,转成mm
-            int fileWidth = px2mm(double.Parse(svgTaskInfo.Width));
-            int fileHeight = px2mm(double.Parse(svgTaskInfo.Height));
-            int fileWidthPx = (int)Math.Ceiling(double.Parse(svgTaskInfo.Width));
-
-            Doc doc = new Doc();
-            doc.Units = UnitType.Mm;
-            //doc.MediaBox.Top = 0;
-            //doc.MediaBox.Left = 0;
-            //doc.MediaBox.Right = fileWidth;
-            //doc.MediaBox.Bottom = fileHeight;
-            string mediaBoxStr = "0 0 " + fileWidth + " " + fileHeight;
-            doc.MediaBox.String = mediaBoxStr;
-            doc.MediaBox.Pin = XRect.Corner.TopLeft;
-            doc.Rect.String = doc.MediaBox.String;
-            doc.Rect.Pin = XRect.Corner.TopLeft;
-            doc.HtmlOptions.Media = MediaType.Print;
-
-            string convertedFileName = Path.ChangeExtension(svgTaskInfo.SvgFileName, ".pdf");
-            string convertedFilePath = completedPDFPath + convertedFileName;
-
-            doc.AddImageUrl(svgTaskInfo.SvgPath, true, fileWidthPx, true);
-            doc.Save(convertedFilePath);
-            doc.Clear();
-            doc.Dispose();
-
-            PDFCallbackInfo pdfCallbackInfo = new PDFCallbackInfo();
-            pdfCallbackInfo.IdDesignOrder = svgTaskInfo.IdDesignOrder;
-            pdfCallbackInfo.PdfFileName = convertedFileName;
-            redisClient.GetDatabase().ListRightPush(redisCallbackKey, JsonConvert.SerializeObject(pdfCallbackInfo));
-
-            context.Post(_ => {
-                memoLog.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
-                " 任务[" + svgTaskInfo.SvgFileName + "]完成");
-            }, null);
+            try {
+                context.Post(_ => {
+                    memoLog.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
+                    " 任务[" + svgTaskInfo.SvgFileName + "]开始");
+                }, null);
+                //传过来的是px,转成mm
+                int fileWidth = px2mm(double.Parse(svgTaskInfo.Width));
+                int fileHeight = px2mm(double.Parse(svgTaskInfo.Height));
+                int fileWidthPx = (int)Math.Ceiling(double.Parse(svgTaskInfo.Width));
+
+                Doc doc = new Doc();
+                doc.Units = UnitType.Mm;
+                //doc.MediaBox.Top = 0;
+                //doc.MediaBox.Left = 0;
+                //doc.MediaBox.Right = fileWidth;
+                //doc.MediaBox.Bottom = fileHeight;
+                string mediaBoxStr = "0 0 " + fileWidth + " " + fileHeight;
+                doc.MediaBox.String = mediaBoxStr;
+                doc.MediaBox.Pin = XRect.Corner.TopLeft;
+                doc.Rect.String = doc.MediaBox.String;
+                doc.Rect.Pin = XRect.Corner.TopLeft;
+                doc.HtmlOptions.Media = MediaType.Print;
+
+                string convertedFileName = Path.ChangeExtension(svgTaskInfo.SvgFileName, ".pdf");
+                string convertedFilePath = completedPDFPath + convertedFileName;
+
+                doc.AddImageUrl(svgTaskInfo.SvgPath, true, fileWidthPx, true);
+                doc.Save(convertedFilePath);
+                doc.Clear();
+                doc.Dispose();
+
+                PDFCallbackInfo pdfCallbackInfo = new PDFCallbackInfo();
+                pdfCallbackInfo.IdDesignOrder = svgTaskInfo.IdDesignOrder;
+                pdfCallbackInfo.PdfFileName = convertedFileName;
+                redisClient.GetDatabase().ListRightPush(redisCallbackKey, JsonConvert.SerializeObject(pdfCallbackInfo));
+
+                context.Post(_ => {
+                    memoLog.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
+                    " 任务[" + svgTaskInfo.SvgFileName + "]完成");
+                }, null);
+            }
+            catch (Exception ex) {
+                context.Post(_ => {
+                    memoLog.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") +
+                    " 任务[" + svgTaskInfo.SvgFileName + "]失败");
+                    memoLog.Items.Add($"{ex.Message}");
+                }, null);
+            }
+
         }
 
         private void btnStartService_Click(object sender, EventArgs e) {