public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var obj = this.Storage.GetObjectByRemoteId(remoteId.Id); string oldName = (remoteId as ICmisObject).Name; // Rename object try { (remoteId as ICmisObject).Rename(localFileSystemInfo.Name, true); } catch (CmisConstraintException e) { if (!Utils.IsValidISO885915(localFileSystemInfo.Name)) { OperationsLogger.Warn(string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFileSystemInfo.Name)); throw new InteractionNeededException(string.Format("Server denied renaming of {0}", oldName), e) { Title = string.Format("Server denied renaming of {0}", oldName), Description = string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFileSystemInfo.Name) }; } throw; } catch (CmisPermissionDeniedException) { OperationsLogger.Warn(string.Format("Unable to renamed remote object from {0} to {1}: Permission Denied", oldName, localFileSystemInfo.Name)); return; } obj.Name = localFileSystemInfo.Name; obj.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); this.Storage.SaveMappedObject(obj); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var savedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); string newPath = remoteId is IFolder ? this.Storage.Matcher.CreateLocalPath(remoteId as IFolder) : this.Storage.Matcher.CreateLocalPath(remoteId as IDocument); if (remoteId is IFolder) { IDirectoryInfo dirInfo = localFileSystemInfo as IDirectoryInfo; string oldPath = dirInfo.FullName; if (!dirInfo.FullName.Equals(newPath)) { dirInfo.MoveTo(newPath); OperationsLogger.Info(string.Format("Moved local folder {0} to {1}", oldPath, newPath)); } else { return; } } else if (remoteId is IDocument) { IFileInfo fileInfo = localFileSystemInfo as IFileInfo; string oldPath = fileInfo.FullName; fileInfo.MoveTo(newPath); OperationsLogger.Info(string.Format("Moved local file {0} to {1}", oldPath, newPath)); } savedObject.Name = (remoteId as ICmisObject).Name; savedObject.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); savedObject.ParentId = remoteId is IFolder ? (remoteId as IFolder).ParentId : (remoteId as IDocument).Parents[0].Id; this.Storage.SaveMappedObject(savedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var obj = this.Storage.GetObjectByRemoteId(remoteId.Id); var localParent = localFileSystemInfo is IFileInfo ? (localFileSystemInfo as IFileInfo).Directory : (localFileSystemInfo as IDirectoryInfo).Parent; var mappedLocalParent = this.Storage.GetObjectByGuid((Guid)localParent.Uuid); var remoteObject = remoteId as IFileableCmisObject; var targetId = mappedLocalParent.RemoteObjectId; var src = this.Session.GetObject(obj.ParentId); var target = this.Session.GetObject(targetId); try { OperationsLogger.Info(string.Format("Moving remote object {2} from folder {0} to folder {1}", src.Name, target.Name, remoteId.Id)); remoteObject = remoteObject.Move(src, target); } catch (CmisPermissionDeniedException) { OperationsLogger.Info(string.Format("Moving remote object failed {0}: Permission Denied", localFileSystemInfo.FullName)); return; } obj.ParentId = targetId; obj.Ignored = remoteObject.AreAllChildrenIgnored(); this.Storage.SaveMappedObject(obj); if (obj.Name != localFileSystemInfo.Name) { this.renameChangeSolver.Solve(localFileSystemInfo, remoteObject, localContent, remoteContent); } else { this.changeChangeSolver.Solve(localFileSystemInfo, remoteObject, localContent, remoteContent); } }
/// <summary> /// Does nothing /// </summary> /// <param name='localFile'> /// Local file. /// </param> /// <param name='remoteId'> /// Remote identifier. /// </param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public virtual void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { // No Operation Needed }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (localFileSystemInfo is IFileInfo && remoteId is IDocument) { var localFile = localFileSystemInfo as IFileInfo; var remoteDocument = remoteId as IDocument; var mappedObject = this.Storage.GetObject(localFile); if (mappedObject == null) { throw new ArgumentException(string.Format("Could not find db entry for {0} => invoke crawl sync", localFileSystemInfo.FullName)); } if (mappedObject.LastChangeToken != (remoteId as ICmisObjectProperties).ChangeToken) { throw new ArgumentException(string.Format("remote {1} {0} has also been changed since last sync => invoke crawl sync", remoteId.Id, remoteId is IDocument ? "document" : "folder")); } if (localFile != null && localFile.IsContentChangedTo(mappedObject, scanOnlyIfModificationDateDiffers: true)) { Logger.Debug(string.Format("\"{0}\" is different from {1}", localFile.FullName, mappedObject.ToString())); OperationsLogger.Debug(string.Format("Local file \"{0}\" has been changed", localFile.FullName)); try { var transmission = this.transmissionManager.CreateTransmission(TransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName); mappedObject.LastChecksum = this.UploadFileWithPWC(localFile, ref remoteDocument, transmission); mappedObject.ChecksumAlgorithmName = "SHA-1"; if (remoteDocument.Id != mappedObject.RemoteObjectId) { this.TransmissionStorage.RemoveObjectByRemoteObjectId(mappedObject.RemoteObjectId); mappedObject.RemoteObjectId = remoteDocument.Id; } } catch (Exception ex) { if (ex.InnerException is CmisPermissionDeniedException) { OperationsLogger.Warn(string.Format("Local changed file \"{0}\" has not been uploaded: PermissionDenied", localFile.FullName)); return; } else if (ex.InnerException is CmisStorageException) { OperationsLogger.Warn(string.Format("Local changed file \"{0}\" has not been uploaded: StorageException", localFile.FullName), ex); return; } throw; } mappedObject.LastRemoteWriteTimeUtc = remoteDocument.LastModificationDate; mappedObject.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; mappedObject.LastContentSize = localFile.Length; OperationsLogger.Info(string.Format("Local changed file \"{0}\" has been uploaded", localFile.FullName)); } mappedObject.LastChangeToken = remoteDocument.ChangeToken; mappedObject.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; this.Storage.SaveMappedObject(mappedObject); } else { this.folderOrFileContentUnchangedSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } return; }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFile">Local file.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { var mappedObject = this.Storage.GetObjectByLocalPath(localFile); this.Storage.RemoveObject(mappedObject); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var savedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); Guid? newParentUuid = localFileSystemInfo is IFileInfo ? (localFileSystemInfo as IFileInfo).Directory.Uuid : (localFileSystemInfo as IDirectoryInfo).Parent.Uuid; string newParentId = this.Storage.GetObjectByGuid((Guid)newParentUuid).RemoteObjectId; savedObject.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); if (localFileSystemInfo.Name == (remoteId as ICmisObject).Name) { // Both names are equal => only move to new remote parent try { (remoteId as IFileableCmisObject).Move(this.Session.GetObject(savedObject.ParentId), this.Session.GetObject(newParentId)); } catch (CmisPermissionDeniedException) { OperationsLogger.Info(string.Format("Permission Denied: Cannot move remote object {0} from {1} to {2}", remoteId.Id, savedObject.ParentId, newParentId)); return; } savedObject.Name = localFileSystemInfo.Name; savedObject.ParentId = newParentId; this.Storage.SaveMappedObject(savedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } else { // Names are different to each other if (localFileSystemInfo.Name == savedObject.Name) { // Remote rename and local move => Move remote and rename locally => change change solver try { remoteId = (remoteId as IFileableCmisObject).Move(this.Session.GetObject(savedObject.ParentId), this.Session.GetObject(newParentId)); } catch (CmisPermissionDeniedException) { OperationsLogger.Info(string.Format("Permission Denied: Cannot move remote object {0} from {1} to {2}", remoteId.Id, savedObject.ParentId, newParentId)); return; } var localParentPath = localFileSystemInfo is IFileInfo ? (localFileSystemInfo as IFileInfo).Directory.FullName : (localFileSystemInfo as IDirectoryInfo).Parent.FullName; string newPath = Path.Combine(localParentPath, (remoteId as ICmisObject).Name); this.MoveTo(localFileSystemInfo, localFileSystemInfo.FullName, newPath); savedObject.Name = localFileSystemInfo.Name; savedObject.ParentId = newParentId; this.Storage.SaveMappedObject(savedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } else { // Both sides have been renamed => Move remote => rename rename solver try { (remoteId as IFileableCmisObject).Move(this.Session.GetObject(savedObject.ParentId), this.Session.GetObject(newParentId)); } catch (CmisPermissionDeniedException) { OperationsLogger.Info(string.Format("Permission Denied: Cannot move remote object {0} from {1} to {2}", remoteId.Id, savedObject.ParentId, newParentId)); return; } savedObject.ParentId = newParentId; this.Storage.SaveMappedObject(savedObject); this.renameRenameSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } } }
/// <summary> /// Renames the specified localFile to the name of the given remoteId object by using the storage, localFile and remoteId. /// </summary> /// <param name="localFile">Local file or folder. It is the source file/folder reference, which should be renamed.</param> /// <param name="remoteId">Remote identifier. Should be an instance of IFolder or IDocument.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { IMappedObject obj = this.Storage.GetObjectByRemoteId(remoteId.Id); if (remoteId is IFolder) { // Rename local folder IFolder remoteFolder = remoteId as IFolder; IDirectoryInfo dirInfo = localFile as IDirectoryInfo; string oldPath = dirInfo.FullName; try { dirInfo.MoveTo(Path.Combine(dirInfo.Parent.FullName, remoteFolder.Name)); obj.Name = remoteFolder.Name; } catch (IOException) { if (dirInfo.Name.Equals(remoteFolder.Name, StringComparison.OrdinalIgnoreCase)) { obj.Name = dirInfo.Name; } else { throw; } } if (remoteFolder.LastModificationDate != null) { dirInfo.LastWriteTimeUtc = (DateTime)remoteFolder.LastModificationDate; } obj.LastChangeToken = remoteFolder.ChangeToken; obj.LastRemoteWriteTimeUtc = remoteFolder.LastModificationDate; obj.LastLocalWriteTimeUtc = dirInfo.LastWriteTimeUtc; obj.Ignored = remoteFolder.AreAllChildrenIgnored(); this.Storage.SaveMappedObject(obj); OperationsLogger.Info(string.Format("Renamed local folder {0} to {1}", oldPath, remoteFolder.Name)); } else if(remoteId is IDocument) { // Rename local file IDocument remoteDocument = remoteId as IDocument; IFileInfo fileInfo = localFile as IFileInfo; string oldPath = fileInfo.FullName; fileInfo.MoveTo(Path.Combine(fileInfo.Directory.FullName, remoteDocument.Name)); if (remoteDocument.LastModificationDate != null) { fileInfo.LastWriteTimeUtc = (DateTime)remoteDocument.LastModificationDate; } obj.Name = remoteDocument.Name; obj.LastChangeToken = remoteContent == ContentChangeType.NONE ? remoteDocument.ChangeToken : obj.LastChangeToken; obj.LastRemoteWriteTimeUtc = remoteContent == ContentChangeType.NONE ? remoteDocument.LastModificationDate : obj.LastRemoteWriteTimeUtc; obj.LastLocalWriteTimeUtc = fileInfo.LastWriteTimeUtc; this.Storage.SaveMappedObject(obj); OperationsLogger.Info(string.Format("Renamed local file {0} to {1}", oldPath, remoteDocument.Name)); if (remoteContent != ContentChangeType.NONE) { throw new ArgumentException("Remote documents content is also changed => force crawl sync."); } } else { throw new ArgumentException("Given remote Id is not an IFolder nor an IDocument instance"); } }
private bool TryDeleteObjectOnServer(IObjectId remoteId, MappedObjectType type) { try { if (type == MappedObjectType.Folder) { (remoteId as IFolder).DeleteTree(false, UnfileObject.DeleteSinglefiled, true); } else { this.Session.Delete(remoteId, true); } } catch (CmisPermissionDeniedException) { return false; } return true; }
/// <summary> /// Solve the specified situation by using the storage and remote object id to remove existing db entries and forces a crawl sync by throwing an IOException. /// </summary> /// <param name="localFile">Deleted Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed. Is not used by this solver.</param> /// <param name="remoteContent">Information if the remote content has been changed. Is not used by this solver.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { var mappedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); this.Storage.RemoveObject(mappedObject); throw new IOException( string.Format( "Local deleted {0} is renamed or moved remotely => invoking crawl sync to download them again", mappedObject.Type == MappedObjectType.File ? "file" : "directory")); }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { if (localFileSystemInfo is IDirectoryInfo) { IDirectoryInfo localFolder = localFileSystemInfo as IDirectoryInfo; IDirectoryInfo localParent = localFolder.Parent; IFolder remoteFolder = remoteId as IFolder; string remoteParentId = remoteFolder.ParentId; IMappedObject mappedParent = this.Storage.GetObjectByRemoteId(remoteParentId); IMappedObject mappedObject = this.Storage.GetObjectByRemoteId(remoteFolder.Id); if (localParent.Uuid == mappedParent.Guid) { // Both folders are in the same parent folder this.SyncNamesAndDates(localFolder, remoteFolder, mappedObject); } else { OperationsLogger.Warn( string.Format( "Synchronization Conflict: The local directory {0} has been moved to {1} with id {2},{4}" + "but the remote folder was moved to {3}{4}You can fix this situation by moving them into the same folder", localFileSystemInfo.Name, localFileSystemInfo.FullName, remoteFolder.Path, Environment.NewLine)); return; } } else if (localFileSystemInfo is IFileInfo) { IFileInfo localFile = localFileSystemInfo as IFileInfo; IDirectoryInfo localParent = localFile.Directory; IDocument remoteFile = remoteId as IDocument; string remoteParentId = remoteFile.Parents[0].Id; IMappedObject mappedParent = this.Storage.GetObjectByRemoteId(remoteParentId); IMappedObject mappedObject = this.Storage.GetObjectByRemoteId(remoteFile.Id); if (localParent.Uuid == mappedParent.Guid) { // Both files are in the same parent folder this.SyncNamesAndDates(localFile, remoteFile, mappedObject); return; } else { OperationsLogger.Warn( string.Format( "Synchronization Conflict: The local file {0} has been moved to {1} with id {2},{4}" + "but the remote file was moved to {3}{4}You can fix this situation by moving them into the same folder", localFileSystemInfo.Name, localFileSystemInfo.FullName, remoteFile.Paths[0], Environment.NewLine)); return; } } }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { // User Interaction needed or the content will be downloaded on next sync. // Possibilities: // - Download new remote content (default, because no user interaction is needed and it is simple to solve) // - Remove remote element // - Ignore until situation is cleared OperationsLogger.Warn(string.Format("The remote object {0} of the corresponding locally deleted element has been changed => Downloading the remote changes", remoteId.Id)); this.Storage.RemoveObject(this.Storage.GetObjectByRemoteId(remoteId.Id)); throw new ArgumentException("Remote object has been changed while the object was deleted locally => force crawl sync"); }
/// <summary> /// Solve the specified situation by using the session, storage, localFile and remoteId. /// If a folder is affected, simply update the local change time of the corresponding local folder. /// If it is a file and the changeToken is not equal to the saved, the new content is downloaded. /// </summary> /// <param name="localFile">Local file.</param> /// <param name="remoteId">Remote identifier.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { IMappedObject obj = this.Storage.GetObjectByRemoteId(remoteId.Id); if (remoteId is IFolder) { var remoteFolder = remoteId as IFolder; DateTime? lastModified = remoteFolder.LastModificationDate; obj.LastChangeToken = remoteFolder.ChangeToken; if (lastModified != null) { try { localFile.LastWriteTimeUtc = (DateTime)lastModified; } catch(IOException e) { Logger.Debug("Couldn't set the server side modification date", e); } obj.Ignored = remoteFolder.AreAllChildrenIgnored(); obj.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; } } else if (remoteId is IDocument) { var remoteDocument = remoteId as IDocument; DateTime? lastModified = remoteDocument.LastModificationDate; if ((lastModified != null && lastModified != obj.LastRemoteWriteTimeUtc) || obj.LastChangeToken != remoteDocument.ChangeToken) { if (remoteContent != ContentChangeType.NONE) { if (obj.LastLocalWriteTimeUtc != localFile.LastWriteTimeUtc) { throw new ArgumentException("The local file has been changed since last write => aborting update"); } obj.LastChecksum = DownloadChanges(localFile as IFileInfo, remoteDocument, obj, this.fsFactory, this.transmissonManager, Logger); } obj.LastRemoteWriteTimeUtc = remoteDocument.LastModificationDate; if (remoteDocument.LastModificationDate != null) { localFile.LastWriteTimeUtc = (DateTime)remoteDocument.LastModificationDate; } obj.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; obj.LastContentSize = remoteDocument.ContentStreamLength ?? 0; } obj.LastChangeToken = remoteDocument.ChangeToken; obj.LastRemoteWriteTimeUtc = lastModified; } this.Storage.SaveMappedObject(obj); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { // Rename local object and call change/change solver var savedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); string oldPath = localFileSystemInfo.FullName; string parentPath = localFileSystemInfo is IFileInfo ? (localFileSystemInfo as IFileInfo).Directory.FullName : (localFileSystemInfo as IDirectoryInfo).Parent.FullName; string newPath = Path.Combine(parentPath, (remoteId as ICmisObject).Name); this.MoveTo(localFileSystemInfo, oldPath, newPath); savedObject.Name = (remoteId as ICmisObject).Name; savedObject.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); this.Storage.SaveMappedObject(savedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var mappedObject = this.Storage.GetObjectByGuid((Guid)localFileSystemInfo.Uuid); this.Storage.RemoveObject(mappedObject); if (localFileSystemInfo is IFileInfo) { this.secondSolver.Solve(localFileSystemInfo, null, ContentChangeType.CREATED, ContentChangeType.NONE); } else if (localFileSystemInfo is IDirectoryInfo) { this.secondSolver.Solve(localFileSystemInfo, null, ContentChangeType.NONE, ContentChangeType.NONE); var dir = localFileSystemInfo as IDirectoryInfo; if (dir.GetFiles().Length > 0 || dir.GetDirectories().Length > 0) { throw new IOException(string.Format("There are unsynced files in local folder {0} => starting crawl sync", dir.FullName)); } } }
/// <summary> /// Deletes the given localFileInfo on file system and removes the stored object from storage. /// </summary> /// <param name="localFileInfo">Local file info.</param> /// <param name="remoteId">Remote identifier.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (localFileInfo is IDirectoryInfo) { if (!this.DeleteLocalObjectIfHasBeenSyncedBefore(localFileInfo)) { this.Storage.RemoveObject(this.Storage.GetObjectByLocalPath(localFileInfo)); throw new IOException(string.Format("Not all local objects under {0} have been synced yet", localFileInfo.FullName)); } else { this.Storage.RemoveObject(this.Storage.GetObjectByLocalPath(localFileInfo)); } } else if (localFileInfo is IFileInfo) { var file = localFileInfo as IFileInfo; file.Refresh(); var mappedFile = this.Storage.GetObjectByLocalPath(file); if (file.Exists) { if (mappedFile != null && file.LastWriteTimeUtc.Equals(mappedFile.LastLocalWriteTimeUtc)) { file.Delete(); OperationsLogger.Info(string.Format("Deleted local file {0} because the mapped remote object {0} has been deleted", file.FullName, mappedFile.RemoteObjectId)); } else { file.Uuid = null; if (mappedFile == null) { return; } OperationsLogger.Info(string.Format("Deletion of local file {0} skipped because of not yet uploaded changes", file.FullName)); } } else { if (mappedFile == null) { return; } else { OperationsLogger.Info(string.Format("Deletion of local file {0} skipped because it has already been deleted", file.FullName)); } } this.Storage.RemoveObject(this.Storage.GetObjectByLocalPath(localFileInfo)); file.Refresh(); if (file.Exists) { throw new IOException(string.Format("Deletion of local file {0} skipped because of not yet uploaded changes", localFileInfo.FullName)); } } }
/// <summary> /// Solves the situation by deleting the corresponding remote object. /// </summary> /// <param name="localFile">Local file.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { var mappedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); if (mappedObject.LastChangeToken != (remoteId as ICmisObject).ChangeToken) { throw new ArgumentException("Remote object has been changed since last sync => force crawl sync"); } bool hasBeenDeleted = this.TryDeleteObjectOnServer(remoteId, mappedObject.Type); if (hasBeenDeleted) { this.Storage.RemoveObject(mappedObject); OperationsLogger.Info(string.Format("Deleted the corresponding remote object {0} of locally deleted object {1}", remoteId.Id, mappedObject.Name)); } else { OperationsLogger.Warn(string.Format("Permission denied while trying to Delete the locally deleted object {0} on the server.", mappedObject.Name)); } }
/// <summary> /// Solve the specified situation by using the session, storage, localFile and remoteId. /// Moves the local file/folder to the new location. /// </summary> /// <param name="localFile">Old local file/folder.</param> /// <param name="remoteId">Remote identifier.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { // Move local object var savedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); string newPath = remoteId is IFolder ? this.Storage.Matcher.CreateLocalPath(remoteId as IFolder) : this.Storage.Matcher.CreateLocalPath(remoteId as IDocument); if (remoteId is IFolder) { IDirectoryInfo dirInfo = localFile as IDirectoryInfo; string oldPath = dirInfo.FullName; if (!dirInfo.FullName.Equals(newPath)) { dirInfo.MoveTo(newPath); dirInfo.LastWriteTimeUtc = (remoteId as IFolder).LastModificationDate != null ? (DateTime)(remoteId as IFolder).LastModificationDate : dirInfo.LastWriteTimeUtc; OperationsLogger.Info(string.Format("Moved local folder {0} to {1}", oldPath, newPath)); } else { return; } } else if (remoteId is IDocument) { IFileInfo fileInfo = localFile as IFileInfo; string oldPath = fileInfo.FullName; fileInfo.MoveTo(newPath); fileInfo.LastWriteTimeUtc = (remoteId as IDocument).LastModificationDate != null ? (DateTime)(remoteId as IDocument).LastModificationDate : fileInfo.LastWriteTimeUtc; OperationsLogger.Info(string.Format("Moved local file {0} to {1}", oldPath, newPath)); } savedObject.Name = (remoteId as ICmisObject).Name; savedObject.ParentId = remoteId is IFolder ? (remoteId as IFolder).ParentId : (remoteId as IDocument).Parents[0].Id; savedObject.LastChangeToken = (remoteId is IDocument && remoteContent != ContentChangeType.NONE) ? savedObject.LastChangeToken : remoteId is ICmisObject ? (remoteId as ICmisObject).ChangeToken : null; savedObject.LastLocalWriteTimeUtc = localFile.LastWriteTimeUtc; savedObject.LastRemoteWriteTimeUtc = (remoteId is IDocument && remoteContent != ContentChangeType.NONE) ? savedObject.LastRemoteWriteTimeUtc : (remoteId as ICmisObject).LastModificationDate; savedObject.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); this.Storage.SaveMappedObject(savedObject); if (remoteId is IDocument && remoteContent != ContentChangeType.NONE) { throw new ArgumentException("Remote content has also been changed => force crawl sync."); } }
public T Get(IObjectId id) { return(_dbContext.GetItemFromDB(id)); }
// delete public void Delete(IObjectId objectId) { Delete(objectId, true); }
public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary <string, object> properties, IObjectId folderId, VersioningState?versioningState, IList <IPolicy> policies, IList <IAce> addAces, IList <IAce> removeAces) { if (source == null || source.Id == null) { throw new ArgumentException("Source must be set!"); } // get the type of the source document IObjectType type = null; if (source is ICmisObject) { type = ((ICmisObject)source).ObjectType; } else { ICmisObject sourceObj = GetObject(source); type = sourceObj.ObjectType; } if (type.BaseTypeId != BaseTypeId.CmisDocument) { throw new ArgumentException("Source object must be a document!"); } string newId = Binding.GetObjectService().CreateDocumentFromSource(RepositoryId, source.Id, ObjectFactory.ConvertProperties(properties, type, (versioningState == VersioningState.CheckedOut ? CreateAndCheckoutUpdatability : CreateUpdatability)), (folderId == null ? null : folderId.Id), versioningState, ObjectFactory.ConvertPolicies(policies), ObjectFactory.ConvertAces(addAces), ObjectFactory.ConvertAces(removeAces), null); return(newId == null ? null : CreateObjectId(newId)); }
public IDocument GetLatestDocumentVersion(IObjectId objectId, bool major, IOperationContext context) { if (objectId == null || objectId.Id == null) { throw new ArgumentNullException("objectId"); } if (context == null) { throw new ArgumentNullException("context"); } ICmisObject result = null; string versionSeriesId = null; // first attempt: if we got a Document object, try getting the version // series ID from it if (objectId is IDocument) { versionSeriesId = ((IDocument)objectId).VersionSeriesId; } // second attempt: if we have a Document object in the cache, retrieve // the version series ID form there if (versionSeriesId == null) { if (context.CacheEnabled) { ICmisObject sourceDoc = Cache.GetById(objectId.Id, context.CacheKey); if (sourceDoc is IDocument) { versionSeriesId = ((IDocument)sourceDoc).VersionSeriesId; } } } // third attempt (Web Services only): get the version series ID from the // repository // (the AtomPub and Browser binding don't need the version series ID -> // avoid roundtrip) if (versionSeriesId == null) { string bindingType = Binding.BindingType; if (bindingType == BindingType.WebServices || bindingType == BindingType.Custom) { // get the document to find the version series ID IObjectData sourceObjectData = Binding.GetObjectService().GetObject(RepositoryId, objectId.Id, PropertyIds.ObjectId + "," + PropertyIds.VersionSeriesId, false, IncludeRelationshipsFlag.None, "cmis:none", false, false, null); if (sourceObjectData.Properties != null) { IPropertyData verionsSeriesIdProp = sourceObjectData.Properties[PropertyIds.VersionSeriesId]; if (verionsSeriesIdProp != null) { versionSeriesId = verionsSeriesIdProp.FirstValue as string; } } // the Web Services binding needs the version series ID -> fail if (versionSeriesId == null) { throw new ArgumentException("Object is not a document or not versionable!"); } } } // get the object IObjectData objectData = Binding.GetVersioningService().GetObjectOfLatestVersion(RepositoryId, objectId.Id, versionSeriesId, major, context.FilterString, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, context.IncludePolicies, context.IncludeAcls, null); result = ObjectFactory.ConvertObject(objectData, context); // put into cache if (context.CacheEnabled) { Cache.Put(result, context.CacheKey); } // check result if (!(result is IDocument)) { throw new ArgumentException("Latest version is not a document!"); } return(result as IDocument); }
public void Read(IObjectId x) { operationQueue.Add(new OperationRequest { OpType = OperationType.Read, Id = x }); }
public override void UpdateTarget(IReference directRef, IObjectId targetId) { }
public IObjectId CreateDocument(IDictionary <string, object> properties, IObjectId folderId, IContentStream contentStream, VersioningState?versioningState) { return(CreateDocument(properties, folderId, contentStream, versioningState, null, null, null)); }
public virtual void StoreInstanceMetadata(IObjectId objectId, InstanceMetadata data) { StoreInstanceMetadata(objectId, data, DataAdapter); }
// content stream public IContentStream GetContentStream(IObjectId docId) { return(GetContentStream(docId, null, null, null)); }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Signalizes how the local content has been modified.</param> /// <param name="remoteContent">Signalizes how the remote content has been modified.</param> public abstract void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent);
public bool Equals(IObjectId other) => equalityHelper.Equals(this, other);
/// <summary> /// Adds the Object to Disk and Database /// </summary> /// <param name='localFile'> /// Local file. /// </param> /// <param name='remoteId'> /// Remote Object (already fetched). /// </param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> /// <exception cref='ArgumentException'> /// Is thrown when remoteId is not prefetched. /// </exception> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (localFile is IDirectoryInfo) { if (!(remoteId is IFolder)) { throw new ArgumentException("remoteId has to be a prefetched Folder"); } var remoteFolder = remoteId as IFolder; IDirectoryInfo localFolder = localFile as IDirectoryInfo; localFolder.Create(); Guid uuid = Guid.Empty; if (localFolder.IsExtendedAttributeAvailable()) { uuid = Guid.NewGuid(); try { localFolder.Uuid = uuid; } catch (RestoreModificationDateException) { } } if (remoteFolder.LastModificationDate != null) { localFolder.LastWriteTimeUtc = (DateTime)remoteFolder.LastModificationDate; } var mappedObject = new MappedObject(remoteFolder); mappedObject.Guid = uuid; mappedObject.LastRemoteWriteTimeUtc = remoteFolder.LastModificationDate; mappedObject.LastLocalWriteTimeUtc = localFolder.LastWriteTimeUtc; this.Storage.SaveMappedObject(mappedObject); OperationsLogger.Info(string.Format("New local folder {0} created and mapped to remote folder {1}", localFolder.FullName, remoteId.Id)); } else if (localFile is IFileInfo) { Guid guid = Guid.NewGuid(); var file = localFile as IFileInfo; if (!(remoteId is IDocument)) { throw new ArgumentException("remoteId has to be a prefetched Document"); } if (file.Exists) { Guid?uuid = file.Uuid; if (uuid != null) { if (this.Storage.GetObjectByGuid((Guid)uuid) != null) { throw new ArgumentException("This file has already been synced => force crawl sync"); } } Logger.Debug(string.Format("This file {0} conflicts with remote file => conflict file will be produced after download", file.FullName)); } var cacheFile = this.fsFactory.CreateDownloadCacheFileInfo(guid); IDocument remoteDoc = remoteId as IDocument; var transmissionEvent = new FileTransmissionEvent(FileTransmissionType.DOWNLOAD_NEW_FILE, localFile.FullName, cacheFile.FullName); this.manager.AddTransmission(transmissionEvent); byte[] hash = null; using (var hashAlg = new SHA1Managed()) using (var fileStream = cacheFile.Open(FileMode.Create, FileAccess.Write, FileShare.Read)) using (var downloader = FileTransmission.ContentTaskUtils.CreateDownloader()) { try { downloader.DownloadFile(remoteDoc, fileStream, transmissionEvent, hashAlg); } catch (Exception ex) { transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { FailedException = ex }); throw; } hash = hashAlg.Hash; } cacheFile.Uuid = guid; try { cacheFile.MoveTo(file.FullName); } catch (IOException e) { file.Refresh(); if (file.Exists) { IFileInfo conflictFile = this.fsFactory.CreateConflictFileInfo(file); IFileInfo targetFile = cacheFile.Replace(file, conflictFile, true); targetFile.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, guid.ToString(), true); conflictFile.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, null, true); } else { transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { FailedException = e }); throw; } } file.Refresh(); if (remoteDoc.LastModificationDate != null) { try { file.LastWriteTimeUtc = (DateTime)remoteDoc.LastModificationDate; } catch (IOException e) { Logger.Debug("Cannot set last modification date", e); } } MappedObject mappedObject = new MappedObject( file.Name, remoteDoc.Id, MappedObjectType.File, remoteDoc.Parents[0].Id, remoteDoc.ChangeToken, remoteDoc.ContentStreamLength ?? 0) { Guid = guid, LastLocalWriteTimeUtc = file.LastWriteTimeUtc, LastRemoteWriteTimeUtc = remoteDoc.LastModificationDate, LastChecksum = hash, ChecksumAlgorithmName = "SHA-1" }; this.Storage.SaveMappedObject(mappedObject); OperationsLogger.Info(string.Format("New local file {0} created and mapped to remote file {1}", file.FullName, remoteId.Id)); transmissionEvent.ReportProgress(new TransmissionProgressEventArgs { Completed = true }); } }
private void Init(IObjectId objectId, string mediaType, string transferSyntax) { DicomObject = objectId; MediaType = mediaType; TransferSyntax = transferSyntax ?? ""; }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFile">Local file.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { var obj = this.Storage.GetObjectByRemoteId(remoteId.Id); // Rename remote object if (remoteId is ICmisObject) { if ((remoteId as ICmisObject).ChangeToken != obj.LastChangeToken) { throw new ArgumentException("Last changetoken is invalid => force crawl sync"); } string oldName = (remoteId as ICmisObject).Name; try { (remoteId as ICmisObject).Rename(localFile.Name, true); } catch (CmisNameConstraintViolationException e) { if (!Utils.IsValidISO885915(localFile.Name)) { OperationsLogger.Warn(string.Format("The server denies the renaming of {2} from {0} to {1}, perhaps because the new name contains UTF-8 characters", oldName, localFile.Name, localFile.FullName)); throw new InteractionNeededException(string.Format("Server denied renaming of {0}", oldName), e) { Title = string.Format("Server denied renaming of {0}", oldName), Description = string.Format("The server denies the renaming of {2} from {0} to {1}, perhaps because the new name contains UTF-8 characters", oldName, localFile.Name, localFile.FullName) }; } else { try { string wishedRemotePath = this.Storage.Matcher.CreateRemotePath(localFile.FullName); var conflictingRemoteObject = this.Session.GetObjectByPath(wishedRemotePath) as IFileableCmisObject; if (conflictingRemoteObject != null && conflictingRemoteObject.AreAllChildrenIgnored()) { OperationsLogger.Warn(string.Format("The server denies the renaming of {2} from {0} to {1}, because there is an ignored file/folder with this name already, trying to create conflict file/folder name", oldName, localFile.Name, localFile.FullName), e); string newName = localFile.Name; if (localFile is IDirectoryInfo) { (localFile as IDirectoryInfo).MoveTo(Path.Combine((localFile as IDirectoryInfo).Parent.FullName, newName + "_Conflict")); } else if (localFile is IFileInfo) { (localFile as IFileInfo).MoveTo(Path.Combine((localFile as IFileInfo).Directory.FullName, newName + "_Conflict")); } return; } } catch (CmisObjectNotFoundException) { } OperationsLogger.Warn(string.Format("The server denies the renaming of {2} from {0} to {1}", oldName, localFile.Name, localFile.FullName), e); } throw; } catch (CmisPermissionDeniedException) { OperationsLogger.Warn(string.Format("Unable to renamed remote object from {0} to {1}: Permission Denied", oldName, localFile.Name)); return; } OperationsLogger.Info(string.Format("Renamed remote object {0} from {1} to {2}", remoteId.Id, oldName, localFile.Name)); } else { throw new ArgumentException("Given remoteId type is unknown: " + remoteId.GetType().Name); } bool isContentChanged = localFile is IFileInfo ? (localFile as IFileInfo).IsContentChangedTo(obj) : false; obj.Name = (remoteId as ICmisObject).Name; obj.LastRemoteWriteTimeUtc = (remoteId as ICmisObject).LastModificationDate; obj.LastLocalWriteTimeUtc = isContentChanged ? obj.LastLocalWriteTimeUtc : localFile.LastWriteTimeUtc; obj.LastChangeToken = (remoteId as ICmisObject).ChangeToken; obj.Ignored = (remoteId as ICmisObject).AreAllChildrenIgnored(); this.Storage.SaveMappedObject(obj); if (isContentChanged) { throw new ArgumentException("Local file content is also changed => force crawl sync."); } }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { if (localFileSystemInfo is IDirectoryInfo) { IDirectoryInfo localFolder = localFileSystemInfo as IDirectoryInfo; IDirectoryInfo localParent = localFolder.Parent; IFolder remoteFolder = remoteId as IFolder; string remoteParentId = remoteFolder.ParentId; IMappedObject mappedParent = this.Storage.GetObjectByRemoteId(remoteParentId); IMappedObject mappedObject = this.Storage.GetObjectByRemoteId(remoteFolder.Id); if (localParent.Uuid == mappedParent.Guid) { // Both folders are in the same parent folder this.SyncNamesAndDates(localFolder, remoteFolder, mappedObject); } else { OperationsLogger.Warn( string.Format( "Synchronization Conflict: The local directory {0} has been moved to {1} with id {2},{4}" + "but the remote folder was moved to {3}{4}You can fix this situation by moving them into the same folder", localFileSystemInfo.Name, localFileSystemInfo.FullName, remoteFolder.Path, Environment.NewLine)); return; } } else if (localFileSystemInfo is IFileInfo) { IFileInfo localFile = localFileSystemInfo as IFileInfo; IDirectoryInfo localParent = localFile.Directory; IDocument remoteFile = remoteId as IDocument; string remoteParentId = remoteFile.Parents[0].Id; IMappedObject mappedParent = this.Storage.GetObjectByRemoteId(remoteParentId); IMappedObject mappedObject = this.Storage.GetObjectByRemoteId(remoteFile.Id); if (localParent.Uuid == mappedParent.Guid) { // Both files are in the same parent folder mappedObject.ParentId = remoteParentId; this.Storage.SaveMappedObject(mappedObject); throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes"); } else { OperationsLogger.Warn( string.Format( "Synchronization Conflict: The local file {0} has been moved to {1} with id {2},{4}" + "but the remote file was moved to {3}{4}You can fix this situation by moving them into the same folder", localFileSystemInfo.Name, localFileSystemInfo.FullName, remoteFile.Paths[0], Environment.NewLine)); return; } } }
/// <summary> /// Solve the specified situation by taking renaming the local or remote object to the name of the last changed object. /// </summary> /// <param name="localFileSystemInfo">Local file system info.</param> /// <param name="remoteId">Remote object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (localFileSystemInfo is IDirectoryInfo) { var localFolder = localFileSystemInfo as IDirectoryInfo; var remoteFolder = remoteId as IFolder; var mappedObject = this.Storage.GetObjectByRemoteId(remoteFolder.Id); if (localFolder.Name.Equals(remoteFolder.Name)) { mappedObject.Name = localFolder.Name; } else if (localFolder.LastWriteTimeUtc.CompareTo((DateTime)remoteFolder.LastModificationDate) > 0) { string oldName = remoteFolder.Name; try { remoteFolder.Rename(localFolder.Name, true); } catch (CmisConstraintException e) { if (!Utils.IsValidISO885915(localFolder.Name)) { OperationsLogger.Warn(string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFolder.Name)); throw new InteractionNeededException(string.Format("Server denied renaming of {0}", oldName), e) { Title = string.Format("Server denied renaming of {0}", oldName), Description = string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFolder.Name) }; } throw; } mappedObject.Name = remoteFolder.Name; OperationsLogger.Info(string.Format("Renamed remote folder {0} with id {2} to {1}", oldName, remoteFolder.Id, remoteFolder.Name)); } else { string oldName = localFolder.Name; localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remoteFolder.Name)); mappedObject.Name = remoteFolder.Name; OperationsLogger.Info(string.Format("Renamed local folder {0} to {1}", Path.Combine(localFolder.Parent.FullName, oldName), remoteFolder.Name)); } mappedObject.LastLocalWriteTimeUtc = localFolder.LastWriteTimeUtc; mappedObject.LastRemoteWriteTimeUtc = (DateTime)remoteFolder.LastModificationDate; mappedObject.LastChangeToken = remoteFolder.ChangeToken; mappedObject.Ignored = remoteFolder.AreAllChildrenIgnored(); this.Storage.SaveMappedObject(mappedObject); } else if (localFileSystemInfo is IFileInfo) { var localFile = localFileSystemInfo as IFileInfo; var remoteFile = remoteId as IDocument; var mappedObject = this.Storage.GetObjectByRemoteId(remoteFile.Id); if (localFile.Name.Equals(remoteFile.Name)) { mappedObject.Name = localFile.Name; this.Storage.SaveMappedObject(mappedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } else { string desc = string.Format( "The local file {0} has been locally renamed from {1} to {2} and remotely to {3}. " + "Fix this conflict by renaming the remote file to {2} or the local file to {3}.", localFile.FullName, mappedObject.Name, localFile.Name, remoteFile.Name); OperationsLogger.Warn("Synchronization Conflict: " + desc); throw new InteractionNeededException("Synchronization Conflict") { Title = "Synchronization Conflict", Description = desc }; } } }
public TestableCommit(IObjectId id) { this.id = id; }
public IDocument GetLatestDocumentVersion(IObjectId objectId, IOperationContext context) { return(GetLatestDocumentVersion(objectId, false, context)); }
/// <summary> /// Solve the specified situation by taking renaming the local or remote object to the name of the last changed object. /// </summary> /// <param name="localFileSystemInfo">Local file system info.</param> /// <param name="remoteId">Remote object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { if (localFileSystemInfo is IDirectoryInfo) { var localFolder = localFileSystemInfo as IDirectoryInfo; var remoteFolder = remoteId as IFolder; var mappedObject = this.Storage.GetObjectByRemoteId(remoteFolder.Id); if (localFolder.Name.Equals(remoteFolder.Name)) { mappedObject.Name = localFolder.Name; } else if (localFolder.LastWriteTimeUtc.CompareTo((DateTime)remoteFolder.LastModificationDate) > 0) { string oldName = remoteFolder.Name; try { remoteFolder.Rename(localFolder.Name, true); } catch (CmisConstraintException e) { if (!Utils.IsValidISO885915(localFolder.Name)) { OperationsLogger.Warn(string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFolder.Name)); throw new InteractionNeededException(string.Format("Server denied renaming of {0}", oldName), e) { Title = string.Format("Server denied renaming of {0}", oldName), Description = string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFolder.Name) }; } throw; } mappedObject.Name = remoteFolder.Name; OperationsLogger.Info(string.Format("Renamed remote folder {0} with id {2} to {1}", oldName, remoteFolder.Id, remoteFolder.Name)); } else { string oldName = localFolder.Name; localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remoteFolder.Name)); mappedObject.Name = remoteFolder.Name; OperationsLogger.Info(string.Format("Renamed local folder {0} to {1}", Path.Combine(localFolder.Parent.FullName, oldName), remoteFolder.Name)); } mappedObject.LastLocalWriteTimeUtc = localFolder.LastWriteTimeUtc; mappedObject.LastRemoteWriteTimeUtc = (DateTime)remoteFolder.LastModificationDate; mappedObject.LastChangeToken = remoteFolder.ChangeToken; this.Storage.SaveMappedObject(mappedObject); } else if (localFileSystemInfo is IFileInfo) { var localFile = localFileSystemInfo as IFileInfo; var remoteFile = remoteId as IDocument; var mappedObject = this.Storage.GetObjectByRemoteId(remoteFile.Id); if (localFile.Name.Equals(remoteFile.Name)) { mappedObject.Name = localFile.Name; this.Storage.SaveMappedObject(mappedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } else { string desc = string.Format( "The local file {0} has been locally renamed from {1} to {2} and remotely to {3}. " + "Fix this conflict by renaming the remote file to {2} or the local file to {3}.", localFile.FullName, mappedObject.Name, localFile.Name, remoteFile.Name); OperationsLogger.Warn("Synchronization Conflict: " + desc); throw new InteractionNeededException("Synchronization Conflict") { Title = "Synchronization Conflict", Description = desc }; } } }
// permissions public IAcl GetAcl(IObjectId objectId, bool onlyBasicPermissions) { if (objectId == null || objectId.Id == null) { throw new ArgumentException("Invalid object id!"); } return Binding.GetAclService().GetAcl(RepositoryId, objectId.Id, onlyBasicPermissions, null); }
/// <summary> /// Solve the specified situation by using localFile and remote object. /// </summary> /// <param name="localFileSystemInfo">Local filesystem info instance.</param> /// <param name="remoteId">Remote identifier or object.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var obj = this.Storage.GetObjectByRemoteId(remoteId.Id); if (localFileSystemInfo is IDirectoryInfo) { obj.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; obj.LastRemoteWriteTimeUtc = (remoteId as IFolder).LastModificationDate; obj.LastChangeToken = (remoteId as IFolder).ChangeToken; this.Storage.SaveMappedObject(obj); } else if (localFileSystemInfo is IFileInfo) { var fileInfo = localFileSystemInfo as IFileInfo; var doc = remoteId as IDocument; bool updateLocalDate = false; bool updateRemoteDate = false; if (remoteContent == ContentChangeType.NONE) { if (fileInfo.IsContentChangedTo(obj, true)) { // Upload local content updateRemoteDate = true; try { obj.LastChecksum = LocalObjectChanged.UploadFile(fileInfo, doc, this.transmissionManager); obj.LastContentSize = doc.ContentStreamLength ?? fileInfo.Length; } catch (Exception ex) { if (ex.InnerException is CmisPermissionDeniedException) { OperationsLogger.Warn(string.Format("Local changed file \"{0}\" has not been uploaded: PermissionDenied", fileInfo.FullName), ex.InnerException); return; } throw; } } else { // Just date sync if (doc.LastModificationDate != null && fileInfo.LastWriteTimeUtc < (DateTime)doc.LastModificationDate) { updateLocalDate = true; } else { updateRemoteDate = true; } } } else { byte[] actualLocalHash; if (fileInfo.IsContentChangedTo(obj, out actualLocalHash, true)) { // Check if both are changed to the same value if (actualLocalHash == null) { using (var f = fileInfo.Open(FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete)) { actualLocalHash = SHA1Managed.Create().ComputeHash(f); } } byte[] remoteHash = doc.ContentStreamHash(); if (remoteHash != null && actualLocalHash.SequenceEqual(remoteHash)) { // Both files are equal obj.LastChecksum = remoteHash; obj.LastContentSize = fileInfo.Length; // Sync dates if (doc.LastModificationDate != null && fileInfo.LastWriteTimeUtc < (DateTime)doc.LastModificationDate) { updateLocalDate = true; } else { updateRemoteDate = true; } } else { // Both are different => Check modification dates // Download remote version and create conflict file updateLocalDate = true; obj.LastChecksum = DownloadChanges(fileInfo, doc, obj, this.fsFactory, this.transmissionManager, Logger); obj.LastContentSize = doc.ContentStreamLength ?? 0; } } else { // Download remote content updateLocalDate = true; obj.LastChecksum = DownloadChanges(fileInfo, doc, obj, this.fsFactory, this.transmissionManager, Logger); obj.LastContentSize = doc.ContentStreamLength ?? 0; } } if (this.ServerCanModifyDateTimes) { if (updateLocalDate) { fileInfo.LastWriteTimeUtc = (DateTime)doc.LastModificationDate; } else if (updateRemoteDate) { doc.UpdateLastWriteTimeUtc(fileInfo.LastWriteTimeUtc); } else { throw new ArgumentException(); } } obj.LastChangeToken = doc.ChangeToken; obj.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc; obj.LastRemoteWriteTimeUtc = doc.LastModificationDate; this.Storage.SaveMappedObject(obj); } }
public void RemovePolicy(IObjectId objectId, params IObjectId[] policyIds) { if (objectId == null || objectId.Id == null) { throw new ArgumentException("Invalid object id!"); } if (policyIds == null || (policyIds.Length == 0)) { throw new ArgumentException("No Policies provided!"); } string[] ids = new string[policyIds.Length]; for (int i = 0; i < policyIds.Length; i++) { if (policyIds[i] == null || policyIds[i].Id == null) { throw new ArgumentException("A Policy Id is not set!"); } ids[i] = policyIds[i].Id; } foreach (string id in ids) { Binding.GetPolicyService().RemovePolicy(RepositoryId, id, objectId.Id, null); } }
public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary <string, object> properties, IObjectId folderId, VersioningState?versioningState) { return(CreateDocumentFromSource(source, properties, folderId, versioningState, null, null, null)); }
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 IDocument GetLatestDocumentVersion(IObjectId objectId) { return(GetLatestDocumentVersion(objectId, false, DefaultContext)); }
public ICmisObject GetObject(IObjectId objectId) { return(GetObject(objectId, DefaultContext)); }
public IAcl ApplyAcl(IObjectId objectId, IList<IAce> addAces, IList<IAce> removeAces, AclPropagation? aclPropagation) { if (objectId == null || objectId.Id == null) { throw new ArgumentException("Invalid object id!"); } return Binding.GetAclService().ApplyAcl(RepositoryId, objectId.Id, ObjectFactory.ConvertAces(addAces), ObjectFactory.ConvertAces(removeAces), aclPropagation, null); }
private void DeleteMediaLocations(IObjectId instance) { var objectMetaRaw = DataAccess.GetInstanceMetadata(instance); DeleteMediaLocations(objectMetaRaw); }
public IDocument CreateDocumentFromSource(IObjectId source, IDictionary<string, object> properties, VersioningState? versioningState) { return CreateDocumentFromSource(source, properties, versioningState, null, null, null, Session.DefaultContext); }
public IObjectId CreatePolicy(IDictionary <string, object> properties, IObjectId folderId) { return(CreatePolicy(properties, folderId, null, null, null)); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { throw new NotImplementedException(); }
public void AddToFolder(IObjectId folderId, bool allVersions) { if (folderId == null || folderId.Id == null) { throw new ArgumentException("Folder Id must be set!"); } Binding.GetMultiFilingService().AddObjectToFolder(RepositoryId, ObjectId, folderId.Id, allVersions, null); }
public override void Solve( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent) { var savedObject = this.Storage.GetObjectByRemoteId(remoteId.Id); string oldPath = localFileSystemInfo.FullName; string oldName = (remoteId as ICmisObject).Name; if ((remoteId as ICmisObject).Name != savedObject.Name) { // Both are renamed and remote is also moved => move & rename/rename string newPath = remoteId is IFolder ? this.Storage.Matcher.CreateLocalPath(remoteId as IFolder) : this.Storage.Matcher.CreateLocalPath(remoteId as IDocument); if ((remoteId as ICmisObject).Name == localFileSystemInfo.Name) { // Move local object to new name, bacause it is the same => only change/change solver is needed this.MoveTo(localFileSystemInfo, oldPath, newPath); savedObject.Name = localFileSystemInfo.Name; savedObject.ParentId = remoteId is IFolder ? (remoteId as IFolder).ParentId : (remoteId as IDocument).Parents[0].Id; this.Storage.SaveMappedObject(savedObject); this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } else { // Only move local object to new folder but keep the old name => both names are different => rename/rename solver needed newPath = newPath.TrimEnd(Path.DirectorySeparatorChar); newPath = newPath.Substring(0, newPath.Length - (remoteId as ICmisObject).Name.Length) + oldName; this.MoveTo(localFileSystemInfo, oldPath, newPath); savedObject.ParentId = remoteId is IFolder ? (remoteId as IFolder).ParentId : (remoteId as IDocument).Parents[0].Id; this.Storage.SaveMappedObject(savedObject); this.renameRenameSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } } else { // Local rename and remote move => move locally and rename remote => change/change try { // rename remote file (remoteId as ICmisObject).Rename(localFileSystemInfo.Name, true); OperationsLogger.Info(string.Format("Renamed remote object {0} from {1} to {2}", remoteId.Id, oldName, localFileSystemInfo.Name)); savedObject.Name = (remoteId as ICmisObject).Name; } catch (CmisConstraintException e) { if (!Utils.IsValidISO885915(localFileSystemInfo.Name)) { OperationsLogger.Warn(string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFileSystemInfo.Name)); throw new InteractionNeededException(string.Format("Server denied renaming of {0}", oldName), e) { Title = string.Format("Server denied renaming of {0}", oldName), Description = string.Format("Server denied to rename {0} to {1}, perhaps because it contains UTF-8 characters", oldName, localFileSystemInfo.Name) }; } throw; } catch (CmisPermissionDeniedException) { OperationsLogger.Info(string.Format("Permission Denied: Cannot rename remote object ({1}): {0}", (remoteId as ICmisObject).Name, remoteId.Id)); return; } string newPath = remoteId is IFolder ? this.Storage.Matcher.CreateLocalPath(remoteId as IFolder) : this.Storage.Matcher.CreateLocalPath(remoteId as IDocument); // move local object to same directory as the remote object is this.MoveTo(localFileSystemInfo, oldPath, newPath); savedObject.ParentId = remoteId is IFolder ? (remoteId as IFolder).ParentId : (remoteId as IDocument).Parents[0].Id; this.Storage.SaveMappedObject(savedObject); // Synchronize the rest with the change change solver this.changeChangeSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent); } }
// operations public IDocument Copy(IObjectId targetFolderId, IDictionary<string, object> properties, VersioningState? versioningState, IList<IPolicy> policies, IList<IAce> addAces, IList<IAce> removeAces, IOperationContext context) { IObjectId newId = Session.CreateDocumentFromSource(this, properties, targetFolderId, 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; }
protected virtual IEnumerable <DicomDataset> QueryInstances(IStudyId studyId, ISeriesId seriesId, IObjectId sopId) { DicomDataset ds = new DicomDataset() { AutoValidate = false }; ds.Add(Dicom.DicomTag.StudyInstanceUID, studyId.StudyInstanceUID); ds.Add(DicomTag.SeriesInstanceUID, seriesId.SeriesInstanceUID); ds.Add(DicomTag.PatientID, ""); ds.Add(DicomTag.PatientName, ""); ds.Add(DicomTag.SeriesDescription, ""); ds.Add(DicomTag.SOPInstanceUID, sopId.SOPInstanceUID); ds.Add(DicomTag.NumberOfFrames, ""); return(QueryService.FindObjectInstances(ds, GetQueryOptions(studyId, seriesId, sopId))); }
public DicomMediaId(IObjectId objectId, DicomMediaProperties mediaInfo) { Init(objectId, mediaInfo.MediaType, GetTransferSyntax(mediaInfo.TransferSyntax)); }
public IFileableCmisObject Move(IObjectId sourceFolderId, IObjectId targetFolderId) { string objectId = ObjectId; if (sourceFolderId == null || sourceFolderId.Id == null) { throw new ArgumentException("Source folder id must be set!"); } if (targetFolderId == null || targetFolderId.Id == null) { throw new ArgumentException("Target folder id must be set!"); } Binding.GetObjectService().MoveObject(RepositoryId, ref objectId, targetFolderId.Id, sourceFolderId.Id, null); if (objectId == null) { return null; } IFileableCmisObject movedObject = Session.GetObject(Session.CreateObjectId(objectId)) as IFileableCmisObject; if (movedObject == null) { throw new CmisRuntimeException("Moved object is invalid!"); } return movedObject; }
public HttpResponseMessage GetInstances(IStudyId studyId, ISeriesId seriesId, IObjectId sopUid) { IEnumerable <DicomDataset> instances = QueryInstances(studyId, seriesId, sopUid); OHIFViewerModel result = GetOHIFModel(instances, studyId); HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(result.ToJson(true)); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); return(response); }
public void RemoveFromFolder(IObjectId folderId) { if (folderId == null || folderId.Id == null) { throw new ArgumentException("Folder Id must be set!"); } Binding.GetMultiFilingService().RemoveObjectFromFolder(RepositoryId, ObjectId, folderId.Id, null); }
protected virtual IQueryOptions GetQueryOptions(IStudyId studyId, ISeriesId seriesId, IObjectId sopId) { return(CreateNewQueryOptions()); }
public IDocument Copy(IObjectId targetFolderId) { return Copy(targetFolderId, null, null, null, null, null, Session.DefaultContext); }
/// <summary> /// Renames the specified localFile to the name of the given remoteId object by using the storage, localFile and remoteId. /// </summary> /// <param name="localFile">Local file or folder. It is the source file/folder reference, which should be renamed.</param> /// <param name="remoteId">Remote identifier. Should be an instance of IFolder or IDocument.</param> /// <param name="localContent">Hint if the local content has been changed.</param> /// <param name="remoteContent">Information if the remote content has been changed.</param> public override void Solve( IFileSystemInfo localFile, IObjectId remoteId, ContentChangeType localContent = ContentChangeType.NONE, ContentChangeType remoteContent = ContentChangeType.NONE) { IMappedObject obj = this.Storage.GetObjectByRemoteId(remoteId.Id); if (remoteId is IFolder) { // Rename local folder IFolder remoteFolder = remoteId as IFolder; IDirectoryInfo dirInfo = localFile as IDirectoryInfo; string oldPath = dirInfo.FullName; try { dirInfo.MoveTo(Path.Combine(dirInfo.Parent.FullName, remoteFolder.Name)); obj.Name = remoteFolder.Name; } catch (IOException) { if (dirInfo.Name.Equals(remoteFolder.Name, StringComparison.OrdinalIgnoreCase)) { obj.Name = dirInfo.Name; } else { throw; } } if (remoteFolder.LastModificationDate != null) { dirInfo.LastWriteTimeUtc = (DateTime)remoteFolder.LastModificationDate; } obj.LastChangeToken = remoteFolder.ChangeToken; obj.LastRemoteWriteTimeUtc = remoteFolder.LastModificationDate; obj.LastLocalWriteTimeUtc = dirInfo.LastWriteTimeUtc; this.Storage.SaveMappedObject(obj); OperationsLogger.Info(string.Format("Renamed local folder {0} to {1}", oldPath, remoteFolder.Name)); } else if (remoteId is IDocument) { // Rename local file IDocument remoteDocument = remoteId as IDocument; IFileInfo fileInfo = localFile as IFileInfo; string oldPath = fileInfo.FullName; fileInfo.MoveTo(Path.Combine(fileInfo.Directory.FullName, remoteDocument.Name)); if (remoteDocument.LastModificationDate != null) { fileInfo.LastWriteTimeUtc = (DateTime)remoteDocument.LastModificationDate; } obj.Name = remoteDocument.Name; obj.LastChangeToken = remoteContent == ContentChangeType.NONE ? remoteDocument.ChangeToken : obj.LastChangeToken; obj.LastRemoteWriteTimeUtc = remoteContent == ContentChangeType.NONE ? remoteDocument.LastModificationDate : obj.LastRemoteWriteTimeUtc; obj.LastLocalWriteTimeUtc = fileInfo.LastWriteTimeUtc; this.Storage.SaveMappedObject(obj); OperationsLogger.Info(string.Format("Renamed local file {0} to {1}", oldPath, remoteDocument.Name)); if (remoteContent != ContentChangeType.NONE) { throw new ArgumentException("Remote documents content is also changed => force crawl sync."); } } else { throw new ArgumentException("Given remote Id is not an IFolder nor an IDocument instance"); } }