CmisSync.Lib.Consumer.SituationSolver.LocalObjectRenamedRemoteObjectMoved.Solve C# (CSharp) Method

Solve() public method

public Solve ( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent ) : void
localFileSystemInfo IFileSystemInfo
remoteId IObjectId
localContent ContentChangeType
remoteContent ContentChangeType
return void
        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);
            }
        }