Advertisement
Guest User

Untitled

a guest
Aug 18th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. private async Task TryToLogin()
  2.         {
  3.             IsLoading = true;
  4.  
  5.             string emailAndPassword = String.Format("{0}:{1}", email, password);
  6.             string encryptedCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(emailAndPassword));
  7.  
  8.             var client = new System.Net.Http.HttpClient() {
  9.                 BaseAddress = new Uri("https://csp1.isolvetech.net:4433/isolvesd.svc")
  10.             };
  11.  
  12.             var loginService = RestService.For<ILoginService>(client);
  13.  
  14.             try
  15.             {
  16.                 CancellationTokenSource tokenSource = new CancellationTokenSource();
  17.                 tokenSource.CancelAfter(1000); // 10000 ms
  18.                 CancellationToken token = tokenSource.Token;
  19.                 var loggedUser = await loginService.Login(email, password, "2.0.0", token);
  20.             }
  21.             catch(ApiException)
  22.             {
  23.                 await DialogService.DisplayAlertAsync("Error", App.WRONG_CREDENTIALS_ERROR, "OK");
  24.             }
  25.             catch(OperationCanceledException)
  26.             {
  27.                 await DialogService.DisplayAlertAsync("Error", "Tardaste un chingo we", "OK");
  28.             }
  29.  
  30.            
  31.  
  32.  
  33.  
  34.                 //Task loginTask = new ApiService().InitiateLogin(Email, Password);
  35.                 //await Task.WhenAny(loginTask, Task.Delay(7000, cancellationToken.Token));
  36.  
  37.                 //if (loginTask.IsCompleted)
  38.                 //{
  39.                 //    if (AppSettings.IsLogged)
  40.                 //    {
  41.                 //        await ApplicationData.Instance.CheckAuthorization();
  42.                 //        ApplicationData.Instance.FirstTime = true;
  43.                 //        await NavigationService.NavigateAsync("app:///Navigator/UnauthorizedOrders", null, null, true);
  44.                 //    }
  45.                 //    else
  46.                 //    {
  47.                 //        await DialogService.DisplayAlertAsync("Error", App.WRONG_CREDENTIALS_ERROR, "OK");
  48.                 //    }
  49.                 //}
  50.                 //else
  51.                 //{
  52.                 //    await DialogService.DisplayAlertAsync("Timeout", App.TIMEOUT_ERROR, "OK");
  53.                 //}
  54.  
  55.                 IsLoading = false;
  56.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement