CreateSession() public static method

Creates a cmis Atom Pub session with the given credentials.
public static CreateSession ( string user, Password password, string url, string repoId, string binding ) : ISession
user string /// User. ///
password CmisSync.Lib.Config.Password /// Password. ///
url string /// URL. ///
repoId string /// Repo identifier. ///
binding string
return ISession
Exemplo n.º 1
0
        public void GetContentStreamHash(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            Regex    entryRegex = new Regex(@"^\{.+\}[0-9a-fA-F]+$");
            ISession session    = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  folder     = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string   filename   = "hashedfile.txt";

            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            using (var oneByteStream = new MemoryStream(new byte[1])) {
                ContentStream contentStream = new ContentStream();
                contentStream.MimeType = MimeType.GetMIMEType(filename);
                contentStream.Length   = 1;
                contentStream.Stream   = oneByteStream;
                var       emptyDoc     = folder.CreateDocument(properties, contentStream, null);
                var       context      = new OperationContext();
                IDocument requestedDoc = session.GetObject(emptyDoc, context) as IDocument;
                foreach (var prop in requestedDoc.Properties)
                {
                    if (prop.Id == "cmis:contentStreamHash")
                    {
                        Assert.That(prop.IsMultiValued, Is.True);
                        if (prop.Values != null)
                        {
                            foreach (string entry in prop.Values)
                            {
                                Assert.That(entryRegex.IsMatch(entry));
                            }
                        }
                    }
                }

                byte[] remoteHash = requestedDoc.ContentStreamHash();
                if (remoteHash != null)
                {
                    Assert.That(remoteHash, Is.EqualTo(SHA1.Create().ComputeHash(new byte[1])));
                }

                requestedDoc.Delete(true);
            }
        }
Exemplo n.º 2
0
        public void RemovingRemoteFolderAndAddingADocumentToItShouldThrowException(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            string   subFolderName = "subFolder";
            ISession session       = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            try {
                IFolder dir = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + subFolderName) as IFolder;
                if (dir != null)
                {
                    dir.DeleteTree(true, null, true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IFolder folder                = (IFolder)session.GetObjectByPath(remoteFolderPath);
            IFolder subFolder             = folder.CreateFolder(subFolderName);
            IFolder subFolderInstanceCopy = (IFolder)session.GetObject(subFolder.Id);

            subFolder.DeleteTree(true, null, true);

            Assert.Throws <CmisObjectNotFoundException>(() => subFolderInstanceCopy.CreateDocument("testFile.bin", "testContent"));
        }
Exemplo n.º 3
0
        public void AppendContentStreamTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            // var watch = Stopwatch.StartNew();
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);

            // watch.Stop();
            // Console.WriteLine(String.Format("Created Session in {0} msec",watch.ElapsedMilliseconds));
            // watch.Restart();
            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            // watch.Stop();
            // Console.WriteLine(String.Format("Requested folder in {0} msec", watch.ElapsedMilliseconds));
            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:document");
            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (Exception) {
            }

            // watch.Restart();
            IDocument emptyDoc = folder.CreateDocument(properties, null, null);

            // watch.Stop();
            // Console.WriteLine(String.Format("Created empty doc in {0} msec", watch.ElapsedMilliseconds));
            Assert.That(emptyDoc.ContentStreamLength == 0 || emptyDoc.ContentStreamLength == null, "returned document shouldn't got any content");
            string content = "test";

            for (int i = 0; i < 10; i++)
            {
                ContentStream contentStream = new ContentStream();
                contentStream.FileName = filename;
                contentStream.MimeType = MimeType.GetMIMEType(filename);
                contentStream.Length   = content.Length;
                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                    contentStream.Stream = memstream;
                    emptyDoc.AppendContentStream(contentStream, i == 9, true);
                }

                Assert.AreEqual(content.Length * (i + 1), emptyDoc.ContentStreamLength);
            }

            emptyDoc.DeleteAllVersions();
        }
