コード例 #1
0
 public DocumentReadModel(DocumentHandle handle, DocumentDescriptorId documentid, FileNameWithExtension fileName, DocumentCustomData customData)
 {
     Handle = handle;
     DocumentDescriptorId = documentid;
     FileName             = fileName;
     CustomData           = customData;
 }
コード例 #2
0
        /// <summary>
        /// Upload a file sent in an http request
        /// </summary>
        /// <param name="httpContent">request's content</param>
        /// <returns>Error message or null</returns>
        private async Task <String> UploadFromHttpContent(HttpContent httpContent)
        {
            if (httpContent == null || !httpContent.IsMimeMultipartContent())
            {
                return("Attachment not found!");
            }

            var provider = await httpContent.ReadAsMultipartAsync(
                new FileStoreMultipartStreamProvider(_blobStore, _configService)
                );

            if (provider.Filename == null)
            {
                return("Attachment not found!");
            }

            if (provider.IsInvalidFile)
            {
                return(string.Format("Unsupported file {0}", provider.Filename));
            }

            if (provider.FormData["custom-data"] != null)
            {
                _customData = JsonConvert.DeserializeObject <DocumentCustomData>(provider.FormData["custom-data"]);
            }

            _fileName = provider.Filename;
            _blobId   = provider.BlobId;
            return(null);
        }
コード例 #3
0
 public DocumentReadModel(DocumentHandle handle, DocumentDescriptorId documentid, FileNameWithExtension fileName, DocumentCustomData customData)
 {
     Handle = handle;
     DocumentDescriptorId = documentid;
     FileName = fileName;
     CustomData = customData;
 }
コード例 #4
0
        public void verify_job_created_with_handle_metadata()
        {
            var          info       = new QueueInfo("test", "", "pdf|docx");
            QueueHandler sut        = new QueueHandler(info, _db);
            var          customData = new DocumentCustomData()
            {
                { "test", "value" },
                { "complex", 42 },
            };
            StreamReadModel rm = new StreamReadModel()
            {
                Id         = 1L,
                Handle     = "FirstHandle",
                Filename   = new FileNameWithExtension("test.docx"),
                EventType  = HandleStreamEventTypes.DocumentHasNewFormat,
                FormatInfo = new FormatInfo()
                {
                    PipelineId     = new PipelineId("soffice"),
                    DocumentFormat = new DocumentFormat("office"),
                    BlobId         = new BlobId("soffice.1")
                },
                DocumentDescriptorId = new DocumentDescriptorId(1),
                DocumentCustomData   = customData,
            };

            sut.Handle(rm, new TenantId("test"));

            var collection = _db.GetCollection <QueuedJob>("queue.test");

            Assert.That(collection.AsQueryable().Single().HandleCustomData, Is.EquivalentTo(customData));
        }
コード例 #5
0
        /// <summary>
        /// Upload a file sent in an http request
        /// </summary>
        /// <param name="httpContent">request's content</param>
        /// <returns>Error message or null</returns>
        private async Task <String> AddFormatFromHttpContent(HttpContent httpContent, DocumentFormat format)
        {
            if (httpContent == null || !httpContent.IsMimeMultipartContent())
            {
                return("Attachment not found!");
            }

            var provider = await httpContent.ReadAsMultipartAsync(
                new FormatStoreMultipartStreamProvider(_blobStore, format)
                );

            if (provider.Filename == null)
            {
                return("Attachment not found!");
            }

            if (provider.FormData["custom-data"] != null)
            {
                _customData = JsonConvert.DeserializeObject <DocumentCustomData>(provider.FormData["custom-data"]);
            }

            _fileName = provider.Filename;
            _blobId   = provider.BlobId;
            return(null);
        }
コード例 #6
0
 public DocumentHandleInfo(
     DocumentHandle handle,
     FileNameWithExtension fileName,
     DocumentCustomData customData = null
     )
 {
     Handle = handle;
     FileName = fileName;
     CustomData = customData;
 }
コード例 #7
0
 public DocumentHandleInfo(
     DocumentHandle handle,
     FileNameWithExtension fileName,
     DocumentCustomData customData = null
     )
 {
     Handle     = handle;
     FileName   = fileName;
     CustomData = customData;
 }
