public AttachementDownload DownloadAttachment(MemoryStream memoryStream, string EIN, Guid fileId) { var attachment = _attachmentRepository.Get() .Where(x => x.ApplicationId == EIN) .SingleOrDefault(x => x.Deleted == false && x.Id == fileId.ToString()); if (attachment == null) { throw new ObjectNotFoundException(); } var stream = _fileRepository.Download(memoryStream, attachment.RepositoryFilePath); // Decrypt file byte[] bytesToBeDecrypted = stream.ToArray(); byte[] keyInBytes = Encoding.UTF8.GetBytes(attachment.EncryptionKey + attachment.OriginalFileName); keyInBytes = SHA256.Create().ComputeHash(keyInBytes); byte[] bytesDecrypted = AES_Decrypt(bytesToBeDecrypted, keyInBytes); stream = new MemoryStream(bytesDecrypted); return(new AttachementDownload() { MemoryStream = stream, Attachment = attachment }); }
public void FileNotFoundException() { // Arrange var einToTest = "99-9999999"; var testFileContents = "test"; var data = Encoding.ASCII.GetBytes(testFileContents); var memoryStream = new MemoryStream(data); var fileName = "test.txt"; var service = new AttachmentService(_fileRepositoryMock, _attachmentRepositoryMock); var upload = service.UploadAttachment(einToTest, memoryStream, fileName, "text/plain"); var existingObj = _attachmentRepositoryMock.Get().FirstOrDefault(x => x.EIN == einToTest); existingObj.RepositoryFilePath = "invalidPath"; _attachmentRepositoryMock.SaveChanges(); using (var outMemoryStream = new MemoryStream()) { service.DownloadAttachment(outMemoryStream, einToTest, upload.Id); string outText = Encoding.ASCII.GetString(outMemoryStream.ToArray()); Assert.AreEqual(outText, testFileContents); } }
public AttachementDownload DownloadAttachment(MemoryStream memoryStream, string EIN, Guid fileId) { var attachment = _attachmentRepository.Get() .Where(x => x.EIN == EIN) .SingleOrDefault(x => x.Deleted == false && x.Id == fileId); if (attachment == null) { throw new ObjectNotFoundException(); } var stream = _fileRepository.Download(memoryStream, attachment.RepositoryFilePath); return(new AttachementDownload() { MemoryStream = stream, Attachment = attachment }); }
public async Task <VmAttachmentItem> GetAttachmentById(int Id) { var dbPageResult = await repo.Get(Id); if (dbPageResult == null) { return(new VmAttachmentItem()); } var resultObj = new VmAttachmentItem(); Copy <Com.BudgetMetal.DBEntities.Attachment, VmAttachmentItem>(dbPageResult, resultObj); return(resultObj); }
/// <summary> /// 为指定用户生成指定附件的拷贝 /// </summary> /// <param name="attachmentId">指定附件的id</param> /// <param name="userId">指定用户的id</param> /// <returns>新附件实体</returns> public T CloneForUser(long attachmentId, long userId) { return(CloneForUser(attachmentRepository.Get(attachmentId), userId)); }
public void OnGet() { Attachment = attachmentRepository.Get(); }