- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
public void Login(ClientHandlers<int> actions)
{
var request = GetGetRequest("/user/xml/{0}", _login);
var act = new Action<IRestResponse<GetUserInfoResult>>(response =>
{
if (CheckUserInfo(response))
{
throw new Exception("Невозможно получить информацию о пользователе\r\nНеобработанное исключение");
}
UserInfo = response.Data.UserInfo;
actions.Completed(UserInfo.idUser);
});
_client.ExecuteAsync(request, act);
}
private bool CheckUserInfo(IRestResponse<GetUserInfoResult> response)
{
if (response != null && response.Data != null && response.Data.UserInfo != null && response.Data.UserInfo.idUser != 0)
{
return true;
}
var message = "Невозможно получить информацию о пользователе";
if (response == null)
{
message = string.Format("{0}\r\n{1}",
message,
"Response is null");
throw new Exception(message);
}
message = string.Format("{0}\r\nResponse data is null\r\nContext: {1}",
message,
response.Content);
if (response.Data == null)
{
throw new Exception(message);
}
message = string.Format("{0}\r\nIs exception: {1}\r\nMessage: {2}",
message,
response.Data.IsException,
response.Data.Message);
if (response.Data.UserInfo == null)
{
throw new Exception(message);
}
message = string.Format("{0}\r\nSiteName: {1}\r\nUserName: {2}\r\nUserRole: {3}",
message,
response.Data.UserInfo.SiteName,
response.Data.UserInfo.UserName,
response.Data.UserInfo.UserRole);
if (response.Data.UserInfo.idUser == 0)
{
throw new Exception(message);
}
return false;
}