-
Notifications
You must be signed in to change notification settings - Fork 0
/
Proxy.cs
55 lines (44 loc) · 1.3 KB
/
Proxy.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.ComponentModel;
using System;
using System.Collections.Generic;
public class RunProxy : IDesingPattern
{
public void Run()
{
Console.WriteLine("Accessing site without protection proxy: ");
RealInternet ri = new RealInternet();
ri.connectTo("www.badsite.com");
ri.connectTo("www.google.com");
ri.connectTo("www.virussite.com");
Console.WriteLine("Accessing site with protection proxy: ");
ProtectionProxy pp = new ProtectionProxy();
pp.connectTo("www.badsite.com");
pp.connectTo("www.google.com");
pp.connectTo("www.virussite.com");
}
}
public interface Internet
{
void connectTo(string url);
}
public class RealInternet : Internet
{
public void connectTo(string url) => Console.WriteLine("\t Connecting to " + url + "...");
}
public class ProtectionProxy : Internet
{
private RealInternet realinternet = new RealInternet();
private List<string> bannedsites = new List<string>{
"www.badsite.com",
"www.virussite.com"
};
public void connectTo(string url)
{
if(!bannedsites.Contains(url)){
realinternet.connectTo(url);
} else
{
Console.WriteLine("\t Access denied");
}
}
}