Esempio n. 1
0
        /// <summary>
        /// A publicly available method for creating a single instance of this cache
        /// if one doesn't already exist, or getting a reference to the single instance.
        /// </summary>
        /// <returns>
        /// A reference to the single instance of this cache class.
        /// </returns>
        public static UploadedFileCache GetInstance()
        {
            //create if not exists
            if (s_Instance == null)
            {
                s_Instance = new UploadedFileCache();
            }

            return(s_Instance);
        }
Esempio n. 2
0
        /// <summary>
        /// A clean-up method.  Call the <see cref="UploadedFileCache.DeleteOldFiles"/> method
        /// to remove all old files from intermediate file storage every time the event is fired.
        /// Call the <see cref="BlobManager.RemoveExpiredTemporaryBlobs"/> method to remove
        /// all old temporary blobs from cloud storage every other time the event is fired.
        /// </summary>
        /// <param name="sender">The timer object that called this event.</param>
        /// <param name="e">Any "Timer's up" arguments. Not used.</param>
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            UploadedFileCache.DeleteOldFiles();

            //Only call when true, alternate each time
            //effectively a 30 min timer for purging blobs
            if (s_ShouldPurgeBlobs)
            {
                BlobManager.RemoveExpiredTemporaryBlobs();
            }

            s_ShouldPurgeBlobs = !s_ShouldPurgeBlobs;
        }
Esempio n. 3
0
        /// <summary>
        /// Method called automatically upon startup.  Initial app setup logic and configuration
        /// goes here.
        /// </summary>
        /// <param name="app">The AE web app</param>
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            //define intermediate upload directory as ~/UploadedFiles/
            string uploadDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "UploadedFiles");
            //news up a static instance of FileCache
            UploadedFileCache uploadedFiles = UploadedFileCache.GetInstance();

            uploadedFiles.BasePath = uploadDir;

            //make sure public blob container exists
            BlobManager blobManager = new BlobManager();

            blobManager.GetOrCreateBlobContainer("public");

            //start app self-cleaning timer
            TimerInit();
        }
        /// <summary>
        /// The user has requested a blob to be downloaded as a file format that doesn't currently
        /// exist in cloud storage.  Download the existing format, run conversion software, and
        /// re-upload the zipped contents of the conversion.
        /// </summary>
        /// <param name="fromBlob"></param>
        /// <param name="userName"></param>
        /// <param name="fileName"></param>
        /// <param name="path"></param>
        /// <param name="requestExtension"></param>
        /// <returns>
        ///     <ul>
        ///         <li>The error detail about the failed conversion</li>
        ///         <li>The name of the zip file blob containing conversion results.</li>
        ///     </ul>
        /// </returns>
        private string ConvertBlobToBlob(CloudBlockBlob fromBlob, string userName, string fileName, string path, string requestExtension)
        {
            Guid               subDir;
            CloudBlockBlob     toBlob        = null;
            CloudBlobContainer container     = fromBlob.Parent.Container;
            string             getFileName   = $"{fileName.Remove(fileName.LastIndexOf('.'))}";
            string             zipFolderName = $"{getFileName}-{requestExtension.Substring(1)}.zip";

            UploadedFileCache uploadedFiles = UploadedFileCache.GetInstance();

            if (!uploadedFiles.DeleteAndRemoveFile(userName, fileName))
            {   //couldn't delete old tracked instance
                return("Error: Unable to download .fbx blob for conversion.");
            }
            else if ((subDir = uploadedFiles.SaveFile(fromBlob, userName, fileName)) != Guid.Empty)
            {   //successfully downloaded original - run conversion and zip results
                if (ConvertAndZip(path, subDir.ToString(), requestExtension, fileName, zipFolderName))
                {
                    //upload converted zipped file to blob storage
                    if (UploadBlobToUserContainer(userName, zipFolderName, path))
                    {   //get reference to blob and get download link
                        toBlob = container.GetBlockBlobReference(zipFolderName);

                        return(toBlob.Name);
                    }
                    else
                    {
                        return($"Error: unable to process converted file: {getFileName}.");
                    }
                }
                else
                {
                    return($"Error: unable to convert {fileName} to type {requestExtension}.");
                }
            }
            else
            {
                return("Error: Unable to download .fbx blob for conversion.");
            }
        }