Esempio n. 1
0
        private int DownloadNextChunk(IDocument remoteDocument, long offset, long remainingBytes, Transmission transmission, Stream outputstream, HashAlgorithm hashAlg)
        {
            lock (this.disposeLock) {
                if (this.disposed)
                {
                    transmission.Status = TransmissionStatus.ABORTED;
                    throw new ObjectDisposedException(transmission.Path);
                }

                IContentStream contentStream = remoteDocument.GetContentStream(remoteDocument.ContentStreamId, offset, remainingBytes);
                transmission.Length   = remoteDocument.ContentStreamLength;
                transmission.Position = offset;

                using (var remoteStream = contentStream.Stream)
                    using (var forwardstream = new ForwardReadingStream(remoteStream))
                        using (var offsetstream = new OffsetStream(forwardstream, offset))
                            using (var progress = transmission.CreateStream(offsetstream)) {
                                byte[] buffer = new byte[8 * 1024];
                                int    result = 0;
                                int    len;
                                while ((len = progress.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    outputstream.Write(buffer, 0, len);
                                    hashAlg.TransformBlock(buffer, 0, len, buffer, 0);
                                    result += len;
                                    outputstream.Flush();
                                }

                                return(result);
                            }
            }
        }
Esempio n. 2
0
 private bool VerifyEmptyStream(IContentStream stream)
 {
     Assert.That(stream, Is.Not.Null);
     Assert.That(stream.Length, Is.EqualTo(0));
     Assert.That(string.IsNullOrEmpty(stream.MimeType), Is.False);
     return(true);
 }
Esempio n. 3
0
        public void UpdateDocument(
            CMISFolder folder,
            string document,
            string docName,
            Dictionary <string, object> props,
            bool major,
            string checkInComment)
        {
            IContentStream contentStream = getContentStream(document, docName);

            try
            {
                IDocument d = GetDocument(folder, docName).IDocument(session);
                d.UpdateProperties(props);
                if (d.AllowableActions == null ||
                    d.AllowableActions.Actions.Contains(PortCMIS.Enums.Action.CanCheckOut))
                {
                    var      pwcId = d.CheckOut();
                    Document pwc   = (Document)session.GetObject(pwcId);
                    pwc.CheckIn(major, props, contentStream, checkInComment);
                }
                else
                {
                    d.CheckIn(major, props, contentStream, checkInComment);
                }
            }
            catch (CmisBaseException e) { throw new Exception(e.ErrorContent != null? e.ErrorContent : e.Message); }
            finally { contentStream.Stream.Dispose(); }
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor for objects.
        /// </summary>
        public AtomEntryWriter(IObjectData objectData, CmisVersion cmisVersion, IContentStream contentStream)
        {
            if (objectData == null || objectData.Properties == null)
            {
                throw new CmisInvalidArgumentException("Object and properties must not be null!");
            }

            if (contentStream != null && contentStream.MimeType == null)
            {
                throw new CmisInvalidArgumentException("Media type must be set if a stream is present!");
            }

            this.objectData    = objectData;
            this.cmisVersion   = cmisVersion;
            this.contentStream = contentStream;
            if (contentStream != null && contentStream.Stream != null)
            {
                // do we need buffering here?
                stream = contentStream.Stream;
            }
            else
            {
                stream = null;
            }
            this.typeDef    = null;
            this.bulkUpdate = null;
        }
Esempio n. 5
0
        /// <summary>
        /// getDocumentContentStream
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IContentStream GetDocumentById(string id)
        {
            IObjectId      objectId      = Session.CreateObjectId(id);
            IDocument      doc           = Session.GetObject(id) as IDocument;
            IContentStream contentStream = doc.GetContentStream();

            return(contentStream);
        }
Esempio n. 6
0
        public IDocument CreateTextDocument(IFolder parent, string name, string content)
        {
            IDictionary <string, object> props = new Dictionary <string, object>();

            props[PropertyIds.Name]         = name;
            props[PropertyIds.ObjectTypeId] = "cmis:document";

            IContentStream contentStream = ContentStreamUtils.CreateTextContentStream(name, content);

            return(parent.CreateDocument(props, contentStream, VersioningState.None));
        }
Esempio n. 7
0
        private static bool VerifyContentStream(IContentStream s, string mimeType, string fileName)
        {
            if (mimeType != null)
            {
                Assert.That(s.MimeType, Is.EqualTo(mimeType));
            }

            // Assert.That(s.Length, Is.Null);
            Assert.That(s.FileName, Is.EqualTo(fileName));
            return(true);
        }
Esempio n. 8
0
 private bool SetupFutureRemoteDocStream(Mock <IDocument> doc, IContentStream stream)
 {
     if (stream == null)
     {
         return(true);
     }
     else
     {
         doc.Setup(d => d.ContentStreamLength).Returns(stream.Length);
         doc.Setup(d => d.ContentStreamFileName).Returns(stream.FileName);
         doc.Setup(d => d.ContentStreamMimeType).Returns(stream.MimeType);
         return(true);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Constructor for types.
        /// </summary>
        public AtomEntryWriter(ITypeDefinition type, CmisVersion cmisVersion)
        {
            if (type == null)
            {
                throw new CmisInvalidArgumentException("Type must not be null!");
            }

            this.typeDef       = type;
            this.cmisVersion   = cmisVersion;
            this.objectData    = null;
            this.contentStream = null;
            this.stream        = null;
            this.bulkUpdate    = null;
        }
Esempio n. 10
0
        /// <summary>
        /// Constructor for bulk updates.
        /// </summary>
        public AtomEntryWriter(BulkUpdate bulkUpdate)
        {
            if (bulkUpdate == null)
            {
                throw new CmisInvalidArgumentException("Bulk update data must not be null!");
            }

            this.bulkUpdate    = bulkUpdate;
            this.typeDef       = null;
            this.cmisVersion   = CmisVersion.Cmis_1_1;
            this.objectData    = null;
            this.contentStream = null;
            this.stream        = null;
        }
Esempio n. 11
0
        public void TestUpdateContent()
        {
            IDocument doc = null;

            try
            {
                // create document
                string contentString1 = "11111";
                doc = CreateTextDocument(Session.GetRootFolder(), "test.txt", contentString1);
                Assert.IsNotNull(doc);

                // get content
                IContentStream content1 = doc.GetContentStream();
                Assert.IsNotNull(content1);
                Assert.IsNotNull(content1.Stream);

                Assert.AreEqual(contentString1, ConvertStreamToString(content1.Stream));

                // update content
                string contentString2 = "22222";
                doc.SetContentStream(ContentStreamUtils.CreateTextContentStream("test2.txt", contentString2), true);

                // get content again
                IContentStream content2 = doc.GetContentStream();
                Assert.IsNotNull(content2);
                Assert.IsNotNull(content2.MimeType);
                Assert.IsTrue(content2.MimeType.StartsWith("text/plain", System.StringComparison.InvariantCultureIgnoreCase));
                Assert.IsNotNull(content2.Stream);

                Assert.AreEqual(contentString2, ConvertStreamToString(content2.Stream));

                // delete the content stream
                doc.DeleteContentStream(true);
                Assert.IsNull(doc.ContentStreamLength);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
Esempio n. 12
0
        private static async Task <string> ReadBuffer(IContentStream contentStream)
        {
            var           length        = contentStream.Length ?? 100;
            StringBuilder outputBuilder = new StringBuilder(length);

            char[] c         = new char[length];
            int    readCount = 0;

            using (var reader = new StreamReader(contentStream.Stream, Encoding.UTF8))
            {
                do
                {
                    readCount = await reader.ReadAsync(c, 0, c.Length);

                    outputBuilder.Append(c, 0, readCount);
                } while (readCount > 0);
            }
            return(outputBuilder.ToString());
        }
Esempio n. 13
0
        private void SetContent(IContentStream inputstream, bool overwrite)
        {
            if (this.Stream != null && this.Stream.Length != null && this.Stream.Length > 0 && !overwrite)
            {
                throw new CmisContentAlreadyExistsException();
            }

            var newContent = new MockedContentStream(inputstream.FileName, null, inputstream.MimeType);

            using (var memStream = new MemoryStream())
                using (var input = inputstream.Stream){
                    input.CopyTo(memStream);
                    newContent.Content = memStream.ToArray();
                }

            this.Stream = newContent.Object;
            this.UpdateChangeToken();
            this.NotifyChanges();
        }
Esempio n. 14
0
        public string GetTextContent(string objectId)
        {
            IContentStream contentStream = Binding.GetObjectService().GetContentStream(RepositoryInfo.Id, objectId, null, null, null, null);

            Assert.NotNull(contentStream);
            Assert.NotNull(contentStream.Stream);

            MemoryStream memStream = new MemoryStream();

            byte[] buffer = new byte[4096];
            int    b;

            while ((b = contentStream.Stream.Read(buffer, 0, buffer.Length)) > 0)
            {
                memStream.Write(buffer, 0, b);
            }

            string result = Encoding.UTF8.GetString(memStream.GetBuffer(), 0, (int)memStream.Length);

            return(result);
        }
Esempio n. 15
0
        private int DownloadNextChunk(IDocument remoteDocument, long offset, long remainingBytes, FileTransmissionEvent status, Stream outputstream, HashAlgorithm hashAlg)
        {
            lock (this.disposeLock)
            {
                if (this.disposed)
                {
                    status.ReportProgress(new TransmissionProgressEventArgs()
                    {
                        Aborted = true
                    });
                    throw new ObjectDisposedException(status.Path);
                }

                IContentStream contentStream = remoteDocument.GetContentStream(remoteDocument.ContentStreamId, offset, remainingBytes);
                status.ReportProgress(new TransmissionProgressEventArgs {
                    Length         = remoteDocument.ContentStreamLength,
                    ActualPosition = offset,
                    Resumed        = offset > 0
                });

                using (Stream remoteStream = contentStream.Stream)
                    using (ForwardReadingStream forwardstream = new ForwardReadingStream(remoteStream))
                        using (OffsetStream offsetstream = new OffsetStream(forwardstream, offset))
                            using (ProgressStream progress = new ProgressStream(offsetstream, status))
                            {
                                byte[] buffer = new byte[8 * 1024];
                                int    result = 0;
                                int    len;
                                while ((len = progress.Read(buffer, 0, buffer.Length)) > 0)
                                {
                                    outputstream.Write(buffer, 0, len);
                                    hashAlg.TransformBlock(buffer, 0, len, buffer, 0);
                                    result += len;
                                    outputstream.Flush();
                                }

                                return(result);
                            }
            }
        }
Esempio n. 16
0
        public IContentStream GetContentStream(IObjectId docId, string streamId, long?offset, long?length)
        {
            if (docId == null || docId.Id == null)
            {
                throw new ArgumentException("Invalid document id!");
            }

            // get the content stream
            IContentStream contentStream = null;

            try
            {
                contentStream = Binding.GetObjectService().GetContentStream(RepositoryId, docId.Id, streamId, offset, length, null);
            }
            catch (CmisConstraintException)
            {
                // no content stream
                return(null);
            }

            return(contentStream);
        }
Esempio n. 17
0
        public void TestCreateBig()
        {
            int docSize = 50 * 1024 * 1024; // 50MiB

            // get root folder
            IFolder   root = Session.GetRootFolder();
            IDocument doc  = null;

            try
            {
                // create document
                StringBuilder sb = new StringBuilder(docSize);
                for (int i = 0; i < docSize; i++)
                {
                    sb.Append('x');
                }

                string contentString = sb.ToString();

                doc = CreateTextDocument(root, "big.txt", contentString);
                Assert.IsNotNull(doc);

                // get content
                IContentStream newContent = doc.GetContentStream();
                Assert.IsNotNull(newContent);
                Assert.IsNotNull(newContent.Stream);

                Assert.AreEqual(contentString, ConvertStreamToString(newContent.Stream));
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
Esempio n. 18
0
        //
        // GET: /OpenDocument/

        // GET api/values/5
        public HttpResponseMessage Get(string id)
        {
            if (String.IsNullOrEmpty(id))
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            CMISQuery query = new CMIS.CMISQuery();

            IContentStream documentContentStream = query.GetDocumentById(id);

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            if (documentContentStream.Stream != null)
            {
                response.Content = new StreamContent(documentContentStream.Stream);
                response.Headers.CacheControl = new CacheControlHeaderValue();
                response.Content.Headers.ContentDisposition          = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = documentContentStream.FileName;
                response.Content.Headers.ContentType = new MediaTypeHeaderValue(documentContentStream.MimeType);
                //  response.AppendHeader("Access-Control-Allow-Origin", "*");
            }
            return(response);
        }
Esempio n. 19
0
        public void StoreDocument(
            CMISFolder folder,                  // where to put the document
            string document,                    // file name of the document
            string docName,                     // name of the new document
            Dictionary <string, object> props,  // document properties
            bool?major)                         // use versioning and which one
        {
            IContentStream contentStream = getContentStream(document, docName);

            try
            {
                IFolder         iFolder = folder.IFolder(session);
                VersioningState?vs      = null;
                if (major != null)
                {
                    vs = major == true? VersioningState.Major : VersioningState.Minor;
                }
                props[PropertyIds.Name] = docName;
                iFolder.CreateDocument(props, contentStream, vs);
                props.Remove(PropertyIds.Name);
            }
            catch (CmisBaseException e) { throw new Exception(e.Message + "\n" + e.ErrorContent); }
            finally { contentStream.Stream.Dispose(); }
        }
Esempio n. 20
0
        public IDocument CreateTextDocument(IFolder parent, string name, string content)
        {
            IDictionary <string, object> props = new Dictionary <string, object>();

            props[PropertyIds.Name]         = name;
            props[PropertyIds.ObjectTypeId] = "cmis:document";

            IContentStream contentStream = ContentStreamUtils.CreateTextContentStream(name, content);

            IDocument newDoc = parent.CreateDocument(props, contentStream, VersioningState.None);


            Assert.IsNotNull(newDoc);
            Assert.AreEqual(BaseTypeId.CmisDocument, newDoc.BaseTypeId);
            Assert.AreEqual("cmis:document", newDoc.DocumentType.Id);
            Assert.AreEqual(name, newDoc.Name);
            Assert.AreEqual(parent.Id, newDoc.Parents[0].Id);
            Assert.IsNotNull(newDoc.CreationDate);
            Assert.IsNotNull(newDoc.CreatedBy);
            Assert.IsNotNull(newDoc.LastModificationDate);
            Assert.IsNotNull(newDoc.LastModifiedBy);

            return(newDoc);
        }
Esempio n. 21
0
        public void TestVersioning()
        {
            IOperationContext noCacheOC = OperationContextUtils.CreateMaximumOperationContext();

            noCacheOC.CacheEnabled = false;

            IFolder   rootFolder = Session.GetRootFolder();
            IDocument doc        = null;

            try
            {
                // create document
                string         name1          = "versioned1.txt";
                IContentStream contentStream1 = ContentStreamUtils.CreateTextContentStream(name1, "v1");

                IDictionary <string, object> props = new Dictionary <string, object>();
                props[PropertyIds.Name]         = name1;
                props[PropertyIds.ObjectTypeId] = "VersionableType";

                doc = rootFolder.CreateDocument(props, contentStream1, VersioningState.Major);

                // create next version
                string         name2          = "versioned2.txt";
                IContentStream contentStream2 = ContentStreamUtils.CreateTextContentStream(name2, "v2");

                IObjectId pwcId = doc.CheckOut();
                IDocument pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);
                Assert.AreEqual(true, pwc.IsPrivateWorkingCopy);

                pwc.Rename(name2);

                IObjectId newVersId = pwc.CheckIn(true, null, contentStream2, "version 2");
                IDocument newVers   = (IDocument)Session.GetObject(newVersId, noCacheOC);

                Assert.AreEqual(name2, newVers.Name);
                Assert.AreEqual("v2", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                IDocument latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next version
                string         name3          = "versioned3.txt";
                IContentStream contentStream3 = ContentStreamUtils.CreateTextContentStream(name3, "v3");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name3);

                newVersId = pwc.CheckIn(true, null, contentStream3, "version 3");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name3, newVers.Name);
                Assert.AreEqual("v3", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(true, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // create next (minor) version
                string         name4          = "versioned4.txt";
                IContentStream contentStream4 = ContentStreamUtils.CreateTextContentStream(name4, "v3.1");

                pwcId = newVers.CheckOut();
                pwc   = (IDocument)Session.GetObject(pwcId, noCacheOC);

                pwc.Rename(name4);

                newVersId = pwc.CheckIn(false, null, contentStream4, "version 3.1");
                newVers   = (IDocument)Session.GetObject(newVersId);

                Assert.AreEqual(name4, newVers.Name);
                Assert.AreEqual("v3.1", ConvertStreamToString(newVers.GetContentStream().Stream));
                Assert.AreEqual(true, newVers.IsLatestVersion);
                Assert.AreEqual(false, newVers.IsMajorVersion);

                latestVersion = Session.GetLatestDocumentVersion(doc);
                Assert.AreEqual(newVers.Id, latestVersion.Id);

                // check version history
                IList <IDocument> versions = doc.GetAllVersions();
                Assert.AreEqual(4, versions.Count);

                Assert.AreEqual(latestVersion.Id, versions[0].Id);
                Assert.AreEqual(doc.Id, versions[3].Id);
            }
            finally
            {
                if (doc != null)
                {
                    doc.Delete();
                    Assert.IsFalse(Session.Exists(doc));
                }
            }
        }
        private static bool VerifyContentStream(IContentStream s, string mimeType, string fileName) {
            if (mimeType != null) {
                Assert.That(s.MimeType, Is.EqualTo(mimeType));
            }

            // Assert.That(s.Length, Is.Null);
            Assert.That(s.FileName, Is.EqualTo(fileName));
            return true;
        }
 private bool SetupFutureRemoteDocStream(Mock<IDocument> doc, IContentStream stream)
 {
     if (stream == null) {
         return true;
     } else {
         doc.Setup(d => d.ContentStreamLength).Returns(stream.Length);
         doc.Setup(d => d.ContentStreamFileName).Returns(stream.FileName);
         doc.Setup(d => d.ContentStreamMimeType).Returns(stream.MimeType);
         return true;
     }
 }
Esempio n. 24
0
        public string CreateDocument(string repositoryId, IProperties properties, string folderId, IContentStream contentStream,
            VersioningState? versioningState, IList<string> policies, IAcl addAces, IAcl removeAces, IExtensionsData extension)
        {
            ObjectServicePortClient port = Provider.GetObjectService();

            try
            {
                cmisExtensionType cmisExtension = Converter.ConvertExtension(extension);

                string objectId = port.createDocument(repositoryId, Converter.Convert(properties), folderId, Converter.Convert(contentStream),
                    (enumVersioningState?)CmisValue.CmisToSerializerEnum(versioningState), Converter.ConvertList(policies),
                    Converter.Convert(addAces), Converter.Convert(removeAces), ref cmisExtension);

                Converter.ConvertExtension(cmisExtension, extension);

                return objectId;
            }
            catch (FaultException<cmisFaultType> fe)
            {
                throw ConvertException(fe);
            }
            catch (Exception e)
            {
                throw new CmisRuntimeException("Error: " + e.Message, e);
            }
        }
Esempio n. 25
0
        public IObjectId CheckIn(bool major, IDictionary<string, object> properties, IContentStream contentStream,
                string checkinComment, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces)
        {
            String newObjectId = null;

            Lock();
            try
            {
                string objectId = ObjectId;

                IObjectFactory of = Session.ObjectFactory;

                HashSet<Updatability> updatebility = new HashSet<Updatability>();
                updatebility.Add(Updatability.ReadWrite);
                updatebility.Add(Updatability.WhenCheckedOut);

                Binding.GetVersioningService().CheckIn(RepositoryId, ref objectId, major, of.ConvertProperties(properties, ObjectType, updatebility),
                    contentStream, checkinComment, of.ConvertPolicies(policies), of.ConvertAces(addAces), of.ConvertAces(removeAces), null);

                newObjectId = objectId;
            }
            finally
            {
                Unlock();
            }

            if (newObjectId == null)
            {
                return null;
            }

            return Session.CreateObjectId(newObjectId);

        }
Esempio n. 26
0
        public IDocument CreateDocument(IDictionary<string, object> properties, IContentStream contentStream, VersioningState? versioningState,
            IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces, IOperationContext context)
        {
            IObjectId newId = Session.CreateDocument(properties, this, contentStream, versioningState, policies, addAces, removeAces);

            // if no context is provided the object will not be fetched
            if (context == null || newId == null)
            {
                return null;
            }

            // get the new object
            IDocument newDoc = Session.GetObject(newId, context) as IDocument;
            if (newDoc == null)
            {
                throw new CmisRuntimeException("Newly created object is not a document! New id: " + newId);
            }

            return newDoc;
        }
Esempio n. 27
0
        public void SetContentStream(string repositoryId, ref string objectId, bool? overwriteFlag, ref string changeToken,
            IContentStream contentStream, IExtensionsData extension)
        {
            ObjectServicePortClient port = Provider.GetObjectService();

            try
            {
                cmisExtensionType cmisExtension = Converter.ConvertExtension(extension);

                port.setContentStream(repositoryId, ref objectId, overwriteFlag, ref changeToken,
                    Converter.Convert(contentStream), ref cmisExtension);

                Converter.ConvertExtension(cmisExtension, extension);
            }
            catch (FaultException<cmisFaultType> fe)
            {
                throw ConvertException(fe);
            }
            catch (Exception e)
            {
                throw new CmisRuntimeException("Error: " + e.Message, e);
            }
        }
Esempio n. 28
0
 public IObjectId CreateDocument(IDictionary <string, object> properties, IObjectId folderId, IContentStream contentStream,
                                 VersioningState?versioningState)
 {
     return(CreateDocument(properties, folderId, contentStream, versioningState, null, null, null));
 }
Esempio n. 29
0
        // create

        public IObjectId CreateDocument(IDictionary <string, object> properties, IObjectId folderId, IContentStream contentStream,
                                        VersioningState?versioningState, IList <IPolicy> policies, IList <IAce> addAces, IList <IAce> removeAces)
        {
            if (properties == null || properties.Count == 0)
            {
                throw new ArgumentException("Properties must not be empty!");
            }

            string newId = Binding.GetObjectService().CreateDocument(RepositoryId, ObjectFactory.ConvertProperties(properties, null,
                                                                                                                   (versioningState == VersioningState.CheckedOut ? CreateAndCheckoutUpdatability : CreateUpdatability)),
                                                                     (folderId == null ? null : folderId.Id), contentStream, versioningState, ObjectFactory.ConvertPolicies(policies),
                                                                     ObjectFactory.ConvertAces(addAces), ObjectFactory.ConvertAces(removeAces), null);

            return(newId == null ? null : CreateObjectId(newId));
        }
Esempio n. 30
0
 public IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
     VersioningState? versioningState)
 {
     return CreateDocument(properties, folderId, contentStream, versioningState, null, null, null);
 }
Esempio n. 31
0
        public IObjectId SetContentStream(IContentStream contentStream, bool overwrite, bool refresh)
        {
            string newObjectId = null;

            Lock();
            try
            {
                string objectId = ObjectId;
                string changeToken = ChangeToken;

                Binding.GetObjectService().SetContentStream(RepositoryId, ref objectId, overwrite, ref changeToken, contentStream, null);

                newObjectId = objectId;
            }
            finally
            {
                Unlock();
            }

            if (refresh)
            {
                Refresh();
            }

            if (newObjectId == null)
            {
                return null;
            }

            return Session.CreateObjectId(newObjectId);
        }
        protected override void ProcessRecord()
        {
            var doc = Document;

            if (doc == null)
            {
                doc = new CmisNavigation(CmisSession, WorkingFolder).GetDocument(Path);
            }
            var writeToPipeline = String.IsNullOrEmpty(Destination);
            var size            = (long)doc.ContentStreamLength;

            // Do some security checks firsat if we should write the output to pipeline
            var msg = String.Format("The content is not plain text, but of type {0}. Do you want to"
                                    + "write it to pipeline anyway?", doc.ContentStreamMimeType);

            if (writeToPipeline && !IsPlaintextType(doc.ContentStreamMimeType) && !Force &&
                !ShouldContinue(msg, "Document Content Warning"))
            {
                return;
            }

            msg = String.Format("The document is pretty big (greater than {0:0.##} MB). " +
                                "Are you sure that you want to write it to the pipeline anyway?",
                                ((double)_pipelineMaxSize) / (1024 * 1024));
            if (writeToPipeline && size > _pipelineMaxSize && !Force &&
                !ShouldContinue(msg, "Big Document Warning"))
            {
                return;
            }

            msg = "The destination already exists. Do you want to overwrite that file?";
            if (!writeToPipeline && File.Exists(Destination) && !Force &&
                !ShouldContinue(msg, "Destination File Exists"))
            {
                return;
            }

            // TODO: better download mechanism anywhere
            byte[] stringBuffer = null;
            Stream outputStream;

            if (writeToPipeline)
            {
                stringBuffer = new byte[size];
                outputStream = new MemoryStream(stringBuffer);
            }
            else
            {
                outputStream = new FileStream(Destination, FileMode.Create);
            }

            IContentStream stream = null;

            try
            {
                var buffer    = new byte[8 * 1024];
                int offset    = 0;
                int bytesRead = 0;
                stream = doc.GetContentStream();

                while ((bytesRead = stream.Stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    outputStream.Write(buffer, 0, bytesRead);
                    offset += bytesRead;
                }
                outputStream.Flush();
            }
            finally
            {
                if (stream != null)
                {
                    stream.Stream.Close();
                }
                outputStream.Close();
            }

            if (writeToPipeline)
            {
                // TODO: support encodings
                WriteObject(Encoding.UTF8.GetString(stringBuffer));
            }
        }
Esempio n. 33
0
 public IObjectId CheckIn(bool major, IDictionary<String, object> properties, IContentStream contentStream, string checkinComment)
 {
     return this.CheckIn(major, properties, contentStream, checkinComment, null, null, null);
 }
Esempio n. 34
0
        public void TestCreate()
        {
            string testFolderName = "porttest";

            if (Session.ExistsPath("/", testFolderName))
            {
                ICmisObject obj = Session.GetObjectByPath("/", testFolderName, OperationContextUtils.CreateMinimumOperationContext());
                if (obj is IFolder)
                {
                    ((IFolder)obj).DeleteTree(true, UnfileObject.Delete, true);
                }
                else
                {
                    obj.Delete();
                }
            }

            // create folder
            IFolder root      = Session.GetRootFolder();
            IFolder newFolder = CreateFolder(root, testFolderName);

            Assert.IsNotNull(newFolder);

            // create document
            string    contentString = "Hello World";
            IDocument newDoc        = CreateTextDocument(newFolder, "test.txt", contentString);

            Assert.IsNotNull(newDoc);

            // get content
            IContentStream newContent = newDoc.GetContentStream();

            Assert.IsNotNull(newContent);
            Assert.IsNotNull(newContent.Stream);

            Assert.AreEqual(contentString, ConvertStreamToString(newContent.Stream));

            // fetch it again to get the updated content stream length property
            IOperationContext ctxt   = OperationContextUtils.CreateMaximumOperationContext();
            ICmisObject       newObj = Session.GetObject(newDoc, ctxt);

            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc2 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Name, newDoc2.Name);
            Assert.AreEqual(Encoding.UTF8.GetBytes(contentString).Length, newDoc2.ContentStreamLength);

            // fetch it again
            newObj = Session.GetLatestDocumentVersion(newDoc, ctxt);
            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc3 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Id, newDoc3.Id);
            Assert.AreEqual(newDoc.Name, newDoc3.Name);

            // delete document
            newDoc.Delete();

            try
            {
                Session.GetObject(newDoc);
                Assert.Fail("Document still exists.");
            }
            catch (CmisObjectNotFoundException)
            {
                // expected
            }

            Assert.IsFalse(Session.Exists(newDoc.Id));


            // try an item
            IList <IObjectType> types = Session.GetTypeChildren(null, false).ToList();

            Assert.IsNotNull(types);
            Assert.IsTrue(types.Count >= 2);
            if (types.Any(type => type.Id == "cmis:item"))
            {
                IItem newItem = CreateItem(newFolder, "testItem");

                newItem.Delete();

                Assert.IsFalse(Session.Exists(newItem.Id));
            }


            // delete folder

            Assert.IsTrue(Session.ExistsPath(newFolder.Path));

            newFolder.Delete();

            Assert.IsFalse(Session.Exists(newFolder));
        }
Esempio n. 35
0
 public IDocument CreateDocument(IDictionary<string, object> properties, IContentStream contentStream, VersioningState? versioningState)
 {
     return CreateDocument(properties, contentStream, versioningState, null, null, null, Session.DefaultContext);
 }
 private bool VerifyEmptyStream(IContentStream stream) {
     Assert.That(stream, Is.Not.Null);
     Assert.That(stream.Length, Is.EqualTo(0));
     Assert.That(string.IsNullOrEmpty(stream.MimeType), Is.False);
     return true;
 }
Esempio n. 37
0
        public IDocument SetContentStream(IContentStream contentStream, bool overwrite)
        {
            IObjectId objectId = SetContentStream(contentStream, overwrite, true);
            if (objectId == null)
            {
                return null;
            }

            if (ObjectId != objectId.Id)
            {
                return (IDocument)Session.GetObject(objectId, CreationContext);
            }

            return this;
        }
Esempio n. 38
0
        public void CheckIn(string repositoryId, ref string objectId, bool? major, IProperties properties,
            IContentStream contentStream, string checkinComment, IList<string> policies, IAcl addAces, IAcl removeAces,
            IExtensionsData extension)
        {
            VersioningServicePortClient port = Provider.GetVersioningService();

            try
            {
                cmisExtensionType cmisExtension = Converter.ConvertExtension(extension);

                port.checkIn(repositoryId, ref objectId, major, Converter.Convert(properties), Converter.Convert(contentStream),
                    checkinComment, Converter.ConvertList(policies), Converter.Convert(addAces), Converter.Convert(removeAces),
                    ref cmisExtension);

                Converter.ConvertExtension(cmisExtension, extension);
            }
            catch (FaultException<cmisFaultType> fe)
            {
                throw ConvertException(fe);
            }
            catch (Exception e)
            {
                throw new CmisRuntimeException("Error: " + e.Message, e);
            }
        }
Esempio n. 39
0
        // create

        public IObjectId CreateDocument(IDictionary<string, object> properties, IObjectId folderId, IContentStream contentStream,
            VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces)
        {
            if (properties == null || properties.Count == 0)
            {
                throw new ArgumentException("Properties must not be empty!");
            }

            string newId = Binding.GetObjectService().CreateDocument(RepositoryId, ObjectFactory.ConvertProperties(properties, null,
                (versioningState == VersioningState.CheckedOut ? CreateAndCheckoutUpdatability : CreateUpdatability)),
                (folderId == null ? null : folderId.Id), contentStream, versioningState, ObjectFactory.ConvertPolicies(policies),
                ObjectFactory.ConvertAces(addAces), ObjectFactory.ConvertAces(removeAces), null);

            return newId == null ? null : CreateObjectId(newId);
        }
Esempio n. 40
0
        public void SmokeTestCreateDocument()
        {
            IDictionary <string, object> properties = new Dictionary <string, object>();

            properties[PropertyIds.Name]         = "test-smoke.txt";
            properties[PropertyIds.ObjectTypeId] = DefaultDocumentType;

            byte[] content = UTF8Encoding.UTF8.GetBytes("Hello World!");

            ContentStream contentStream = new ContentStream();

            contentStream.FileName = properties[PropertyIds.Name] as string;
            contentStream.MimeType = "text/plain";
            contentStream.Length   = content.Length;
            contentStream.Stream   = new MemoryStream(content);

            IDocument doc = TestFolder.CreateDocument(properties, contentStream, null);

            // check doc
            Assert.NotNull(doc);
            Assert.NotNull(doc.Id);
            Assert.AreEqual(properties[PropertyIds.Name], doc.Name);
            Assert.AreEqual(BaseTypeId.CmisDocument, doc.BaseTypeId);
            Assert.True(doc.AllowableActions.Actions.Contains(Actions.CanGetProperties));
            Assert.False(doc.AllowableActions.Actions.Contains(Actions.CanGetChildren));

            // check type
            IObjectType type = doc.ObjectType;

            Assert.NotNull(type);
            Assert.NotNull(type.Id);
            Assert.AreEqual(properties[PropertyIds.ObjectTypeId], type.Id);

            // check versions
            IList <IDocument> versions = doc.GetAllVersions();

            Assert.NotNull(versions);
            Assert.AreEqual(1, versions.Count);
            //Assert.AreEqual(doc.Id, versions[0].Id);

            // check content
            IContentStream retrievedContentStream = doc.GetContentStream();

            Assert.NotNull(retrievedContentStream);
            Assert.NotNull(retrievedContentStream.Stream);

            MemoryStream byteStream = new MemoryStream();

            byte[] buffer = new byte[4096];
            int    b      = 1;

            while (b > 0)
            {
                b = retrievedContentStream.Stream.Read(buffer, 0, buffer.Length);
                byteStream.Write(buffer, 0, b);
            }

            byte[] retrievedContent = byteStream.ToArray();
            Assert.NotNull(retrievedContent);
            Assert.AreEqual(content.Length, retrievedContent.Length);
            for (int i = 0; i < content.Length; i++)
            {
                Assert.AreEqual(content[i], retrievedContent[i]);
            }

            // update name
            properties = new Dictionary <string, object>();
            properties[PropertyIds.Name] = "test2-smoke.txt";

            IObjectId newId = doc.UpdateProperties(properties);
            IDocument doc2  = Session.GetObject(newId) as IDocument;

            Assert.NotNull(doc2);

            doc2.Refresh();
            Assert.AreEqual(properties[PropertyIds.Name], doc2.Name);
            Assert.AreEqual(properties[PropertyIds.Name], doc2.GetPropertyValue(PropertyIds.Name));

            IProperty nameProperty = doc2[PropertyIds.Name];

            Assert.NotNull(nameProperty.PropertyType);
            Assert.AreEqual(properties[PropertyIds.Name], nameProperty.Value);
            Assert.AreEqual(properties[PropertyIds.Name], nameProperty.FirstValue);


            byte[] content2 = UTF8Encoding.UTF8.GetBytes("Hello Universe!");

            ContentStream contentStream2 = new ContentStream();

            contentStream2.FileName = properties[PropertyIds.Name] as string;
            contentStream2.MimeType = "text/plain";
            contentStream2.Length   = content2.Length;
            contentStream2.Stream   = new MemoryStream(content2);

            // doc.SetContentStream(contentStream2, true);

            doc2.Delete(true);

            try
            {
                doc.Refresh();
                Assert.Fail("Document shouldn't exist anymore!");
            }
            catch (CmisObjectNotFoundException) { }
        }