Example #1
0
        /// <summary>
        /// Adds a new document to the given phase.
        /// </summary>
        /// <param name="container">The container holding the document.</param>
        /// <param name="stream">The stream for the document.</param>
        /// <param name="name">The name for the document.</param>
        /// <param name="creator">The creator of the document.</param>
        public Document AddDocument(IDocumentContainer container, Stream stream, string name, User creator)
        {
            Condition.Requires(container)
               .IsNotNull();
            Condition.Requires(stream)
                .IsNotNull()
                .Evaluate(f => f.Length > 0);
            Condition.Requires(name)
                .IsNotNullOrWhiteSpace();
            Condition.Requires(creator)
                .IsNotNull();

            string attachementId = this.CreateNewAttachementId();
            this._documentSession.Advanced.DocumentStore.DatabaseCommands.PutAttachment(attachementId, null, stream, null);

            var document = new Document
            {
                CreatedByUserId = creator.Id,
                Name = name,
                AttachementId = attachementId
            };

            container.Documents.Add(document);

            return document;
        }
Example #2
0
        /// <summary>
        /// Returns the stream of the document.
        /// </summary>
        /// <param name="document">The document.</param>
        public Stream GetDocumentData(Document document)
        {
            Condition.Requires(document, "document")
                .IsNotNull();
            Condition.Requires(document.AttachementId, "document.AttachementId")
                .IsNotNullOrWhiteSpace();

            Attachment attachement = this._documentSession.Advanced.DocumentStore.DatabaseCommands.GetAttachment(document.AttachementId);

            return attachement.Data();
        }