프로젝트

일반

사용자정보

개정판 c095f3cb

IDc095f3cbdb2be782d73fa429b596929532299645
상위 66bd3240
하위 f1f822e9

김태성이(가) 일년 이상 전에 추가함

issue #0000 database markup Data SQL function

Change-Id: Ifcb29fadc40de92bd4a79d8fe235f6d308ee368c

차이점 보기:

MarkupDataParse/InsertAss.SQL
1

2
exec sp_configure
3

  
4
exec sp_configure 'clr enabled',1
5
reconfigure with override
6

  
7

  
8
exec sp_configure 'show advanced options',1
9
reconfigure with override
10

  
11

  
12
exec sp_configure 'clr strict security',0;
13
reconfigure with override
14

  
15

  
16
USE master;   
17
GO    
18

  
19
CREATE ASSEMBLY MarkupDataParse 
20
FROM 'D:\Markus_V3\dbFunctions\MarkupDataParse.dll'
21
WITH PERMISSION_SET = SAFE;  
22

  
23
-- dll 트러스터 오류 발생시/ 어셈블리 참조를 찾지 못한다고 나오는 경우
24
EXEC sp_changedbowner 'sa'
25
ALTER DATABASE [markus_SEC] SET TRUSTWORTHY ON;
26

  
27
-- 특정 .net dll을 못찾는 경우 select * from sys.dm_clr_properties로 .net framework의 경로에 들어가서 복사한다.
28

  
29
select * from sys.assemblies
30

  
31
USE markus_SEC;   
32
GO    
33

  
34
CREATE FUNCTION MarkupDataCompress(@inputString NVARCHAR(MAX))
35
RETURNS NVARCHAR(MAX)
36
AS EXTERNAL NAME MarkupDataParse.[MarkupDataParse.MarkupDataFunctions].CompressString;
MarkupDataParse/MarkupDataFunctions.cs
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
}
MarkupDataParse/MarkupDataParse.csproj
1
<?xml version="1.0" encoding="utf-8"?>
2
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4
  <PropertyGroup>
5
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7
    <ProjectGuid>{C8BB3E31-C512-4B87-B78F-6042A02594B0}</ProjectGuid>
8
    <OutputType>Library</OutputType>
9
    <AppDesignerFolder>Properties</AppDesignerFolder>
10
    <RootNamespace>MarkupDataParse</RootNamespace>
11
    <AssemblyName>MarkupDataParse</AssemblyName>
12
    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13
    <FileAlignment>512</FileAlignment>
14
    <Deterministic>true</Deterministic>
15
    <TargetFrameworkProfile>
16
    </TargetFrameworkProfile>
17
  </PropertyGroup>
18
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19
    <DebugSymbols>true</DebugSymbols>
20
    <DebugType>full</DebugType>
21
    <Optimize>false</Optimize>
22
    <OutputPath>bin\Debug\</OutputPath>
23
    <DefineConstants>DEBUG;TRACE</DefineConstants>
24
    <ErrorReport>prompt</ErrorReport>
25
    <WarningLevel>4</WarningLevel>
26
    <Prefer32Bit>false</Prefer32Bit>
27
    <PlatformTarget>AnyCPU</PlatformTarget>
28
  </PropertyGroup>
29
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30
    <DebugType>pdbonly</DebugType>
31
    <Optimize>true</Optimize>
32
    <OutputPath>bin\Release\</OutputPath>
33
    <DefineConstants>TRACE</DefineConstants>
34
    <ErrorReport>prompt</ErrorReport>
35
    <WarningLevel>4</WarningLevel>
36
    <Prefer32Bit>false</Prefer32Bit>
37
  </PropertyGroup>
38
  <PropertyGroup>
39
    <SignAssembly>true</SignAssembly>
40
  </PropertyGroup>
41
  <PropertyGroup>
42
    <AssemblyOriginatorKeyFile>MarkupDataParseKey.pfx</AssemblyOriginatorKeyFile>
43
  </PropertyGroup>
44
  <PropertyGroup>
45
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
46
  </PropertyGroup>
47
  <ItemGroup>
48
    <Reference Include="System" />
49
    <Reference Include="System.Core" />
50
    <Reference Include="System.Runtime.Serialization" />
51
    <Reference Include="System.Xml.Linq" />
52
    <Reference Include="System.Data.DataSetExtensions" />
53
    <Reference Include="Microsoft.CSharp" />
54
    <Reference Include="System.Data" />
55
    <Reference Include="System.Net.Http" />
56
    <Reference Include="System.Xml" />
57
  </ItemGroup>
58
  <ItemGroup>
59
    <Compile Include="MarkupDataFunctions.cs" />
60
    <Compile Include="Properties\AssemblyInfo.cs" />
61
  </ItemGroup>
62
  <ItemGroup>
63
    <None Include="MarkupDataParseKey.pfx" />
64
    <None Include="package.nuspec" />
65
  </ItemGroup>
66
  <ItemGroup>
67
    <Content Include="InsertAss.SQL" />
68
  </ItemGroup>