コード例 #8
0
        public void UpdateCustomData(DocumentHandle handle, DocumentCustomData customData)
        {
            Logger.DebugFormat("UpdateCustomData on handle {0}", handle);

            var result = _collection.FindOneAndUpdate(
                Builders <DocumentReadModel> .Filter.Eq(x => x.Handle, handle),
                Builders <DocumentReadModel> .Update.Set(x => x.CustomData, customData),
                new FindOneAndUpdateOptions <DocumentReadModel, DocumentReadModel>()
            {
                ReturnDocument = ReturnDocument.After
            });
        }
コード例 #9
0
        public void update_custom_data()
        {
            _writer.Create(_documentHandle);
            var handleCustomData = new DocumentCustomData()
            {
                { "a", "b" }
            };

            _writer.UpdateCustomData(_documentHandle, handleCustomData);
            var h = _writer.FindOneById(_documentHandle);

            Assert.NotNull(h.CustomData);
            Assert.AreEqual("b", (string)h.CustomData["a"]);
        }
コード例 #10
0
        private void CreateDocument(
            DocumentDescriptorId documentDescriptorId,
            BlobId blobId,
            DocumentHandle handle,
            DocumentHandle fatherHandle,
            DocumentDescriptorId fatherDocumentDescriptorId,
            FileNameWithExtension fileName,
            DocumentCustomData customData
            )
        {
            var      descriptor = _blobStore.GetDescriptor(blobId);
            ICommand createDocument;
            var      handleInfo = new DocumentHandleInfo(handle, fileName, customData);

            if (fatherHandle == null)
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat("Initialize DocumentDescriptor {0} ", documentDescriptorId);
                }

                createDocument = new InitializeDocumentDescriptor(documentDescriptorId, blobId, handleInfo, descriptor.Hash, fileName);
            }
            else
            {
                if (Logger.IsDebugEnabled)
                {
                    Logger.DebugFormat("Initialize DocumentDescriptor as attach {0} ", documentDescriptorId);
                }

                createDocument = new InitializeDocumentDescriptorAsAttach(
                    documentDescriptorId,
                    blobId,
                    handleInfo,
                    fatherHandle,
                    fatherDocumentDescriptorId,
                    descriptor.Hash, fileName);
            }
            CommandBus.Send(createDocument, "api");
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void update_custom_data()
        {
            _writer.Create(_documentHandle);
            var handleCustomData = new DocumentCustomData() { { "a", "b" } };
            _writer.UpdateCustomData(_documentHandle, handleCustomData);
            var h = _writer.FindOneById(_documentHandle);

            Assert.NotNull(h.CustomData);
            Assert.AreEqual("b", (string)h.CustomData["a"]);
        }
コード例 #13
0
 private void CreateDocument(
     DocumentDescriptorId documentDescriptorId,
     BlobId blobId,
     DocumentHandle handle,
     DocumentHandle fatherHandle,
     DocumentDescriptorId fatherDocumentDescriptorId,
     FileNameWithExtension fileName,
     DocumentCustomData customData
 )
 {
     var descriptor = _blobStore.GetDescriptor(blobId);
     ICommand createDocument;
     var handleInfo = new DocumentHandleInfo(handle, fileName, customData);
     if (fatherHandle == null)
     {
         if (Logger.IsDebugEnabled) Logger.DebugFormat("Initialize DocumentDescriptor {0} ", documentDescriptorId);
         createDocument = new InitializeDocumentDescriptor(documentDescriptorId, blobId, handleInfo, descriptor.Hash, fileName);
     }
     else
     {
         if (Logger.IsDebugEnabled) Logger.DebugFormat("Initialize DocumentDescriptor as attach {0} ", documentDescriptorId);
         createDocument = new InitializeDocumentDescriptorAsAttach(
             documentDescriptorId,
             blobId,
             handleInfo,
             fatherHandle,
             fatherDocumentDescriptorId,
             descriptor.Hash, fileName);
     }
     CommandBus.Send(createDocument, "api");
 }
