From cfaf0bdd1419def6cd19b34440a1e83b4f258732 Mon Sep 17 00:00:00 2001 From: syneffort Date: Wed, 17 Aug 2022 18:07:15 +0900 Subject: [PATCH] proxy pattern --- DesignPattern/DesignPattern.sln | 6 ++ DesignPattern/Proxy/App.config | 6 ++ DesignPattern/Proxy/Client.cs | 19 +++++++ DesignPattern/Proxy/IWeb.cs | 13 +++++ DesignPattern/Proxy/Program.cs | 23 ++++++++ .../Proxy/Properties/AssemblyInfo.cs | 36 ++++++++++++ DesignPattern/Proxy/Proxy.csproj | 57 +++++++++++++++++++ DesignPattern/Proxy/ProxyWeb.cs | 28 +++++++++ DesignPattern/Proxy/RealWeb.cs | 19 +++++++ 9 files changed, 207 insertions(+) create mode 100644 DesignPattern/Proxy/App.config create mode 100644 DesignPattern/Proxy/Client.cs create mode 100644 DesignPattern/Proxy/IWeb.cs create mode 100644 DesignPattern/Proxy/Program.cs create mode 100644 DesignPattern/Proxy/Properties/AssemblyInfo.cs create mode 100644 DesignPattern/Proxy/Proxy.csproj create mode 100644 DesignPattern/Proxy/ProxyWeb.cs create mode 100644 DesignPattern/Proxy/RealWeb.cs diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln index 8b7bb9d..22f1228 100644 --- a/DesignPattern/DesignPattern.sln +++ b/DesignPattern/DesignPattern.sln @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Decorator", "Decorator\Deco EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Facade", "Facade\Facade.csproj", "{968D6295-75C3-46FF-AAB9-1579DB405B31}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Proxy", "Proxy\Proxy.csproj", "{F6C67C41-900D-4606-A6D6-BA059D6485A0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -69,6 +71,10 @@ Global {968D6295-75C3-46FF-AAB9-1579DB405B31}.Debug|Any CPU.Build.0 = Debug|Any CPU {968D6295-75C3-46FF-AAB9-1579DB405B31}.Release|Any CPU.ActiveCfg = Release|Any CPU {968D6295-75C3-46FF-AAB9-1579DB405B31}.Release|Any CPU.Build.0 = Release|Any CPU + {F6C67C41-900D-4606-A6D6-BA059D6485A0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F6C67C41-900D-4606-A6D6-BA059D6485A0}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F6C67C41-900D-4606-A6D6-BA059D6485A0}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F6C67C41-900D-4606-A6D6-BA059D6485A0}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/DesignPattern/Proxy/App.config b/DesignPattern/Proxy/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/Proxy/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/Proxy/Client.cs b/DesignPattern/Proxy/Client.cs new file mode 100644 index 0000000..c0690a1 --- /dev/null +++ b/DesignPattern/Proxy/Client.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Proxy +{ + class Client + { + public static void HowToTest(string url) + { + IWeb web = new ProxyWeb(); + string result = web.Visit(url); + + Console.WriteLine(result); + } + } +} diff --git a/DesignPattern/Proxy/IWeb.cs b/DesignPattern/Proxy/IWeb.cs new file mode 100644 index 0000000..cfc2140 --- /dev/null +++ b/DesignPattern/Proxy/IWeb.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Proxy +{ + interface IWeb + { + string Visit(string url); + } +} diff --git a/DesignPattern/Proxy/Program.cs b/DesignPattern/Proxy/Program.cs new file mode 100644 index 0000000..55cba23 --- /dev/null +++ b/DesignPattern/Proxy/Program.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Proxy +{ + /* + * 카테고리: 구조 패턴 + * 개요: 클라이언트가 사용을 원하는 객체를 직접 사용하는것이 아니라 + * 객체에 대한 대리자(Proxy) 역할을 하는 객체를 두고 이를 통해 사용하는 방식 + */ + class Program + { + static void Main(string[] args) + { + Client.HowToTest("https://phishingsite.com"); + + Console.ReadKey(); + } + } +} diff --git a/DesignPattern/Proxy/Properties/AssemblyInfo.cs b/DesignPattern/Proxy/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..31a3ff4 --- /dev/null +++ b/DesignPattern/Proxy/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("Proxy")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Proxy")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("f6c67c41-900d-4606-a6d6-ba059d6485a0")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Proxy/Proxy.csproj b/DesignPattern/Proxy/Proxy.csproj new file mode 100644 index 0000000..5627d89 --- /dev/null +++ b/DesignPattern/Proxy/Proxy.csproj @@ -0,0 +1,57 @@ + + + + + Debug + AnyCPU + {F6C67C41-900D-4606-A6D6-BA059D6485A0} + Exe + Proxy + Proxy + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DesignPattern/Proxy/ProxyWeb.cs b/DesignPattern/Proxy/ProxyWeb.cs new file mode 100644 index 0000000..953b5f1 --- /dev/null +++ b/DesignPattern/Proxy/ProxyWeb.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Proxy +{ + class ProxyWeb : IWeb + { + private IWeb realWeb = new RealWeb(); + + List BAD_SITES = new List() + { + "https://hackersite.com", + "https://fraudsite.com", + "https://phishingsite.com" + }; + + public string Visit(string url) + { + if (BAD_SITES.Contains(url.ToLower())) + return "BAD_SITES"; + + return realWeb.Visit(url); + } + } +} diff --git a/DesignPattern/Proxy/RealWeb.cs b/DesignPattern/Proxy/RealWeb.cs new file mode 100644 index 0000000..21a9d73 --- /dev/null +++ b/DesignPattern/Proxy/RealWeb.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; + +namespace Proxy +{ + class RealWeb : IWeb + { + public string Visit(string url) + { + WebClient wc = new WebClient(); + + return wc.DownloadString(url); + } + } +}