public String GetS3ContextAsText(string bucket, string key) { var s3client = new Amazon.S3.AmazonS3Client(); var response = s3client.GetObjectAsync(new GetObjectRequest { BucketName = bucket, Key = key }); response.Wait(); return(new StreamReader(response.Result.ResponseStream).ReadToEnd()); }
async Task <IMailMessage> GetObject(Amazon.S3.Model.S3Object item) { var request = new Amazon.S3.Model.GetObjectRequest { Key = item.Key, BucketName = item.BucketName }; var response = await S3Client.GetObjectAsync(request); var sesMessage = MimeMessage.Load(response.ResponseStream); return(Account.CreateMailMessage(sesMessage, Account.S3Bucket)); }
public static FontFamily GetCaptionFontFamily() { try { return(SystemFonts.Find("DejaVu Sans")); } catch (SixLabors.Fonts.Exceptions.FontFamilyNotFoundException) { using (Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.USEast2)) using (Amazon.S3.Model.GetObjectResponse response = client.GetObjectAsync("appraisal-bot", "DejaVuSans-Bold.ttf").GetAwaiter().GetResult()) using (MemoryStream memoryStream = new MemoryStream()) { // ResponseStream is a HashStream which doesn't support Seeking // which is required to install a font. So first we copy the // data to a MemoryStream which does support seeking. response.ResponseStream.CopyTo(memoryStream); memoryStream.Seek(0, SeekOrigin.Begin); FontCollection fonts = new FontCollection(); FontFamily font = fonts.Install(memoryStream); return(font); } } }
public static Bitmap LoadImage(LoadImageType type, string fileName) { string directory = type == LoadImageType.Source ? "sourceArt" : "testArt"; Console.WriteLine("LoadImage: " + fileName); if (Program.IsRunningTests()) { return(Image.Load <PixelColor>("../../../" + directory + "/" + fileName)); } else { if (Directory.Exists(directory)) { return(Image.Load <PixelColor>(directory + "/" + fileName)); } else { Amazon.S3.AmazonS3Client client = new Amazon.S3.AmazonS3Client(Amazon.RegionEndpoint.USEast2); Amazon.S3.Model.GetObjectResponse response = client.GetObjectAsync("appraisal-bot", fileName).GetAwaiter().GetResult(); return(Image.Load <PixelColor>(response.ResponseStream)); } } }