프로젝트

일반

사용자정보

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

markus / KCOM / Events / PasteCommand.cs @ 26ec6226

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

1 b37ef4b3 humkyung
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 ac4f1e13 taeseongkim
        public async void Execute()
58 b37ef4b3 humkyung
        {
59
            if (Clipboard.GetText().Contains("|OR||DZ|"))
60
            {
61 26ec6226 taeseongkim
                string[] delimiterChars = { "|OR|" };
62
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
63
                string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
64
65
                if (data.Count() > 0)
66
                {
67
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
68
69
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
70
71
                    //강인구 Undo/Redo 보류
72
                    MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
73
                    {
74
                        IsUndo = false,
75
                        Event = Event_Type.Create,
76
                        EventTime = DateTime.Now,
77
                        Markup_List = new List<Multi_Undo_data>()
78
                    };
79
80
                    foreach (string parse in data)
81
                    {
82
                        if (parse != "")
83
                        {
84
                            string[] data2 = new string[2];
85
                            data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
86
87
                            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);
88
89
                            var control = (item as MarkupToPDF.Common.CommentUserInfo);
90
91
                            control.CommentID = Commons.shortGuid();
92
                            control.MarkupInfoID = App.Custom_ViewInfoId;
93
                            control.IsNew = true;
94
95
                            if (data2.Length >= 2)
96
                            {
97
                                control.SymbolID = data2[1];
98
                            }
99
100
                            //CreateCommand.Instance.Execute(control);
101
                            adornerSet.Add(control);
102
                            multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(control);
103
                            UndoData.Markup_List.Add(multi_Undo_Data);
104
                            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
105
106
                            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.UpdateMyMarkupList();
107
                            //ViewerDataModel.Instance.MarkupControls_USER.Remove(control);
108
109
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
110
                                MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
111
                        }
112
                    }
113
114
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
115
116
                    /// place controls at current mouse position
117
                    var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid);
118
                    final.TranslateItems(diff.X, diff.Y);
119
120
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
121
                }
122
            }
123
            /// 외부 이미지 붙여넣기
124
            else if (Clipboard.GetImage() != null)
125
            {
126
                try
127
                {
128
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
129
130
                    MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
131
                    {
132
                        IsUndo = false,
133
                        Event = Event_Type.Create,
134
                        EventTime = DateTime.Now,
135
                        Markup_List = new List<Multi_Undo_data>()
136
                    };
137
138
                    string temppath = System.IO.Path.GetTempPath();
139
                    string filename = Commons.shortFileKey();
140
141
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
142
                    clipboardImage.Save(Path.Combine(temppath, filename));
143
144
                    /// upload image file to server
145
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath, filename));
146
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
147
                    long numByte = fileInfo.Length;
148
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
149
                    kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader;
150
                    if (dLen < 4)
151
                    {
152
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
153
                        System.IO.FileMode.Open, System.IO.FileAccess.Read, FileShare.Read);
154
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
155
                        byte[] data = br.ReadBytes((int)numByte);
156
157
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
158
                        Check_Uri.UriCheck(filename);
159
160
                        br.Close();
161
                        fStream.Close();
162
                        fStream.Dispose();
163
                    }
164
                    else
165
                    {
166
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
167
                        return;
168
                    }
169
170
                    fileInfo.Delete();
171
172
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
173
                    IntPtr hBitmap = bmp.GetHbitmap();
174
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
175
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
176
                    if (filename.Contains(".svg"))
177
                    {
178
                        SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename);
179
                        img.Source = (DrawingImage)svgImage.ProvideValue(null);
180
                    }
181
                    else
182
                    {
183
                        img.Source = new BitmapImage(new Uri(filename));
184
                    }
185
186
187
                    var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height);
188
                    var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize);
189
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
190
                    {
191
                        PointSet = new List<Point>(),
192
                        FilePath = filename,
193
                        ImageData = img.Source,
194
                        StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint,
195
                        EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize),
196
                        TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X,
197
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y),
198
                        LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X,
199
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y)
200
                    };
201
202
                    currentControl.PointSet = new List<Point>
203
                    {
204
                        currentControl.StartPoint,
205
                        currentControl.LeftBottomPoint,
206
                        currentControl.EndPoint,
207
                        currentControl.TopRightPoint,
208
                    };
