public static void AddTransmission(this Mock<IFileTransmissionStorage> storage, IFileTransmissionObject obj) { var allTransmissions = new List<IFileTransmissionObject>(storage.Object.GetObjectList() ?? new List<IFileTransmissionObject>()); allTransmissions.Add(obj); storage.Setup(s => s.GetObjectByLocalPath(It.Is<string>(path => path == obj.LocalPath))).Returns(obj); storage.Setup(s => s.GetObjectByRemoteObjectId(It.Is<string>(id => id == obj.RemoteObjectId))).Returns(obj); storage.Setup(s => s.GetObjectList()).Returns(allTransmissions); }
private IDocument CreateOrLoadExistingRemoteDocument(IFileInfo localFile, IObjectId parentId) { IDocument result; IFileTransmissionObject transmissionObject = this.TransmissionStorage.GetObjectByLocalPath(localFile.FullName); if (transmissionObject != null) { try { result = this.Session.GetObject(transmissionObject.RemoteObjectId) as IDocument; } catch (CmisObjectNotFoundException) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(transmissionObject.RemoteObjectId); result = this.CreateCheckedOutDocument(localFile, parentId); } } else { result = this.CreateCheckedOutDocument(localFile, parentId); } return(result); }
public void SaveObject(IFileTransmissionObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } if (obj.LocalPath == null) { throw new ArgumentNullException("obj.LocalPath"); } if (string.IsNullOrEmpty(obj.LocalPath)) { throw new ArgumentException("empty string", "obj.LocalPath"); } if (obj.RemoteObjectId == null) { throw new ArgumentNullException("obj.RemoteObjectId"); } if (string.IsNullOrEmpty(obj.RemoteObjectId)) { throw new ArgumentException("empty string", "obj.RemoteObjectId"); } if (!(obj is FileTransmissionObject)) { throw new ArgumentException("require FileTransmissionObject type", "obj"); } using (var tran = this.engine.GetTransaction()) { tran.Insert <string, DbCustomSerializer <FileTransmissionObject> >(FileTransmissionObjectsTable, obj.RemoteObjectId, obj as FileTransmissionObject); tran.Commit(); } }
private bool LoadCacheFile(IFileInfo target, IDocument remoteDocument, IFileSystemInfoFactory fsFactory) { if (this.TransmissionStorage == null) { return(false); } IFileTransmissionObject obj = this.TransmissionStorage.GetObjectByRemoteObjectId(remoteDocument.Id); if (obj == null) { return(false); } IFileInfo localFile = fsFactory.CreateFileInfo(obj.LocalPath); if (!localFile.Exists) { return(false); } if (obj.LastChangeToken != remoteDocument.ChangeToken || localFile.Length != obj.LastContentSize) { localFile.Delete(); return(false); } try { byte[] localHash; using (var f = localFile.Open(FileMode.Open, FileAccess.Read, FileShare.None)) { localHash = SHA1Managed.Create().ComputeHash(f); } if (!localHash.SequenceEqual(obj.LastChecksum)) { localFile.Delete(); return(false); } if (target.FullName != obj.LocalPath) { if (target.Exists) { Guid?uuid = target.Uuid; if (uuid != null) { localFile.Uuid = uuid; } target.Delete(); } localFile.MoveTo(target.FullName); target.Refresh(); } return(true); } catch (Exception) { localFile.Delete(); return(false); } }
public void SaveObject(IFileTransmissionObject obj) { if (obj == null) { throw new ArgumentNullException("obj"); } if (obj.LocalPath == null) { throw new ArgumentNullException("obj.LocalPath"); } if (string.IsNullOrEmpty(obj.LocalPath)) { throw new ArgumentException("empty string", "obj.LocalPath"); } if (obj.RemoteObjectId == null) { throw new ArgumentNullException("obj.RemoteObjectId"); } if (string.IsNullOrEmpty(obj.RemoteObjectId)) { throw new ArgumentException("empty string", "obj.RemoteObjectId"); } if (!(obj is FileTransmissionObject)) { throw new ArgumentException("require FileTransmissionObject type", "obj"); } using (var tran = this.engine.GetTransaction()) { tran.Insert<string, DbCustomSerializer<FileTransmissionObject>>(FileTransmissionObjectsTable, obj.RemoteObjectId, obj as FileTransmissionObject); tran.Commit(); } }
public static void AddTransmission(this Mock <IFileTransmissionStorage> storage, IFileTransmissionObject obj) { var allTransmissions = new List <IFileTransmissionObject>(storage.Object.GetObjectList() ?? new List <IFileTransmissionObject>()); allTransmissions.Add(obj); storage.Setup(s => s.GetObjectByLocalPath(It.Is <string>(path => path == obj.LocalPath))).Returns(obj); storage.Setup(s => s.GetObjectByRemoteObjectId(It.Is <string>(id => id == obj.RemoteObjectId))).Returns(obj); storage.Setup(s => s.GetObjectList()).Returns(allTransmissions); }