public bool AmendRegistration(ApiRegistrationModel apiRegistrationModel)
        {
            try
            {
                var incomingEntity = new ApiRegistrationTableEntity()
                {
                    Password   = apiRegistrationModel.Password,
                    BaseUrl    = apiRegistrationModel.BaseUrl,
                    Username   = apiRegistrationModel.Username,
                    LicenceKey = apiRegistrationModel.LicenceKey
                };

                _azureTableStorageClient.Execute(TableOperation.InsertOrMerge(incomingEntity));
            }
            catch (StorageException)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        public bool SaveRegistration(ApiRegistrationModel apiModel)
        {
            _apiRegistrationRepository.AmendRegistration(apiModel);

            //use a simple call to verify creds
            try
            {
                _cellularService.GetTerminals();
            }
            catch (CellularConnectivityException exception)
            {
                //API does not give error code for the remote name.
                if (exception.Message.Contains(Strings.RemoteNameNotResolved) ||
                    exception.Message == Strings.CellularInvalidCreds)
                {
                    _apiRegistrationRepository.DeleteApiDetails();
                    return(false);
                }

                //the user may have valid creds but no devices. Which throws exception from API this is ok.
            }
            return(true);
        }
Ejemplo n.º 3
0
        public async Task <bool> SaveRegistration(ApiRegistrationModel apiModel)
        {
            try
            {
                // get the current registration model
                var oldRegistrationDetails = _apiRegistrationRepository.RecieveDetails();
                // ammend the new details
                _apiRegistrationRepository.AmendRegistration(apiModel);

                // check credentials work. If they do not work revert the change.
                if (!CheckCredentials())
                {
                    _apiRegistrationRepository.AmendRegistration(oldRegistrationDetails);
                    return(false);
                }

                // if api provider has changed then disassociate all associated devices
                if (oldRegistrationDetails != null && oldRegistrationDetails.ApiRegistrationProvider != apiModel.ApiRegistrationProvider)
                {
                    var disassociateDeviceResult = await DisassociateAllDevices();

                    // if this has failed revert the change
                    if (!disassociateDeviceResult)
                    {
                        _apiRegistrationRepository.AmendRegistration(oldRegistrationDetails);
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                _apiRegistrationRepository.DeleteApiDetails();
                return(false);
            }

            return(true);
        }