コード例 #14
0
        /// <summary>
        /// Upload a file sent in an http request
        /// </summary>
        /// <param name="httpContent">request's content</param>
        /// <returns>Error message or null</returns>
        private async Task<String> AddFormatFromHttpContent(HttpContent httpContent, DocumentFormat format)
        {
            if (httpContent == null || !httpContent.IsMimeMultipartContent())
                return "Attachment not found!";

            var provider = await httpContent.ReadAsMultipartAsync(
                new FormatStoreMultipartStreamProvider(_blobStore, format)
            );

            if (provider.Filename == null)
                return "Attachment not found!";

            if (provider.FormData["custom-data"] != null)
            {
                _customData = JsonConvert.DeserializeObject<DocumentCustomData>(provider.FormData["custom-data"]);
            }

            _fileName = provider.Filename;
            _blobId = provider.BlobId;
            return null;
        }
コード例 #15
0
        /// <summary>
        /// Upload a file sent in an http request
        /// </summary>
        /// <param name="httpContent">request's content</param>
        /// <returns>Error message or null</returns>
        private async Task<String> UploadFromHttpContent(HttpContent httpContent)
        {
            if (httpContent == null || !httpContent.IsMimeMultipartContent())
                return "Attachment not found!";

            var provider = await httpContent.ReadAsMultipartAsync(
                new FileStoreMultipartStreamProvider(_blobStore, _configService)
            );

            if (provider.Filename == null)
                return "Attachment not found!";

            if (provider.IsInvalidFile)
                return string.Format("Unsupported file {0}", provider.Filename);

            if (provider.FormData["custom-data"] != null)
            {
                _customData = JsonConvert.DeserializeObject<DocumentCustomData>(provider.FormData["custom-data"]);
            }

            _fileName = provider.Filename;
            _blobId = provider.BlobId;
            return null;
        }
コード例 #16
0
 protected bool Equals(DocumentHandleInfo other)
 {
     return(Equals(FileName, other.FileName) &&
            DocumentCustomData.IsEquals(CustomData, other.CustomData) &&
            Equals(Handle, other.Handle));
 }
コード例 #17
0
 public DocumentCustomDataSet(DocumentHandle handle, DocumentCustomData customData)
 {
     Handle = handle;
     CustomData = customData;
 }
コード例 #18
0
 public DocumentCustomDataSet(DocumentHandle handle, DocumentCustomData customData)
 {
     Handle     = handle;
     CustomData = customData;
 }
コード例 #19
0
 public void SetCustomData(DocumentCustomData data)
 {
     this.CustomData = data;
 }
コード例 #20
0
        public void UpdateCustomData(DocumentHandle handle, DocumentCustomData customData)
        {
            Logger.DebugFormat("UpdateCustomData on handle {0}", handle);

            var result = _collection.FindOneAndUpdate(
               Builders<DocumentReadModel>.Filter.Eq(x => x.Handle, handle),
               Builders<DocumentReadModel>.Update.Set(x => x.CustomData, customData),
            new FindOneAndUpdateOptions<DocumentReadModel, DocumentReadModel>()
            {
                ReturnDocument = ReturnDocument.After
            });
        }
コード例 #21
0
        public void verify_job_created_with_handle_metadata()
        {
            var info = new QueueInfo("test", "", "pdf|docx");
            QueueHandler sut = new QueueHandler(info, _db);
            var customData = new DocumentCustomData() 
                {
                    {"test" , "value"},
                    {"complex" , 42},
                };
            StreamReadModel rm = new StreamReadModel()
            {
                Id = 1L,
                Handle = "FirstHandle",
                Filename = new FileNameWithExtension("test.docx"),
                EventType = HandleStreamEventTypes.DocumentHasNewFormat,
                FormatInfo = new FormatInfo()
                {
                    PipelineId = new PipelineId("soffice"),
                    DocumentFormat = new DocumentFormat("office"),
                    BlobId = new BlobId("soffice.1")
                },
                DocumentDescriptorId = new DocumentDescriptorId(1),
                DocumentCustomData = customData,
            };

            sut.Handle(rm, new TenantId("test"));

            var collection = _db.GetCollection<QueuedJob>("queue.test");
            Assert.That(collection.AsQueryable().Single().HandleCustomData, Is.EquivalentTo(customData));
        }
コード例 #22
0
 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);
 }