CmisSync.Lib.Consumer.SituationSolver.LocalObjectMovedRemoteObjectMoved.SyncNamesAndDates C# (CSharp) Метод

SyncNamesAndDates() приватный Метод

private SyncNamesAndDates ( IFileSystemInfo local, IFileableCmisObject remote, IMappedObject mappedObject ) : void
local IFileSystemInfo
remote IFileableCmisObject
mappedObject IMappedObject
Результат void
        private void SyncNamesAndDates(IFileSystemInfo local, IFileableCmisObject remote, IMappedObject mappedObject)
        {
            DateTime? oldRemoteModificationDate = remote.LastModificationDate;
            DateTime oldLocalModificationDate = local.LastWriteTimeUtc;

            // Sync Names
            if (mappedObject.Name != local.Name && mappedObject.Name == remote.Name) {
                // local has been renamed => rename remote
                remote.Rename(local.Name, true);
                mappedObject.Name = local.Name;
            } else if (mappedObject.Name == local.Name && mappedObject.Name != remote.Name) {
                // remote has been renamed => rename local
                if (local is IFileInfo) {
                    IFileInfo localFile = local as IFileInfo;
                    localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                } else if (local is IDirectoryInfo) {
                    IDirectoryInfo localFolder = local as IDirectoryInfo;
                    localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                } else {
                    throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                }

                mappedObject.Name = remote.Name;
            } else if (mappedObject.Name != local.Name && mappedObject.Name != remote.Name) {
                // both are renamed => rename to the latest change
                DateTime localModification = local.LastWriteTimeUtc;
                DateTime remoteModification = (DateTime)remote.LastModificationDate;
                if (localModification > remoteModification) {
                    // local modification is newer
                    remote.Rename(local.Name, true);
                    mappedObject.Name = local.Name;
                } else {
                    // remote modification is newer
                    if (local is IFileInfo) {
                        IFileInfo localFile = local as IFileInfo;
                        localFile.MoveTo(Path.Combine(localFile.Directory.FullName, remote.Name));
                    } else if (local is IDirectoryInfo) {
                        IDirectoryInfo localFolder = local as IDirectoryInfo;
                        localFolder.MoveTo(Path.Combine(localFolder.Parent.FullName, remote.Name));
                    } else {
                        throw new ArgumentException("Solved move conflict => invoke crawl sync to detect other changes");
                    }

                    local.LastWriteTimeUtc = (DateTime)remote.LastModificationDate;
                    mappedObject.Name = remote.Name;
                }
            }

            // Sync modification dates
            if (oldRemoteModificationDate != null) {
                if (oldLocalModificationDate > oldRemoteModificationDate && this.ServerCanModifyDateTimes) {
                    remote.UpdateLastWriteTimeUtc(oldLocalModificationDate);
                    local.LastWriteTimeUtc = oldLocalModificationDate;
                } else if (oldLocalModificationDate < (DateTime)oldRemoteModificationDate) {
                    local.LastWriteTimeUtc = (DateTime)oldRemoteModificationDate;
                }
            }

            mappedObject.LastLocalWriteTimeUtc = local.LastWriteTimeUtc;
            mappedObject.LastRemoteWriteTimeUtc = (DateTime)remote.LastModificationDate;
            mappedObject.ParentId = remote.Parents[0].Id;
            mappedObject.LastChangeToken = remote.ChangeToken;
            mappedObject.Ignored = remote.AreAllChildrenIgnored();
            this.Storage.SaveMappedObject(mappedObject);
        }
    }