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