프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Events / PasteCommand.cs @ c7b02506

이력 | 보기 | 이력해설 | 다운로드 (20.9 KB)

1
using KCOM.Common;
2
using KCOM.Controls;
3
using KCOM.Views;
4
using MarkupToPDF.Common;
5
using MarkupToPDF.Controls.Parsing;
6
using Newtonsoft.Json;
7
using Newtonsoft.Json.Converters;
8
using Newtonsoft.Json.Linq;
9
using Newtonsoft.Json.Serialization;
10
using System;
11
using System.Collections;
12
using System.Collections.Generic;
13
using System.ComponentModel;
14
using System.Data;
15
using System.IO;
16
using System.Linq;
17
using System.Reflection;
18
using System.Runtime.Serialization.Formatters;
19
using System.Runtime.Serialization.Formatters.Binary;
20
using System.Runtime.Serialization.Json;
21
using System.Text;
22
using System.Windows;
23
using System.Windows.Media;
24
using System.Windows.Media.Imaging;
25
using System.Xml;
26
using System.Xml.Serialization;
27

    
28
namespace KCOM
29
{
30
    public class PasteCommand
31
    {
32
        private static readonly PasteCommand _instance = new PasteCommand();
33

    
34
        // Explicit static constructor to tell C# compiler
35
        // not to mark type as beforefieldinit
36
        static PasteCommand()
37
        {
38
        }
39

    
40
        private PasteCommand()
41
        {
42
        }
43

    
44
        public static PasteCommand Instance
45
        {
46
            get
47
            {
48
                return _instance;
49
            }
50
        }
51
        /// <summary>
52
        /// paste controls
53
        /// </summary>
54
        /// <author>humkyung</author>
55
        /// <date>2019.06.18</date>
56
        /// <param name="comments"></param>
57
        public async void Execute()
58
        {
59
            var markupData = Clipboard.GetData(DataFormats.StringFormat);
60

    
61
            if (markupData?.ToString().Contains("|OR||DZ|") == true)
62
            {
63
                string[] delimiterChars = { "|OR|" };
64
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
65
                string[] data = markupData.ToString().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
66

    
67
                if (data.Count() > 0)
68
                {
69
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
70

    
71
                    UndoData multi_UndoData = new UndoData();
72

    
73
                    //강인구 Undo/Redo 보류
74
                    MarkupToPDF.Common.UndoDataGroup UndoData = new UndoDataGroup()
75
                    {
76
                        IsUndo = false,
77
                        Event = EventType.Create,
78
                        EventTime = DateTime.Now,
79
                        MarkupDataColl = new List<UndoData>()
80
                    };
81

    
82
                    foreach (string parse in data)
83
                    {
84
                        if (parse != "")
85
                        {
86
                            string[] data2 = new string[2];
87
                            data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
88

    
89
                            System.Windows.Controls.Control item = await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, data2[0], ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, "#FFFF0000", string.Empty,
90
                                STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
91

    
92
                            var control = (item as MarkupToPDF.Common.CommentUserInfo);
93

    
94
                            control.CommentID = Commons.ShortGuid();
95
                            control.MarkupInfoID = App.Custom_ViewInfoId;
96
                            control.IsNew = true;
97

    
98
                            if (data2.Length >= 2)
99
                            {
100
                                control.SymbolID = data2[1];
101
                            }
102

    
103
                            //CreateCommand.Instance.Execute(control);
104
                            adornerSet.Add(control);
105
                            multi_UndoData = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(control);
106
                            UndoData.MarkupDataColl.Add(multi_UndoData);
107
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
108

    
109
                            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.UpdateMyMarkupList();
110
                            //ViewerDataModel.Instance.MarkupControls_USER.Remove(control);
111

    
112
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
113
                                MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
114
                        }
115
                    }
116

    
117
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
118

    
119
                    /// place controls at current mouse position
120
                    var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid);
121
                    final.TranslateItems(diff.X, diff.Y);
122

    
123
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
124
                }
125
            }
126
            /// 외부 이미지 붙여넣기
127
            else if (Clipboard.GetImage() != null)
128
            {
129
                try
130
                {
131
                    UndoData multi_UndoData = new UndoData();
132

    
133
                    MarkupToPDF.Common.UndoDataGroup UndoData = new UndoDataGroup()
134
                    {
135
                        IsUndo = false,
136
                        Event = EventType.Create,
137
                        EventTime = DateTime.Now,
138
                        MarkupDataColl = new List<UndoData>()
139
                    };
140

    
141
                    string temppath = System.IO.Path.GetTempPath();
142
                    string filename = Commons.ShortFileKey();
143

    
144
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
145
                    clipboardImage.Save(Path.Combine(temppath, filename));
146

    
147
                    /// upload image file to server
148
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath, filename));
149
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
150
                    long numByte = fileInfo.Length;
151
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
152
                    kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader;
153
                    if (dLen < 4)
154
                    {
155
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
156
                        System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.Read);
157
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
158
                        byte[] data = br.ReadBytes((int)numByte);
159

    
160
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
161
                        Check_Uri.UriCheck(filename);
162

    
163
                        br.Close();
164
                        fStream.Close();
165
                        fStream.Dispose();
166
                    }
167
                    else
168
                    {
169
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
170
                        return;
171
                    }
172

    
173
                    fileInfo.Delete();
174

    
175
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
176
                    IntPtr hBitmap = bmp.GetHbitmap();
177
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
178
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
179
                    if (filename.Contains(".svg"))
180
                    {
181
                        SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename);
182
                        img.Source = (DrawingImage)svgImage.ProvideValue(null);
183
                    }