209
210
                    multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
211
                    UndoData.Markup_List.Add(multi_Undo_Data);
212
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
213
214
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
215
                    currentControl.CommentID = Commons.shortGuid();
216
217
                    currentControl.ApplyTemplate();
218
                    currentControl.SetImage();
219
220
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
221
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
222
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
223
224
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
225
                        MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
226
                }
227
                catch (Exception ex)
228
                {
229
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
230
                }
231
            }
232
        }
233
        /// <summary>
234
        /// paste controls
235
        /// </summary>
236
        /// <author>humkyung</author>
237
        /// <date>2019.06.18</date>
238
        /// <param name="comments"></param>
239
        public async void Execute2()
240
        {
241
            if (Clipboard.GetText().Contains("|OR||DZ|"))
242
            {
243 b37ef4b3 humkyung
                List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
244
245
                SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
246
247
                Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
248
249
                //강인구 Undo/Redo 보류
250
                MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
251
                {
252
                    IsUndo = false,
253
                    Event = Event_Type.Create,
254
                    EventTime = DateTime.Now,
255
                    Markup_List = new List<Multi_Undo_data>()
256
                };
257
258
                ViewerDataModel.Instance.UndoDataList.Where(data1 => data1.IsUndo == true).ToList().ForEach(i =>
259
                {
260
                    ViewerDataModel.Instance.UndoDataList.Remove(i);
261
                });
262
263
                string[] delimiterChars = { "|OR|" };
264
                string[] delimiterChars2 = { "|OR|", "|SymbolID|" };
265
                string[] data = Clipboard.GetText().Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
266
                foreach (string parse in data)
267
                {
268
                    if (parse != "")
269
                    {
270
                        string[] data2 = new string[2];
271
                        data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
272
273 d2050059 taeseongkim
                        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);
274 b37ef4b3 humkyung
                        (item as MarkupToPDF.Common.CommentUserInfo).CommentID = Commons.shortGuid();
275
                        if (data2.Length >= 2)
276
                        {
277
                            (item as MarkupToPDF.Common.CommentUserInfo).SymbolID = data2[1];
278
                        }
279 26ec6226 taeseongkim
280 b37ef4b3 humkyung
                        ViewerDataModel.Instance.MarkupControls.Remove(item as MarkupToPDF.Common.CommentUserInfo);
281
                        ViewerDataModel.Instance.MarkupControls_USER.Remove(item as MarkupToPDF.Common.CommentUserInfo);
282
283
                        adornerSet.Add(item as MarkupToPDF.Common.CommentUserInfo);
284
285
                        multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(item as MarkupToPDF.Common.CommentUserInfo);
286
287
                        UndoData.Markup_List.Add(multi_Undo_Data);
288
                        ViewerDataModel.Instance.UndoDataList.Add(UndoData);
289 4eb052e4 ljiyeon
290 39f0624f ljiyeon
                        ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
291 4eb052e4 ljiyeon
                        MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
292 26ec6226 taeseongkim
293
                        (item as MarkupToPDF.Common.CommentUserInfo).ApplyOverViewData();
294 b37ef4b3 humkyung
                    }
295
                }
296
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
297
298 025ebf74 humkyung
                /// place controls at current mouse position
299
                var diff = Point.Subtract(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, final.Centeroid);
300
                final.TranslateItems(diff.X, diff.Y);
301
302 b37ef4b3 humkyung
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
303 105359ce ljiyeon
               
304 b37ef4b3 humkyung
            }
305
            /// 외부 이미지 붙여넣기
306
            else if (Clipboard.GetImage() != null)
