Esempio n. 1
0
        private void EndCallbackGetListObjects(IAsyncResult ar)
        {
            TransportClass oObject = null;

            try
            {
                oObject = ar.AsyncState as TransportClass;
                oObject.m_oListObjectsResponse = oObject.m_oS3Client.EndListObjects(ar);

                if (oObject.m_oListObjectsResponse.S3Objects.Count > 0)
                {
                    Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest();
                    oDeleteObjectsRequest.WithBucketName(m_strBucketName);

                    foreach (Amazon.S3.Model.S3Object oS3Obj in oObject.m_oListObjectsResponse.S3Objects)
                    {
                        oDeleteObjectsRequest.AddKey(oS3Obj.Key);
                    }

                    oObject.m_oS3Client.BeginDeleteObjects(oDeleteObjectsRequest, m_oRemoveDirectory.m_fCallback, m_oRemoveDirectory.m_oParam);
                }
                else
                {
                    oObject.FireCallback();
                }
            }
            catch
            {
                m_oRemoveDirectory.m_eError = ErrorTypes.StorageRemoveDir;
                m_oRemoveDirectory.DisposeAndCallback();
            }
        }
Esempio n. 2
0
        public ErrorTypes RemovePath(string strPath)
        {
            ErrorTypes eResult = ErrorTypes.StorageRemoveDir;

            try
            {
                string strDirKey = GetDirPath(strPath);

                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oListObjectsRequest.WithBucketName(m_strBucketName).WithPrefix(strDirKey);

                    using (Amazon.S3.Model.ListObjectsResponse oListObjectsResponse = oS3Client.ListObjects(oListObjectsRequest))
                    {
                        int nDeletedObjectCount   = 0;
                        int nObjectsToDeleteCount = oListObjectsResponse.S3Objects.Count;
                        if (nObjectsToDeleteCount > 0)
                        {
                            Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest();
                            oDeleteObjectsRequest.WithBucketName(m_strBucketName);

                            foreach (Amazon.S3.Model.S3Object oS3Obj in oListObjectsResponse.S3Objects)
                            {
                                oDeleteObjectsRequest.AddKey(oS3Obj.Key);
                            }

                            using (Amazon.S3.Model.DeleteObjectsResponse oDeleteObjectsResponse = oS3Client.DeleteObjects(oDeleteObjectsRequest))
                            {
                                nDeletedObjectCount = oDeleteObjectsResponse.DeletedObjects.Count;
                            }
                        }

                        if (nObjectsToDeleteCount == nDeletedObjectCount)
                        {
                            eResult = ErrorTypes.NoError;
                        }
                    }
                }
            }
            catch
            {
            }

            return(eResult);
        }
