// use: tylko po przycisku zaloguj public static async Task Login(String username, String password) { try { ClientBackend.StroreCredentials(username, password); String json = await ClientBackend.GetResponse("/user"); ServerAnswerRecievedUser userData = JsonConvert.DeserializeObject <ServerAnswerRecievedUser>(await ClientBackend.GetResponse("/user")); if (userData.Status.Equals("success", StringComparison.OrdinalIgnoreCase)) { //ClientBackend.StroreCredentials(username, password); //zapisz dane do pliku jesli sie udalo zalogowac //jesli nie exception throw new LoginException() } else { throw new LoginException(); } } catch (LoginException) { throw new LoginException(); } catch (System.Exception) { throw new UnknownException(); } }
// use: sieganie po zasoby usera( W TRAKCIE UZYTKOWANIA APPKI) public static UserPersonalInfo GetPersonalInfo() { try { //wczytaj dane z pliku i ustaw credential REST.StoreCredential(string login,password); //jesli danych nie ma throw new SessionExpiredException() -> ponowne zalogowanie ServerAnswerRecievedUser recievedUser = ClientBackend.CurrentUser().Result; if (recievedUser.Status.Equals("success")) { return(recievedUser.User); } else { throw new DataFormatException(); } } catch (TaskCanceledException) { throw; } catch (SessionExpiredException) { throw; } catch (System.Exception) { throw new UnknownException(); } }
public static async Task <ServerAnswerRecievedUser> GetUser(int userID) { try { String json = await ClientBackend.GetResponse("/user"); ServerAnswerRecievedUser data = JsonConvert.DeserializeObject <ServerAnswerRecievedUser>(await ClientBackend.GetResponse("/user/" + userID)); return(data); } catch (System.Exception) { throw new UnknownException(); } }