main / Source / WebClient / Web.BizLogic / Services / BlobService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataUp.Web.DataLayer;
using DataUp.Web.Common;
using DataUp.Web.BizLogic.Properties;

namespace DataUp.Web.BizLogic
{
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BlobService : IBlobService
    {
        private IBlobDataRepository blobDataRepository;

        /// <summary>
        /// Initializes a new instance of the BlobService class.
        /// </summary>
        /// <param name="blobDataRepository">
        /// Instance of blob data repository.
        /// </param>
        public BlobService(IBlobDataRepository blobDataRepository)
        {
            this.blobDataRepository = blobDataRepository;
        }

        /// <summary>
        /// Gets the files from azure which is identified by file id.
        /// </summary>
        /// <param name="fileID">
        /// ID of the file.
        /// </param>
        /// <returns>
        /// Blob details.
        /// </returns>
        public BlobDetails GetFile(Guid fileId)
        {
            return this.blobDataRepository.GetBlobContent(fileId.ToString().ToUpperInvariant());
        }

        /// <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 CheckIfExists(string fileName)
        {
            OperationStatus operationStatus = null;
            BlobDetails fileBlob = new BlobDetails()
            {
                BlobID = fileName,
            };

            try
            {
                if (this.blobDataRepository.CheckIfExists(fileBlob))
                {
                    operationStatus = OperationStatus.CreateSuccessStatus();
                }
                else
                {
                    operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage);
                }
            }
            catch (Exception ex)
            {
                operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage, ex);
            }

            return operationStatus;
        }

        /// <summary>
        /// Uploads the file to db/azure.
        /// </summary>
        /// <param name="fileDetail">Details of the file.</param>
        /// <returns>True if content is uploaded; otherwise false.</returns>
        public OperationStatus UploadFile(DataDetail fileDetail)
        {
            OperationStatus operationStatus = null;

            // Make sure file detail is not null
            this.CheckNotNull(() => new { fileDetail });

            BlobDetails fileBlob = new BlobDetails()
            {
                BlobID = fileDetail.AzureId.ToString(),
                Data = fileDetail.DataStream,
                MimeType = fileDetail.MimeType
            };

            try
            {
                this.blobDataRepository.UploadFile(fileBlob);
                operationStatus = OperationStatus.CreateSuccessStatus();
            }
            catch (Exception)
            {
                operationStatus = OperationStatus.CreateFailureStatus(Resources.UnknownErrorMessage);
            }

            return operationStatus;
        }
    }
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.