184
                    else
185
                    {
186
                        img.Source = new BitmapImage(new Uri(filename));
187
                    }
188

    
189

    
190
                    var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height);
191
                    var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize);
192
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
193
                    {
194
                        PointSet = new List<Point>(),
195
                        FilePath = filename,
196
                        ImageData = img.Source,
197
                        StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint,
198
                        EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize),
199
                        TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X,
200
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y),
201
                        LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X,
202
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y)
203
                    };
204

    
205
                    currentControl.PointSet = new List<Point>
206
                    {
207
                        currentControl.StartPoint,
208
                        currentControl.LeftBottomPoint,
209
                        currentControl.EndPoint,
210
                        currentControl.TopRightPoint,
211
                    };
212

    
213
                    multi_UndoData = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
214
                    UndoData.MarkupDataColl.Add(multi_UndoData);
215
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
216

    
217
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
218
                    currentControl.CommentID = Commons.ShortGuid();
219

    
220
                    currentControl.ApplyTemplate();
221
                    currentControl.SetImage();
222

    
223
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
224
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
225
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
226

    
227
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
228
                        MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
229
                }
230
                catch (Exception ex)
231
                {
232
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
233
                }
234
            }
235
        }
236
        /// <summary>
237
        /// paste controls
238
        /// </summary>
239
        /// <author>humkyung</author>
240
        /// <date>2019.06.18</date>
241
        /// <param name="comments"></param>
242
        public async void Execute2()
