public StorageTreeNode GetTreeNode(string strPath) { StorageTreeNode oNode = null; try { using (Amazon.S3.AmazonS3 oS3Client = Amazon.AWSClientFactory.CreateAmazonS3Client(m_oRegion)) { string strPrefix = GetDirPath(strPath); Amazon.S3.Model.ListObjectsRequest oRequest = new Amazon.S3.Model.ListObjectsRequest(); oRequest.WithBucketName(m_strBucketName).WithPrefix(strPrefix); using (Amazon.S3.Model.ListObjectsResponse oResponse = oS3Client.ListObjects(oRequest)) { oNode = new StorageTreeNode(strPrefix.Substring(0, strPrefix.Length - 1), true); foreach (Amazon.S3.Model.S3Object entry in oResponse.S3Objects) { AddNodeRecursive(oNode, entry.Key.Substring(strPrefix.Length)); } } } } catch { } return(oNode); }
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); }