프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (15.1 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 53880c83 ljiyeon
using Svg2Xaml;
30 684ef11c ljiyeon
using MarkupToPDF.Controls.Cad;
31 40d88a02 ljiyeon
using MarkupToPDF.Controls.Common;
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
        public static CommentUserInfo FromString(string item, SolidColorBrush brush, string sProjectNo)
68
        {
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
                    instance = ArrowTextControl.FromString(item, brush, sProjectNo);
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);
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 5529d2a2 humkyung
        public static void Parse(string sProjectNo, string MarkupString, Canvas Layer, string DisplayColor, string ToolTipMessage)
211 661b7416 humkyung
        {
212
            if (MarkupString != "False")
213
            {
214
                SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor));
215 787a4489 KangIngu
                //SolidColorBrush _SetColor = new SolidColorBrush(Colors.Red);
216 661b7416 humkyung
                string[] delimiterChars = { "|DZ|" };
217
                string[] delimiterChars2 = { "|" };
218 5529d2a2 humkyung
                string[] tokens = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
219 661b7416 humkyung
220 5529d2a2 humkyung
                foreach (var token in tokens)
221 661b7416 humkyung
                {
222 5529d2a2 humkyung
                    var item = JsonSerializerHelper.UnCompressString(token); //언패킹작업
223 661b7416 humkyung
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
224
                    if (control != null)
225
                    {
226 5529d2a2 humkyung
                        Layer.Children.Add(control);
227 661b7416 humkyung
                        control.ApplyTemplate();
228
                        control.SetValue(ToolTipService.ToolTipProperty, ToolTipMessage);
229
230
                        if (control is ArrowTextControl)
231
                        {
232
                            ArrowTextControl _instance = control as ArrowTextControl;
233
                            if (_instance.UnderLine == TextDecorations.Underline)
234
                            {
235
                                _instance.Base_TextBox.TextDecorations = _instance.UnderLine;
236
                            }
237
                            _instance.Base_TextBox.IsHitTestVisible = false;
238
                        }
239
                        else if (control is TextControl)
240
                        {
241
                            TextControl text = control as TextControl;
242
                            text.Base_TextBlock.TextDecorations = text.UnderLine;
243
                            text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0);
244
                            text.Base_TextBox.Visibility = Visibility.Collapsed;
245
                            text.Base_TextBlock.Visibility = Visibility.Visible;
246
                        }
247
                        else if (control is SymControlN)
248
                        {
249
                            SymControlN _instance = control as SymControlN;
250
251 cd988cd8 djkim
                            var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData);
252
                            
253 661b7416 humkyung
                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
254
                            System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
255
                            writer.Write(xamlData);
256
                            writer.Flush();
257
                            stream.Position = 0;
258
259
                            object obj = XamlReader.Load(stream);
260
                            _instance.Base_ViewBox.Child = obj as UIElement;
261
                            _instance.SetViewBox();
262
                        }
263
                    }
264
                }
265
            }
266 787a4489 KangIngu
        }
267 b200de5a KangIngu
268 787a4489 KangIngu
        /// <summary>
269
        /// 데이터베이스의 마크업데이터를 컨트롤로 변환한다.
270
        /// </summary>
271
        /// <param name="MarkupString"></param>
272 5529d2a2 humkyung
        public static Control ParseEx(string sProjectNo, string MarkupString, ObservableCollection<CommentUserInfo> baseLayer, string DisplayColor, string ToolTipMessage, string markupInfoID = null, string commentId = null)
273 787a4489 KangIngu
        {
274 5529d2a2 humkyung
            Control res = null;
275
276 787a4489 KangIngu
            if (MarkupString != "False")
277
            {
278
                SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor));
279
                string[] delimiterChars = { "|DZ|" };
280
                string[] delimiterChars2 = { "|" };
281
                string[] data = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
282
283
                foreach (var dataPease in data)
284
                {
285
                    var item = JsonSerializerHelper.UnCompressString(dataPease); //언패킹작업
286 5529d2a2 humkyung
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
287
                    res = control as Control;
288
                    if (control != null)
289 787a4489 KangIngu
                    {
290 5529d2a2 humkyung
                        if (!string.IsNullOrEmpty(commentId)) control.CommentID = commentId;
291
                        if (!string.IsNullOrEmpty(markupInfoID)) control.MarkupInfoID = markupInfoID;
292 c00d0547 humkyung
                        if (baseLayer != null)
293 5529d2a2 humkyung
                        {
294 c00d0547 humkyung
                            baseLayer.Add(control);
295
                            control.ApplyTemplate();
296
297
                            if (control is ArrowTextControl)
298 684ef11c ljiyeon
                            {
299 c00d0547 humkyung
                                ArrowTextControl _instance = control as ArrowTextControl;
300
                                if (_instance.UnderLine == TextDecorations.Underline)
301
                                {
302
                                    _instance.Base_TextBox.TextDecorations = _instance.UnderLine;
303
                                }
304
                                _instance.Base_TextBox.IsHitTestVisible = false;
305 684ef11c ljiyeon
                            }
306 c00d0547 humkyung
                            else if (control is TextControl)
307
                            {
308
                                TextControl text = control as TextControl;
309
                                text.Base_TextBlock.TextDecorations = text.UnderLine;
310
                                text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0);
311
                                text.Base_TextBox.Visibility = Visibility.Collapsed;
312
                                text.Base_TextBlock.Visibility = Visibility.Visible;
313
                            }
314
                            else if (control is SymControlN)
315
                            {
316
                                SymControlN _instance = control as SymControlN;
317 787a4489 KangIngu
318 cd988cd8 djkim
                                var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData);
319
                                
320 c00d0547 humkyung
                                System.IO.MemoryStream stream = new System.IO.MemoryStream();
321
                                System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
322
                                writer.Write(xamlData);
323
                                writer.Flush();
324
                                stream.Position = 0;
325 661b7416 humkyung
326 c00d0547 humkyung
                                object obj = XamlReader.Load(stream);
327
                                _instance.Base_ViewBox.Child = obj as UIElement;
328
                                _instance.SetViewBox();
329
                            }
330 5529d2a2 humkyung
                        }
331 661b7416 humkyung
                    }
332
                }
333
            }
334
335 5529d2a2 humkyung
            return res;
336 661b7416 humkyung
        }
337
338 5529d2a2 humkyung
        public static S_BaseControl GetBaseControl(string MarkupString)
339 661b7416 humkyung
        {
340
            var item = JsonSerializerHelper.UnCompressString(MarkupString); //언패킹작업
341
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
342
            return unknownData;
343
        }
344 787a4489 KangIngu
345 5529d2a2 humkyung
        public static string GetMemo(string MarkupString)
346
        {
347
            var item = JsonSerializerHelper.UnCompressString(MarkupString); //언패킹작업
348
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
349
            return unknownData.Memo;
350
        }
351 684ef11c ljiyeon
352 5529d2a2 humkyung
        //GUID생성(최민수 사원 수정)
353
        private static string shortGuid()
354
        {
355
            byte[] bytes = new byte[16];
356
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
357
            {
358
                provider.GetBytes(bytes);
359
            }
360 661b7416 humkyung
361 5529d2a2 humkyung
            var guid = new Guid(bytes);
362 787a4489 KangIngu
363 5529d2a2 humkyung
            return Convert.ToBase64String(guid.ToByteArray())
364
                .Substring(0, 10)
365
                .Replace("/", "")
366
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
367 787a4489 KangIngu
        }
368
    }
369 5529d2a2 humkyung
}
클립보드 이미지 추가 (최대 크기: 500 MB)