public ImageResultsControl(UploadImageResult r)
        {
            this.InitializeComponent();
            _result = r;

            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("Link (email & IM)", String.Format("http://imgur.com/{0}", _result.Result.Data.ID), true));
            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("Direct Link (email & IM)", String.Format("http://i.imgur.com/{0}{1}", _result.Result.Data.ID, _result.Image.File.FileType), true));
            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("HTML Image (websites & blogs)", String.Format(@"<a href=""http://imgur.com/{0}""><img src=""http://i.imgur.com/{0}{1}"" alt="" title=""Hosted by imgur.com"" /></a>", _result.Result.Data.ID, _result.Image.File.FileType), false));
            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("BBCode (message boards & forums)", String.Format(@"[IMG]http://i.imgur.com/{0}{1}[/IMG]", _result.Result.Data.ID, _result.Image.File.FileType), false));
            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("Linked BBCode (message boards)", String.Format(@"[URL=http://imgur.com/{0}][IMG]http://i.imgur.com/{0}{1}[/IMG][/URL]", _result.Result.Data.ID, _result.Image.File.FileType), false));
            CopyableLinksStackPanel.Children.Add(new CopyableLinkControl("Markdown Link (reddit comment)", String.Format(@"[Imgur](http://i.imgur.com/{0}{1})", _result.Result.Data.ID, _result.Image.File.FileType), false));
        }
Ejemplo n.º 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;
                }
            }
        }