예제 #1
0
 public UploadAlbumResult(UploadResultCollection images, Basic<AlbumCreateData> albumCreateResults)
 {
     Images = images;
     Results = albumCreateResults;
 }
예제 #2
0
        private async void UploadImagesButton_Click(object sender, RoutedEventArgs e)
        {
            if (QueuedImages.Count <= 0)
            {
                MessageDialog msg = new MessageDialog("You can't upload nothing, silly!");
                await msg.ShowAsync();
            }
            else
            {
                Rect windowBounds = Window.Current.Bounds;

                Popup uploadPopup = new Popup();
                //uploadPopup.Closed += OnPopupClosed;
                //Window.Current.Activated += OnWindowActivated;
                uploadPopup.IsLightDismissEnabled = false;
                uploadPopup.Width = windowBounds.Width;
                uploadPopup.Height = windowBounds.Height;

                // Add the proper animation for the panel.
                /*
                settingsPopup.ChildTransitions = new TransitionCollection();
                settingsPopup.ChildTransitions.Add(new PaneThemeTransition()
                {
                    Edge = (SettingsPane.Edge == SettingsEdgeLocation.Right) ?
                           EdgeTransitionLocation.Right :
                           EdgeTransitionLocation.Left
                });
                */

                // Create a SettingsFlyout the same dimenssions as the Popup.
                UploadingProgressPopup mypane = new UploadingProgressPopup(QueuedImages.Count);
                mypane.UploadCancelButton.Click += UploadCancel;
                mypane.Width = windowBounds.Width;
                mypane.Height = windowBounds.Height;

                // Place the SettingsFlyout inside our Popup window.
                uploadPopup.Child = mypane;

                // Let's define the location of our Popup.
                uploadPopup.SetValue(Canvas.LeftProperty, 0);
                uploadPopup.SetValue(Canvas.TopProperty, 0);
                uploadPopup.IsOpen = true;


                System.Diagnostics.Debug.WriteLine(String.Format("Now uploading {0} items...", QueuedImages.Count));

                UploadResultCollection uploadedImageResults = new UploadResultCollection();

                try
                {

                    foreach (QueuedImage queuedImage in QueuedImages)
                    {
                        if (_uploadCancelRequested) { throw new OperationCanceledException("Cancelled"); }

                        Basic<UploadData> uploadData = await _api.Upload(queuedImage.File, queuedImage.Title, queuedImage.Description, null);
                        UploadImageResult result = new UploadImageResult(queuedImage, uploadData);
                        uploadedImageResults.UploadedImageResults.Add(result);

                        mypane.CompletedFiles++;
                    }

                    if (QueuedImages.Count >= 1 && uploadedImageResults.SuccessfulUploads.Count > 0)
                    {
                        if (QueuedImages.Count == 1)
                        {
                            this.Frame.Navigate(typeof(UploadResultPage), uploadedImageResults.UploadedImageResults[0]);
                        }
                        else
                        {
                            //Make an album
                            List<string> uploadedImageIds = new List<string>();
                            foreach (UploadImageResult r in uploadedImageResults.SuccessfulUploads)
                            {
                                uploadedImageIds.Add(r.Result.Data.ID);
                            }

                            if (_uploadCancelRequested) { throw new OperationCanceledException("Cancelled"); }
                            Basic<AlbumCreateData> createAlbumResult = await _api.CreateAlbum(uploadedImageIds.ToArray(), null, null, null);

                            if (createAlbumResult.Success)
                            {
                                UploadAlbumResult albumResult = new UploadAlbumResult(uploadedImageResults, createAlbumResult);

                                this.Frame.Navigate(typeof(UploadResultPage), albumResult);
                            }
                            else
                            {
                                MessageDialog msg = new MessageDialog("Unable to create album. Please ensure that you are logged in.");
                                await msg.ShowAsync();
                            }
                        }
                    }
                    else
                    {
                        MessageDialog msg = new MessageDialog("Unable to upload anything. Sorry!");
                        await msg.ShowAsync();
                    }
                }
                catch (OperationCanceledException) { }
                finally
                {
                    _uploadCancelRequested = false;
                    uploadPopup.IsOpen = false;
                }
            }
        }