프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Parsing / MarkupParse.cs @ a9a82876

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