Exemplo n.º 4
0
        public void GetSyncPropertyFromFile(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            session.EnsureSelectiveIgnoreSupportIsAvailable();
            IFolder folder   = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string  filename = "testfile.txt";

            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            IList <string> devices = new List <string>();

            devices.Add("*");
            properties.Add("gds:ignoreDeviceIds", devices);
            IList <string> ids = new List <string>();

            ids.Add("gds:sync");
            properties.Add(PropertyIds.SecondaryObjectTypeIds, ids);

            IDocument emptyDoc = folder.CreateDocument(properties, null, null);

            Assert.That(emptyDoc.ContentStreamLength == 0 || emptyDoc.ContentStreamLength == null);
            var       context       = new OperationContext();
            IDocument requestedDoc  = session.GetObject(emptyDoc, context) as IDocument;
            bool      propertyFound = false;

            foreach (var prop in requestedDoc.Properties)
            {
                if (prop.Id == "gds:ignoreDeviceIds")
                {
                    propertyFound = true;
                    Assert.AreEqual("*", prop.FirstValue as string);
                }
            }

            Assert.IsTrue(propertyFound);
            emptyDoc.DeleteAllVersions();
        }
Exemplo n.º 5
0
        public void SetJPEGContentStream(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session  = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  folder   = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string   filename = "testfile.jpg";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            }
            catch (CmisObjectNotFoundException) {
            }

            IDocument emptyDoc = folder.CreateDocument(properties, null, null);

            Assert.That(emptyDoc.ContentStreamLength == null || emptyDoc.ContentStreamLength == 0, "returned document shouldn't got any content");
            int contentLength = 1024;

            byte[] content = new byte[contentLength];
            using (RandomNumberGenerator random = RandomNumberGenerator.Create()) {
                random.GetBytes(content);
            }

            ContentStream contentStream = new ContentStream();

            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;

            using (var memstream = new MemoryStream(content)) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }

            Assert.AreEqual(content.Length, emptyDoc.ContentStreamLength, "Setting content failed");
            IDocument randomDoc = session.GetObjectByPath(emptyDoc.Paths[0]) as IDocument;

            Assert.That(randomDoc != null);
            Assert.AreEqual(content.Length, randomDoc.ContentStreamLength, "Getting content on new object failed");
            emptyDoc.DeleteAllVersions();
        }
Exemplo n.º 6
0
        public void AppendContentStreamTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  folder  = (IFolder)session.GetObjectByPath(remoteFolderPath);

            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            IDocument doc = null;

            try {
                doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (Exception) {
            }

            string content         = "test";
            string expectedContent = string.Empty;

            doc             = folder.CreateDocument(filename, content);
            expectedContent = content;
            Assert.That(doc.ContentStreamLength == content.Length, "returned document should have got content");
            for (int i = 0; i < 10; i++)
            {
                doc              = doc.AppendContent(content, i == 9) ?? doc;
                expectedContent += content;
                Assert.AreEqual(expectedContent.Length, doc.ContentStreamLength);
            }

            doc.AssertThatIfContentHashExistsItIsEqualTo(expectedContent);

            for (int i = 0; i < 10; i++)
            {
                doc              = doc.AppendContent(content) ?? doc;
                expectedContent += content;
                Assert.AreEqual(expectedContent.Length, doc.ContentStreamLength);
                doc.AssertThatIfContentHashExistsItIsEqualTo(expectedContent);
            }

            doc.DeleteAllVersions();
        }
Exemplo n.º 7
0
        public void GetRootFolderOfRepository(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session      = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);
            IFolder  remoteFolder = (IFolder)session.GetObject(repositoryId);

            Assert.IsNotNull(remoteFolder);
        }
