EmailValidator.cs 3.13 KB
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));
        }
    }

}