Exemple #1
0
        // List files in a bucket

        public override List <CloudFile> ListFiles(CloudFolder bucket)
        {
            List <CloudFile> results = new List <CloudFile>();

            CloudBlobContainer container = bucket.PlatformObject as CloudBlobContainer; // new CloudBlobContainer(new Uri(bucket.Name));

            IEnumerable <IListBlobItem> blobs = container.ListBlobs();                  //this.StorageClient.ListBlobs(bucket.Name, true, BlobListingDetails.Metadata);

            CloudBlob b = null;

            if (blobs != null)
            {
                foreach (var blob in blobs)
                {
                    if (blob is CloudBlob)
                    {
                        b = blob as CloudBlob;
                        b.FetchAttributes();
                        results.Add(new CloudFile(bucket, b.Name, (ulong)b.Properties.Length, b.Properties.ContentType, b.Properties.LastModified.HasValue ? b.Properties.LastModified.Value.DateTime : DateTime.MinValue, b.Properties.ETag, b));
                    }
                }
            }

            bucket.ItemsLoaded = true;

            return(results);
        }
Exemple #2
0
        // List files in a folder

        public override List <CloudFile> ListFiles(CloudFolder folder)
        {
            try
            {
                this.Exception = null;

                List <CloudFile> results = new List <CloudFile>();

                var fileList = StorageClient.ListObjects(folder.Name);

                if (fileList != null)
                {
                    foreach (Google.Apis.Storage.v1.Data.Object file in fileList)
                    {
                        results.Add(new CloudFile(folder, file.Name, file.Size.HasValue ? file.Size.Value : 0, file.ContentType, file.TimeCreated.HasValue ? file.TimeCreated.Value : DateTime.MinValue, file.ETag, file));
                    }
                }

                folder.ItemsLoaded = true;

                return(results);
            }
            catch (Exception ex)
            {
                this.Exception = ex;
                if (!this.HandleErrors)
                {
                    throw ex;
                }
                return(null);
            }
        }
 public CloudFile(CloudFolder folder, String name, ulong size, String contentType, DateTime created, String ETag, Object platformObject = null)
 {
     this.Folder        = folder;
     this.Name          = name;
     this.Size          = size;
     this.ContentType   = contentType;
     this.Created       = created;
     this.ETag          = ETag;
     this.StorageObject = platformObject;
 }
        // Upload local file to bucket
        // Returns true on success, false on error.

        public override bool UploadFile(CloudFolder bucket, String file)
        {
            try
            {
                this.Exception = null;
                TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(this.AccessKey, this.SecretKey, this.RegionEndpoint));
                fileTransferUtility.Upload(file, bucket.Name);
                return(true);
            }
            catch (Exception ex)
            {
                this.Exception = ex;
                if (!this.HandleErrors)
                {
                    throw ex;
                }
                return(false);
            }
        }
        // List files in a bucket (note: cloud platform may limit response to first 1,000)
        // Returns collection of CloudFile objects, or null on error.

        public override List <CloudFile> ListFiles(CloudFolder bucket)
        {
            try
            {
                this.Exception = null;

                List <CloudFile> results = new List <CloudFile>();

                ListObjectsRequest request = new ListObjectsRequest()
                {
                    BucketName = bucket.Name
                };

                Task <ListObjectsResponse> task = this.StorageClient.ListObjectsAsync(request);
                task.Wait();
                ListObjectsResponse response = task.Result;
                if (response != null && response.S3Objects != null)
                {
                    foreach (S3Object obj in response.S3Objects)
                    {
                        results.Add(new CloudFile(bucket, obj.Key, (ulong)obj.Size, null /* ContentType */, obj.LastModified, null /* ETag */, obj));
                    }
                    bucket.ItemsLoaded = true;
                }
                return(results);
            }
            catch (Exception ex)
            {
                this.Exception = ex;
                if (!this.HandleErrors)
                {
                    throw ex;
                }
                return(null);
            }
        }
Exemple #6
0
        // Upload file

        public override bool UploadFile(CloudFolder bucket, String file)
        {
            return(this.UploadFile(bucket.Name, file));
        }
        // Upload file

        public virtual bool UploadFile(CloudFolder folder, String file)
        {
            return(false);
        }
        // List files in a folder

        public virtual List <CloudFile> ListFiles(CloudFolder folder)
        {
            return(new List <CloudFile>());
        }
Exemple #9
0
        // Upload local file to folder (bucket).
        // Returns true on success, false on error.

        public override bool UploadFile(CloudFolder folder, String file)
        {
            return(UploadFile(folder.Name, file));
        }