Exemplo n.º 8
0
        public void CheckoutTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            string subFolderName = "subFolder";
            string fileName      = "testFile.bin";
            string subFolderPath = remoteFolderPath.TrimEnd('/') + "/" + subFolderName;
            string filePath      = subFolderPath + "/" + fileName;

            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            if (!session.ArePrivateWorkingCopySupported())
            {
                Assert.Ignore("PWCs are not supported");
            }

            try {
                IFolder dir = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + subFolderName) as IFolder;
                if (dir != null)
                {
                    dir.DeleteTree(true, null, true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IFolder folder    = (IFolder)session.GetObjectByPath(remoteFolderPath);
            IFolder subFolder = folder.CreateFolder(subFolderName);

            IDocument doc         = subFolder.CreateDocument(fileName, "testContent", checkedOut: true);
            IObjectId checkoutId  = doc.CheckOut();
            IDocument docCheckout = (IDocument)session.GetObject(checkoutId);

            Assert.AreEqual(doc.ContentStreamLength, docCheckout.ContentStreamLength);
            doc.Refresh();
            Assert.IsTrue(doc.IsVersionSeriesCheckedOut.GetValueOrDefault());
            Assert.AreEqual(checkoutId.Id, doc.VersionSeriesCheckedOutId);

            docCheckout.CancelCheckOut();
            doc.Refresh();
            Assert.IsFalse(doc.IsVersionSeriesCheckedOut.GetValueOrDefault());
            Assert.IsNull(doc.VersionSeriesCheckedOutId);
        }
Exemplo n.º 9
0
        public void GetRootFolderAndAllowableActions(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session      = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  remoteFolder = (IFolder)session.GetObject(repositoryId);

            Assert.That(remoteFolder.AllowableActions, Is.Not.Null);
            Assert.That(remoteFolder.AllowableActions.Actions, Is.Not.Null.Or.Empty);
        }
Exemplo n.º 10
0
        public void EnsureFileNameStaysEqualWhileUploading(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IDocument emptyDoc = folder.CreateDocument(properties, null, null);
            int       length   = 1024 * 1024;

            byte[]        content       = new byte[length];
            ContentStream contentStream = new ContentStream();

            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;
            Action assert = delegate {
                Assert.That((session.GetObject(emptyDoc.Id, OperationContextFactory.CreateNonCachingPathIncludingContext(session)) as IDocument).Name, Is.EqualTo(filename));
            };

            using (var memstream = new AssertingStream(new MemoryStream(content), assert)) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }
        }
Exemplo n.º 11
0
        public void CreateDocumentWithCreationAndModificationDate(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            if (!session.IsServerAbleToUpdateModificationDate())
            {
                Assert.Ignore("Server is not able to sync modification dates");
            }

            string    filename = "name";
            IDocument doc;

            try {
                doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            DateTime creationDate     = DateTime.UtcNow - TimeSpan.FromDays(1);
            DateTime modificationDate = DateTime.UtcNow - TimeSpan.FromHours(1);
            IFolder  folder           = (IFolder)session.GetObjectByPath(remoteFolderPath);

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.CreationDate, creationDate);
            properties.Add(PropertyIds.LastModificationDate, modificationDate);

            doc = folder.CreateDocument(properties, null, null);

            Assert.That(((DateTime)doc.LastModificationDate - modificationDate).Seconds, Is.EqualTo(0), "Wrong modification date");
            Assert.That(((DateTime)doc.CreationDate - creationDate).Seconds, Is.EqualTo(0), "Wrong creation date");
            doc.DeleteAllVersions();
        }
Exemplo n.º 12
0
        public void CreateDocumentWithContentStream(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);

            IFolder   folder  = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string    content = "content";
            IDocument doc     = folder.CreateDocument("name", content);

            Assert.That(doc.ContentStreamLength, Is.EqualTo(content.Length));
            doc.DeleteAllVersions();
        }
Exemplo n.º 13
0
        public void RenameRemoteFolderChangesChangeLogToken(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session       = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);
            IFolder  rootFolder    = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string   folderName    = "1";
            string   newFolderName = "2";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, folderName);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:folder");
            try {
                IFolder folder = session.GetObjectByPath(remoteFolderPath + "/" + folderName) as IFolder;
                if (folder != null)
                {
                    folder.Delete(true);
                }

                folder = session.GetObjectByPath(remoteFolderPath + "/" + newFolderName) as IFolder;
                if (folder != null)
                {
                    folder.Delete(true);
                }
            }
            catch (CmisObjectNotFoundException) {
            }

            IFolder newFolder      = rootFolder.CreateFolder(properties);
            string  changeLogToken = session.RepositoryInfo.LatestChangeLogToken;
            string  changeToken    = newFolder.ChangeToken;

            newFolder.Rename(newFolderName, true);

            Assert.That(newFolder.ChangeToken, Is.Not.EqualTo(changeToken));

            newFolder.Delete(true);
        }