243
        {
244
            if (Clipboard.GetText().Contains("|OR||DZ|"))
245
            {
246
                List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
247

    
248
                SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
249

    
250
                UndoData multi_UndoData = new UndoData();
251

    
252
                //강인구 Undo/Redo 보류
253
                MarkupToPDF.Common.UndoDataGroup UndoData = new UndoDataGroup()
254
                {
255
                    IsUndo = false,
256
                    Event = EventType.Create,
257
                    EventTime = DateTime.Now,
258
                    MarkupDataColl = new List<UndoData>()
259
                };
260

    
261
                ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
262
                {
263
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
264
                });
265

    
266
                string[] delimiterChars = { "|OR|" };
267
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
268
                string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
269
                foreach (string parse in data)
270
                {
271
                    if (parse != "")
272
                    {
273
                        string[] data2 = new string[2];
274
                        data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
275

    
276
                        System.Windows.Controls.Control item = await MarkupParser.ParseExAsync(App.BaseAddress, ViewerDataModel.Instance.NewMarkupCancelToken(), App.ViewInfo.ProjectNO, data2[0], ViewerDataModel.Instance.MarkupControls_USER, ViewerDataModel.Instance.PageAngle, "#FFFF0000", string.Empty,
277
                            STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
278
                        (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.ShortGuid();
279
                        if (data2.Length >= 2)
280
                        {
281
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = data2[1];
282
                        }
283

    
284
                        ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
285
                        ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
286

    
287
                        adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
288

    
289
                        multi_UndoData = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
290

    
291
                        UndoData.MarkupDataColl.Add(multi_UndoData);
292
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
293

    
294
                        ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
295
                        MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
296

    
297
                        (item as MarkupToPDF.Common.CommentUserInfo).ApplyOverViewData();
298
                    }
299
                }
300
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
301

    
302
                /// place controls at current mouse position
303
                var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid);
304
                final.TranslateItems(diff.X, diff.Y);
305

    
306
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
307
               
308
            }
309
            /// 외부 이미지 붙여넣기
310
            else if (Clipboard.GetImage() != null)
311
            {
312
                try
313
                {
314
                    UndoData multi_UndoData = new UndoData();
315

    
316
                    MarkupToPDF.Common.UndoDataGroup UndoData = new UndoDataGroup()
317
                    {
318
                        IsUndo = false,
319
                        Event = EventType.Create,
320
                        EventTime = DateTime.Now,
321
                        MarkupDataColl = new List<UndoData>()
322
                    };
323

    
324
                    string temppath = System.IO.Path.GetTempPath();
325
                    string filename = Commons.ShortFileKey();
326

    
327
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
328
                    clipboardImage.Save(Path.Combine(temppath , filename));
329

    
330
                    /// upload image file to server
331
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath , filename));
332
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
333
                    long numByte = fileInfo.Length;
334
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
335
                    kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader;
336
                    if (dLen < 4)
337
                    {
338
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
339
                        System.IO.FileMode.Open, System.IO.FileAccess.Read,FileShare.Read);
340
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
341
                        byte[] data = br.ReadBytes((int)numByte);
342

    
343
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
344
                        Check_Uri.UriCheck(filename);
345

    
346
                        br.Close();
347
                        fStream.Close();
348
                        fStream.Dispose();
349
                    }
350
                    else
351
                    {
352
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
353
                        return;
354
                    }
355

    
356
                    fileInfo.Delete();
357

    
358
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
359
                    IntPtr hBitmap = bmp.GetHbitmap();
360
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
361
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
362
                    if (filename.Contains(".svg"))
363
                    {
364
                        SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename);
365
                        img.Source = (DrawingImage)svgImage.ProvideValue(null);
366
                    }
367
                    else
368
                    {
369
                        img.Source = new BitmapImage(new Uri(filename));
370
                    }
371

    
372

    
373
                    var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height);
374
                    var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize);
375
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
376
                    {
377
                        PointSet = new List<Point>(),
378
                        FilePath = filename,
379
                        ImageData = img.Source,
380
                        StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint,
381
                        EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize),
382
                        TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X,
383
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y),
384
                        LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, 
385
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y)
386
                    };
387

    
388
                    currentControl.PointSet = new List<Point>
389
                    {
390
                        currentControl.StartPoint,
391
                        currentControl.LeftBottomPoint,
392
                        currentControl.EndPoint,
393
                        currentControl.TopRightPoint,
394
                    };
395

    
396
                    multi_UndoData = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
397
                    UndoData.MarkupDataColl.Add(multi_UndoData);
398
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
399

    
400
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
401
                    currentControl.CommentID = Commons.ShortGuid();
402

    
403
                    currentControl.ApplyTemplate();
404
                    currentControl.SetImage();
405

    
406
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
407
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
408
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
409

    
410
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
411
                        MarkupParser.MarkupToString(multi_UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
412
                }
413
                catch (Exception ex)
414
                {
415
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
416
                }
417
            }
418
        }
419
    }
420
}
클립보드 이미지 추가 (최대 크기: 500 MB)