示例#1
0
        public async Task AddFile_With_ValidFile_Should_ReturnTrue()
        {
            //Arrange
            mockFileRepository
            .Setup(x => x.AddFile(It.IsAny <File>()))
            .Returns(Task.FromResult(true));

            // Act
            var result = await fileService.AddFile("filename.zip", "application/zip", new MemoryStream(Encoding.UTF8.GetBytes("test file")));

            // Asset
            Assert.IsTrue(result);
        }
示例#2
0
        public async Task <IActionResult> AddFilesForm(IFormFile uploadedFile)
        {
            FileService service = new FileService();
            await service.AddFile(uploadedFile);

            return(RedirectToAction("Index", "Home"));
        }
示例#3
0
        protected void btnPostFile_Click(object sender, EventArgs e)
        {
            int          files        = 0;
            UploadStatus uploadstatus = HttpUploadModule.GetUploadStatus();
            bool         flag         = uploadstatus.Reason == UploadTerminationReason.NotTerminated;

            if (flag)
            {
                foreach (UploadedFile file in uploadstatus.GetUploadedFiles())
                {
                    string clientFileName = file.ClientName;
                    bool   flag2          = file.ContentLength.Equals(0L);
                    if (flag2)
                    {
                        base.PromptDialog(string.Format("[{0}]文件大小为0字节,系统不支持文件大小为0字节的文件上传,请重新选择文件上传。", clientFileName));
                        return;
                    }
                    bool flag3 = !this.filelist.MaxFileSize.Equals(0.0) && file.ContentLength > this.filelist.MaxFileSize;
                    if (flag3)
                    {
                        base.PromptDialog(string.Format("[{0}]文件大小已超出规定的 {1}上限,上传失败。", clientFileName, this.filelist.MaxFileSize.FormatFileSize()));
                        return;
                    }
                    DocFileInfo fileInfo = FileService.AddFile(file.ServerPath, clientFileName, file.ContentLength, this.hidFileGroup.Value.ToDouble());
                    this.hidFileGroup.Value   = fileInfo.FileGroupId.ToString();
                    this.filelist.FileGroupId = fileInfo.FileGroupId;
                    this.UpdateBusinessFileGroup();
                    files = this.UpdateBusinessFiles();
                }
            }
            this.UpdateTempletFileFieldRI(files);
            base.CurMaster_OnQuery(null, null);
        }
示例#4
0
 public ActionResult AddFiles(AddFilesViewModel Model)
 {
     // We check if if the user can't open the project.
     if (Pservice.CanUserOpenProject(Model.ProjectID, User.Identity.Name))
     {
         if (ModelState.IsValid)
         {
             // The AddFile(Model) returns a boolean.
             if (!FService.AddFile(Model))
             {
                 // This is the message we send to the Ajax controller,
                 // if the file has the same name, which handles the error message.
                 if (Model.Name == "ReadMe.txt")
                 {
                     return(Json("SameName", JsonRequestBehavior.AllowGet));
                 }
                 return(Json("SameName", JsonRequestBehavior.AllowGet));
             }
             // If succeded we return to Editor
             return(RedirectToAction("Index", new { id = Model.ProjectID }));
         }
         else if (Model.Name == null)
         {
             return(Json("EmptyString", JsonRequestBehavior.AllowGet));
         }
     }
     // If the user can't open the project, or modelstate isn't valid we throw
     // an ArgumentException.
     throw new ArgumentException();
 }
        public async Task <ImageFile> AddAsync(Image image)
        {
            var libraryDirectory = FileService.GetFileInfo(image.ImageFile.LibraryFullName).Directory.FullName;

            if (!libraryDirectory.EndsWith("\\"))
            {
                libraryDirectory += "\\";
            }

            var filePath = FileSystemInfo.FileSystemInfo.RootDirectory + libraryDirectory + FileSystemInfo.FileSystemInfo.ImagesDirectory + Guid.NewGuid().ToString() + ImageExtensionHelper.ExtensionToString(image.ImageFile.Extension);
            var path     = await Task.Run(() => FileService.AddFile(filePath, image.ImageContent));

            var fileInfo = FileService.GetFileInfo(path);

            var imageFile =
                ImageFileBuilder
                .StartBuilding()
                .WithName(image.ImageFile.Name)
                .WithExtension(image.ImageFile.Extension)
                .WithFullName(path)
                .WithLibraryFullName(image.ImageFile.LibraryFullName)
                .WithCreationTime(fileInfo.CreationTimeUtc)
                .WithLastAccessTime(fileInfo.LastAccessTimeUtc)
                .WithLastWriteTime(fileInfo.LastWriteTimeUtc)
                .WithSize(fileInfo.Length)
                .WithTags(new List <Tag>())
                .Build();

            Logger.LogInformation("New added image: " + imageFile.FullName);

            return(imageFile);
        }
