Exemplo n.º 1
0
 public static void DoRegister(string username, string password, StreamWriter sw, StreamReader sr)
 {
     try
     {
         //controllo che username e password non siano nulli
         if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(password))
         {
             //TODO eccezzione ad hoc per campi invalidi
             throw new Exception("Username o password hanno campi invalidi");
         }
         //Fillo una nuova richiesta di registrazione e la invio
         RegisterRequest register = new RegisterRequest(username, password);
         NetworkWriteLine(sw,register.ToJSON());
         string receive = NetworkReadLine(sr);
         //Parso la risposta e leggo l'esito della risposta
         Response res = Response.fromJson(receive);
         if (res.Result != 200)
         {
             throw new Exception(BadRegistrationResponse.fromJson(receive).Msg);
         }
         Console.WriteLine("Registrazione avvenuta con successo.");
     }
     catch (Exception e)
     {
         throw new RegisterExceptionU(e.Message);
     }
 }