private void SetCommands() { AddAttachmentCommand = new RelayCommand(async() => { var picker = new FileOpenPicker(); picker.ViewMode = PickerViewMode.List; picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary; picker.FileTypeFilter.Add("*"); var files = await picker.PickMultipleFilesAsync(); foreach (var file in files) { byte[] bytes = null; using (var stream = await file.OpenReadAsync()) { IBuffer buffer = WindowsRuntimeBuffer.Create((int)stream.Size); await stream.ReadAsync(buffer, (uint)stream.Size, InputStreamOptions.None); bytes = buffer.ToArray(); } var attach = new FeedbackAttachment(file.Name, bytes, file.ContentType); this.Attachments.Add(new FeedbackAttachmentVM(attach) { FeedbackMessageVM = this }); } }); OpenAttachmentCommand = new RelayCommand(async(o) => { await((FeedbackAttachmentVM)o).OpenAttachmentAsync(); }); SendMessageCommand = new RelayCommand(async(o) => { bool success = true; if (await ValidateInputAsync()) { if (NetworkInterface.GetIsNetworkAvailable()) { this.IsBusy = true; try { IFeedbackMessage sentMessage = await this.SendFeedbackAsync(); this.FeedbackThreadVM.HandleSentMessage(sentMessage); } catch (Exception e) { HockeyClient.Current.AsInternal().HandleInternalUnhandledException(e); success = false; } finally { this.IsBusy = false; } if (!success) { await new MessageDialog(LocalizedStrings.LocalizedResources.FeedbackSendError).ShowAsync(); FeedbackFlyoutVM.ShowFlyout(); } } else { await new MessageDialog(LocalizedStrings.LocalizedResources.FeedbackNoInternet).ShowAsync(); FeedbackFlyoutVM.ShowFlyout(); } } else { FeedbackFlyoutVM.ShowFlyout(); } }); CancelMessageCommand = new RelayCommand((o) => { this.Message = null; this.Attachments.Clear(); }); if (!String.IsNullOrWhiteSpace(this.Email)) { Task t = this.ReLoadGravatar(); } else { this.Gravatar = GravatarHelper.DefaultGravatar; } }
public FeedbackAttachmentVM(FeedbackAttachment attachment = null) { this.FeedbackAttachment = attachment ?? new FeedbackAttachment(null, null, "image/jpeg"); SetCommands(); }