프로젝트

일반

사용자정보

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

markus / KCOM / Events / PasteCommand.cs @ 51c6ce90

이력 | 보기 | 이력해설 | 다운로드 (10.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.Any())
68
                {
69
                    List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>();
70

    
71
                    MarkupToPDF.Common.UndoDataGroup UndoDataGrp = new UndoDataGroup()
72
                    {
73
                        IsUndo = false,
74
                        Event = EventType.Create
75
                    };
76

    
77
                    foreach (string parse in data)
78
                    {
79
                        if (!string.IsNullOrEmpty(parse))
80
                        {
81
                            string[] data2 = parse.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries);
82

    
83
                            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,
84
                                STAMP_Contents: App.SystemInfo.STAMP_CONTENTS);
85
                            if (!(item is MarkupToPDF.Common.CommentUserInfo control)) continue;
86
                            #region 리스트의 맨 끝에 추가
87
                            int index = ViewerDataModel.Instance.MarkupControls_USER.ToList().FindIndex(x => x == control);
88
                            ViewerDataModel.Instance.MarkupControls_USER.RemoveAt(index);
89
                            ViewerDataModel.Instance.MarkupControls_USER.Add(control);
90
                            control.Index = ViewerDataModel.Instance.MarkupControls_USER.ToList().FindIndex(x => x == control);
91
                            #endregion
92

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

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

    
103
                            adornerSet.Add(control);
104
                            var UndoData = new UndoData(control);
105
                            UndoDataGrp.MarkupDataColl.Add(UndoData);
106
                            ViewerDataModel.Instance.UndoDataList.Add(UndoDataGrp);
107

    
108
                            Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.UpdateMyMarkupList();
109

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

    
115
                    Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
116

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

    
121
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
122
                }
123
            }
124
            /// 외부 이미지 붙여넣기
125
            else if (Clipboard.GetImage() != null)
126
            {
127
                try
128
                {
129
                    MarkupToPDF.Common.UndoDataGroup UndoDataGrp = new UndoDataGroup()
130
                    {
131
                        IsUndo = false,
132
                        Event = EventType.Create
133
                    };
134

    
135
                    string temppath = System.IO.Path.GetTempPath();
136
                    string filename = Commons.ShortFileKey();
137

    
138
                    System.Drawing.Image clipboardImage = System.Windows.Forms.Clipboard.GetImage();
139
                    clipboardImage.Save(Path.Combine(temppath, filename));
140

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

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

    
157
                        br.Close();
158
                        fStream.Close();
159
                        fStream.Dispose();
160
                    }
161
                    else
162
                    {
163
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("Available Memory less than 4 mega byte", "Alert");
164
                        return;
165
                    }
166

    
167
                    fileInfo.Delete();
168

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

    
183

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

    
199
                    currentControl.PointSet = new List<Point>
200
                    {
201
                        currentControl.StartPoint,
202
                        currentControl.LeftBottomPoint,
203
                        currentControl.EndPoint,
204
                        currentControl.TopRightPoint,
205
                    };
206

    
207
                    var UndoData = new UndoData(currentControl as MarkupToPDF.Common.CommentUserInfo);
208
                    UndoDataGrp.MarkupDataColl.Add(UndoData);
209
                    ViewerDataModel.Instance.UndoDataList.Add(UndoDataGrp);
210

    
211
                    ViewerDataModel.Instance.MarkupControls_USER.Add(currentControl as MarkupToPDF.Common.CommentUserInfo);
212
                    currentControl.CommentID = Commons.ShortGuid();
213

    
214
                    currentControl.ApplyTemplate();
215
                    currentControl.SetImage();
216

    
217
                    ViewerDataModel.Instance.MarkupControls_USER.Remove(currentControl as MarkupToPDF.Common.CommentUserInfo);
218
                    Controls.AdornerFinal final = new Controls.AdornerFinal(currentControl as MarkupToPDF.Common.CommentUserInfo);
219
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
220

    
221
                    ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
222
                        MarkupParser.MarkupToString(UndoData.Markup, App.ViewInfo.UserID), EventType.Create, null, null);
223
                }
224
                catch (Exception ex)
225
                {
226
                    Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.DialogMessage_Alert("" + ex, "Alert");
227
                }
228
            }
229
        }
230
    }
231
}
클립보드 이미지 추가 (최대 크기: 500 MB)