Esempio n. 3
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult> DeleteAsync(System.String BucketName, System.String[] StorageFileNames)
        {
            SoftmakeAll.SDK.CloudStorage.AWS.Environment.Validate();

            SoftmakeAll.SDK.OperationResult OperationResult = new SoftmakeAll.SDK.OperationResult();

            if ((System.String.IsNullOrWhiteSpace(BucketName)) || (StorageFileNames == null) || (StorageFileNames.Length == 0))
            {
                OperationResult.Message = "The BucketName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            System.Collections.Generic.List <Amazon.S3.Model.KeyVersion> Objects = new System.Collections.Generic.List <Amazon.S3.Model.KeyVersion>();
            foreach (System.String StorageFileName in StorageFileNames)
            {
                Objects.Add(new Amazon.S3.Model.KeyVersion()
                {
                    Key = StorageFileName
                });
            }
            Amazon.S3.Model.DeleteObjectsRequest DeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest {
                BucketName = BucketName, Objects = Objects
            };

            try
            {
                await SoftmakeAll.SDK.CloudStorage.AWS.Environment._S3Client.DeleteObjectsAsync(DeleteObjectsRequest);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }
        private void EndCallbackGetListObjects(IAsyncResult ar)
        {
            TransportClass oObject = null;
            try
            {
                oObject = ar.AsyncState as TransportClass;
                oObject.m_oListObjectsResponse = oObject.m_oS3Client.EndListObjects(ar);

                if (oObject.m_oListObjectsResponse.S3Objects.Count > 0)
                {
                    Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest();
                    oDeleteObjectsRequest.WithBucketName(m_strBucketName);

                    foreach (Amazon.S3.Model.S3Object oS3Obj in oObject.m_oListObjectsResponse.S3Objects)
                    {
                        oDeleteObjectsRequest.AddKey(oS3Obj.Key);
                    }

                    oObject.m_oS3Client.BeginDeleteObjects(oDeleteObjectsRequest, m_oRemoveDirectory.m_fCallback, m_oRemoveDirectory.m_oParam);
                }
                else
                {
                    oObject.FireCallback();
                }
            }
            catch
            {
                m_oRemoveDirectory.m_eError = ErrorTypes.StorageRemoveDir;
                m_oRemoveDirectory.DisposeAndCallback();
            }
        }
        public ErrorTypes RemovePath(string strPath)
        {
            ErrorTypes eResult = ErrorTypes.StorageRemoveDir;
            try
            {
                string strDirKey = GetDirPath(strPath);

                using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion))
                {
                    Amazon.S3.Model.ListObjectsRequest oListObjectsRequest = new Amazon.S3.Model.ListObjectsRequest();
                    oListObjectsRequest.WithBucketName(m_strBucketName).WithPrefix(strDirKey);

                    using (Amazon.S3.Model.ListObjectsResponse oListObjectsResponse = oS3Client.ListObjects(oListObjectsRequest))
                    {
                        int nDeletedObjectCount = 0;
                        int nObjectsToDeleteCount = oListObjectsResponse.S3Objects.Count;
                        if (nObjectsToDeleteCount > 0)
                        {
                            Amazon.S3.Model.DeleteObjectsRequest oDeleteObjectsRequest = new Amazon.S3.Model.DeleteObjectsRequest();
                            oDeleteObjectsRequest.WithBucketName(m_strBucketName);

                            foreach (Amazon.S3.Model.S3Object oS3Obj in oListObjectsResponse.S3Objects)
                            {
                                oDeleteObjectsRequest.AddKey(oS3Obj.Key);
                            }

                            using (Amazon.S3.Model.DeleteObjectsResponse oDeleteObjectsResponse = oS3Client.DeleteObjects(oDeleteObjectsRequest))
                            {
                                nDeletedObjectCount = oDeleteObjectsResponse.DeletedObjects.Count;
                            }
                        }

                        if (nObjectsToDeleteCount == nDeletedObjectCount)
                            eResult = ErrorTypes.NoError;
                    }
                }
            }
            catch
            {
            }

            return eResult;
        }
Esempio n. 6
0
        public ActionResult BulkDeleteConfirmed(string prefix = "", int maxKeys = 100)
        {
            if (!String.IsNullOrWhiteSpace(prefix))
              {
            ViewBag.prefix = prefix;
            ViewBag.maxKeys = maxKeys;

            var list = new Amazon.S3.Model.ListObjectsRequest();
            list.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]);
            if (!String.IsNullOrWhiteSpace(prefix))
            {
              list.WithPrefix(prefix);
            }

            list.WithMaxKeys(maxKeys);

            var keys = s3.ListObjects(list).S3Objects.Select(e => new Amazon.S3.Model.KeyVersion(e.Key)).ToArray();

            var bulkDelete = new Amazon.S3.Model.DeleteObjectsRequest();
            bulkDelete.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]);
            bulkDelete.WithKeys(keys);
            s3.DeleteObjects(bulkDelete);
              }

              return RedirectToAction("Index", new { prefix = prefix, maxKeys = maxKeys });
        }