/// <summary> /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.ContentChangeEvent"/> class. /// </summary> /// <param name='type'> /// Type of the change. /// </param> /// <param name='objectId'> /// Object identifier. /// </param> public ContentChangeEvent(DotCMIS.Enums.ChangeType? type, string objectId) { if (objectId == null) { throw new ArgumentNullException("objectId"); } if (type == null) { throw new ArgumentNullException("type"); } this.Type = (DotCMIS.Enums.ChangeType)type; this.ObjectId = objectId; }
/** * Download a file, without retrying */ private void DownloadFile(DotCMIS.Data.IContentStream contentStream, string filePath) { SparkleLogger.LogInfo("Sync", "Downloading " + filePath); Stream file = File.OpenWrite(filePath); byte[] buffer = new byte[8 * 1024]; int len; while ((len = contentStream.Stream.Read(buffer, 0, buffer.Length)) > 0) // TODO catch WebException here and retry { file.Write(buffer, 0, len); } file.Close(); contentStream.Stream.Close(); SparkleLogger.LogInfo("Sync", "Downloaded"); }
/// <summary> /// Download a file, without retrying. /// </summary> private byte[] DownloadStream(DotCMIS.Data.IContentStream contentStream, string filePath) { byte[] hash = { }; using (Stream file = File.OpenWrite(filePath)) using (SHA1 hashAlg = new SHA1Managed()) using (CryptoStream hashstream = new CryptoStream(file, hashAlg, CryptoStreamMode.Write)) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = contentStream.Stream.Read(buffer, 0, buffer.Length)) > 0) { hashstream.Write(buffer, 0, len); } hashstream.FlushFinalBlock(); hash = hashAlg.Hash; } contentStream.Stream.Close(); return hash; }
public static bool ItemExistsWithType(ISession session, string path, DotCMIS.Enums.BaseTypeId type) { try { ICmisObject cmisObject = session.GetObjectByPath(path); if (cmisObject == null) { return false; } return cmisObject.ObjectType.BaseTypeId.Equals(type) || cmisObject.ObjectType.GetBaseType().BaseTypeId.Equals(type); } catch (Exception e) { if (e is ArgumentNullException || e is CmisObjectNotFoundException) { // In DotCMIS, this exception actually means that the document does not exist. return false; } else { throw; } } }
private static List<IChangeEvent> GenerateSingleChangeListMock(DotCMIS.Enums.ChangeType type, string objectId = "objId") { var changeList = new List<IChangeEvent>(); changeList.Add(GenerateChangeEvent(type, objectId).Object); return changeList; }
public static Mock<ISession> GetSessionMockReturningDocumentChange(DotCMIS.Enums.ChangeType type, string id, string documentContentStreamId = null) { var session = MockSessionUtil.PrepareSessionMockForSingleChange(type, id); var newRemoteObject = MockOfIDocumentUtil.CreateRemoteDocumentMock(documentContentStreamId, id, "name", (string)null); session.Setup(s => s.GetObject(id, It.IsAny<IOperationContext>())).Returns(newRemoteObject.Object); session.Setup(s => s.GetObject(id)).Returns(newRemoteObject.Object); return session; }
public static Mock<ISession> GetSessionMockReturning3Changesin2Batches(DotCMIS.Enums.ChangeType type = DotCMIS.Enums.ChangeType.Updated, bool overlapping = false) { var changeEvents = new Mock<IChangeEvents>(); changeEvents.Setup(ce => ce.HasMoreItems).ReturnsInOrder((bool?)true, (bool?)false); changeEvents.Setup(ce => ce.LatestChangeLogToken).ReturnsInOrder("A", "B"); changeEvents.Setup(ce => ce.TotalNumItems).ReturnsInOrder(3, overlapping ? 2 : 1); var event1 = MockSessionUtil.GenerateChangeEvent(type, "one"); var event2 = MockSessionUtil.GenerateChangeEvent(type, "two"); var event3 = MockSessionUtil.GenerateChangeEvent(type, "three"); List<IChangeEvent> changeList1 = new List<IChangeEvent>(); changeList1.Add(event1.Object); changeList1.Add(event2.Object); List<IChangeEvent> changeList2 = new List<IChangeEvent>(); if (overlapping) { changeList2.Add(event2.Object); } changeList2.Add(event3.Object); changeEvents.Setup(ce => ce.ChangeEventList).ReturnsInOrder(changeList1, changeList2); var session = new Mock<ISession>(); session.SetupSessionDefaultValues(); session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(It.IsAny<string>(), null).LatestChangeLogToken).Returns("token"); session.Setup(s => s.GetContentChanges(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<long>())).Returns(changeEvents.Object); return session; }
public static Mock<ISession> GetSessionMockReturningFolderChange(DotCMIS.Enums.ChangeType type, string id = "folderid", string folderName = "name", string path = "path", string parentId = "", string changetoken = "changetoken") { if (path.Contains("\\")) { throw new ArgumentException("Given remote path: " + path + " contains \\"); } var session = PrepareSessionMockForSingleChange(type, id); var newRemoteObject = MockOfIFolderUtil.CreateRemoteFolderMock(id, folderName, path, parentId, changetoken); session.Setup(s => s.GetObject(It.IsAny<string>())).Returns(newRemoteObject.Object); session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(newRemoteObject.Object); return session; }
public static Mock<ISession> PrepareSessionMockForSingleChange(DotCMIS.Enums.ChangeType type, string objectId = "objectId", string changeLogToken = "token", string latestChangeLogToken = "latestChangeLogToken") { var changeEvents = new Mock<IChangeEvents>(); var changeList = GenerateSingleChangeListMock(type, objectId); changeEvents.Setup(ce => ce.HasMoreItems).Returns((bool?)false); changeEvents.Setup(ce => ce.LatestChangeLogToken).Returns(latestChangeLogToken); changeEvents.Setup(ce => ce.TotalNumItems).Returns(1); changeEvents.Setup(ce => ce.ChangeEventList).Returns(changeList); var session = new Mock<ISession>(); session.SetupSessionDefaultValues(); session.SetupChangeLogToken(changeLogToken); session.Setup(s => s.GetContentChanges(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<long>())).Returns(changeEvents.Object); return session; }
public static Mock<IChangeEvent> GenerateChangeEvent(DotCMIS.Enums.ChangeType type, string objectId) { var changeEvent = new Mock<IChangeEvent>(); changeEvent.Setup(ce => ce.ObjectId).Returns(objectId); changeEvent.Setup(ce => ce.ChangeType).Returns(type); return changeEvent; }
/// <summary> /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.ProxyAuthRequiredEvent"/> class. /// </summary> /// <param name='e'> /// thrown CmisRuntimException indicating the proxy settings problem /// </param> public ProxyAuthRequiredEvent(DotCMIS.Exceptions.CmisRuntimeException e) : base(e) { }
/// <summary> /// Download a file, without retrying. /// </summary> private void DownloadStream(DotCMIS.Data.IContentStream contentStream, string filePath) { using (Stream file = File.OpenWrite(filePath)) { byte[] buffer = new byte[8 * 1024]; int len; while ((len = contentStream.Stream.Read(buffer, 0, buffer.Length)) > 0) { file.Write(buffer, 0, len); } } contentStream.Stream.Close(); }
private ContentChangeEvent PrepareFolderEvent(DotCMIS.Enums.ChangeType type) { var e = new ContentChangeEvent(type, Id); var remoteObject = new Mock<IFolder>(); var session = new Mock<ISession>(); session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(remoteObject.Object); e.UpdateObject(session.Object); return e; }
private ContentChangeEvent PrepareEvent(DotCMIS.Enums.ChangeType type, bool hasContentStream, byte[] contentHash = null) { var e = new ContentChangeEvent(type, Id); var remoteObject = MockOfIDocumentUtil.CreateRemoteDocumentMock(hasContentStream ? "streamId" : null, Id, "name", (string)null); if (contentHash != null) { remoteObject.SetupContentStreamHash(contentHash); } var session = new Mock<ISession>(); session.Setup(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>())).Returns(remoteObject.Object); e.UpdateObject(session.Object); return e; }