EmailValidator.cs
3.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Text.RegularExpressions;
using System.Collections.Specialized;
using System.Runtime.CompilerServices;
namespace PerformanceService
{
[ServiceContract]
public interface IEmailValidator
{
[OperationContract]
bool ValidateAddress(string emailAddress);
[OperationContract]
int RegisterAdress(string emailAddress);
[OperationContract]
string GetAdress(int userID);
[OperationContract]
bool checkIfFull();
[OperationContract]
bool checkIfFull2();
}
// Implementation
public class EmailValidator : IEmailValidator
{
public bool ValidateAddress(string emailAddress)
{
Console.WriteLine("Validating: {0}", emailAddress);
string pattern = @"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$";
Random random = new Random();
System.Threading.Thread.Sleep(random.Next(50, 250));
return Regex.IsMatch(emailAddress, pattern);
}
public Int32 RegisterAdress(string emailAdress)
{
int userID = 0;
myRegistry.add();
return userID;
}
public string GetAdress(int userID)
{
string emailAdress = "thisisatest@testamera.com";
return emailAdress;
}
public bool checkIfFull()
{
if (myRegistry.checkIfFull() > 1) return false; else return true;
}
public bool checkIfFull2()
{
if (myRegistry.checkIfFull2() > 1) return false; else return true;
}
}
public class myRegistry
{
static int _val1 = 1, _val2 = 1, _val3 = 1;
private static StringCollection myParams = new StringCollection();
public static int checkIfFull()
{
Random random = new Random();
_val1 = 1; _val2 = 1; _val3 = 0;
if (_val2 != 0)
{
System.Threading.Thread.Sleep(random.Next(50, 100));
_val3 = (_val1 / _val2);
}
_val2 = 0;
System.Threading.Thread.Sleep(random.Next(50, 100));
return _val3;
}
[MethodImpl(MethodImplOptions.Synchronized)]
public static int checkIfFull2()
{
Random random = new Random();
_val1 = 1; _val2 = 1; _val3 = 0;
if (_val2 != 0)
{
System.Threading.Thread.Sleep(random.Next(50, 100));
_val3 = (_val1 / _val2);
}
_val2 = 0;
System.Threading.Thread.Sleep(random.Next(50, 100));
return _val3;
}
public static void add()
{
Random random = new Random();
string str1 = "";
for (int x = 0; x < 5000; x++)
{
str1 = str1 + "abc123abc123 ";
}
myParams.Add(str1);
System.Threading.Thread.Sleep(random.Next(50, 100));
}
}
}