Ver código fonte

DXF / WPF - error message for DXF processing error

Nick-PRSDigital@bitbucket.org 2 anos atrás
pai
commit
2a46050c2c

+ 7 - 1
inabox.dxf/DxfUtils.cs

@@ -1,5 +1,6 @@
 using System.Drawing;
 using System.Drawing.Drawing2D;
+using System.Security.Cryptography.X509Certificates;
 using netDxf;
 using netDxf.Entities;
 using Point = System.Drawing.Point;
@@ -8,6 +9,8 @@ namespace InABox.Dxf
 {
     public static class DxfUtils
     {
+        public static event ProcessError OnProcessError;
+
         // Draw a rotated string at a particular position.
         private static void DrawRotatedTextAt(Graphics gr, float angle,
             string txt, float x, float y, Font the_font, Brush the_brush)
@@ -58,8 +61,10 @@ namespace InABox.Dxf
             return new PointF(Scale(vector.X, offset.X, scale, border.X), Scale(vector.Y, offset.Y, scale, border.Y));
         }
 
+        public delegate void ProcessError(string message);
+
         public static Bitmap ProcessImage(Stream stream, string caption)
-        {
+        {         
             var minX = double.MaxValue;
             var minY = double.MaxValue;
             var maxX = double.MinValue;
@@ -218,6 +223,7 @@ namespace InABox.Dxf
                 catch (Exception e)
                 {
                     result = null;
+                    OnProcessError?.Invoke(e.Message);
                 }
             }
 

+ 19 - 12
inabox.wpf/DynamicGrid/Columns/DynamicImageManagerColumn.cs

@@ -7,6 +7,7 @@ using System.Linq.Expressions;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Media.Imaging;
+using System.Windows.Threading;
 using InABox.Clients;
 using InABox.Core;
 using InABox.Dxf;
@@ -19,13 +20,13 @@ namespace InABox.DynamicGrid
     public class DynamicImagePreviewColumn<T> : DynamicImageColumn
         where T : BaseObject
     {
-        
-        private static readonly BitmapImage _preview =Wpf.Resources.doc_png.AsBitmapImage();
+
+        private static readonly BitmapImage _preview = Wpf.Resources.doc_png.AsBitmapImage();
 
         protected static Expression<Func<T, ImageDocumentLink>> Property { get; private set; }
-        
+
         protected static string ImageIDProperty => Property != null ? CoreUtils.GetFullPropertyName(Property, ".") + ".ID" : "";
-        
+
         public DynamicImagePreviewColumn(Expression<Func<T, ImageDocumentLink>> property) : base(PreviewImage)
         {
             Property = property;
@@ -34,14 +35,14 @@ namespace InABox.DynamicGrid
             FilterRecord = DoFilterImages;
             ToolTip = CreateImageToolTip;
         }
-        
+
         private static BitmapImage PreviewImage(CoreRow arg)
         {
             if (arg == null || arg.Get<Guid>(ImageIDProperty) == Guid.Empty)
                 return null;
             return _preview;
         }
-        
+
         protected Bitmap LoadBitmapFromDatabase(Guid imageid)
         {
             if (imageid == Guid.Empty)
@@ -59,7 +60,7 @@ namespace InABox.DynamicGrid
 
             return result;
         }
-        
+
         private FrameworkElement CreateImageToolTip(DynamicActionColumn column, CoreRow arg)
         {
             FrameworkElement result = null;
@@ -73,7 +74,7 @@ namespace InABox.DynamicGrid
 
             return result;
         }
-        
+
         private bool DoFilterImages(CoreRow row, string[] filter)
         {
             var hasimage = row.Get<Guid>(ImageIDProperty) != Guid.Empty;
@@ -84,7 +85,7 @@ namespace InABox.DynamicGrid
             return false;
         }
     }
-    
+
     public class DynamicImageManagerColumn<T> : DynamicImagePreviewColumn<T>
         where T : Entity, IRemotable, IPersistent, new()
     {
@@ -93,7 +94,7 @@ namespace InABox.DynamicGrid
         private readonly bool _canupdate;
 
         private readonly IDynamicGrid _parent;
-        
+
         private static string _imagefilename => Property != null ? CoreUtils.GetFullPropertyName(Property, ".") + ".FileName" : "";
 
         public DynamicImageManagerColumn(IDynamicGrid parent, Expression<Func<T, ImageDocumentLink>> property, bool canupdate) : base(property)
@@ -102,7 +103,7 @@ namespace InABox.DynamicGrid
             _canupdate = canupdate;
             ContextMenu = CreateImageMenu;
         }
-        
+
         private MenuItem CreateMenu(string caption, RoutedEventHandler click)
         {
             var item = new MenuItem();
@@ -110,7 +111,7 @@ namespace InABox.DynamicGrid
             item.Click += click;
             return item;
         }
-        
+
         private void SaveBitmapToDatabase(CoreRow row, Guid id, string filename, Bitmap bitmap)
         {
             var docid = id;
@@ -195,7 +196,13 @@ namespace InABox.DynamicGrid
 
                     Bitmap bmp = null;
                     if (Path.GetExtension(filename).ToLower().Equals(".dxf"))
+                    {
+                        DxfUtils.OnProcessError += ((message) =>
+                        {
+                            MessageBox.Show("Error - " + message);
+                        });
                         bmp = DxfUtils.DXFToBitmap(filename);
+                    }
                     else
                         bmp = System.Drawing.Image.FromFile(filename) as Bitmap;