예제 #1
0
        public ActionResult OverWriteUpload(string overWrite, string uploadFileName)
        {
            string            userName      = User.Identity.Name;
            UploadedFileCache uploadedFiles = UploadedFileCache.GetInstance();

            if (string.IsNullOrEmpty(s_BasePath))
            {
                s_BasePath = uploadedFiles.BasePath;
            }

            if (overWrite == "Yes")
            {
                //files are stored in subdir named by GUIDs
                string subDir = uploadedFiles.FindContainingFolderGUIDForFile(userName, uploadFileName).ToString();
                if (Guid.Parse(subDir) == Guid.Empty)
                {
                    ViewBag.Message = $"{uploadFileName} was not found to upload.  It may have expired from temporary storage.";
                }
                else
                {
                    string description = uploadedFiles.GetFileDescription(userName, uploadFileName);
                    bool   isPublic    = uploadedFiles.IsSavedFilePublic(userName, uploadFileName);

                    UploadToBlob(uploadFileName, "", subDir, description, isPublic, true);
                    ViewBag.Message = "File uploaded successfully";
                }
            }
            else
            {
                uploadedFiles.DeleteAndRemoveFile(User.Identity.Name, uploadFileName);
                ViewBag.Message = "File upload failed.";
            }

            return(View("UploadFile"));
        }
예제 #2
0
        public void Test_Init()
        {
            UploadedFileCache cache = null;

            Assert.IsNull(cache);

            cache = UploadedFileCache.GetInstance();

            Assert.IsNotNull(cache);
            Assert.IsInstanceOfType(cache, typeof(UploadedFileCache));
        }
예제 #3
0
        public void Test_PrivateConstructor()
        {
            UploadedFileCache cache = null;
            Type cacheType          = typeof(UploadedFileCache);

            Assert.IsNull(cache);

            //assert couldn't create, still null
            Assert.ThrowsException <MissingMethodException>(() =>
            {
                cache = (Activator.CreateInstance(cacheType) as UploadedFileCache);
            });

            Assert.IsNull(cache);
        }
예제 #4
0
        public ActionResult UploadFile(HttpPostedFileBase baseFile, HttpPostedFileBase matFile, bool publicFile, string altFileName, string fileDescription)
        {
            string            subDir        = string.Empty;
            string            uploadMessage = "File Uploaded Successfully.";
            UploadedFileCache uploadedFiles = UploadedFileCache.GetInstance();

            if (string.IsNullOrEmpty(s_BasePath))
            {
                s_BasePath = uploadedFiles.BasePath;
            }

            if (baseFile.ContentLength > 0)
            {
                string matFileName    = string.Empty;
                string fileName       = Path.GetFileName(baseFile.FileName);
                string fileExt        = fileName.Substring(fileName.LastIndexOf('.'));
                string uploadFileName = (string.IsNullOrEmpty(altFileName) ? fileName : altFileName);

                if (matFile != null)
                {
                    matFileName = Path.GetFileName(matFile.FileName);
                }

                try
                {
                    if (uploadedFiles.SaveFile(baseFile, User.Identity.Name, fileName, altFileName, fileDescription, publicFile))
                    {
                        if (!string.IsNullOrEmpty(matFileName))
                        {
                            if (!uploadedFiles.SaveFile(matFile, User.Identity.Name, matFileName, "", fileDescription, publicFile))
                            {
                                ViewBag.Message = $"Unable to save {matFileName} prior to upload.  {fileName} was uploaded without it.";
                            }
                        }

                        BlobManager blobManager = new BlobManager();
                        subDir = uploadedFiles.FindContainingFolderGUIDForFile(User.Identity.Name, uploadFileName).ToString();
                        if (Guid.Parse(subDir) == Guid.Empty)
                        {
                            ViewBag.Message = $"{fileName} was not found to upload.  It may have expired from temporary storage.";
                        }
                        else
                        {
                            if (fileExt == ".fbx") //no conversion necessary - upload
                            {
                                UploadToBlob(fileName, altFileName, subDir, fileDescription, publicFile);
                            }
                            else //uploaded file is not fbx -- convert
                            {
                                ConvertAndUploadToBlob(fileName, altFileName, subDir, fileDescription, publicFile);
                            }
                        }
                    }
                    else
                    {
                        ViewBag.Message = $"Failed to save {fileName} prior to upload.";
                    }
                }
                catch (Exception ex) { uploadMessage = ex.ToString(); }

                //give user change to overwrite
                if (string.IsNullOrEmpty(ViewBag.FileExists))
                {
                    //if file wasn't saved - does nothing,
                    //else marks subdirectory containing file for deletion
                    uploadedFiles.MarkForDelete(User.Identity.Name, fileName);
                }
            }

            if (string.IsNullOrEmpty(ViewBag.Message))
            {
                ViewBag.Message = uploadMessage;
            }
            return(View());
        }