示例#1
0
        public async Task <bool> NewDeviceOrUpdateTokenIfExistsAsync(Callback newDeviceCallback = null)
        {
            bool newDeviceResult;

            RequestBuilder requestBuilder = new RequestBuilder();
            Request        request        = requestBuilder
                                            .SetDevice_id(DeviceId)
                                            .SetDevice_tokenFirebase(DeviceToken)
                                            .SetEmail(User.Email)
                                            .SetPass(User.Pass)
                                            .Build();

            ServerRequest serverRequest = new ServerRequest();

            try {
                string serverResponse = await serverRequest.SendDataToServerAsync(
                    ServerConfig.Instance.server_url_new_device, request);

                Response response = ServerResponse.ParsingJsonResponse(serverResponse);

                if (!response.Error)
                {
                    Debug.WriteLine(string.Format("Nuovo dispositivo aggiunto con successo"));
                    newDeviceResult = true;
                }
                else
                {
                    Debug.WriteLine(string.Format("Il server ha restituito un errore durante l'aggiunta del nuovo dispositivo." +
                                                  "Messaggio : {0}", response.Message));
                    newDeviceResult = false;
                }

                if (!newDeviceResult && response.Message != null && response.Message == SystemErrors.DEVICE_EXISTS)
                {
                    return(await this.UpdateTokenAsync(newDeviceCallback));
                }

                LastErrorMessage = response.Message;
            }
            catch (Exception e) {
                string errorMsg = "Error connecting while \"adding new device\"\r\n";
                errorMsg += e.Message;
                Debug.WriteLine(e.StackTrace);

                newDeviceResult  = false;
                LastErrorMessage = errorMsg;
            }


            newDeviceCallback?.Invoke(newDeviceResult, LastErrorMessage);
            return(newDeviceResult);
        }
示例#2
0
        public async Task <bool> UpdateTokenAsync(Callback updateTokenCallback = null)
        {
            bool updateTokenResult;

            RequestBuilder requestBuilder = new RequestBuilder();
            Request        request        = requestBuilder
                                            .SetDevice_id(DeviceId)
                                            .SetDevice_tokenFirebase(DeviceToken)
                                            .SetEmail(User.Email)
                                            .Build();

            ServerRequest serverRequest = new ServerRequest();

            try {
                string serverResponse = await serverRequest.SendDataToServerAsync(
                    ServerConfig.Instance.server_url_update_token, request);

                Response response = ServerResponse.ParsingJsonResponse(serverResponse);

                if (!response.Error)
                {
                    Debug.WriteLine(string.Format("Token aggiornato con successo"));
                    updateTokenResult = true;
                }
                else
                {
                    Debug.WriteLine(string.Format("Il server ha restituito un errore durante l'aggiornamento del token. " +
                                                  "Messaggio : {0}", response.Message));
                    updateTokenResult = false;
                }

                LastErrorMessage = response.Message;
            }
            catch (Exception e) {
                string errorMsg = "Error connecting while \"updating token\"\r\n";
                errorMsg += e.Message;
                Debug.WriteLine(e.StackTrace);

                updateTokenResult = false;
                LastErrorMessage  = errorMsg;
            }

            updateTokenCallback?.Invoke(updateTokenResult, LastErrorMessage);
            return(updateTokenResult);
        }
示例#3
0
        public async Task <bool> SignUpAsync(Callback signUpCallback = null)
        {
            bool signupResult;

            RequestBuilder requestBuilder = new RequestBuilder();
            Request        request        = requestBuilder
                                            .SetEmail(Email)
                                            .SetPass(Pass)
                                            .SetLang(Lang)
                                            .Build();

            ServerRequest serverRequest = new ServerRequest();

            try {
                string serverResponse = await serverRequest.SendDataToServerAsync(ServerConfig.Instance.server_url_new_user, request);

                Response response = ServerResponse.ParsingJsonResponse(serverResponse);

                if (!response.Error)
                {
                    Debug.WriteLine(string.Format("Registrazione utente avvenuta con successo"));
                    signupResult = true;
                }
                else
                {
                    Debug.WriteLine(string.Format("Il server ha restituito un errore durante la registrazione del nuovo utente. Messaggio : {0}",
                                                  response.Message));
                    signupResult = false;
                }

                LastErrorMessage = response.Message;
            }
            catch (Exception e) {
                string errorMsg = "Error connecting while \"adding new user\"\r\n";
                errorMsg += e.Message;
                Debug.WriteLine(e.StackTrace);

                signupResult     = false;
                LastErrorMessage = errorMsg;
            }

            signUpCallback?.Invoke(signupResult, LastErrorMessage);
            return(signupResult);
        }
示例#4
0
        public async Task <bool> LoginAsync(Callback loginCallback = null)
        {
            bool loginResult;

            RequestBuilder requestBuilder = new RequestBuilder();
            Request        request        = requestBuilder
                                            .SetEmail(Email)
                                            .SetPass(Pass)
                                            .Build();

            ServerRequest serverRequest = new ServerRequest();

            try {
                string serverResponse = await serverRequest.SendDataToServerAsync(
                    ServerConfig.Instance.server_url_login, request);

                Response response = ServerResponse.ParsingJsonResponse(serverResponse);

                if (!response.Error)
                {
                    Debug.WriteLine(string.Format("Login avvenuto con successo"));
                    loginResult = true;
                }
                else
                {
                    Debug.WriteLine(string.Format("Il server ha restituito un errore durante la login. Messaggio : {0}",
                                                  response.Message));
                    loginResult = false;
                }

                LastErrorMessage = response.Message;
            }
            catch (Exception e) {
                string errorMsg = "Error connecting while \"logging in\"\r\n";
                errorMsg += e.Message;
                Debug.WriteLine(e.StackTrace);

                loginResult      = false;
                LastErrorMessage = errorMsg;
            }

            loginCallback?.Invoke(loginResult, LastErrorMessage);
            return(loginResult);
        }