예제 #1
0
        /// <inheritdoc />
        public override void Move(IBlobContentLocation source, IBlobContentLocation destination)
        {
            this.Copy(source, destination);
            var sourceBlob = this.GetBlob(source);

            sourceBlob.BeginDelete(null, null);
        }
예제 #2
0
        private CloudBlockBlob GetBlob(IBlobContentLocation blobLocation)
        {
            var container = this.client.GetContainerReference(this.containerName);
            var blob      = container.GetBlockBlobReference(this.GetBlobName(blobLocation));

            return(blob);
        }
        /// <summary>
        /// Copies the source content to the specified destination on the remote blob storage.
        /// </summary>
        /// <param name="source">Descriptor of the source item on the remote blob storage.</param>
        /// <param name="destination">Descriptor of the destination item on the remote blob storage.</param>
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var request = new CopyObjectRequest()
                .WithSourceBucket(this.bucketName).WithSourceKey(source.FilePath)
                .WithDestinationBucket(this.bucketName).WithDestinationKey(destination.FilePath);

            transferUtility.S3Client.CopyObject(request);
        }
        /// <summary>
        /// Copies the source content to the specified destination on the remote blob storage.
        /// </summary>
        /// <param name="source">Descriptor of the source item on the remote blob storage.</param>
        /// <param name="destination">Descriptor of the destination item on the remote blob storage.</param>
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var request = new CopyObjectRequest()
                          .WithSourceBucket(this.bucketName).WithSourceKey(source.FilePath)
                          .WithDestinationBucket(this.bucketName).WithDestinationKey(destination.FilePath);

            transferUtility.S3Client.CopyObject(request);
        }
 /// <summary>
 /// Deletes the blob item stored under the specified blob location
 /// </summary>
 /// <param name="location">Descriptor of the item on the remote blob storage.</param>
 public override void Delete(IBlobContentLocation location)
 {
     var request = new DeleteObjectRequest()
     {
         BucketName = this.bucketName,
         Key = location.FilePath
     };
     transferUtility.S3Client.DeleteObject(request);
 }
예제 #6
0
        /// <inheritdoc />
        public override void SetProperties(IBlobContentLocation content, IBlobProperties properties)
        {
            var blob = this.GetBlob(content);

            blob.Properties.ContentType  = properties.ContentType;
            blob.Properties.CacheControl = properties.CacheControl;

            blob.BeginSetProperties(null, null);
        }
        /// <summary>
        /// Deletes the blob item stored under the specified blob location
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        public override void Delete(IBlobContentLocation location)
        {
            var request = new DeleteObjectRequest()
            {
                BucketName = this.bucketName,
                Key        = location.FilePath
            };

            transferUtility.S3Client.DeleteObject(request);
        }
        /// <summary>
        /// Gets the content type, cache control settings, etc. of a blob.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <returns>The retrieved properties.</returns>
        public override IBlobProperties GetProperties(IBlobContentLocation location)
        {
            var request = new GetObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);
            GetObjectResponse response = transferUtility.S3Client.GetObject(request);

            return(new BlobProperties
            {
                ContentType = response.Headers["Content-Type"],
                CacheControl = response.Headers["Cache-Control"],
            });
        }
