コード例 #1
0
        private async void BtGetPhotoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            Image img = new Image
            {
                uid = this.tb_PhotoUidForEditPhoto.Text,
                title = this.tb_PhotoTitleForGetPhoto.Text,
                tags = this.tb_PhotoTagsForGetPhoto.Text,
                synopse = this.tb_PhotoSynopseForGetPhoto.Text
            };

            Image returnedImage = await client.EditImageDetailsAsync(img);

            if (returnedImage != null)
                tblock_Result.Text = 
                    String.Format("Uri: {0}; tags: {1}; title: {2}; synopse: {3}",
                        img.uid, 
                        img.tags, 
                        img.title,
                        img.synopse);
        }
コード例 #2
0
        private async void BtDummyEchoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            this.tblock_Result.Text = await client.DummyEchoAsync(this.tb_echoStr.Text);
        }
コード例 #3
0
        private async void BtGetUserAlbumsClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            Album[] albums = await client.GetUserAlbumsList();

            foreach (Album album in albums)
            {
                this.tblock_Result.Text += String.Format("title: {0}, aid: {1}; ", album.title, album.id);
            }
        }
コード例 #4
0
        private async void BtGetUserImageListClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            Image[] images = await client.GetUserImageList();

            foreach (Image img in images)
            {
                this.tblock_Result.Text += String.Format("title: {0}, aid: {1}; ", img.title, img.uid);
            }
        }
コード例 #5
0
        private async void BtGetUserTagsClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            string[] tags = await client.GetUserTags();

            foreach (string tag in tags)
            {
                this.tblock_Result.Text += tag+"; ";
            }
        }
コード例 #6
0
        private async void BtGetPhotoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            Image img = await client.GetImageDetailsAsync(this.tb_PhotoUidForGetPhoto.Text);

            if (img != null)
                tblock_Result.Text = String.Format("Uri: {0}, username: {1}, title: {2}, date: {3}",
                                                                   img.url, img.user.username, img.title,
                                                                   img.creationDate);
        }
コード例 #7
0
        private async void BtDeletePhotoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            bool success = await client.DeleteImageAsync(this.tb_PhotoUidForDeletePhoto.Text);

            this.tblock_Result.Text = 
                success 
                ? String.Format("Photo with uid {0} sucessfully deleted", this.tb_PhotoUidForDeletePhoto.Text) 
                : "Error!";
        }
コード例 #8
0
        private async void BtCreateAlbumClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

            Album album = new Album
            {
                title = this.tb_AlbumTitleForCreateAlbum.Text
            };

            album = await client.CreateAlbumAsync(album);

            this.tblock_Result.Text = String.Format("Uri: {0}, username: {1}", album.url, album.user.username);
        }
コード例 #9
0
        private async void BtAddPhotoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;

            var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);


            //You MUST provide to albums for this example to work
            bool result =
                await
                client.AddImageToAlbums(this.tb_PhotoUidForAddPhotoToAlbum.Text,
                                                     new int[]
                                                         {
                                                             Convert.ToInt32(this.tb_Album1AidForAddPhotoToAlbum.Text),
                                                             Convert.ToInt32(this.tb_Album2AidForAddPhotoToAlbum.Text)
                                                         });

            this.tblock_Result.Text = result ? "Photo sucessfully added to the specified albums" : "Error!";
        }
コード例 #10
0
        private async void BtPickPhotoClick(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker
                                            {
                                                ViewMode = PickerViewMode.Thumbnail,
                                                SuggestedStartLocation = PickerLocationId.PicturesLibrary
                                            };
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                App app = Application.Current as App;

                if (app == null)
                    return;

                var client = new PhotosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);

                Image img = new Image
                {
                    title = file.DisplayName,
                    tags = file.DisplayName
                };

                CreateImageResult createImageResult = await client.CreateImageAsync(file, img);
                this.tblock_Result.Text = createImageResult.ResponseResult;
                if (createImageResult.Img != null)
                    this.tblock_Result.Text += " -> uri: " + createImageResult.Img.url;
            }
            else
            {
                this.tblock_Result.Text = "Error reading file";
            }
        }
コード例 #11
0
        public async Task <CreateImageResult> CreateImageAsync(IStorageFile file, Image img)
        {
            ImageCreateResult res = null;

            try
            {
                using (EnsureCredentialsUseContext context = new EnsureCredentialsUseContext(
                           this.Username, this.Password, this.Accesskey, _client.InnerChannel))
                {
                    res = await this._client.ImageCreateAsync(img, FotosSapoPtInterface);
                }
            }
            catch (FaultException faultException)
            {
                MessageFault messageFault = faultException.CreateMessageFault();

                if (messageFault.HasDetail)
                {
                    string innerErrorXml;
                    using (var xmlReader = messageFault.GetReaderAtDetailContents())
                    {
                        innerErrorXml = xmlReader.ReadInnerXml();
                    }
                    if (innerErrorXml != null)
                    {
                        throw new Exception(innerErrorXml);
                    }
                    throw;
                }
            }
            if (res != null && res.result.ok)
            {
                BackgroundUploader uploader = new BackgroundUploader();

                //Default HTTP Method is POST (http://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.networking.backgroundtransfer.backgrounduploader.method.aspx)
                //uploader.Method = "POST";

                UploadOperation uploadOperation =
                    await PhotosServiceClient.CreateUploadOperationForCreateImage(file, res.token, uploader);

                await uploadOperation.StartAsync();

                ResponseInformation responseInformation = uploadOperation.GetResponseInformation();

                uint contentLength = Convert.ToUInt32(responseInformation.Headers["Content-Length"]);

                uint statusCode = responseInformation.StatusCode;

                IInputStream resultStreamAt = uploadOperation.GetResultStreamAt(0);

                IBuffer result = await resultStreamAt.ReadAsync(
                    new Windows.Storage.Streams.Buffer(contentLength),
                    contentLength,
                    InputStreamOptions.None);

                Stream responseStream = result.AsStream();

                XDocument xDocument = XDocument.Load(responseStream);

                /*
                 *
                 * Bug!! Root element ("Upload") as diferent cases in error and in success responses
                 *
                 * Must ask SAPO Photos Team about the latency at User creation
                 *
                 * How can an application post photos for a user not being that user? Seems to be possible.
                 *
                 * Return usefull information
                 *
                 */

                string resultCode =
                    xDocument
                    .Descendants("uploadPost")
                    .Select(e => e.Element("Result").Value)
                    .SingleOrDefault();
                return(new CreateImageResult(res.image, resultCode));
            }
            throw new Exception("Request cannot be fulfilled");
        }