Esempio n. 1
0
        public string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
        {
            try
            {
                var client = GetAmazonS3Client();

                var stream = DataAccessHelper.GetStream(picture.S3Image, ImageFormat.Jpeg);                 //We are assuming all JPG for our images

                var key = $"{currentConnectionProfile.FolderName}/{picture.FileName}";
                if (currentConnectionProfile.FolderName.Length == 0)
                {
                    key = $"{picture.FileName}";
                }

                var request = new PutObjectRequest
                {
                    BucketName      = currentConnectionProfile.BucketName,
                    InputStream     = stream,
                    ContentType     = "image/jpeg",
                    Key             = key,
                    CannedACL       = S3CannedACL.FindValue(currentConnectionProfile.CannedACL),
                    AutoCloseStream = true,
                    StorageClass    = S3StorageClass.Standard,
                };


                client.PutObject(request);
                return(key);
            }
            catch (Exception exception)
            {
                throw new Exception($"Error {exception.Message}");
            }
        }
Esempio n. 2
0
 public static void DeleteS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         DataAccess.DeleteS3Media(currentConnectionProfile, currentS3MediaSelected);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 3
0
 public static string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
 {
     try
     {
         return(DataAccess.SaveImageToS3(currentConnectionProfile, picture));
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 4
0
 public static Bitmap GetS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         return(DataAccess.GetS3Media(currentConnectionProfile, currentS3MediaSelected));
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 5
0
 public void DeleteS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         var client = GetAmazonS3Client(currentConnectionProfile);
         client.DeleteObject(currentConnectionProfile.BucketName, currentS3MediaSelected.Key);
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
 private Bitmap GetS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         return(S3Library.GetS3Media(currentConnectionProfile, currentS3MediaSelected));
     }
     catch (Exception exception)
     {
         AddUserMessage(exception.Message);
         return(null);
     }
 }
Esempio n. 7
0
 public static List <S3MediaEntity> GetS3MediaList(S3ConnectionProfileEntity currentConnectionProfile, int takeXRecords)
 {
     try
     {
         var data = DataAccess.GetS3MediaList(currentConnectionProfile, takeXRecords);
         return(data);
     }
     catch (Exception exception)
     {
         throw new SystemException(exception.Message);
     }
 }
Esempio n. 8
0
        public Bitmap GetS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
        {
            try
            {
                var objectResponse = (GetAmazonS3Client()).GetObject(currentConnectionProfile.BucketName, currentS3MediaSelected.Key);
                var bitmap         = DataAccessHelper.GetBitmapFromByteArray(S3ObjectToByteArray(objectResponse).ToArray());

                return(bitmap);
            }
            catch (Exception exception)
            {
                throw new Exception(exception.Message);
            }
        }
Esempio n. 9
0
 public static List <S3MediaEntity> GetS3MediaList(S3ConnectionProfileEntity currentConnectionProfile, int takeXRecords)
 {
     try
     {
         if (currentConnectionProfile.KeyBasedAccessFlag)
         {
             return((new AmazonS3V2.DAL.S3Access()).GetS3MediaList(currentConnectionProfile, takeXRecords));
         }
         else
         {
             return((new AmazonS3V3.DAL.S3Access()).GetS3MediaList(currentConnectionProfile, takeXRecords));
         }
     }
     catch (Exception exception)
     {
         throw new SystemException(exception.Message);
     }
 }
Esempio n. 10
0
 public static void DeleteS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         if (currentConnectionProfile.KeyBasedAccessFlag)
         {
             (new AmazonS3V2.DAL.S3Access()).DeleteS3Media(currentConnectionProfile, currentS3MediaSelected);
         }
         else
         {
             (new AmazonS3V3.DAL.S3Access()).DeleteS3Media(currentConnectionProfile, currentS3MediaSelected);
         }
     }
     catch (Exception exception)
     {
         throw new Exception($"Error {exception.Message}");
     }
 }