Exemplo n.º 14
0
        public void GetChildrenDoesNotProducesServerProtocolViolationException(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);

            for (int i = 0; i < 1000; i++)
            {
                IFolder root = (IFolder)session.GetObjectByPath(remoteFolderPath);
                foreach (var child in root.GetChildren())
                {
                    Console.WriteLine(child.Name);
                }
            }
        }
Exemplo n.º 15
0
        public void RenameRemoteFolderChangesChangeLogToken(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session       = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  rootFolder    = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string   folderName    = "1";
            string   newFolderName = "2";

            try {
                IFolder folder = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + folderName) as IFolder;
                if (folder != null)
                {
                    folder.DeleteTree(true, null, true);
                }

                folder = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + newFolderName) as IFolder;
                if (folder != null)
                {
                    folder.DeleteTree(true, null, true);
                }
            }
            catch (CmisObjectNotFoundException) {
            }

            IFolder newFolder      = rootFolder.CreateFolder(folderName);
            string  changeLogToken = session.RepositoryInfo.LatestChangeLogToken;
            string  changeToken    = newFolder.ChangeToken;

            newFolder.Rename(newFolderName, true);

            Assert.That(newFolder.ChangeToken, Is.Not.EqualTo(changeToken));

            newFolder.DeleteTree(true, null, true);
        }
Exemplo n.º 16
0
        public void RemovingRemoteFolderAndAddingADocumentToItShouldThrowException(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);

            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            IFolder subFolder = folder.CreateFolder("subFolder");

            IFolder subFolderInstanceCopy = (IFolder)session.GetObject(subFolder.Id);

            subFolder.DeleteTree(true, null, true);

            Assert.Throws <CmisObjectNotFoundException>(() => subFolderInstanceCopy.CreateDocument("testFile.bin", "testContent"));
        }
Exemplo n.º 17
0
        public void RenameFolder(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session       = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);
            IFolder  rootFolder    = (IFolder)session.GetObjectByPath(remoteFolderPath);
            string   folderName    = "1";
            string   newFolderName = "was 1 in past";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, folderName);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:folder");
            try {
                IFolder folder = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + folderName) as IFolder;
                if (folder != null)
                {
                    folder.Delete(true);
                }

                folder = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + newFolderName) as IFolder;
                if (folder != null)
                {
                    folder.Delete(true);
                }
            }
            catch (CmisObjectNotFoundException) {
            }

            IFolder newFolder = rootFolder.CreateFolder(properties);

            newFolder.Rename(newFolderName, true);
            Assert.That(newFolder.Name, Is.EqualTo(newFolderName));
            newFolder.Delete(true);
        }
Exemplo n.º 18
0
        public void AppendContentStreamTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId);

            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, "cmis:document");
            IDocument doc = null;

            try {
                doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (Exception) {
            }
            string content = "test";

            doc = folder.CreateDocument(filename, content);
            Assert.That(doc.ContentStreamLength == content.Length, "returned document should have got content");
            for (int i = 0; i < 10; i++)
            {
                ContentStream contentStream = new ContentStream();
                contentStream.FileName = filename;
                contentStream.MimeType = MimeType.GetMIMEType(filename);
                contentStream.Length   = content.Length;
                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                    contentStream.Stream = memstream;
                    doc.AppendContentStream(contentStream, i == 9, true);
                }

                Assert.AreEqual(content.Length * (i + 2), doc.ContentStreamLength);
            }

            for (int i = 0; i < 10; i++)
            {
                ContentStream contentStream = new ContentStream();
                contentStream.FileName = filename;
                contentStream.MimeType = MimeType.GetMIMEType(filename);
                contentStream.Length   = content.Length;
                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                    contentStream.Stream = memstream;
                    doc.AppendContentStream(contentStream, true, true);
                }

                Assert.AreEqual(content.Length * (i + 2 + 10), doc.ContentStreamLength);
            }

            doc.DeleteAllVersions();
        }
