/// <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."); } }