Esempio n. 11
0
 public static Bitmap GetS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     try
     {
         if (currentConnectionProfile.KeyBasedAccessFlag)
         {
             return((new AmazonS3V2.DAL.S3Access()).GetS3Media(currentConnectionProfile, currentS3MediaSelected));
         }
         else
         {
             return((new AmazonS3V3.DAL.S3Access()).GetS3Media(currentConnectionProfile, currentS3MediaSelected));
         }
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }
Esempio n. 12
0
        public static string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
        {
            try
            {
                var key = String.Empty;

                if (currentConnectionProfile.KeyBasedAccessFlag)
                {
                    key = (new AmazonS3V2.DAL.S3Access()).SaveImageToS3(currentConnectionProfile, picture);
                }
                else
                {
                    key = (new AmazonS3V3.DAL.S3Access()).SaveImageToS3(currentConnectionProfile, picture);
                }

                return(key);
            }
            catch (Exception exception)
            {
                throw new Exception($"Error {exception.Message}");
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Gets a list of object Keys when given the specified parameters. Please note that the maximum value of takeXRecords is determined by the bucket setup.
        /// </summary>
        /// <param name="currentConnectionProfile">Contains the profile information driving the type of connection we will use with Amazon S3.</param>
        /// <param name="takeXRecords">Specifies how many records to pull. This might be limited to 1000 records, as set up in the Amazon account.</param>
        /// <returns>A list of entity S3MediaEntity, where the Key is probably the most important data used.</returns>
        public List <S3MediaEntity> GetS3MediaList(S3ConnectionProfileEntity currentConnectionProfile, int takeXRecords)
        {
            try
            {
                var s3Client           = GetAmazonS3Client();
                var listObjectsRequest = new ListObjectsRequest
                {
                    MaxKeys    = takeXRecords,
                    BucketName = currentConnectionProfile.BucketName,
                    Prefix     = currentConnectionProfile.FolderName
                };

                var files     = s3Client.ListObjects(listObjectsRequest);
                var mediaList = new List <S3MediaEntity>();

                foreach (var record in files.S3Objects)
                {
                    if (record.Key.Contains("_$folder$"))
                    {
                        continue;
                    }
                    var media = new S3MediaEntity()
                    {
                        ProfileName = currentConnectionProfile.ProfileName,
                        BucketName  = currentConnectionProfile.BucketName,
                        FolderName  = currentConnectionProfile.FolderName,
                        Key         = record.Key
                    };
                    mediaList.Add(media);
                }

                return(mediaList);
            }
            catch (Exception exception)
            {
                throw new SystemException(exception.Message);
            }
        }
Esempio n. 14
0
        private static AmazonS3Client GetAmazonS3Client(S3ConnectionProfileEntity currentConnectionProfile)
        {
            try
            {
                var region = RegionEndpoint.GetBySystemName(currentConnectionProfile.Region);

                if (currentConnectionProfile.KeyBasedAccessFlag)
                {
                    var accessKey = currentConnectionProfile.AccessKeyId;
                    var secretKey = currentConnectionProfile.SecretAccessKey;
                    var client    = new AmazonS3Client(accessKey, secretKey, region);
                    return(client);
                }
                else
                {
                    throw new SystemException("Access mode selected is not yet supported");
                }
            }
            catch (Exception exception)
            {
                throw new SystemException(exception.Message);
            }
        }
Esempio n. 15
0
 public void DeleteS3Media(S3ConnectionProfileEntity currentConnectionProfile, S3MediaEntity currentS3MediaSelected)
 {
     throw new NotImplementedException();
 }
Esempio n. 16
0
 string IMediaRequests.SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
 {
     return(SaveImageToS3(currentConnectionProfile, picture));
 }
        private void UpdateLoadedS3Image(S3ConnectionProfileEntity connectionProfileEntity, S3MediaEntity mediaEntity)
        {
            var s3Media = GetS3Media(connectionProfileEntity, mediaEntity);

            amazonLoadedPicture.Image = s3Media;
        }