Exemplo n.º 19
0
        public void CheckinTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            string subFolderName = "subFolder";
            string fileName      = "testFile.bin";
            string subFolderPath = remoteFolderPath.TrimEnd('/') + "/" + subFolderName;
            string filePath      = subFolderPath + "/" + fileName;

            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            if (!session.ArePrivateWorkingCopySupported())
            {
                Assert.Ignore("PWCs are not supported");
            }

            try {
                IFolder dir = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + subFolderName) as IFolder;
                if (dir != null)
                {
                    dir.DeleteTree(true, null, true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IFolder folder    = (IFolder)session.GetObjectByPath(remoteFolderPath);
            IFolder subFolder = folder.CreateFolder(subFolderName);

            string content = "testContent";

            IDocument doc         = subFolder.CreateDocument(fileName, "testContent", checkedOut: true);
            IObjectId checkoutId  = doc.CheckOut();
            IDocument docCheckout = session.GetObject(checkoutId) as IDocument;

            Assert.AreEqual(doc.ContentStreamLength, docCheckout.ContentStreamLength);

            ContentStream contentStream = new ContentStream();

            contentStream.FileName = fileName;
            contentStream.MimeType = MimeType.GetMIMEType(fileName);
            contentStream.Length   = content.Length;
            for (int i = 0; i < 10; ++i)
            {
                using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                    contentStream.Stream = memstream;
                    docCheckout.AppendContentStream(contentStream, i == 9);
                }
                Assert.That(docCheckout.ContentStreamLength, Is.EqualTo(content.Length * (i + 2)));
            }

            IObjectId checkinId  = docCheckout.CheckIn(true, null, null, "checkin");
            IDocument docCheckin = session.GetObject(checkinId) as IDocument;

            docCheckin.Refresh();   //  refresh is required, or DotCMIS will re-use the cached properties if checinId is the same as doc.Id
            Assert.That(docCheckin.ContentStreamLength, Is.EqualTo(content.Length * (9 + 2)));
        }
Exemplo n.º 20
0
        public void SetContentStreamTest(
            string canonical_name,
            string localPath,
            string remoteFolderPath,
            string url,
            string user,
            string password,
            string repositoryId,
            string binding)
        {
            ISession session = DotCMISSessionTests.CreateSession(user, password, url, repositoryId, binding);

            IFolder folder = (IFolder)session.GetObjectByPath(remoteFolderPath);

            string filename = "testfile.txt";
            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add(PropertyIds.Name, filename);
            properties.Add(PropertyIds.ObjectTypeId, BaseTypeId.CmisDocument.GetCmisValue());
            try {
                IDocument doc = session.GetObjectByPath(remoteFolderPath.TrimEnd('/') + "/" + filename) as IDocument;
                if (doc != null)
                {
                    doc.Delete(true);
                }
            } catch (CmisObjectNotFoundException) {
            }

            IDocument emptyDoc = folder.CreateDocument(properties, null, null);

            Assert.That(emptyDoc.ContentStreamLength == null || emptyDoc.ContentStreamLength == 0, "returned document shouldn't got any content");
            string content = string.Empty;

            content += "Test ";
            ContentStream contentStream = new ContentStream();

            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;
            using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }

            Assert.AreEqual(content.Length, emptyDoc.ContentStreamLength);
            emptyDoc.DeleteContentStream(true);
            content               += "Test ";
            contentStream          = new ContentStream();
            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;
            using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }

            Assert.AreEqual(content.Length, emptyDoc.ContentStreamLength);
            emptyDoc.DeleteContentStream(true);
            content               += "Test ";
            contentStream          = new ContentStream();
            contentStream.FileName = filename;
            contentStream.MimeType = MimeType.GetMIMEType(filename);
            contentStream.Length   = content.Length;
            using (var memstream = new MemoryStream(Encoding.UTF8.GetBytes(content))) {
                contentStream.Stream = memstream;
                emptyDoc.SetContentStream(contentStream, true, true);
            }

            Assert.AreEqual(content.Length, emptyDoc.ContentStreamLength);
            emptyDoc.DeleteAllVersions();
        }