markus / MarkupDataParse / MarkupDataFunctions.cs @ master
이력 | 보기 | 이력해설 | 다운로드 (2.41 KB)
1 |
using Microsoft.SqlServer.Server; |
---|---|
2 |
using System; |
3 |
using System.IO; |
4 |
using System.IO.Compression; |
5 |
using System.Runtime.Serialization.Json; |
6 |
using System.Text; |
7 |
|
8 |
namespace MarkupDataParse |
9 |
{ |
10 |
public class MarkupDataFunctions |
11 |
{ |
12 |
[SqlFunction] |
13 |
public static string CompressString(string str) |
14 |
{ |
15 |
string result = null; |
16 |
|
17 |
using (MemoryStream outStream = new MemoryStream()) |
18 |
{ |
19 |
using (GZipStream gzipStream = new GZipStream(outStream, CompressionMode.Compress)) |
20 |
using (MemoryStream srcStream = new MemoryStream(Encoding.UTF8.GetBytes(str))) |
21 |
srcStream.CopyTo(gzipStream); |
22 |
|
23 |
result = Convert.ToBase64String(outStream.ToArray()); |
24 |
} |
25 |
|
26 |
return result; |
27 |
} |
28 |
|
29 |
[SqlFunction] |
30 |
public static string DecompressString(string str) |
31 |
{ |
32 |
string result = null; |
33 |
|
34 |
str = str.Replace("|DZ|", ""); |
35 |
|
36 |
byte[] buffer = Convert.FromBase64String(str); |
37 |
using (MemoryStream outStream = new MemoryStream()) |
38 |
{ |
39 |
using (GZipStream gzipStream = new GZipStream(new MemoryStream(buffer), CompressionMode.Decompress)) |
40 |
gzipStream.CopyTo(outStream); |
41 |
|
42 |
result = Encoding.UTF8.GetString(outStream.ToArray()); |
43 |
} |
44 |
|
45 |
return result; |
46 |
} |
47 |
|
48 |
[SqlFunction] |
49 |
public static string GetMarkupText(string str) |
50 |
{ |
51 |
string result = null; |
52 |
|
53 |
var markupdata = DecompressString(str); |
54 |
|
55 |
//var control = Newtonsoft.Json.JsonConvert.DeserializeObject<TextControl>(markupdata); |
56 |
//result = control.Text; |
57 |
|
58 |
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TextControl)); |
59 |
|
60 |
using (MemoryStream mstream = new MemoryStream(Encoding.Unicode.GetBytes(markupdata))) |
61 |
{ |
62 |
var control = (TextControl)serializer.ReadObject(mstream); |
63 |
|
64 |
if (control.Text != null) |
65 |
{ |
66 |
result = control.Text; |
67 |
} |
68 |
else if(control.ArrowText != null) |
69 |
{ |
70 |
result = control.ArrowText; |
71 |
} |
72 |
|
73 |
} |
74 |
|
75 |
return result; |
76 |
} |
77 |
} |
78 |
|
79 |
public class TextControl |
80 |
{ |
81 |
public string Text { get; set; } |
82 |
public string ArrowText { get; set; } |
83 |
} |
84 |
} |