예제 #9
0
        /// <inheritdoc />
        public override IBlobProperties GetProperties(IBlobContentLocation location)
        {
            var blob = this.GetBlob(location);

            blob.FetchAttributes();

            return(new Telerik.Sitefinity.Modules.Libraries.BlobStorage.BlobProperties
            {
                ContentType = blob.Properties.ContentType,
                CacheControl = blob.Properties.CacheControl
            });
        }
        /// <summary>
        /// Copies the source content to the specified destination on the remote blob storage.
        /// </summary>
        /// <param name="source">Descriptor of the source item on the remote blob storage.</param>
        /// <param name="destination">Descriptor of the destination item on the remote blob storage.</param>
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var request = new CopyObjectRequest()
            {
                SourceBucket      = this.bucketName,
                SourceKey         = source.FilePath,
                DestinationBucket = this.bucketName,
                DestinationKey    = destination.FilePath,
                CannedACL         = S3CannedACL.PublicRead
            };

            transferUtility.S3Client.CopyObject(request);
        }
        /// <summary>
        /// Copies the source content to the specified destination on the remote blob storage.
        /// </summary>
        /// <param name="source">Descriptor of the source item on the remote blob storage.</param>
        /// <param name="destination">Descriptor of the destination item on the remote blob storage.</param>
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var request = new CopyObjectRequest()
            {
                SourceBucket = this.bucketName,
                SourceKey = source.FilePath,
                DestinationBucket = this.bucketName,
                DestinationKey = destination.FilePath,
                CannedACL = S3CannedACL.PublicRead
            };

            transferUtility.S3Client.CopyObject(request);
        }
        /// <summary>
        /// Determines whether a blob item under the specified location exists.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <returns>True if the item exists, otherwise - false</returns>
        public override bool BlobExists(IBlobContentLocation location)
        {
            var request = new GetObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);

            try
            {
                var response = transferUtility.S3Client.GetObject(request);
                return true;
            }
            catch (AmazonS3Exception err)
            {
            }
            return false;
        }
        /// <summary>
        /// Determines whether a blob item under the specified location exists.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <returns>True if the item exists, otherwise - false</returns>
        public override bool BlobExists(IBlobContentLocation location)
        {
            var request = new GetObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);

            try
            {
                var response = transferUtility.S3Client.GetObject(request);
                return(true);
            }
            catch (AmazonS3Exception err)
            {
            }
            return(false);
        }
        /// <summary>
        /// Sets the properties, like cacheControl, content type, etc.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <param name="properties">The properties to set.</param>
        public override void SetProperties(IBlobContentLocation location, IBlobProperties properties)
        {
            //No properties to set by default
            var req = new CopyObjectRequest()
                      .WithDirective(S3MetadataDirective.REPLACE)
                      .WithSourceBucket(this.bucketName)
                      .WithSourceKey(location.FilePath)
                      .WithDestinationBucket(this.bucketName)
                      .WithDestinationKey(location.FilePath);

            req.AddHeader("x-amz-acl", "public-read");
            req.AddHeader("Cache-Control", properties.CacheControl);
            req.AddHeader("Content-Type", properties.ContentType);

            transferUtility.S3Client.CopyObject(req);
        }
예제 #15
0
        /// <inheritdoc />
        public override void Delete(IBlobContentLocation content)
        {
            CloudBlob blob = this.GetBlob(content);

            try
            {
                var requestOptions = new Storage.Blob.BlobRequestOptions()
                {
                    RetryPolicy = new Storage.RetryPolicies.NoRetry() // RetryPolicies.Retry(1, TimeSpan.FromSeconds(1))
                };
                blob.DeleteIfExists(DeleteSnapshotsOption.None, null, requestOptions, null);
            }
            catch (Exception e)
            {
                throw new BlobStorageException(string.Format("Cannot delete BLOB '{0}' from library storage '{1}'. {2}: {3}.", this.GetBlobName(content), this.Name, e.Source, e.Message), e);
            }
        }
        /// <summary>
        /// Sets the properties, like cacheControl, content type, etc.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <param name="properties">The properties to set.</param>
        public override void SetProperties(IBlobContentLocation location, IBlobProperties properties)
        {
            //No properties to set by default
            var req = new CopyObjectRequest()
            {
                MetadataDirective = S3MetadataDirective.REPLACE,
                SourceBucket      = this.bucketName,
                SourceKey         = location.FilePath,
                DestinationBucket = this.bucketName,
                DestinationKey    = location.FilePath,
                CannedACL         = S3CannedACL.PublicRead
            };

            req.Headers.CacheControl = properties.CacheControl;
            req.Headers.ContentType  = properties.ContentType;

            transferUtility.S3Client.CopyObject(req);
        }
