/// <summary> /// We have no real Raw storage option for Gridfs, but we can simply store all raw bytes /// inside the gridfs. /// </summary> /// <param name="blobId"></param> /// <param name="descriptor"></param> public void RawStore(BlobId blobId, IBlobDescriptor descriptor) { using (var writer = CreateBlobWriterFromBlobId(blobId.Format, descriptor.FileNameWithExtension, blobId)) using (var inputStream = descriptor.OpenRead()) { inputStream.CopyTo(writer.WriteStream); } }
public void RawStore(BlobId blobId, IBlobDescriptor descriptor) { Logger.InfoFormat("Ask for raw storage of blob {0} for file {1}", blobId, descriptor.FileNameWithExtension); using (var stream = descriptor.OpenRead()) { InnerPersistOfBlob(blobId, descriptor.FileNameWithExtension, stream); FileSystemBlobDescriptor newDescriptor = new FileSystemBlobDescriptor() { BlobId = blobId, ContentType = descriptor.ContentType, FileNameWithExtension = descriptor.FileNameWithExtension, Length = descriptor.Length, Md5 = descriptor.Hash.ToString(), Timestamp = DateTime.UtcNow, }; _mongodDbFileSystemBlobDescriptorStorage.SaveDescriptor(newDescriptor); } }
private void SetHandleToReturn() { var customData = new DocumentCustomData() { { "handle1", "test" }, { "handle2", new { isComplex = true, theTruth = 42 } }, }; handle = new DocumentReadModel( new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new FileNameWithExtension("test.txt"), customData ); _handleWriter .FindOneById(Arg.Any <DocumentHandle>()) .Returns(handle); IBlobDescriptor stub = Substitute.For <IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any <BlobId>()).Returns(stub); }
public void verify_handle_linked_to_document_with_formats() { SetHandleToReturn(); IBlobDescriptor stub = Substitute.For <IBlobDescriptor>(); stub.FileNameWithExtension.Returns(new FileNameWithExtension("test.txt")); _blobStore.GetDescriptor(Arg.Any <BlobId>()).Returns(stub); var docRm = new DocumentDescriptorReadModel(1L, new DocumentDescriptorId(1), new BlobId("file_1")); docRm.AddFormat(new PipelineId("tika"), new DocumentFormat("blah"), new BlobId("pdf")); docRm.AddFormat(new PipelineId("test"), new DocumentFormat("blah blah"), new BlobId("test")); docRm.Created = true; rmDocuments.Add(docRm); CreateSut(); var evt = new DocumentLinked(new DocumentHandle("rev_1"), new DocumentDescriptorId(1), new DocumentDescriptorId(2), new FileNameWithExtension("test.txt")); _sut.Handle(evt, false); //I'm expecting new format added to handle Assert.That(rmStream, Has.Count.EqualTo(3)); Assert.That(rmStream[0].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[0].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[0].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("original")); Assert.That(rmStream[0].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[0].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[1].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[1].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[1].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah")); Assert.That(rmStream[1].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[1].Filename.Extension, Is.EqualTo("txt")); Assert.That(rmStream[2].EventType, Is.EqualTo(HandleStreamEventTypes.DocumentHasNewFormat)); Assert.That(rmStream[2].Handle, Is.EqualTo("rev_1")); Assert.That(rmStream[2].FormatInfo.DocumentFormat.ToString(), Is.EqualTo("blah blah")); Assert.That(rmStream[2].Filename.FileName, Is.EqualTo("test")); Assert.That(rmStream[2].Filename.Extension, Is.EqualTo("txt")); }