private void UploadImagesAndSavePost() { this.Focus(); //hide the keyboard ApplicationBar.IsVisible = false; //hide the application bar App.WaitIndicationService.ShowIndicator(_localizedStrings.Messages.UploadingMedia); //fire off the worker rpcs if (_mediaUploadRPCs.Count > 0) { UploadFileRPC item = _mediaUploadRPCs.First() as UploadFileRPC; item.ExecuteAsync(); } }
private void OnUploadMediaRPCCompleted(object sender, XMLRPCCompletedEventArgs <Media> args) { UploadFileRPC rpc = sender as UploadFileRPC; rpc.Completed -= OnUploadMediaRPCCompleted; lock (_syncRoot) { _mediaUploadRPCs.Remove(rpc); if (args.Cancelled) { return; } if (args.Items.Count == 0 || args.Error != null) { //uh oh, media upload problem App.WaitIndicationService.KillSpinner(); //Move UIThread.Invoke(() => { ApplicationBar.IsVisible = true; if (!_messageBoxIsShown) { _messageBoxIsShown = true; String msg = args.Error != null ? args.Error.Message : _localizedStrings.Prompts.MediaError; MessageBoxResult result = MessageBox.Show(msg, _localizedStrings.Prompts.MediaError, MessageBoxButton.OK); _messageBoxIsShown = false; } }); this.emptyImagesUploadingQueue(); return; } else { //Image uploaded correctly. Upload the next picture in the list if (_mediaUploadRPCs.Count > 0) { UploadFileRPC item = _mediaUploadRPCs.First() as UploadFileRPC; item.ExecuteAsync(); return; } App.WaitIndicationService.KillSpinner(); SavePost(); } }//end lock }
private void OnSaveButtonClick(object sender, EventArgs e) { _messageBoxIsShown = false; Post post = DataContext as Post; //Do not publish pages with no title or content. if (!post.HasMedia()) { //check the content if (titleTextBox.Text.Trim() == "" && contentTextBox.Text.Trim() == "") { MessageBox.Show( string.Format(_localizedStrings.Messages.TitleAndContentEmpty, _localizedStrings.Prompts.Page), _localizedStrings.PageTitles.Error, MessageBoxButton.OK); return; } } switch (this.statusPicker.SelectedIndex) { case 0: post.PostStatus = "publish"; break; case 1: post.PostStatus = "draft"; break; case 2: post.PostStatus = "pending"; break; case 3: post.PostStatus = "private"; break; case 4: post.PostStatus = "localdraft"; break; } //make sure the post has the latest UI data--the Save button is a ToolbarButton //which doesn't force focus to change post.Title = titleTextBox.Text; if (post.HasMedia()) { if (!post.IsLocalDraft()) { foreach (Media currentMedia in post.Media) { // If there is an error posting the user may try again. // Media that has already been uploaded will have a good URL. // Check for this and don't upload media a second time. if (currentMedia.Url != null && currentMedia.Url.Length > 0) continue; UploadFileRPC rpc = new UploadFileRPC(App.MasterViewModel.CurrentBlog, currentMedia, true); rpc.Completed += OnUploadMediaRPCCompleted; //store this for later--we'll upload the files once the user hits save _mediaUploadRPCs.Add(rpc); } if (_mediaUploadRPCs.Count > 0) { UploadImagesAndSavePost(); return; } } } SavePost(); }
private void OnSaveButtonClick(object sender, EventArgs e) { _messageBoxIsShown = false; Post post = DataContext as Post; //Do not publish pages with no title or content. if (!post.HasMedia()) { //check the content if (titleTextBox.Text.Trim() == "" && contentTextBox.Text.Trim() == "") { MessageBox.Show( string.Format(_localizedStrings.Messages.TitleAndContentEmpty, _localizedStrings.Prompts.Page), _localizedStrings.PageTitles.Error, MessageBoxButton.OK); return; } } switch (this.statusPicker.SelectedIndex) { case 0: post.PostStatus = "publish"; break; case 1: post.PostStatus = "draft"; break; case 2: post.PostStatus = "pending"; break; case 3: post.PostStatus = "private"; break; case 4: post.PostStatus = "localdraft"; break; } //make sure the post has the latest UI data--the Save button is a ToolbarButton //which doesn't force focus to change post.Title = titleTextBox.Text; if (post.HasMedia()) { if (!post.IsLocalDraft()) { foreach (Media currentMedia in post.Media) { // If there is an error posting the user may try again. // Media that has already been uploaded will have a good URL. // Check for this and don't upload media a second time. if (currentMedia.Url != null && currentMedia.Url.Length > 0) { continue; } UploadFileRPC rpc = new UploadFileRPC(App.MasterViewModel.CurrentBlog, currentMedia, true); rpc.Completed += OnUploadMediaRPCCompleted; //store this for later--we'll upload the files once the user hits save _mediaUploadRPCs.Add(rpc); } if (_mediaUploadRPCs.Count > 0) { UploadImagesAndSavePost(); return; } } } SavePost(); }