markus / MarkupToPDF / Controls / Parsing / MarkupParse.cs @ 0d2d2a08
이력 | 보기 | 이력해설 | 다운로드 (16.8 KB)
1 |
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 |
using MarkupToPDF.Controls.Cad; |
30 |
using MarkupToPDF.Controls.Common; |
31 |
using System.Threading.Tasks; |
32 |
|
33 |
namespace MarkupToPDF.Controls.Parsing |
34 |
{ |
35 |
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 |
Data.DATA_TYPE = (int)Control.ControlType; |
51 |
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 |
/// <summary> |
63 |
/// create a commentuserinfo from given string |
64 |
/// </summary> |
65 |
/// <param name="str"></param> |
66 |
/// <returns></returns> |
67 |
public static CommentUserInfo FromString(string baseUri,string item, SolidColorBrush brush, string sProjectNo,double PageAngle) |
68 |
{ |
69 |
CommentUserInfo instance = null; |
70 |
var unkown = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
71 |
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 |
instance = ArrowTextControl.FromString(item, brush, sProjectNo,PageAngle); |
145 |
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 |
instance = ImgControl.FromString(item, brush, sProjectNo, baseUri); |
165 |
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 |
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 |
{ |
212 |
bool result = false; |
213 |
|
214 |
if (MarkupString != "False") |
215 |
{ |
216 |
SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor)); |
217 |
//SolidColorBrush _SetColor = new SolidColorBrush(Colors.Red); |
218 |
string[] delimiterChars = { "|DZ|" }; |
219 |
string[] delimiterChars2 = { "|" }; |
220 |
string[] tokens = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries); |
221 |
|
222 |
foreach (var token in tokens) |
223 |
{ |
224 |
var item = await JsonSerializerHelper.UnCompressStringAsync(token,cts); //언패킹작업 |
225 |
CommentUserInfo control = MarkupParser.FromString(baseUri, item, _SetColor, sProjectNo,PageAngle); |
226 |
|
227 |
if (control != null) |
228 |
{ |
229 |
Layer.Children.Add(control); |
230 |
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 |
var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData); |
255 |
|
256 |
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 |
else if(control is ImgControl) |
267 |
{ |
268 |
|
269 |
} |
270 |
|
271 |
result = true; |
272 |
} |
273 |
} |
274 |
} |
275 |
|
276 |
return result; |
277 |
} |
278 |
|
279 |
/// <summary> |
280 |
/// 데이터베이스의 마크업데이터를 컨트롤로 변환한다. |
281 |
/// </summary> |
282 |
/// <param name="MarkupString"></param> |
283 |
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 |
{ |
285 |
Control res = null; |
286 |
|
287 |
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 |
string item = ""; |
297 |
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 |
|
309 |
// item = await JsonSerializerHelper.UnCompressStringAsync(dataPease, cts); //언패킹작업 |
310 |
//} |
311 |
|
312 |
CommentUserInfo control = MarkupParser.FromString(baseUri, item, _SetColor, sProjectNo, PageAngle); |
313 |
|
314 |
res = control as Control; |
315 |
if (control != null) |
316 |
{ |
317 |
if (!string.IsNullOrEmpty(commentId)) control.CommentID = commentId; |
318 |
if (!string.IsNullOrEmpty(markupInfoID)) control.MarkupInfoID = markupInfoID; |
319 |
if (baseLayer != null) |
320 |
{ |
321 |
baseLayer.Add(control); |
322 |
control.ApplyTemplate(); |
323 |
|
324 |
if (control is ArrowTextControl) |
325 |
{ |
326 |
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 |
} |
333 |
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 |
|
345 |
var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData); |
346 |
|
347 |
System.IO.MemoryStream stream = new System.IO.MemoryStream(); |
348 |
System.IO.StreamWriter writer = new System.IO.StreamWriter(stream); |
349 |
xamlData = xamlData.Replace("#FFFF0000", DisplayColor); |
350 |
|
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 |
writer.Write(xamlData); |
360 |
writer.Flush(); |
361 |
stream.Position = 0; |
362 |
|
363 |
object obj = XamlReader.Load(stream); |
364 |
_instance.Base_ViewBox.Child = obj as UIElement; |
365 |
_instance.SetViewBox(); |
366 |
} |
367 |
} |
368 |
} |
369 |
} |
370 |
} |
371 |
|
372 |
return res; |
373 |
} |
374 |
|
375 |
public static async Task<S_BaseControl> GetBaseControlAsync(string MarkupString, System.Threading.CancellationToken cts) |
376 |
{ |
377 |
var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString,cts); //언패킹작업 |
378 |
var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
379 |
return unknownData; |
380 |
} |
381 |
|
382 |
public static async Task<string> GetMemoAsync(string MarkupString) |
383 |
{ |
384 |
var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString,null); //언패킹작업 |
385 |
var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업 |
386 |
return unknownData.Memo; |
387 |
} |
388 |
|
389 |
//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 |
|
398 |
var guid = new Guid(bytes); |
399 |
|
400 |
return Convert.ToBase64String(guid.ToByteArray()) |
401 |
.Substring(0, 10) |
402 |
.Replace("/", "") |
403 |
.Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x"); |
404 |
} |
405 |
} |
406 |
} |