private async void ExecuteAttachImageCommand(string fileName) { string selectedFile = fileName; if (selectedFile == null) { var fsa = new FileServiceArgs("Image files|*.png;*.jpg;*.jpeg;*.bmp;*.gif"); selectedFile = await ViewServiceRepository.OpenFile(fsa).ConfigureAwait(false); } if (selectedFile == null) { return; } await AttachImage(selectedFile); }
private async void ExecuteAttachImageCommand() { var fsa = new FileServiceArgs("Image files|*.png;*.jpg;*.jpeg;*.bmp;*.gif"); var selectedFile = await ViewServiceRepository.OpenFile(fsa).ConfigureAwait(false); if (selectedFile == null) { return; } IsSending = true; byte[] mediaData = File.ReadAllBytes(selectedFile); if (mediaData.Length > TwitterConfig.MaxImageSize) { Notifier.DisplayMessage(Strings.ImageSizeTooBig, NotificationType.Error); IsSending = false; return; } var usedAccounts = Accounts.Where(a => a.Use).ToArray(); var acc = usedAccounts.First(); var additionalOwners = usedAccounts.Skip(1).Select(a => a.Context.UserId); string mediaType = GetMimeType(selectedFile); var media = await acc.Context.Twitter.UploadMediaAsync(mediaData, mediaType, additionalOwners).ContinueWith(t => { IsSending = false; return(t.Result); }); await Dispatcher.RunAsync(() => { Medias.Add(media); AttachedMedias.Add(new MediaItem(media.MediaID, mediaData)); }); }