Exemple #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);
            Button button = FindViewById <Button> (Resource.Id.myButton);

            imageView = FindViewById <SmartImageView> (Resource.Id.image);
            imageView.SetImageUrl("http://cdn1.xamarin.com/webimages/images/index/icon-cross-platform.png");


            _uploader = new PhotoUploader();
            _listener = new PhotoListener();

            _listener.NewPhotosReceived += (sender, urls) =>
            {
                RunOnUiThread(() =>
                {
                    foreach (var url in urls)
                    {
                        imageView.SetImageUrl(url);
                        var toast = Toast.MakeText(BaseContext, "New Image: " + url.ToString(), ToastLength.Long);
                        toast.Show();
                    }
                });
            };

            _listener.StartListening();

            button.Click += delegate {
                UploadPicture();
            };
        }
Exemple #2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NavigationItem.RightBarButtonItem          = new UIBarButtonItem(UIBarButtonSystemItem.Add);
            NavigationItem.RightBarButtonItem.Clicked += delegate { UploadPicture(); };

            _uploader = new PhotoUploader();
            _listener = new PhotoListener();

            _listener.NewPhotosReceived += (sender, urls) =>
            {
                InvokeOnMainThread(() =>
                {
                    foreach (var url in urls)
                    {
                        _imageSection.Add(
                            new ImageStringElement(DateTime.Now.ToString(),
                                                   UIImage.LoadFromData(NSData.FromUrl(new NSUrl(url))))
                            );
                    }
                });
            };

            _listener.StartListening();
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'."));
            }

            if (Input.Email != user.Email)
            {
                var setEmailResult = await _userManager.SetEmailAsync(user, Input.Email);

                if (!setEmailResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting email for user with ID '{userId}'.");
                }
            }

            if (Input.PhoneNumber != user.PhoneNumber)
            {
                var setPhoneResult = await _userManager.SetPhoneNumberAsync(user, Input.PhoneNumber);

                if (!setPhoneResult.Succeeded)
                {
                    var userId = await _userManager.GetUserIdAsync(user);

                    throw new InvalidOperationException($"Unexpected error occurred setting phone number for user with ID '{userId}'.");
                }
            }

            if (Input.Biography != user.Biography)
            {
                await _myUserManager.UpdateBiographyAsync(Input.Biography);
            }

            if (Input.ProfilePhoto != null)
            {
                if (Input.ProfilePhoto.Length > 0 && Input.ProfilePhoto.ContentType == "image/jpeg")
                {
                    var photoUploader = new PhotoUploader(_env);
                    var uploadedPhoto = await photoUploader.Upload(Input.ProfilePhoto, new ProfilePhotoUploadPath());

                    await _myUserManager.UpdatePhotoAsync(uploadedPhoto);
                }
            }

            await _signInManager.RefreshSignInAsync(user);

            StatusMessage = "Your profile has been updated";
            return(RedirectToPage());
        }
Exemple #4
0
        private async Task <Uri> UploadPetToStorage(byte[] content)
        {
            var storageName = _settings.PetsConfig.BlobName;
            var auth        = _settings.PetsConfig.BlobKey;
            var uploader    = new PhotoUploader(storageName, auth);
            var blob        = await uploader.UploadPetPhoto(content);

            return(blob.Uri);
        }
Exemple #5
0
        public async Task UploadAsAdPhotoAsync()
        {
            var response = await PhotoUploader.UploadAsAdPhotoAsync(TestsBase.TestPicturePath, TestsBase.AdAccountId, TestsBase.AccessToken);

            Assert.IsTrue(response.Code == ResponseCode.SUCCESS, response.ReasonPhrase ?? String.Empty);

            var jobj = JObject.Parse(response.Data);

            Assert.IsTrue(jobj["images"] != null);
        }
Exemple #6
0
        public async Task UploadAsync()
        {
            var message = Guid.NewGuid().ToString("N");

            var response = await PhotoUploader.UploadAsync(TestsBase.TestPicturePath, TestsBase.PageId, message, TestsBase.PageAccessToken);

            Assert.IsTrue(response.Code == ResponseCode.SUCCESS, response.ReasonPhrase ?? String.Empty);

            var jobj = JObject.Parse(response.Data);

            Assert.IsTrue((jobj["post_id"] != null && !String.IsNullOrEmpty(jobj["post_id"].ToString())) &&
                          (jobj["id"] != null && !String.IsNullOrEmpty(jobj["id"].ToString())));
        }
        /// <summary>
        /// Загрузка питомца в хранилище
        /// </summary>
        private async Task <Uri> UploadPetToStorageAsync(byte[] content)
        {
            // Хранилище
            var storageName = _settingsSvc.LocalSettings.PetsConfig.BlobName;
            // Ключ
            var auth = _settingsSvc.LocalSettings.PetsConfig.BlobKey;
            // Загрузчик
            var uploader = new PhotoUploader(storageName, auth);
            // Загрузка
            var blob = await uploader.UploadPetPhotoAsync(content);

            return(blob.Uri);
        }
            public MyCameraHandler(MainActivity activity)
            {
                Activity = activity;

                _lastKnownLocation = new LocationWrapper(null);
                _locationProvider  = new MyLocationListener(activity);
                _locationProvider.OnLocationUpdated += HandleLocationUpdated;

                _uploader = new PhotoUploader();
                _uploader.OnStateChanged += SetNetworkStatus;

                _handlerThread = new HandlerThread("MyCameraHandler");
                _handlerThread.Start();
            }
Exemple #9
0
        /// <summary>
        ///     Gets the url of specified facebook ad photo as an asynchronous operation.
        /// </summary>
        /// <param name="photo">
        ///     The url or filepath of the ad photo.
        /// </param>
        /// <param name="adAccountId">
        ///     The ad account id of user.
        /// </param>
        /// <param name="accessToken">
        ///     User access token.
        /// </param>
        /// <returns>
        ///     The task object representing the asynchronous operation.
        /// </returns>
        /// <exception cref="FileNotFoundException">
        ///     Throw if the target photo file doesn't exist.
        /// </exception>
        private static async Task <(string AdPhotoUrl, ResponseMessage <string> AdPhotoResponse)> GetAdPhotoUrlAsync(string photo, string adAccountId, string accessToken)
        {
            var imgUrl = String.Empty;
            ResponseMessage <string> response = null;
            JObject jobj = null;

            if (RegexUtil.IsUrl(photo))
            {
                imgUrl = photo;

                response = new ResponseMessage <string>
                {
                    Code = ResponseCode.SUCCESS
                };
            }
            else
            {
                // Uploads photo to facebook.
                response = await PhotoUploader.UploadAsAdPhotoAsync(photo, adAccountId, accessToken);

                if (response.Code == ResponseCode.SUCCESS)
                {
                    jobj = JObject.Parse(response.Data);

                    var urlToken = jobj.Descendants()
                                   .Where(pp => pp.Type == JTokenType.Property && ((JProperty)pp).Name == "url")
                                   .Select(pp => ((JProperty)pp).Value)
                                   .FirstOrDefault();

                    if (urlToken == null)
                    {
                        response = new ResponseMessage <string>
                        {
                            Code         = ResponseCode.UNKNOWN_ERROR,
                            ReasonPhrase = $"Failed to upload photo {photo} to facebook."
                        };
                    }
                    else
                    {
                        imgUrl = urlToken.ToString();
                    }
                }
            }

            return(imgUrl, response);
        }