/// <summary> /// Uploads a file to azure as a blob. /// </summary> /// <param name="details"> /// Details of the file which has to be uploaded to azure. /// </param> /// <returns> /// True if the file is uploaded successfully; otherwise false. /// </returns> public bool UploadAsset(BlobDetails details) { this.CheckNotNull(() => details); return UploadBlobContent(details, Constants.AssetContainerName); }
/// <summary> /// Deletes file from azure. /// </summary> /// <param name="fileDetail">Details of the file.</param> private void DeleteFile(FileDetail fileDetail) { var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), MimeType = fileDetail.MimeType }; // Delete file from azure. _blobDataRepository.DeleteFile(fileBlob); }
/// <summary> /// Uploads file to azure. /// </summary> /// <param name="fileDetails">Details of the file.</param> public OperationStatus UploadAsset(FileDetail fileDetails) { OperationStatus operationStatus = null; this.CheckNotNull(() => new { fileDetails }); var fileBlob = new BlobDetails() { BlobID = fileDetails.Name, Data = fileDetails.DataStream, MimeType = fileDetails.MimeType }; try { if (_blobDataRepository.UploadAsset(fileBlob)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return operationStatus; }
/// <summary> /// Upload the blob content to azure. /// </summary> /// <param name="details"> /// Details of the blob. /// </param> /// <param name="containerName"> /// Name of the container. /// </param> /// <returns> /// True, if the blob is successfully uploaded to azure;otherwise false. /// </returns> private bool UploadBlobContent(BlobDetails details, string containerName) { this.CheckNotNull(() => details); try { var container = GetContainer(containerName); // Seek to start. details.Data.Position = 0; // TODO: Check if the input file type and then use either block blob or page blob. // For plate file we need to upload the file as page blob. var blob = container.GetBlockBlobReference(details.BlobID.ToUpperInvariant()); blob.Properties.ContentType = details.MimeType; blob.UploadFromStream(details.Data); return true; } catch (InvalidOperationException) { // "Error uploading blob {0}: {1}", ContainerUrl + _PathSeparator + blobName, se.Message } return false; }
/// <summary> /// Move temporary file to actual container in azure. /// </summary> /// <param name="fileDetails">Details of the file.</param> private bool MoveFile(FileDetail fileDetails) { var fileBlob = new BlobDetails() { BlobID = fileDetails.AzureID.ToString(), MimeType = fileDetails.MimeType }; return _blobDataRepository.MoveFile(fileBlob); }
/// <summary> /// Checks a file in azure. /// </summary> /// <param name="details"> /// Details of the file which has to be checked. /// </param> /// <returns> /// True if the file is found successfully; otherwise false. /// </returns> public bool CheckIfAssetExists(BlobDetails details) { return ExistsBlobContent(details, Constants.AssetContainerName); }
/// <summary> /// Checks if the blob content is present in azure or not. /// </summary> /// <param name="details"> /// Details of the blob. /// </param> /// <param name="containerName"> /// Name of the container. /// </param> /// <returns> /// True, if the blob is successfully found to azure;otherwise false. /// </returns> private static bool ExistsBlobContent(BlobDetails details, string containerName) { try { var container = GetContainer(containerName); // TODO: Check if the input file type and then use either block blob or page blob. // For plate file we need to upload the file as page blob. var blob = container.GetBlobReferenceFromServer(details.BlobID.ToUpperInvariant()); blob.FetchAttributes(); return true; } catch (StorageException) { // "Error uploading blob {0}: {1}", ContainerUrl + _PathSeparator + blobName, se.Message } return false; }
/// <summary> /// Deletes Thumbnail from azure. /// </summary> /// <param name="azureId">Id of the thumbnail to be deleted.</param> private void DeleteThumbnail(Guid? azureId) { if (azureId.HasValue && !azureId.Equals(Guid.Empty)) { var fileBlob = new BlobDetails() { BlobID = azureId.ToString(), }; // Delete file from azure. _blobDataRepository.DeleteThumbnail(fileBlob); } }
/// <summary> /// Moves thumbnail from temporary storage to thumbnail storage in azure. /// </summary> /// <param name="thumbnail">Details of the thumbnail</param> private bool MoveThumbnail(FileDetail thumbnail) { var thumbnailBlob = new BlobDetails() { BlobID = thumbnail.AzureID.ToString() }; return _blobDataRepository.MoveThumbnail(thumbnailBlob); }
/// <summary> /// Gets the file stream based on the blobDetails /// </summary> /// <param name="blobDetails">Details of the blob</param> /// <returns>File Stream Result </returns> private FileStreamResult GetFileStream(BlobDetails blobDetails) { // Update the response header. Response.AddHeader("Content-Encoding", blobDetails.MimeType); // Set the position to Begin. blobDetails.Data.Seek(0, SeekOrigin.Begin); return new FileStreamResult(blobDetails.Data, blobDetails.MimeType); }
/// <summary> /// Moves thumbnail from temporary storage to thumbnail storage in azure. /// </summary> /// <param name="profileImageId">Guid of the temporary profile image.</param> private Guid? MoveThumbnail(Guid? profileImageId) { Guid? thumbnailId = null; if (profileImageId.HasValue && !profileImageId.Equals(Guid.Empty)) { var thumbnailBlob = new BlobDetails() { BlobID = profileImageId.ToString() }; thumbnailId = _blobDataRepository.MoveThumbnail(thumbnailBlob) ? profileImageId.Value : Guid.Empty; } return thumbnailId; }
/// <summary> /// Uploads the associated file to temporary container. /// </summary> /// <param name="fileDetail">Details of the associated file.</param> /// <returns>True if content is uploaded; otherwise false.</returns> public OperationStatus UploadTemporaryFile(FileDetail fileDetail) { OperationStatus operationStatus = null; // Make sure file detail is not null this.CheckNotNull(() => new { fileDetail }); var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), Data = fileDetail.DataStream, MimeType = fileDetail.MimeType }; try { _blobDataRepository.UploadTemporaryFile(fileBlob); operationStatus = OperationStatus.CreateSuccessStatus(); } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return operationStatus; }
/// <summary> /// Checks the file from azure which is identified by file name. /// </summary> /// <param name="fileName"> /// file name. /// </param> /// <returns> /// Operation Status /// </returns> public OperationStatus CheckIfAssetExists(string fileName) { OperationStatus operationStatus = null; var fileBlob = new BlobDetails() { BlobID = fileName, }; try { if (_blobDataRepository.CheckIfAssetExists(fileBlob)) { operationStatus = OperationStatus.CreateSuccessStatus(); } else { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } } catch (Exception ex) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage, ex); } return operationStatus; }
/// <summary> /// Deletes the file from azure which is identified by file name. /// </summary> /// <param name="fileName"> /// file name. /// </param> /// <returns> /// Operation Status /// </returns> public OperationStatus DeleteAsset(string fileName) { OperationStatus operationStatus = null; var fileBlob = new BlobDetails() { BlobID = fileName, }; try { _blobDataRepository.DeleteAsset(fileBlob); operationStatus = OperationStatus.CreateSuccessStatus(); } catch (Exception) { operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage); } return operationStatus; }
/// <summary> /// Deletes a file from azure. /// </summary> /// <param name="details"> /// Details of the file which has to be deleted. /// </param> /// <returns> /// True if the file is deleted successfully; otherwise false. /// </returns> public bool DeleteAsset(BlobDetails details) { return DeleteBlob(details, Constants.AssetContainerName); }
/// <summary> /// Move a thumbnail from temporary container to thumbnail container in azure. /// </summary> /// <param name="details"> /// Details of the thumbnail which has to be uploaded to azure. /// </param> /// <returns> /// True if the thumbnail is moved successfully; otherwise false. /// </returns> public bool MoveThumbnail(BlobDetails details) { return MoveBlob(details, Constants.TemporaryContainerName, Constants.ThumbnailContainerName); }
/// <summary> /// Move a file from temporary container to asset container in azure. /// </summary> /// <param name="details"> /// Details of the file which has to be uploaded to azure. /// </param> /// <returns> /// True if the file is moved successfully; otherwise false. /// </returns> public bool MoveAssetFile(BlobDetails details) { return MoveBlob(details, Constants.TemporaryContainerName, Constants.AssetContainerName); }
/// <summary> /// Uploads a thumbnail to azure as a blob. /// </summary> /// <param name="details"> /// Details of the thumbnail which has to be uploaded. /// </param> /// <returns> /// True if the thumbnail is uploaded successfully; otherwise false. /// </returns> public bool UploadThumbnail(BlobDetails details) { this.CheckNotNull(() => details); return UploadBlobContent(details, Constants.ThumbnailContainerName); }
private static bool MoveBlob(BlobDetails details, string sourceContainerName, string destinationContainerName) { try { var sourceContainer = GetContainer(sourceContainerName); var destinationContainer = GetContainer(destinationContainerName); // TODO: Check if the input file type and then use either block blob or page blob. // For plate file we need to upload the file as page blob. var sourceBlob = sourceContainer.GetBlockBlobReference(details.BlobID.ToUpperInvariant()); var destinationBlob = destinationContainer.GetBlockBlobReference(details.BlobID.ToUpperInvariant()); destinationBlob.StartCopyFromBlob(sourceBlob); destinationBlob.Properties.ContentType = sourceBlob.Properties.ContentType; sourceBlob.Delete(); return true; } catch (Exception) { // "Error moving blob {0}: {1}", ContainerUrl + _PathSeparator + blobName, se.Message } return false; }
/// <summary> /// Uploads a file to azure as a blob in temporary container. /// </summary> /// <param name="details"> /// Details of the file which has to be uploaded to azure. /// </param> /// <returns> /// True if the file is uploaded successfully; otherwise false. /// </returns> public bool UploadTemporaryFile(BlobDetails details) { this.CheckNotNull(() => details); return UploadBlobContent(details, Constants.TemporaryContainerName); }
/// <summary> /// Deletes the specified file pointed by the blob. /// </summary> /// <param name="details"> /// Details of the blob. /// </param> /// <param name="containerName"> /// Name of the container. /// </param> private static bool DeleteBlob(BlobDetails details, string containerName) { try { var container = GetContainer(containerName); container.GetBlobReferenceFromServer(details.BlobID.ToUpperInvariant()).Delete(); return true; } catch (InvalidOperationException) { // "Error deleting blob {0}: {1}", ContainerUrl + _PathSeparator + blobName, se.Message return false; } }
/// <summary> /// Deletes a file from azure. /// </summary> /// <param name="details"> /// Details of the file which has to be uploaded to azure. /// </param> /// <returns> /// True if the file is deleted successfully; otherwise false. /// </returns> public bool DeleteFile(BlobDetails details) { return DeleteBlob(details, Constants.ContainerName); }
/// <summary> /// Moves thumbnail from temporary storage to thumbnail storage in azure. /// </summary> /// <param name="fileDetails">Details of the thumbnail.</param> private Guid MoveThumbnail(FileDetail fileDetails) { var thumbnailId = Guid.Empty; if (fileDetails != null && fileDetails.AzureID != Guid.Empty) { var thumbnailBlob = new BlobDetails() { BlobID = fileDetails.AzureID.ToString() }; thumbnailId = _blobDataRepository.MoveThumbnail(thumbnailBlob) ? fileDetails.AzureID : Guid.Empty; } return thumbnailId; }
/// <summary> /// Deletes a thumbnail from azure. /// </summary> /// <param name="details"> /// Details of the thumbnail which has to be uploaded. /// </param> /// <returns> /// True if the thumbnail is deleted successfully; otherwise false. /// </returns> public bool DeleteThumbnail(BlobDetails details) { return DeleteBlob(details, Constants.ThumbnailContainerName); }
private void DeleteTemporaryThumbnail(ContentDetails contentDetails) { var thumbnailBlob = new BlobDetails() { BlobID = contentDetails.Thumbnail.AzureID.ToString() }; // Delete thumbnail from azure. _blobDataRepository.DeleteThumbnail(thumbnailBlob); }
/// <summary> /// Deletes a temporary file from azure. /// </summary> /// <param name="details"> /// Details of the file which has to be uploaded to azure. /// </param> /// <returns> /// True if the file is deleted successfully; otherwise false. /// </returns> public bool DeleteTemporaryFile(BlobDetails details) { return DeleteBlob(details, Constants.TemporaryContainerName); }
/// <summary> /// Uploads the associated file to temporary container. /// </summary> /// <param name="fileDetail">Details of the associated file.</param> /// <returns>True if content is uploaded; otherwise false.</returns> public bool UploadTemporaryFile(FileDetail fileDetail) { // Make sure file detail is not null this.CheckNotNull(() => new { fileDetail }); var fileBlob = new BlobDetails() { BlobID = fileDetail.AzureID.ToString(), Data = fileDetail.DataStream, MimeType = fileDetail.MimeType }; return _blobDataRepository.UploadTemporaryFile(fileBlob); }
/// <summary> /// Gets the file stream based on the blobDetails /// </summary> /// <param name="blobDetails">Details of the blob</param> /// <returns>File Stream Result </returns> private Stream GetFileStream(BlobDetails blobDetails) { // Update the response header. Response.ContentType = blobDetails.MimeType; // Set the position to Begin. blobDetails.Data.Seek(0, SeekOrigin.Begin); return blobDetails.Data; }