コード例 #1
0
        protected override async void OnHandleIntent(Intent intent)
        {
            Logger.Verbose("OnHandleIntent");

            var customerPhotoUploader = new CustomerPhotoUploader();

            if (intent.Extras != null)
            {
                //from the intent get a list of photos to upload
                var photoListString = intent.GetStringExtra(PhotoList);

                if (!string.IsNullOrEmpty(photoListString))
                {
                    Logger.Verbose("OnHandleIntent values retrieved from Intent");
                    Logger.Verbose(photoListString);

                    try
                    {
                        _customerPhotoList = JsonConvert.DeserializeObject <List <CustomerPhoto> >(photoListString);
                        var photoUploadStatusDictionaryResult = await customerPhotoUploader.UploadPhotos(_customerPhotoList);

                        _photoUploadStatusDictionaryString = JsonConvert.SerializeObject(photoUploadStatusDictionaryResult);
                    }
                    catch (JsonException je)
                    {
                        Logger.Error(je);
                    }
                }
            }
            else
            {
                Logger.Verbose("OnHandleIntent NO values retrieved from Intent");

                //if the intent has no extras then upload all pending photos, if any
                try
                {
                    var photoUploadStatusDictionaryResult = await customerPhotoUploader.UploadPhotos();

                    if (photoUploadStatusDictionaryResult != null)
                    {
                        Logger.Verbose(photoUploadStatusDictionaryResult.ToString());
                        _photoUploadStatusDictionaryString =
                            JsonConvert.SerializeObject(photoUploadStatusDictionaryResult);
                    }
                }
                catch (Exception e)
                {
                    Logger.Verbose("OnHandleIntent Exception");
                    Logger.Verbose(e.Message);
                    Logger.Error(e);
                }
            }

            Logger.Verbose("OnHandleIntent value of dictionary string sent to receiver");
            Logger.Verbose(_photoUploadStatusDictionaryString);

            var photosIntent = new Intent(PhotosUploadedAction);

            photosIntent.PutExtra(PhotoUploadStatusDictionaryString, _photoUploadStatusDictionaryString);
            SendOrderedBroadcast(photosIntent, null);
        }
コード例 #2
0
        public void OnServiceConnected(ComponentName name, IBinder service)
        {
            var customerPhotoUploader = new CustomerPhotoUploader();

            customerPhotoUploader.UploadPhotos();
        }