markus / MarkupToPDF / Controls / Parsing / MarkupParse.cs @ 0d2d2a08
이력 | 보기 | 이력해설 | 다운로드 (16.8 KB)
1 | 787a4489 | KangIngu | using System; |
---|---|---|---|
2 | using System.Net; |
||
3 | using System.Windows; |
||
4 | using System.Windows.Controls; |
||
5 | using System.Windows.Documents; |
||
6 | using System.Windows.Ink; |
||
7 | using System.Windows.Input; |
||
8 | using System.Windows.Media; |
||
9 | using System.Windows.Media.Animation; |
||
10 | using System.Windows.Shapes; |
||
11 | using System.Collections.Generic; |
||
12 | using MarkupToPDF.Serialize.S_Control; |
||
13 | using MarkupToPDF.Serialize.Core; |
||
14 | using System.Linq; |
||
15 | using MarkupToPDF.Controls.Line; |
||
16 | using MarkupToPDF.Controls.Text; |
||
17 | using MarkupToPDF.Controls.Shape; |
||
18 | using MarkupToPDF.Controls.Etc; |
||
19 | using MarkupToPDF.Controls.Polygon; |
||
20 | //using Telerik.Windows.Controls; |
||
21 | using System.IO; |
||
22 | using System.Windows.Media.Imaging; |
||
23 | //using MarkupToPDF.Common; |
||
24 | using System.Windows.Markup; |
||
25 | //using Telerik.Windows.Controls; |
||
26 | using System.Net.Cache; |
||
27 | using System.Collections.ObjectModel; |
||
28 | using MarkupToPDF.Common; |
||
29 | 684ef11c | ljiyeon | using MarkupToPDF.Controls.Cad; |
30 | 40d88a02 | ljiyeon | using MarkupToPDF.Controls.Common; |
31 | ac4f1e13 | taeseongkim | using System.Threading.Tasks; |
32 | 787a4489 | KangIngu | |
33 | namespace MarkupToPDF.Controls.Parsing |
||
34 | { |
||
35 | 036650a0 | humkyung | public class MarkupParser |
36 | { |
||
37 | ///강인구 추가(2017.11.02) |
||
38 | ///DATA_TYPE추가로 인한 클래스 변수 추가 |
||
39 | public class MarkupReturn |
||
40 | { |
||
41 | public string ConvertData { get; set; } |
||
42 | public int DATA_TYPE { get; set; } |
||
43 | public string CommentID { get; set; } |
||
44 | } |
||
45 | |||
46 | public static MarkupReturn MarkupToString(CommentUserInfo Control, string UserId) |
||
47 | { |
||
48 | MarkupReturn Data = new MarkupReturn(); |
||
49 | Data.ConvertData = ""; |
||
50 | 8cf823d0 | djkim | Data.DATA_TYPE = (int)Control.ControlType; |
51 | 036650a0 | humkyung | Data.CommentID = Control.CommentID; |
52 | if (Data.CommentID == null) |
||
53 | { |
||
54 | Data.CommentID = shortGuid(); |
||
55 | } |
||
56 | |||
57 | Data.ConvertData = Control.Serialize(); |
||
58 | |||
59 | return Data; |
||
60 | } |
||
61 | |||
62 | 661b7416 | humkyung | /// <summary> |
63 | /// create a commentuserinfo from given string |
||
64 | /// </summary> |
||
65 | /// <param name="str"></param> |
||
66 | /// <returns></returns> |
||
67 | a1e2ba68 | taeseongkim | public static CommentUserInfo FromString(string baseUri,string item, SolidColorBrush brush, string sProjectNo,double PageAngle) |
68 | 661b7416 | humkyung | { |
69 | CommentUserInfo instance = null; |
||
70 | 5529d2a2 | humkyung | var unkown = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
71 | 661b7416 | humkyung | switch (unkown.Name) |
72 | { |
||
73 | #region Shape |
||
74 | #region Rectangle |
||
75 | case "RectangleControl": |
||
76 | instance = RectangleControl.FromString(item, brush, sProjectNo); |
||
77 | break; |
||
78 | #endregion |
||
79 | #region Triangle |
||
80 | case "TriControl": |
||
81 | instance = TriControl.FromString(item, brush, sProjectNo); |
||
82 | break; |
||
83 | #endregion |
||
84 | #region Cicle |
||
85 | case "CircleControl": |
||
86 | instance = CircleControl.FromString(item, brush, sProjectNo); |
||
87 | break; |
||
88 | #endregion |
||
89 | #region RectCloud |
||
90 | case "RectCloudControl": |
||
91 | instance = RectCloudControl.FromString(item, brush, sProjectNo); |
||
92 | break; |
||
93 | #endregion |
||
94 | #endregion |
||
95 | |||
96 | #region Polygon |
||
97 | #region Poly |
||
98 | case "PolygonControl": |
||
99 | instance = PolygonControl.FromString(item, brush, sProjectNo); |
||
100 | break; |
||
101 | #endregion |
||
102 | #region InkControl |
||
103 | case "InkControl": |
||
104 | instance = InkControl.FromString(item, brush, sProjectNo); |
||
105 | break; |
||
106 | #endregion |
||
107 | #region Cloud |
||
108 | case "CloudControl": |
||
109 | instance = CloudControl.FromString(item, brush, sProjectNo); |
||
110 | break; |
||
111 | #endregion |
||
112 | #endregion |
||
113 | |||
114 | #region Line |
||
115 | #region Line |
||
116 | case "LineControl": |
||
117 | instance = LineControl.FromString(item, brush, sProjectNo); |
||
118 | break; |
||
119 | #endregion |
||
120 | #region Arrow_Multi |
||
121 | case "ArrowControl_Multi": |
||
122 | instance = ArrowControl_Multi.FromString(item, brush, sProjectNo); |
||
123 | break; |
||
124 | #endregion |
||
125 | #region Arc |
||
126 | case "ArcControl": |
||
127 | instance = ArcControl.FromString(item, brush, sProjectNo); |
||
128 | break; |
||
129 | #endregion |
||
130 | #region ArrowArc |
||
131 | case "ArrowArcControl": |
||
132 | instance = ArrowArcControl.FromString(item, brush, sProjectNo); |
||
133 | break; |
||
134 | #endregion |
||
135 | #endregion |
||
136 | #region Text |
||
137 | case "TextControl": |
||
138 | instance = TextControl.FromString(item, brush, sProjectNo); |
||
139 | break; |
||
140 | #endregion |
||
141 | |||
142 | #region ArrowText |
||
143 | case "ArrowTextControl": |
||
144 | 4f017ed3 | taeseongkim | instance = ArrowTextControl.FromString(item, brush, sProjectNo,PageAngle); |
145 | 661b7416 | humkyung | break; |
146 | #endregion |
||
147 | |||
148 | #region ETC |
||
149 | #region Ink |
||
150 | case "InkPresenter": |
||
151 | using (S_PensilControl s = JsonSerializerHelper.JsonDeserialize<S_PensilControl>(item)) |
||
152 | { |
||
153 | |||
154 | } |
||
155 | break; |
||
156 | #endregion |
||
157 | #region Date |
||
158 | case "DateControl": |
||
159 | instance = DateControl.FromString(item, brush, sProjectNo); |
||
160 | break; |
||
161 | #endregion |
||
162 | #region Image |
||
163 | case "ImgControl": |
||
164 | a1e2ba68 | taeseongkim | instance = ImgControl.FromString(item, brush, sProjectNo, baseUri); |
165 | 661b7416 | humkyung | break; |
166 | #endregion |
||
167 | #region Sign |
||
168 | case "SignControl": |
||
169 | instance = SignControl.FromString(item, brush, sProjectNo); |
||
170 | break; |
||
171 | #endregion |
||
172 | #region Symbol |
||
173 | case "SymControl": |
||
174 | instance = SymControl.FromString(item, brush, sProjectNo); |
||
175 | break; |
||
176 | #endregion |
||
177 | |||
178 | #region SymbolN |
||
179 | case "SymControlN": |
||
180 | instance = SymControlN.FromString(item, brush, sProjectNo); |
||
181 | break; |
||
182 | #endregion |
||
183 | #endregion |
||
184 | |||
185 | #region Cad |
||
186 | case "InsideWhiteControl": |
||
187 | instance = InsideWhiteControl.FromString(item, brush, sProjectNo); |
||
188 | break; |
||
189 | case "OverlapWhiteControl": |
||
190 | instance = OverlapWhiteControl.FromString(item, brush, sProjectNo); |
||
191 | break; |
||
192 | case "ClipWhiteControl": |
||
193 | instance = ClipWhiteControl.FromString(item, brush, sProjectNo); |
||
194 | break; |
||
195 | case "CoordinateControl": |
||
196 | instance = CoordinateControl.FromString(item, brush, sProjectNo); |
||
197 | break; |
||
198 | #endregion |
||
199 | default: |
||
200 | break; |
||
201 | } |
||
202 | |||
203 | return instance; |
||
204 | } |
||
205 | |||
206 | /// <summary> |
||
207 | /// 데이터베이스의 마크업데이터를 컨트롤로 변환한다. |
||
208 | /// </summary> |
||
209 | /// <param name="MarkupString"></param> |
||
210 | a1e2ba68 | taeseongkim | public static async Task<bool> ParseAsync(string baseUri, string sProjectNo, string MarkupString, Canvas Layer,double PageAngle, string DisplayColor, string ToolTipMessage, System.Threading.CancellationToken cts) |
211 | 661b7416 | humkyung | { |
212 | e1c892f7 | taeseongkim | bool result = false; |
213 | |||
214 | 661b7416 | humkyung | if (MarkupString != "False") |
215 | { |
||
216 | SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor)); |
||
217 | 787a4489 | KangIngu | //SolidColorBrush _SetColor = new SolidColorBrush(Colors.Red); |
218 | 661b7416 | humkyung | string[] delimiterChars = { "|DZ|" }; |
219 | string[] delimiterChars2 = { "|" }; |
||
220 | 5529d2a2 | humkyung | string[] tokens = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
221 | 661b7416 | humkyung | |
222 | 5529d2a2 | humkyung | foreach (var token in tokens) |
223 | 661b7416 | humkyung | { |
224 | 24c5e56c | taeseongkim | var item = await JsonSerializerHelper.UnCompressStringAsync(token,cts); //언패킹작업 |
225 | a1e2ba68 | taeseongkim | CommentUserInfo control = MarkupParser.FromString(baseUri, item, _SetColor, sProjectNo,PageAngle); |
226 | 24c5e56c | taeseongkim | |
227 | 661b7416 | humkyung | if (control != null) |
228 | { |
||
229 | 5529d2a2 | humkyung | Layer.Children.Add(control); |
230 | 661b7416 | humkyung | control.ApplyTemplate(); |
231 | control.SetValue(ToolTipService.ToolTipProperty, ToolTipMessage); |
||
232 | |||
233 | if (control is ArrowTextControl) |
||
234 | { |
||
235 | ArrowTextControl _instance = control as ArrowTextControl; |
||
236 | if (_instance.UnderLine == TextDecorations.Underline) |
||
237 | { |
||
238 | _instance.Base_TextBox.TextDecorations = _instance.UnderLine; |
||
239 | } |
||
240 | _instance.Base_TextBox.IsHitTestVisible = false; |
||
241 | } |
||
242 | else if (control is TextControl) |
||
243 | { |
||
244 | TextControl text = control as TextControl; |
||
245 | text.Base_TextBlock.TextDecorations = text.UnderLine; |
||
246 | text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0); |
||
247 | text.Base_TextBox.Visibility = Visibility.Collapsed; |
||
248 | text.Base_TextBlock.Visibility = Visibility.Visible; |
||
249 | } |
||
250 | else if (control is SymControlN) |
||
251 | { |
||
252 | SymControlN _instance = control as SymControlN; |
||
253 | |||
254 | cd988cd8 | djkim | var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData); |
255 | |||
256 | 661b7416 | humkyung | System.IO.MemoryStream stream = new System.IO.MemoryStream(); |
257 | System.IO.StreamWriter writer = new System.IO.StreamWriter(stream); |
||
258 | writer.Write(xamlData); |
||
259 | writer.Flush(); |
||
260 | stream.Position = 0; |
||
261 | |||
262 | object obj = XamlReader.Load(stream); |
||
263 | _instance.Base_ViewBox.Child = obj as UIElement; |
||
264 | _instance.SetViewBox(); |
||
265 | } |
||
266 | a1e2ba68 | taeseongkim | else if(control is ImgControl) |
267 | { |
||
268 | |||
269 | } |
||
270 | e1c892f7 | taeseongkim | |
271 | result = true; |
||
272 | 661b7416 | humkyung | } |
273 | } |
||
274 | } |
||
275 | e1c892f7 | taeseongkim | |
276 | return result; |
||
277 | 787a4489 | KangIngu | } |
278 | b200de5a | KangIngu | |
279 | 787a4489 | KangIngu | /// <summary> |
280 | /// 데이터베이스의 마크업데이터를 컨트롤로 변환한다. |
||
281 | /// </summary> |
||
282 | /// <param name="MarkupString"></param> |
||
283 | 43e1d368 | taeseongkim | public static async Task<Control> ParseExAsync(string baseUri, System.Threading.CancellationToken? cts,string sProjectNo, string MarkupString, ObservableCollection<CommentUserInfo> baseLayer,double PageAngle, string DisplayColor, string ToolTipMessage, string markupInfoID = null, string commentId = null,Dictionary<string,string> STAMP_Contents = null) |
284 | 787a4489 | KangIngu | { |
285 | 5529d2a2 | humkyung | Control res = null; |
286 | |||
287 | 787a4489 | KangIngu | if (MarkupString != "False") |
288 | { |
||
289 | SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor)); |
||
290 | string[] delimiterChars = { "|DZ|" }; |
||
291 | string[] delimiterChars2 = { "|" }; |
||
292 | string[] data = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
||
293 | |||
294 | foreach (var dataPease in data) |
||
295 | { |
||
296 | 24c5e56c | taeseongkim | string item = ""; |
297 | 1edefbdf | taeseongkim | item = await JsonSerializerHelper.UnCompressStringAsync(dataPease, null); //언패킹작업 |
298 | //if (cts == null) |
||
299 | //{ |
||
300 | // item = await JsonSerializerHelper.UnCompressStringAsync(dataPease, null); //언패킹작업 |
||
301 | //} |
||
302 | //else |
||
303 | //{ |
||
304 | // if(cts.Value.IsCancellationRequested) |
||
305 | // { |
||
306 | // return null; |
||
307 | // } |
||
308 | 24c5e56c | taeseongkim | |
309 | 1edefbdf | taeseongkim | // item = await JsonSerializerHelper.UnCompressStringAsync(dataPease, cts); //언패킹작업 |
310 | //} |
||
311 | 366f00c2 | taeseongkim | |
312 | a1e2ba68 | taeseongkim | CommentUserInfo control = MarkupParser.FromString(baseUri, item, _SetColor, sProjectNo, PageAngle); |
313 | 366f00c2 | taeseongkim | |
314 | 5529d2a2 | humkyung | res = control as Control; |
315 | if (control != null) |
||
316 | 787a4489 | KangIngu | { |
317 | 5529d2a2 | humkyung | if (!string.IsNullOrEmpty(commentId)) control.CommentID = commentId; |
318 | if (!string.IsNullOrEmpty(markupInfoID)) control.MarkupInfoID = markupInfoID; |
||
319 | c00d0547 | humkyung | if (baseLayer != null) |
320 | 5529d2a2 | humkyung | { |
321 | c00d0547 | humkyung | baseLayer.Add(control); |
322 | control.ApplyTemplate(); |
||
323 | |||
324 | if (control is ArrowTextControl) |
||
325 | 684ef11c | ljiyeon | { |
326 | c00d0547 | humkyung | ArrowTextControl _instance = control as ArrowTextControl; |
327 | if (_instance.UnderLine == TextDecorations.Underline) |
||
328 | { |
||
329 | _instance.Base_TextBox.TextDecorations = _instance.UnderLine; |
||
330 | } |
||
331 | _instance.Base_TextBox.IsHitTestVisible = false; |
||
332 | 684ef11c | ljiyeon | } |
333 | c00d0547 | humkyung | else if (control is TextControl) |
334 | { |
||
335 | TextControl text = control as TextControl; |
||
336 | text.Base_TextBlock.TextDecorations = text.UnderLine; |
||
337 | text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0); |
||
338 | text.Base_TextBox.Visibility = Visibility.Collapsed; |
||
339 | text.Base_TextBlock.Visibility = Visibility.Visible; |
||
340 | } |
||
341 | else if (control is SymControlN) |
||
342 | { |
||
343 | SymControlN _instance = control as SymControlN; |
||
344 | 787a4489 | KangIngu | |
345 | cd988cd8 | djkim | var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData); |
346 | |||
347 | c00d0547 | humkyung | System.IO.MemoryStream stream = new System.IO.MemoryStream(); |
348 | System.IO.StreamWriter writer = new System.IO.StreamWriter(stream); |
||
349 | 58b52175 | ljiyeon | xamlData = xamlData.Replace("#FFFF0000", DisplayColor); |
350 | 43e1d368 | taeseongkim | |
351 | if (STAMP_Contents?.Count > 0) |
||
352 | { |
||
353 | foreach (var Content in STAMP_Contents) |
||
354 | { |
||
355 | xamlData = xamlData.Replace(Content.Key, System.Security.SecurityElement.Escape(Content.Value)); |
||
356 | } |
||
357 | } |
||
358 | |||
359 | c00d0547 | humkyung | writer.Write(xamlData); |
360 | writer.Flush(); |
||
361 | stream.Position = 0; |
||
362 | 661b7416 | humkyung | |
363 | c00d0547 | humkyung | object obj = XamlReader.Load(stream); |
364 | _instance.Base_ViewBox.Child = obj as UIElement; |
||
365 | _instance.SetViewBox(); |
||
366 | } |
||
367 | 5529d2a2 | humkyung | } |
368 | 661b7416 | humkyung | } |
369 | } |
||
370 | } |
||
371 | |||
372 | 5529d2a2 | humkyung | return res; |
373 | 661b7416 | humkyung | } |
374 | |||
375 | 24c5e56c | taeseongkim | public static async Task<S_BaseControl> GetBaseControlAsync(string MarkupString, System.Threading.CancellationToken cts) |
376 | 661b7416 | humkyung | { |
377 | 24c5e56c | taeseongkim | var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString,cts); //언패킹작업 |
378 | 661b7416 | humkyung | var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
379 | return unknownData; |
||
380 | } |
||
381 | 787a4489 | KangIngu | |
382 | ac4f1e13 | taeseongkim | public static async Task<string> GetMemoAsync(string MarkupString) |
383 | 5529d2a2 | humkyung | { |
384 | 24c5e56c | taeseongkim | var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString,null); //언패킹작업 |
385 | 5529d2a2 | humkyung | var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
386 | return unknownData.Memo; |
||
387 | } |
||
388 | 684ef11c | ljiyeon | |
389 | 5529d2a2 | humkyung | //GUID생성(최민수 사원 수정) |
390 | private static string shortGuid() |
||
391 | { |
||
392 | byte[] bytes = new byte[16]; |
||
393 | using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create()) |
||
394 | { |
||
395 | provider.GetBytes(bytes); |
||
396 | } |
||
397 | 661b7416 | humkyung | |
398 | 5529d2a2 | humkyung | var guid = new Guid(bytes); |
399 | 787a4489 | KangIngu | |
400 | 5529d2a2 | humkyung | return Convert.ToBase64String(guid.ToByteArray()) |
401 | .Substring(0, 10) |
||
402 | .Replace("/", "") |
||
403 | .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
||
404 | 787a4489 | KangIngu | } |
405 | } |
||
406 | 5529d2a2 | humkyung | } |