예제 #17
0
        /// <inheritdoc />
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var sourceBlob = this.GetBlob(source);
            var destBlob   = this.GetBlob(destination);

            if (!(this.client.Credentials is StorageCredentials))
            {
                using (var uploadStream = sourceBlob.OpenRead())
                {
                    destBlob.UploadFromStream(uploadStream);
                }
            }
            else
            {
                // This is a workaround for the SAS authorization case, for which CopyFromBlob throws an exception.
                // It imposes PERFORMANCE, NETWORK and FINANCIAL costs. :(
                using (var uploadSteam = destBlob.OpenWrite())
                    sourceBlob.DownloadToStream(uploadSteam);

                this.SetProperties(destination, this.GetProperties(source));
            }
        }
        /// <inheritdoc />
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            var sourceBlob = this.GetBlob(source);
            var destBlob = this.GetBlob(destination);

            if (!(this.client.Credentials is StorageCredentials))
            {
                using (var uploadStream = sourceBlob.OpenRead())
                {
                    destBlob.UploadFromStream(uploadStream);
                }
            }
            else
            {
                // This is a workaround for the SAS authorization case, for which CopyFromBlob throws an exception.
                // It imposes PERFORMANCE, NETWORK and FINANCIAL costs. :(
                using (var uploadSteam = destBlob.OpenWrite())
                    sourceBlob.DownloadToStream(uploadSteam);

                this.SetProperties(destination, this.GetProperties(source));
            }
        }
 private string GetBlobPath(IBlobContentLocation content)
 {
     return string.Concat(this.containerName, "/", this.GetBlobName(content));
 }
 /// <inheritdoc />
 public override bool BlobExists(IBlobContentLocation location)
 {
     CloudBlob blob = this.GetBlob(location);
     return blob.Exists();
 }
 /// <inheritdoc />
 public override void Delete(IBlobContentLocation content)
 {
     CloudBlob blob = this.GetBlob(content);
     try
     {
         var requestOptions = new Storage.Blob.BlobRequestOptions()
         {
             RetryPolicy = new Storage.RetryPolicies.NoRetry() // RetryPolicies.Retry(1, TimeSpan.FromSeconds(1))
         };
         blob.DeleteIfExists(DeleteSnapshotsOption.None, null, requestOptions, null);
     }
     catch (Exception e)
     {
         throw new BlobStorageException(string.Format("Cannot delete BLOB '{0}' from library storage '{1}'. {2}: {3}.", this.GetBlobName(content), this.Name, e.Source, e.Message), e);
     }
 }
        /// <summary>
        /// Deletes the blob item stored under the specified blob location
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        public override void Delete(IBlobContentLocation location)
        {
            var request = new DeleteObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);

            transferUtility.S3Client.BeginDeleteObject(request, null, null);
        }
 /// <summary>
 /// Deletes the specified location.
 /// </summary>
 /// <param name="location">The location.</param>
 public override void Delete(IBlobContentLocation location)
 {
     try
     {
         this.ContainerBucket.DeleteObject(this.GetBlobPath(location));
     }
     catch (ObjectNotFoundException oex)
     {
         Logger.Writer.Write("Object not found: Error deleting {0} from the cloudfiles CDN. {1}".Arrange(location.FilePath, oex.Message));
     }
 }
        /// <summary>
        /// Gets the content type, cache control settings, etc. of a blob.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <returns>The retrieved properties.</returns>
        public override IBlobProperties GetProperties(IBlobContentLocation location)
        {
            var request = new GetObjectRequest()
            {
                BucketName = this.bucketName,
                Key = location.FilePath
            };
            GetObjectResponse response = transferUtility.S3Client.GetObject(request);

            return new BlobProperties
            {
                ContentType = response.Headers["Content-Type"],
                CacheControl = response.Headers["Cache-Control"],
            };
        }
 /// <summary>
 /// Deletes the blob item stored under the specified blob location
 /// </summary>
 /// <param name="location">Descriptor of the item on the remote blob storage.</param>
 public override void Delete(IBlobContentLocation location)
 {
     var request = new DeleteObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);
     transferUtility.S3Client.BeginDeleteObject(request, null, null);
 }
 public override void Move(IBlobContentLocation source, IBlobContentLocation destination)
 {
     this.Copy(source, destination);
     this.Delete(source);
 }
 /// <summary>
 /// Sets the properties.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <param name="properties">The properties.</param>
 public override void SetProperties(IBlobContentLocation location, IBlobProperties properties)
 {
     //??
 }