69
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
70
</Project>
MarkupDataParse/Properties/AssemblyInfo.cs
1
using System.Reflection;
2
using System.Runtime.CompilerServices;
3
using System.Runtime.InteropServices;
4

  
5
// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 
6
// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면
7
// 이러한 특성 값을 변경하세요.
8
[assembly: AssemblyTitle("MarkupDataParse")]
9
[assembly: AssemblyDescription("")]
10
[assembly: AssemblyConfiguration("")]
11
[assembly: AssemblyCompany("")]
12
[assembly: AssemblyProduct("MarkupDataParse")]
13
[assembly: AssemblyCopyright("Copyright ©  2023")]
14
[assembly: AssemblyTrademark("")]
15
[assembly: AssemblyCulture("")]
16

  
17
// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 
18
// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면
19
// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요.
20
[assembly: ComVisible(false)]
21

  
22
// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다.
23
[assembly: Guid("c8bb3e31-c512-4b87-b78f-6042a02594b0")]
24

  
25
// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다.
26
//
27
//      주 버전
28
//      부 버전 
29
//      빌드 번호
30
//      수정 버전
31
//
32
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
33
// 기본값으로 할 수 있습니다.
34
// [assembly: AssemblyVersion("1.0.*")]
35
[assembly: AssemblyVersion("1.0.0.0")]
36
[assembly: AssemblyFileVersion("1.0.0.0")]
MarkupDataParse/package.nuspec
1
<?xml version="1.0"?>
2
<package>
3
  <metadata>
4
    <!--*-->
5
    <id>$id$</id>
6
    <!--*-->
7
    <version>$version$</version>
8
    <title></title>
9
    <!--*-->
10
    <authors>$author$</authors>
11
    <owners>$author$</owners>
12
<!--
13
    <licenseUrl></licenseUrl>
14
    <projectUrl></projectUrl>
15
    <iconUrl></iconUrl>
16
-->
17
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
18
    <!--*-->
19
    <description>$description$</description>
20
    <!--*-->
21
    <releaseNotes> </releaseNotes>
22
    <copyright>$copyright$</copyright>
23
    <tags> </tags>
24
    <dependencies>
25
      <!--
26
      <dependency id="SampleDependency" version="1.0" />
27
-->
28
    </dependencies>
29
  </metadata>
30
</package>
MarkupDataParseTest/MarkupDataParseTest.csproj
1
<Project Sdk="Microsoft.NET.Sdk">
2

  
3
  <PropertyGroup>
4
    <TargetFramework>net48</TargetFramework>
5

  
6
    <IsPackable>false</IsPackable>
7
  </PropertyGroup>
8

  
9
  <ItemGroup>
10
    <PackageReference Include="NUnit" Version="3.12.0" />
11
    <PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
12
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
13
  </ItemGroup>
14

  
15
  <ItemGroup>
16
    <ProjectReference Include="..\MarkupDataParse\MarkupDataParse.csproj" />
17
  </ItemGroup>
18

  
19
</Project>
MarkupDataParseTest/UnitTest1.cs
1
using NUnit.Framework;
2

  
3
namespace MarkupDataParseTest
4
{
5
    public class Tests
6
    {
7
        string markupData = "|DZ|H4sIAAAAAAAEAJVSwW4TMRD9lWi4gLC29tpee1cCqU0oQWoLIgEOFFVW4k0sNuvK60LaEokP4cIvwJkfoj/B7G5CgVPxxX5jzbw3b+Ya9utFZaGgBIbBmminboUQTvdGCO6zTAtNqeaKcv2Q5pQ+ON0DAk/q+Qvv6gjFNZytoWBcpQnlMhVCikxJqQmcXUKhM5ZozE0Fk5wqLTYEju3KQ1FfVBWBE9Ox7YfgP07tOg59HYOvkOH5uZlhXQIdz8Qi1dstV6pkInKVsVwJqaWQPZdSIhFMy5wLyaiWXG3ITl3KE5VlgqdMZJxKvlXHdMIEStaaphRRfptx137eEZhEE+LfdvyHRJgGUzelD6ttCaCfKBrwqrHh2Whn1GsbGufrHewMm8TLdnQpufUPs8c+uCu00VSDR48HH2yIbmaqm69fBjffP//89gNLH/gwt2Hirmwr+MDH6FdQoClHtozd46VbLPvX1J/jvWmT1mPbhzPdwTduHpeIMkFgZJplX7AXeOz+XZC7jwDaQt3EgUNrb/Dv7dBXPmDk3iEeigd/SmwTN6Z0C1wO3KX6YvXUx6Wb4d8JGmqqPx+SAg7LNYdubedQlKZqbIvH2NRR39jvWDeTLd78AsRac6QlAwAA";
8
        [SetUp]
9
        public void Setup()
10
        {
11
        }
12

  
13
        [Test]
14
        public void Test1()
15
        {
16
            var text =MarkupDataParse.MarkupDataFunctions.GetMarkupText(markupData);
17
            Assert.IsNotNull(text);
18
        }
19
    }
20
}

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)