프로젝트

일반

사용자정보

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

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

이력 | 보기 | 이력해설 | 다운로드 (15.3 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
using System.Threading.Tasks;
33

    
34
namespace MarkupToPDF.Controls.Parsing
35
{
36
    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
            MarkupReturn Data = new MarkupReturn();
50
            Data.ConvertData = "";
51
            Data.DATA_TYPE = (int)Control.ControlType;
52
            Data.CommentID = Control.CommentID;
53
            if (Data.CommentID == null)
54
            {
55
                Data.CommentID = shortGuid();
56
            }
57

    
58
            Data.ConvertData = Control.Serialize();
59

    
60
            return Data;
61
        }
62

    
63
        /// <summary>
64
        /// create a commentuserinfo from given string
65
        /// </summary>
66
        /// <param name="str"></param>
67
        /// <returns></returns>
68
        public static CommentUserInfo FromString(string item, SolidColorBrush brush, string sProjectNo)
69
        {
70
            CommentUserInfo instance = null;
71
            var unkown = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
72
            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
                    instance = ArrowTextControl.FromString(item, brush, sProjectNo);
146
                    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
                    instance = ImgControl.FromString(item, brush, sProjectNo);
166
                    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
        public static async Task ParseAsync(string sProjectNo, string MarkupString, Canvas Layer, string DisplayColor, string ToolTipMessage)
212
        {
213
            if (MarkupString != "False")
214
            {
215
                SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor));
216
                //SolidColorBrush _SetColor = new SolidColorBrush(Colors.Red);
217
                string[] delimiterChars = { "|DZ|" };
218
                string[] delimiterChars2 = { "|" };
219
                string[] tokens = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
220

    
221
                foreach (var token in tokens)
222
                {
223
                    var item = await JsonSerializerHelper.UnCompressStringAsync(token); //언패킹작업
224
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
225
                    if (control != null)
226
                    {
227
                        Layer.Children.Add(control);
228
                        control.ApplyTemplate();
229
                        control.SetValue(ToolTipService.ToolTipProperty, ToolTipMessage);
230

    
231
                        if (control is ArrowTextControl)
232
                        {
233
                            ArrowTextControl _instance = control as ArrowTextControl;
234
                            if (_instance.UnderLine == TextDecorations.Underline)
235
                            {
236
                                _instance.Base_TextBox.TextDecorations = _instance.UnderLine;
237
                            }
238
                            _instance.Base_TextBox.IsHitTestVisible = false;
239
                        }
240
                        else if (control is TextControl)
241
                        {
242
                            TextControl text = control as TextControl;
243
                            text.Base_TextBlock.TextDecorations = text.UnderLine;
244
                            text.Base_TextBlock.Margin = new Thickness(0, 0, 10, 0);
245
                            text.Base_TextBox.Visibility = Visibility.Collapsed;
246
                            text.Base_TextBlock.Visibility = Visibility.Visible;
247
                        }
248
                        else if (control is SymControlN)
249
                        {
250
                            SymControlN _instance = control as SymControlN;
251

    
252
                            var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData);
253
                            
254
                            System.IO.MemoryStream stream = new System.IO.MemoryStream();
255
                            System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
256
                            writer.Write(xamlData);
257
                            writer.Flush();
258
                            stream.Position = 0;
259

    
260
                            object obj = XamlReader.Load(stream);
261
                            _instance.Base_ViewBox.Child = obj as UIElement;
262
                            _instance.SetViewBox();
263
                        }
264
                    }
265
                }
266
            }
267
        }
268

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

    
277
            if (MarkupString != "False")
278
            {
279
                SolidColorBrush _SetColor = new SolidColorBrush(Common.ValueConverter.StringToColorConverter.Parse(DisplayColor));
280
                string[] delimiterChars = { "|DZ|" };
281
                string[] delimiterChars2 = { "|" };
282
                string[] data = MarkupString.Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
283

    
284
                foreach (var dataPease in data)
285
                {
286
                    var item = await JsonSerializerHelper.UnCompressStringAsync(dataPease); //언패킹작업
287
                    CommentUserInfo control = MarkupParser.FromString(item, _SetColor, sProjectNo);
288
                    res = control as Control;
289
                    if (control != null)
290
                    {
291
                        if (!string.IsNullOrEmpty(commentId)) control.CommentID = commentId;
292
                        if (!string.IsNullOrEmpty(markupInfoID)) control.MarkupInfoID = markupInfoID;
293
                        if (baseLayer != null)
294
                        {
295
                            baseLayer.Add(control);
296
                            control.ApplyTemplate();
297

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

    
319
                                var xamlData = MarkupToPDF.Serialize.Core.JsonSerializerHelper.UnCompressStamp(_instance.PathXathData);
320
                                
321
                                System.IO.MemoryStream stream = new System.IO.MemoryStream();
322
                                System.IO.StreamWriter writer = new System.IO.StreamWriter(stream);
323
                                xamlData = xamlData.Replace("#FFFF0000", DisplayColor);
324
                                writer.Write(xamlData);
325
                                writer.Flush();
326
                                stream.Position = 0;
327

    
328
                                object obj = XamlReader.Load(stream);
329
                                _instance.Base_ViewBox.Child = obj as UIElement;
330
                                _instance.SetViewBox();
331
                            }
332
                        }
333
                    }
334
                }
335
            }
336

    
337
            return res;
338
        }
339

    
340
        public static async Task<S_BaseControl> GetBaseControlAsync(string MarkupString)
341
        {
342
            var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString); //언패킹작업
343
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
344
            return unknownData;
345
        }
346

    
347
        public static async Task<string> GetMemoAsync(string MarkupString)
348
        {
349
            var item = await JsonSerializerHelper.UnCompressStringAsync(MarkupString); //언패킹작업
350
            var unknownData = JsonSerializerHelper.JsonDeserialize<S_BaseControl>(item); //복호화작업
351
            return unknownData.Memo;
352
        }
353

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

    
363
            var guid = new Guid(bytes);
364

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