예제 #28
0
 private string GetBlobPath(IBlobContentLocation content)
 {
     return(string.Concat(this.containerName, "/", this.GetBlobName(content)));
 }
 private StorageObject GetBlob(IBlobContentLocation blobLocation)
 {
     return this.ContainerBucket.GetObject(this.GetBlobPath(blobLocation));
 }
예제 #30
0
 /// <inheritdoc />
 public override string GetItemUrl(IBlobContentLocation content)
 {
     return(string.Concat(this.rootUrl, this.GetBlobPath(content)));
 }
 private string GetBlobPath(IBlobContentLocation content)
 {
     return this.GetBlobName(content);
 }
        /// <summary>
        /// Gets the item URL.
        /// </summary>
        /// <param name="content">The content.</param>
        /// <returns></returns>
        public override string GetItemUrl(IBlobContentLocation content)
        {
            try{
                var cloudObject = this.GetBlob(content);

                return (cloudObject != null) ? cloudObject.CdnUri.AbsoluteUri : String.Empty;
            }catch(ObjectNotFoundException oex){
                Logger.Writer.Write("Object not found: Error obtaining the Url for file {0} on the CDN as {1} CDN. {2}".Arrange(content.FilePath, content.FilePath, oex.Message));
                return "http://127.0.0.1/{0}".Arrange(content.FilePath); //Cant return nothing, service will die
            }
        }
 private CloudBlockBlob GetBlob(IBlobContentLocation blobLocation)
 {
     var container = this.client.GetContainerReference(this.containerName);
     var blob = container.GetBlockBlobReference(this.GetBlobName(blobLocation));
     return blob;
 }
 /// <summary>
 /// Resolves the content item's external URL on the remote blob storage.
 /// </summary>
 /// <param name="content">Descriptor of the item on the remote blob storage for which to retrieve the URL.</param>
 /// <returns>The resolved content item's external URL on the remote blob storage.</returns>
 public override string GetItemUrl(IBlobContentLocation content)
 {
     return string.Concat("https://", this.bucketName, ".s3.amazonaws.com/", content.FilePath);
 }
 public IBlobProperties GetProperties(IBlobContentLocation location)
 {
     return null;
 }
        /// <summary>
        /// Sets the properties, like cacheControl, content type, etc.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <param name="properties">The properties to set.</param>
        public override void SetProperties(IBlobContentLocation location, IBlobProperties properties)
        {
            //No properties to set by default
            var req = new CopyObjectRequest()
            {
                MetadataDirective = S3MetadataDirective.REPLACE,
                SourceBucket = this.bucketName,
                SourceKey = location.FilePath,
                DestinationBucket = this.bucketName,
                DestinationKey = location.FilePath,
                CannedACL = S3CannedACL.PublicRead
            };

            req.Headers.CacheControl = properties.CacheControl;
            req.Headers.ContentType = properties.ContentType;

            transferUtility.S3Client.CopyObject(req);
        }
 public void Move(IBlobContentLocation source, IBlobContentLocation destination)
 {
     File.Move(this.GetFilePath(source), this.GetFilePath(destination));
 }
        /// <summary>
        /// Copies the specified source.
        /// </summary>
        /// <param name="source">Source is the new file uploaded to the cloud, Delete will be called immediatly after copy completes</param>
        /// <param name="destination">The existing object</param>
        public override void Copy(IBlobContentLocation source, IBlobContentLocation destination)
        {
            try
            {
                var sourceBlobPath = this.GetBlobPath(source);
                var destBlobPath = this.GetBlobPath(destination);

                this.ContainerBucket.CopyObject(sourceBlobPath, destBlobPath);
            }
            catch(Exception ex){
                Logger.Writer.Write("Error Copying Source File: {0} to Destination {1} on the CDN".Arrange(source.FilePath, destination.FilePath, ex.Message));
            }
        }
 public void SetProperties(IBlobContentLocation location, IBlobProperties properties)
 {
 }
 /// <summary>
 /// BLOBs the exists.
 /// </summary>
 /// <param name="location">The location.</param>
 /// <returns></returns>
 public override bool BlobExists(IBlobContentLocation location)
 {
     try
     {
         var blob = this.GetBlob(location);
         return (blob == null) ? false : true; //Not sure why I'm bothering, it'll throw an exception if there's no object
     }
     catch (ObjectNotFoundException oex)
     {
         Logger.Writer.Write("Object not found: Checking if Blob {0} Exists on the cloudfiles CDN. {1}".Arrange(location.FilePath, oex.Message));
         return false;
     }
 }
 protected override string GetFilePath(IBlobContentLocation location)
 {
     return Path.Combine(this.StorageFolder, location.FilePath);
 }
 private void EnsureFilePath(IBlobContentLocation location)
 {
     FileInfo file = new FileInfo(this.GetFilePath(location));
     if (!file.Directory.Exists)
         file.Directory.Create();
 }
        /// <summary>
        /// Sets the properties, like cacheControl, content type, etc.
        /// </summary>
        /// <param name="location">Descriptor of the item on the remote blob storage.</param>
        /// <param name="properties">The properties to set.</param>
        public override void SetProperties(IBlobContentLocation location, IBlobProperties properties)
        {
            //No properties to set by default
            var req = new CopyObjectRequest()
                             .WithDirective(S3MetadataDirective.REPLACE)
                             .WithSourceBucket(this.bucketName)
                             .WithSourceKey(location.FilePath)
                             .WithDestinationBucket(this.bucketName)
                             .WithDestinationKey(location.FilePath);

            req.AddHeader("x-amz-acl", "public-read");
            req.AddHeader("Cache-Control", properties.CacheControl);
            req.AddHeader("Content-Type", properties.ContentType);

            transferUtility.S3Client.CopyObject(req);
        }
