Пример #1
0
        /// <summary>
        /// Lists the products for the user.
        /// </summary>
        /// <returns>Products.</returns>
        public async Task <List <Product> > ListProducts()
        {
            Log.Verbose("List Products.");
            List <Product> products = new List <Product>();
            var            settings = Settings.Instance;
            var            dsrPhone = settings.DsrPhone;

            if (_connectivityService.HasConnection())
            {
                Log.Verbose("Connection exists, get products from API.");
                var productDtos = await api.GetProducts(dsrPhone);

                // only process the api call, when there is a result
                if (productDtos != null)
                {
                    products = productDtos.Select(productDto => new Product
                    {
                        DisplayName   = productDto.DisplayName,
                        ProductTypeId = productDto.ProductTypeId,
                        SerialNumber  = productDto.SerialNumber,
                        DateAcquired  = productDto.DateAcquired
                    }).ToList();
                }
            }

            return(products);
        }
Пример #2
0
 private void go()
 {
     if (!_connectivityService.HasConnection())
     {
         ShowFragment(resetPinFailedFragment);
     }
     else
     {
         ShowFragment(progressFragment);
         DoResetPin();
     }
 }
Пример #3
0
        private async void Login(string pin, string mobileNumber, CountryCodes country, bool isFirstTime)
        {
            Settings.DsrPhone    = mobileNumber;
            Settings.DsrLanguage = LanguagesEnum.EN;
            EnteredPin           = pin;

            if (_connectivityService.HasConnection())
            {
                await LoginOnline();
            }
            else
            {
                _textViewError.Visibility = ViewStates.Visible;
                _textViewError.Text       = GetText(Resource.String.network_connection_required);
            }
        }
Пример #4
0
        private async Task <Dictionary <Guid, PhotoUploadStatus> > Upload(List <CustomerPhoto> photos)
        {
            var               photoUploadStatusDict = new Dictionary <Guid, PhotoUploadStatus>();
            CustomerPhoto     currentPhotoForUpload = null;
            PhotoUploadStatus photoUploadStatus     = PhotoUploadStatus.Pending;

            try
            {
                if (_connectivityService.HasConnection() && photos.Any())
                {
                    Logger.Verbose("Total number of Photos available " + photos.Count);

                    // loop through existing customer photos, if any
                    foreach (var photo in photos)
                    {
                        currentPhotoForUpload = photo;
                        photoUploadStatus     = photo.PhotoUploadStatus;

                        var photoName = Path.GetFileName(currentPhotoForUpload.FilePath);
                        Logger.Verbose("About to process Photo : " + photoName);

                        Logger.Verbose("DSR Country Code");
                        Logger.Verbose(Settings.Instance.DsrCountryCode.ToString().ToLower());

                        // build up a blob name that includes the phone and national id number of the customer as well as country prefix
                        var blobName  = currentPhotoForUpload.Phone + "_" + currentPhotoForUpload.CustomerIdentifier + "_" + Settings.Instance.DsrCountryCode.ToString().ToLower() + "_" + Path.GetFileName(photoName);
                        var blockBlob = _photoBlobContainer.GetBlockBlobReference(Path.GetFileName(blobName));

                        // set the metadata of the blob to have customer's national id, type and description of photo
                        if (!string.IsNullOrEmpty(currentPhotoForUpload.CustomerIdentifier))
                        {
                            blockBlob.Metadata["NationalID"] = currentPhotoForUpload.CustomerIdentifier;
                        }

                        if (!string.IsNullOrEmpty(currentPhotoForUpload.Phone))
                        {
                            blockBlob.Metadata["PhoneNumber"] = currentPhotoForUpload.Phone;
                        }

                        if (currentPhotoForUpload.TypeOfPhoto > 0)
                        {
                            blockBlob.Metadata["PhotoType"] = currentPhotoForUpload.TypeOfPhoto.ToString();
                        }

                        // upload each photo to Azure Blob Storage
                        if (File.Exists(currentPhotoForUpload.FilePath))
                        {
                            using (var fileStream = File.OpenRead(currentPhotoForUpload.FilePath))
                            {
                                await blockBlob.UploadFromStreamAsync(fileStream);

                                Logger.Verbose("Photo uploaded to Azure Blob Storage : " + blobName);
                            }
                        }

                        // set the upload status to success
                        photoUploadStatus = PhotoUploadStatus.Successfull;

                        // save the photo's status to the database
                        currentPhotoForUpload.PhotoUploadStatus = photoUploadStatus;
                        await _photoController.SaveAsync(currentPhotoForUpload);

                        // update the photo status dictionary
                        photoUploadStatusDict.Add(currentPhotoForUpload.Id, currentPhotoForUpload.PhotoUploadStatus);

                        Logger.Verbose("Updated Customer Photo Status to Success");
                    }
                }
            }
            catch (StorageException se)
            {
                Logger.Verbose("StorgeException Caught On Photo Upload");

                // set the upload status to Fail
                photoUploadStatus = PhotoUploadStatus.Failed;

                var requestInformation = se.RequestInformation;
                var errorCode          = requestInformation.ExtendedErrorInformation.ErrorCode;
                var statusCode         = (HttpStatusCode)requestInformation.HttpStatusCode;

                Logger.Verbose(errorCode);
                Logger.Verbose(statusCode.ToString());

                // if it is an authentication failure then it means the SAS Token has probably expired and a new one is needed
                if (errorCode == StorageErrorCodeStrings.AuthenticationFailed)
                {
                    // SAS Token probably has expired
                    Logger.Verbose("SAS Token Expired");

                    // TODO Add code to request new SAS Token from OTA Settings or API Call
                }
            }
            catch (Exception e)
            {
                Logger.Verbose("General Exception Caught On Photo Upload");
                Logger.Verbose(e.Message);

                // set the upload status to Fail
                photoUploadStatus = PhotoUploadStatus.Failed;

                Logger.Error(e);
            }

            try
            {
                // if the upload failed, update the database accordingly, but from another try/catch block
                if (photoUploadStatus == PhotoUploadStatus.Failed && currentPhotoForUpload != null)
                {
                    currentPhotoForUpload.PhotoUploadStatus = photoUploadStatus;
                    await _photoController.SaveAsync(currentPhotoForUpload);

                    // update the photo status dictionary
                    photoUploadStatusDict.Add(currentPhotoForUpload.Id, currentPhotoForUpload.PhotoUploadStatus);

                    Logger.Verbose("Updated Customer Photo Status to Failed");
                }
            }
            catch (Exception dbe)
            {
                Logger.Verbose("General Exception Caught In CustomerPhoto Table Updated on Failed Upload");
                Logger.Verbose(dbe);
                Logger.Error(dbe);
            }

            return(photoUploadStatusDict);
        }