/// <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"); } }