· 7 years ago · Jun 07, 2018, 05:54 PM
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Threading;
6
7public class Foo1
8{
9 public static void Run()
10 {
11 var clients = GetClients();
12 Console.WriteLine($"Ðайдено {clients.Count} клиентов. Ðктивных {clients.Where(e => e.IsActive).Count()}, неактивных {clients.Where(e => !e.IsActive).Count()}");
13
14 var appropriateClients = new List<Client>();
15 foreach (var client in clients)
16 {
17 if (!IsAppropriateEmail(client))
18 {
19 continue;
20 }
21
22 if (!client.IsActive)
23 {
24 continue;
25 }
26
27 appropriateClients.Add(client);
28 }
29
30 Console.WriteLine($"Ðайдено {appropriateClients.Count}");
31 Console.ReadLine();
32 }
33
34 private static bool IsAppropriateEmail(Client client)
35 {
36 return client.Email.EndsWith(".ru");
37 }
38
39 private static List<Client> GetClients()
40 {
41 //TODO: получать данных из БД
42 string[] domains = { "yandex.ru", "gmail.com", "mail.ru", "yandex.ua", "yandex.kz" };
43 var result = new List<Client>();
44
45 for (int i = 1; i <= 10000000; i++)
46 {
47 var client = new Client(name: GetName(i),
48 email: GetEmail(GetName(i), GetRandom(domains)),
49 isActive: GetRandomBool());
50
51 result.Add(client);
52 }
53 return result;
54 }
55
56 private static Random R = new Random();
57
58 private static bool GetRandomBool()
59 {
60 return R.Next(0, 2) == 0;
61 }
62
63 private static string GetName(int id)
64 {
65 return $"client{id}";
66 }
67
68 private static string GetRandom(string[] domains)
69 {
70 return domains[R.Next(0, domains.Length)];
71 }
72
73 private static string GetEmail(string name, string domain)
74 {
75 return $"{name}@{domain}";
76 }
77
78 public class Client
79 {
80
81 public string Name { get; set; }
82 public string Email { get; set; }
83 public bool IsActive { get; set; }
84
85 public Client()
86 {
87
88 }
89
90 public Client(string name, string email, bool isActive)
91 {
92 Name = name;
93 Email = email;
94 IsActive = isActive;
95 }
96 }
97}