forked from aenicaz/Console_Game
/
Form1.cs
112 lines (97 loc) · 3.11 KB
/
Form1.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using AUT.ServiceReference1;
using System.Threading;
namespace AUT
{
public partial class Form1 : Form
{
AuthorizationClient client = null;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
client = new AuthorizationClient();
Thread ServerStatus = new Thread(CheckServerStatus);
ServerStatus.IsBackground = true;
ServerStatus.Start();
}
private void CheckServerStatus()
{
while(true)
{
bool status = true;
//Если сервер работает
while (status)
{
try
{
client.ServerStatus();
Thread.Sleep(250);
}
catch
{
status = false;
MessageBox.Show("Сервер недоступен. Нажмите ОК для переподключения...");
}
}
//Если сервер не работает
while (!status)
{
try
{
client.ServerStatus();
status = true;
MessageBox.Show("Подключение восстановлено");
}
catch
{
MessageBox.Show("Сервер недоступен. Попытка переподключения...");
Thread.Sleep(250);
}
}
}
}
private void btConnect_Click(object sender, EventArgs e)
{
try
{
var result = client.Authorization(tbLogin.Text, tbPassword.Text);
if (result)
MessageBox.Show("Удачно");
else
MessageBox.Show("Неудачно");
}
catch(Exception ex)
{
MessageBox.Show("Не удаётся подключиться к серверу");
}
}
private void tbLogin_TextChanged(object sender, EventArgs e)
{
var result = client.AvailabilityLogin(tbLogin.Text);
if(result)
{
StatusLogin.ForeColor = Color.Green;
StatusLogin.Text = "Ник доступен";
btConnect.Enabled = true;
}
else
{
StatusLogin.ForeColor = Color.Red;
StatusLogin.Text = "Ник занят";
btConnect.Enabled = false;
}
}
}
}