프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Parsing / MarkupParse.cs @ 33df85e7

이력 | 보기 | 이력해설 | 다운로드 (15.1 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 Svg2Xaml;
30
using MarkupToPDF.Controls.Cad;
31
using MarkupToPDF.Controls.Common;
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 item, SolidColorBrush brush, string sProjectNo)
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);
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
        public static void Parse(string sProjectNo, string MarkupString, Canvas Layer, string DisplayColor, string ToolTipMessage)
211
        {
212
            if (MarkupString != "False")
213
            {
214
                SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor));
215
                //SolidColorBrush _SetColor = new SolidColorBrush(Colors.Red);
216
                string[] delimiterChars = { "|DZ|" };
217
                string[] delimiterChars2 = { "|" };
218
                string[] tokens = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
219

    
220
                foreach (var token in tokens)
221
                {
222
                    var item = JsonSerializerHelper.UnCompressString(token); //언패킹작업
223
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
224
                    if (control != null)
225
                    {
226
                        Layer.Children.Add(control);
227
                        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
                            var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(_instance.PathXathData);
252
                            xamlData = xamlData.Replace("daelim", "DAELIM");
253
                            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
        }
267

    
268
        /// <summary>
269
        /// 데이터베이스의 마크업데이터를 컨트롤로 변환한다.
270
        /// </summary>
271
        /// <param name="MarkupString"></param>
272
        public static Control ParseEx(string sProjectNo, string MarkupString, ObservableCollection<CommentUserInfo> baseLayer, string DisplayColor, string ToolTipMessage, string markupInfoID = null, string commentId = null)
273
        {
274
            Control res = null;
275

    
276
            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
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
287
                    res = control as Control;
288
                    if (control != null)
289
                    {
290
                        if (!string.IsNullOrEmpty(commentId)) control.CommentID = commentId;
291
                        if (!string.IsNullOrEmpty(markupInfoID)) control.MarkupInfoID = markupInfoID;
292
                        if(baseLayer != null) baseLayer.Add(control);
293
                        control.ApplyTemplate();
294
                        ///control.SetValue(ToolTipService.ToolTipProperty, ToolTipMessage);
295

    
296
                        if (control is ArrowTextControl)
297
                        {
298
                            ArrowTextControl _instance = control as ArrowTextControl;
299
                            if (_instance.UnderLine == TextDecorations.Underline)
300
                            {
301
                                _instance.Base_TextBox.TextDecorations = _instance.UnderLine;
302
                            }
303
                            _instance.Base_TextBox.IsHitTestVisible = false;
304
                        }
305
                        else if (control is TextControl)
306
                        {
307
                            TextControl text = control as TextControl;
308
                            text.Base_TextBlock.TextDecorations = text.UnderLine;
309
                            text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0);
310
                            text.Base_TextBox.Visibility = Visibility.Collapsed;
311
                            text.Base_TextBlock.Visibility = Visibility.Visible;
312
                        }
313
                        else if (control is SymControlN)
314
                        {
315
                            SymControlN _instance = control as SymControlN;
316

    
317
                            var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressString_NonPrefix(_instance.PathXathData);
318
                            xamlData = xamlData.Replace("daelim", "DAELIM");
319
                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
320
                            System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
321
                            writer.Write(xamlData);
322
                            writer.Flush();
323
                            stream.Position = 0;
324

    
325
                            object obj = XamlReader.Load(stream);
326
                            _instance.Base_ViewBox.Child = obj as UIElement;
327
                            _instance.SetViewBox();
328
                        }
329
                    }
330
                }
331
            }
332

    
333
            return res;
334
        }
335

    
336
        public static S_BaseControl GetBaseControl(string MarkupString)
337
        {
338
            var item = JsonSerializerHelper.UnCompressString(MarkupString); //언패킹작업
339
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
340
            return unknownData;
341
        }
342

    
343
        public static string GetMemo(string MarkupString)
344
        {
345
            var item = JsonSerializerHelper.UnCompressString(MarkupString); //언패킹작업
346
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
347
            return unknownData.Memo;
348
        }
349

    
350
        //GUID생성(최민수 사원 수정)
351
        private static string shortGuid()
352
        {
353
            byte[] bytes = new byte[16];
354
            using (var provider = System.Security.Cryptography.RandomNumberGenerator.Create())
355
            {
356
                provider.GetBytes(bytes);
357
            }
358

    
359
            var guid = new Guid(bytes);
360

    
361
            return Convert.ToBase64String(guid.ToByteArray())
362
                .Substring(0, 10)
363
                .Replace("/", "")
364
                .Replace("+", "") + DateTime.UtcNow.Ticks.ToString("x");
365
        }
366
    }
367
}
클립보드 이미지 추가 (최대 크기: 500 MB)