307
            {
308
                try
309
                {
310
                    Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
311
312
                    MarkupToPDF.Common.Undo_data UndoData = new Undo_data()
313
                    {
314
                        IsUndo = false,
315
                        Event = Event_Type.Create,
316
                        EventTime = DateTime.Now,
317
                        Markup_List = new List<Multi_Undo_data>()
318
                    };
319
320
                    string temppath = System.IO.Path.GetTempPath();
321
                    string filename = Commons.shortFileKey();
322
323
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
324
                    clipboardImage.Save(Path.Combine(temppath , filename));
325
326
                    /// upload image file to server
327
                    System.IO.FileInfo fileInfo = new System.IO.FileInfo(Path.Combine(temppath , filename));
328
                    String strFile = System.IO.Path.GetFileName(fileInfo.FullName);
329
                    long numByte = fileInfo.Length;
330
                    double dLen = Convert.ToDouble(fileInfo.Length / 1000000);
331 76dc223b taeseongkim
                    kr.co.devdoftech.cloud.FileUpload fileUploader = App.FileUploader;
332 b37ef4b3 humkyung
                    if (dLen < 4)
333
                    {
334
                        System.IO.FileStream fStream = new System.IO.FileStream(fileInfo.FullName,
335 43e1d368 taeseongkim
                        System.IO.FileMode.Open, System.IO.FileAccess.Read,FileShare.Read);
336 b37ef4b3 humkyung
                        System.IO.BinaryReader br = new System.IO.BinaryReader(fStream);
337
                        byte[] data = br.ReadBytes((int)numByte);
338
339
                        filename = fileUploader.Run(App.ViewInfo.ProjectNO, Common.ViewerDataModel.Instance.SystemMain.dzMainMenu._DocItem.DOCUMENT_NO, App.ViewInfo.UserID, strFile + ".png", data);
340
                        Check_Uri.UriCheck(filename);
341
342
                        br.Close();
343
                        fStream.Close();
344
                        fStream.Dispose();
345
                    }
346
                    else
347
                    {
348
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
349
                        return;
350
                    }
351
352
                    fileInfo.Delete();
353
354
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(clipboardImage);
355
                    IntPtr hBitmap = bmp.GetHbitmap();
356
                    System.Windows.Media.ImageSource WpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
357
                    System.Windows.Controls.Image img = new System.Windows.Controls.Image();
358
                    if (filename.Contains(".svg"))
359
                    {
360 f1f822e9 taeseongkim
                        SharpVectors.Converters.SvgImageExtension svgImage = new SharpVectors.Converters.SvgImageExtension(filename);
361
                        img.Source = (DrawingImage)svgImage.ProvideValue(null);
362 b37ef4b3 humkyung
                    }
363
                    else
364
                    {
365
                        img.Source = new BitmapImage(new Uri(filename));
366
                    }
367 2184f659 humkyung
368
369
                    var vecSize = new Vector(clipboardImage.Width, clipboardImage.Height);
370
                    var EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize);
371 b37ef4b3 humkyung
                    var currentControl = new MarkupToPDF.Controls.Etc.ImgControl
372
                    {
373
                        PointSet = new List<Point>(),
374
                        FilePath = filename,
375
                        ImageData = img.Source,
376 2184f659 humkyung
                        StartPoint = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint,
377
                        EndPoint = Point.Add(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint, vecSize),
378
                        TopRightPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X + vecSize.X,
379
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y),
380
                        LeftBottomPoint = new Point(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.X, 
381
                                                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.getCurrentPoint.Y + vecSize.Y)
382 b37ef4b3 humkyung
                    };
383
384
                    currentControl.PointSet = new List<Point>
385 2184f659 humkyung
                    {
386
                        currentControl.StartPoint,
387
                        currentControl.LeftBottomPoint,
388
                        currentControl.EndPoint,
389
                        currentControl.TopRightPoint,
390
                    };
391 b37ef4b3 humkyung
392
                    multi_Undo_Data = Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.Control_Style(currentControl as MarkupToPDF.Common.CommentUserInfo);
393
                    UndoData.Markup_List.Add(multi_Undo_Data);
394
                    ViewerDataModel.Instance.UndoDataList.Add(UndoData);
395
396
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
397
                    currentControl.CommentID = Commons.shortGuid();
398
399
                    currentControl.ApplyTemplate();
400
                    currentControl.SetImage();
401
402
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
403
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
404
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
405 4eb052e4 ljiyeon
406 39f0624f ljiyeon
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
407 4eb052e4 ljiyeon
                        MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
408 b37ef4b3 humkyung
                }
409
                catch (Exception ex)
410
                {
411
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
412
                }
413
            }
414
        }
415
    }
416
}
클립보드 이미지 추가 (최대 크기: 500 MB)