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(); } }
public void SmokeTestVersioning() { IDictionary <string, object> properties = new Dictionary <string, object>(); properties[PropertyIds.Name] = "test-version-smoke.txt"; properties[PropertyIds.ObjectTypeId] = DefaultDocumentType; IDocument doc = TestFolder.CreateDocument(properties, null, null); Assert.NotNull(doc); Assert.NotNull(doc.Id); Assert.AreEqual(properties[PropertyIds.Name], doc.Name); IList <IDocument> versions = doc.GetAllVersions(); Assert.NotNull(versions); Assert.AreEqual(1, versions.Count); IObjectId pwcId = doc.CheckOut(); Assert.NotNull(pwcId); IDocument pwc = Session.GetObject(pwcId) as IDocument; // check PWC Assert.NotNull(pwc); Assert.NotNull(pwc.Id); Assert.AreEqual(BaseTypeId.CmisDocument, doc.BaseTypeId); IDictionary <string, object> newProperties = new Dictionary <string, object>(); newProperties[PropertyIds.Name] = "test-version2-smoke.txt"; IObjectId doc2Id = pwc.CheckIn(true, newProperties, null, "new DotCMIS version"); Assert.NotNull(doc2Id); IDocument doc2 = Session.GetObject(doc2Id) as IDocument; doc2.Refresh(); // check new version Assert.NotNull(doc2); Assert.NotNull(doc2.Id); Assert.AreEqual(newProperties[PropertyIds.Name], doc2.Name); Assert.AreEqual(BaseTypeId.CmisDocument, doc2.BaseTypeId); versions = doc2.GetAllVersions(); Assert.NotNull(versions); Assert.AreEqual(2, versions.Count); doc2.DeleteAllVersions(); try { doc2.Refresh(); Assert.Fail("Document shouldn't exist anymore!"); } catch (CmisObjectNotFoundException) { } }
private IDocument CreateRemotePWCDocument(IDocument remoteDocument) { if (this.TransmissionStorage.GetObjectByRemoteObjectId(remoteDocument.Id) != null) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id); } if (string.IsNullOrEmpty(remoteDocument.VersionSeriesCheckedOutId)) { remoteDocument.CheckOut(); remoteDocument.Refresh(); } var remotePWCDocument = this.Session.GetObject(remoteDocument.VersionSeriesCheckedOutId) as IDocument; remotePWCDocument.DeleteContentStream(); return remotePWCDocument; }
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); }
private IDocument CreateRemotePWCDocument(IDocument remoteDocument) { if (this.TransmissionStorage.GetObjectByRemoteObjectId(remoteDocument.Id) != null) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(remoteDocument.Id); } if (string.IsNullOrEmpty(remoteDocument.VersionSeriesCheckedOutId)) { remoteDocument.CheckOut(); remoteDocument.Refresh(); } var remotePWCDocument = this.Session.GetObject(remoteDocument.VersionSeriesCheckedOutId) as IDocument; remotePWCDocument.DeleteContentStream(); return(remotePWCDocument); }
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)); } } }
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))); }