Пример #1
0
        private async Task <bool> AttemptDataRegistration(BL.Models.People.Customer customer)
        {
            if (!Resolver.Instance.Get <IConnectivityService>().HasConnection())
            {
                return(false);
            }

            // try to post the person via the API, for configurable x tries
            CustomerRegistrationResponse response = null;
            int apiTries = 1;

            while (apiTries <= this.numberOfRetries)
            {
                Log.Verbose("API register try " + apiTries);

                // call the API and await response
                response = await this.RegisterViaApi(customer);

                response.Customer = customer;

                if (response.Successful)
                {
                    this.RegistrationSuccessful = true;

                    if (response.RegistrationId != Guid.Empty)
                    {
                        var registrationCompletedEventArgs = new CustomerRegistrationCompletedEventArgs(
                            DataChannel.Full,
                            true)
                        {
                            RegistrationId = response.RegistrationId
                        };

                        this.FireRegistrationCompleted(registrationCompletedEventArgs);
                    }
                    else
                    {
                        this.FireRegistrationCompleted(DataChannel.Full, true);
                    }

                    return(true);
                }

                this.FireRegistrationAttempted(DataChannel.Full, apiTries);

                // exception on reported 500 error, do not continue
                if (response.ResponseText.Equals("HttpResponse500Exception"))
                {
                    Log.Error("API threw 500 error (HttpResponse500Exception).");
                    break;
                }

                // next retry
                apiTries++;
            }

            // make sure the warning logging never fails, it is extra information
            try
            {
                var responseText = response == null ? "response=null" : response.ResponseText;
                Log.Warning("Fallback Registration: Attempts to register via Internet failed. ResponseText = " +
                            responseText);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }


            return(false);
        }