Example #1
0
 // 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();
     }
 }
Example #2
0
        // 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();
            }
        }
Example #3
0
        // use: sieganie po posty w konkretnym eventcie
        public static async Task <ObservableCollection <Post> > GetPosts(int eventID)
        {
            try
            {
                ServerAnswerRecievedPosts sarp = JsonConvert.DeserializeObject
                                                 <ServerAnswerRecievedPosts>(await ClientBackend.GetResponse("/posts/" + eventID));

                if (sarp.Status.Equals("success", StringComparison.OrdinalIgnoreCase))
                {
                    eventMap[eventID].Posts = sarp.PostList;
                    if (eventMap[eventID].Posts == null)
                    {
                        throw new System.Exception();
                    }

                    return(eventMap[eventID].Posts);
                }
                else
                {
                    throw new DataFormatException();
                }
            }
            catch (DataFormatException)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw new UnknownException();
            }
        }
Example #4
0
        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();
            }
        }
Example #5
0
        public static async Task RegisterUser(UserPersonalInfo userPersonalInfo)
        {
            try
            {
                string json = JsonConvert.SerializeObject(userPersonalInfo);

                var response = await ClientBackend.client.PostAsync((ClientBackend.api_domain + "/user"),
                                                                    new StringContent(json, Encoding.UTF8, "application/json"));

                string responseContent = await response.Content.ReadAsStringAsync();

                ServerFeedback serverFeedback = JsonConvert.DeserializeObject <ServerFeedback>(responseContent);
                if (serverFeedback.Status.Equals("success", StringComparison.OrdinalIgnoreCase))
                {
                    ClientBackend.StroreCredentials(userPersonalInfo.Login, userPersonalInfo.Password);
                }
                else
                {
                    throw new DataFormatException();
                }
            }
            catch (DataFormatException)
            {
                throw;
            }
            catch (ArgumentNullException)
            {
                throw;
            }
            catch (HttpRequestException)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw new UnknownException();
            }
        }
Example #6
0
        // use: sieganie po eventy usera
        public static async Task <ObservableCollection <Event> > GetEvents(int userID)
        {
            try
            {
                ServerAnswerRecievedEvents recievedEvent = JsonConvert.DeserializeObject <ServerAnswerRecievedEvents>
                                                               (await ClientBackend.GetResponse("/events/" + userID));

                if (recievedEvent.Status.Equals("success", StringComparison.OrdinalIgnoreCase))
                {
                    eventMap.Clear();
                    events = recievedEvent.EventList;
                    if (events == null)
                    {
                        throw new UnknownException();
                    }

                    foreach (Event element in events)
                    {
                        eventMap.Add(element.ID, element);
                    }

                    return(events);
                }
                else
                {
                    throw new DataFormatException();
                }
            }
            catch (DataFormatException)
            {
                throw;
            }
            catch (System.Exception)
            {
                throw new UnknownException();
            }
        }
Example #7
0
 //use: usuwa z pliku login,haslo
 public static void Logout()
 {
     ClientBackend.RemoveCredentials();
     //try catch throw new UnExpectedException();
 }