예제 #44
0
 /// <summary>
 /// Resolves the content item's external URL on the remote blob storage.
 /// </summary>
 /// <param name="content">Descriptor of the item on the remote blob storage for which to retrieve the URL.</param>
 /// <returns>The resolved content item's external URL on the remote blob storage.</returns>
 public override string GetItemUrl(IBlobContentLocation content)
 {
     return(string.Concat("http://", this.cloudFrontUrl + "/", content.FilePath));
 }
        /// <summary>
        /// Gets the properties.
        /// </summary>
        /// <param name="location">The location.</param>
        /// <returns></returns>
        public override IBlobProperties GetProperties(IBlobContentLocation location)
        {
            var blob = this.GetBlob(location);

            return new BlobProperties
            {
                ContentType = blob.ContentType
            };
        }
 /// <summary>
 /// Resolves the content item's external URL on the remote blob storage.
 /// </summary>
 /// <param name="content">Descriptor of the item on the remote blob storage for which to retrieve the URL.</param>
 /// <returns>The resolved content item's external URL on the remote blob storage.</returns>
 public override string GetItemUrl(IBlobContentLocation content)
 {
     return(string.Concat("http://", this.bucketName, ".s3.amazonaws.com/", content.FilePath));
 }
예제 #47
0
        /// <inheritdoc />
        public override bool BlobExists(IBlobContentLocation location)
        {
            CloudBlob blob = this.GetBlob(location);

            return(blob.Exists());
        }
 public string GetItemUrl(IBlobContentLocation content)
 {
     return string.Concat(this.rootUrl, "/", content.FilePath);
 }
        /// <inheritdoc />
        public override void SetProperties(IBlobContentLocation content, IBlobProperties properties)
        {
            var blob = this.GetBlob(content);

            blob.Properties.ContentType = properties.ContentType;
            blob.Properties.CacheControl = properties.CacheControl;

            blob.BeginSetProperties(null, null);
        }