public async Task DownloadImageAsync(MessageGroupItem item)
        {
            IsLoading = true;
            var saved = true;

            try
            {
                var imageBytes =
                    await
                    _messageManager.GetMessageContent(SelectedMessageGroup.MessageGroupId,
                                                      item.Message.SentMessageId,
                                                      Shell.Instance.ViewModel.CurrentTokens,
                                                      Shell.Instance.ViewModel.CurrentUser.Region,
                                                      Shell.Instance.ViewModel.CurrentUser.Language);

                await FileAccessCommands.SaveStreamToCameraRoll(imageBytes, item.Message.SentMessageId + ".png");
            }
            catch (Exception ex)
            {
                //Insights.Report(ex);
                saved = false;
            }

            var loader = new ResourceLoader();

            if (!saved)
            {
                await ResultChecker.SendMessageDialogAsync(loader.GetString("ErrorSaveImage/Text"), false);
            }
            else
            {
                await ResultChecker.SendMessageDialogAsync(loader.GetString("ImageSaved/Text"), true);
            }
            IsLoading = false;
        }
Пример #2
0
        private async void Save_OnClick(object sender, RoutedEventArgs e)
        {
            var error = "";

            try
            {
                var imageSource = sender as Button;
                var attachment  = imageSource?.CommandParameter as Attachment;
                if (attachment == null)
                {
                    return;
                }
                var fileName = Path.GetFileName(new Uri(attachment.Url).AbsolutePath);
                var client   = new HttpClient();
                var stream   = await client.GetStreamAsync(attachment.Url);

                await FileAccessCommands.SaveStreamToCameraRoll(stream, fileName);

                // TODO: Setup alert system to say photo saved to camera roll.
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }

            if (string.IsNullOrEmpty(error))
            {
                await MessageDialogMaker.SendMessageDialogAsync("Saved the picture to your camera roll!", true);
            }
            else
            {
                await MessageDialogMaker.SendMessageDialogAsync(error, false);
            }
        }
        private static async Task <bool> DownloadImageAsync(string url)
        {
            try
            {
                var fileName = Path.GetFileName(new Uri(url).AbsolutePath);
                var client   = new HttpClient();
                var stream   = await client.GetStreamAsync(url);

                await FileAccessCommands.SaveStreamToCameraRoll(stream, fileName);
            }
            catch (Exception ex)
            {
                AwfulDebugger.SendMessageDialogAsync("Failed to download image", ex.InnerException);
                return(false);
            }
            return(true);
        }