示例#6
0
        public IActionResult UploadFile([FromForm] IFormCollection formData)
        {
            var file     = formData.Files[0];
            var filename = fileService.AddFile(file.OpenReadStream(), "." + file.FileName.Split('.').Last());

            return(Json(new { errno = "0", data = new List <string> {
                                  "File/" + filename
                              } }));
        }
示例#7
0
        public async Task <ActionResult <string> > AddFile([FromForm] FileModel uploadedFile)
        {
            var result = await _fileService.AddFile(uploadedFile.FormFile);

            if (result == "")
            {
                return(BadRequest());
            }
            return(Ok(result));
        }
        public ActionResult UploadNewFiles(FineUpload upload, string extraParam1, int?extraParam2)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var owner = ((MyMembershipProvider)Membership.Provider).GetUserByEmail(User.Identity.Name);

            if (owner == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var fileName      = Path.GetFileNameWithoutExtension(upload.FileName);
            var fileExtension = Path.GetExtension(upload.FileName);

            if (string.IsNullOrWhiteSpace(fileName) || string.IsNullOrWhiteSpace(fileExtension))
            {
                return(new FineUploaderResult(false, error: "The file or file name is empty!"));
            }

            var fullName = fileName.ToHashedString() + fileExtension;

            var fileSectionNumber = int.Parse(upload.FileSection);

            var ipAdress = ConfigurationManager.AppSettings["Server"];

            var filePath = string.Format(@"d:\UploadFiles\{0}\{1}", fileSectionNumber, fullName);

            //var pathToSave = Path.Combine(ipAdress, filePath);
            var pathToSave = string.Format(@"{0}\{1}", ipAdress, filePath);

            if (System.IO.File.Exists(pathToSave))
            {
                return(new FineUploaderResult(false, error: "The same file is already exists!"));
            }

            var fileSize = upload.InputStream.Length;

            upload.SaveAs(pathToSave);

            var fileSection = _homeService.GetFileSectionById(fileSectionNumber);

            try
            {
                _fileService.AddFile(fileName, fullName, fileSize, filePath, ipAdress, fileSection, owner);
            }
            catch (DataException ex)
            {
                return(new FineUploaderResult(false, error: ex.Message));
            }

            return(new FineUploaderResult(true, new { message = "Upload is finished successfully!" }));
        }
示例#9
0
 public async Task AddAFile()
 {
     await FileService.AddFile((file) =>
     {
         var expenseFiles = new ExpenseFile {
             ExpenseId = Item.ExpenseId, File = file.Bytes, Name = file.Name, Size = file.Size
         };
         Item.ExpenseFiles.Add(expenseFiles);
         ExpensesDataStore.UpdateItemAsync(Item);
         ExpenseFiles.Add(expenseFiles);
     });
 }
        public async Task <ImageFile> UpdateAsync(Image entity)
        {
            if (!FileService.FileExists(entity.ImageFile.FullName))
            {
                throw new ContentNotFoundException("Couldn't find specified file.");
            }

            // overwrites the file
            var path = await Task.Run(() => FileService.AddFile(entity.ImageFile.FullName, entity.ImageContent));

            Logger.LogInformation("Updated content of an image: " + path);

            return(entity.ImageFile);
        }
示例#11
0
        public void CopyFile_Copy_CreateFolderStructureIsSuccessful()
        {
            //arrange
            string savingfilepath = savingpath + @"\" + _currentYear; //new file
            var    fileSystem     = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { filepath, new MockFileData("Testing is...") }
            });
            var fileService = new FileService(fileSystem, savingpath, "irrelevant");

            //act
            fileService.AddFile(filepath, newFileName, true);

            //assert
            Assert.That(fileSystem.Directory.Exists(savingpath), Is.True);
        }
示例#12
0
        public void AddFile_MoveFile_IsSuccessful()
        {
            //arrange
            string savingfilepath = savingpath + @"\" + _currentYear; //new file
            var    fileSystem     = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { filepath, new MockFileData("Testing is fun") }
            });
            var fileService = new FileService(fileSystem, savingpath, "irrelevant");

            //act
            fileService.AddFile(filepath, newFileName, true);

            //assert
            Assert.That(fileSystem.File.Exists(savingpath + @"\" + newFileName), Is.True);
            Assert.That(fileSystem.File.Exists(filepath), Is.False);
        }
示例#13
0
 public ActionResult AddFile(List <IFormFile> files)
 {
     fileService.AddFile(files);
     return(Ok());
 }