A local object has been changed and should be uploaded (if necessary) to server or updated on the server.
Inheritance: AbstractEnhancedSolver
示例#1
0
        private ISolver[,] CreateSolver() {
            int dim = Enum.GetNames(typeof(SituationType)).Length;
            ISolver[,] solver = new ISolver[dim, dim];
            ISolver changeChangeSolver = new LocalObjectChangedRemoteObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            ISolver addedNochangeSolver = new LocalObjectAdded(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            ISolver changedNoChangeSolver = new LocalObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            if (this.session.ArePrivateWorkingCopySupported()) {
                addedNochangeSolver = new LocalObjectAddedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, addedNochangeSolver);
                changedNoChangeSolver = new LocalObjectChangedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, changedNoChangeSolver);
                changeChangeSolver = new LocalObjectChangedRemoteObjectChangedWithPWC(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager, changeChangeSolver);
            }

            ISolver renameRenameSolver = new LocalObjectRenamedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver);
            ISolver renameChangeSolver = new LocalObjectRenamedRemoteObjectChanged(this.session, this.storage, changeChangeSolver);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.NOCHANGE] = new NothingToDoSolver();
            solver[(int)SituationType.ADDED, (int)SituationType.NOCHANGE] = addedNochangeSolver;
            solver[(int)SituationType.CHANGED, (int)SituationType.NOCHANGE] = changedNoChangeSolver;
            solver[(int)SituationType.MOVED, (int)SituationType.NOCHANGE] = new LocalObjectMoved(this.session, this.storage);
            solver[(int)SituationType.RENAMED, (int)SituationType.NOCHANGE] = new LocalObjectRenamed(this.session, this.storage);
            solver[(int)SituationType.REMOVED, (int)SituationType.NOCHANGE] = new LocalObjectDeleted(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.ADDED] = new RemoteObjectAdded(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.CHANGED] = new RemoteObjectChanged(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.CHANGED, (int)SituationType.CHANGED] = changeChangeSolver;
            solver[(int)SituationType.MOVED, (int)SituationType.CHANGED] = new LocalObjectMovedRemoteObjectChanged(this.session, this.storage, renameChangeSolver, changeChangeSolver);
            solver[(int)SituationType.RENAMED, (int)SituationType.CHANGED] = renameChangeSolver;
            solver[(int)SituationType.REMOVED, (int)SituationType.CHANGED] = new LocalObjectDeletedRemoteObjectChanged(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.MOVED] = new RemoteObjectMoved(this.session, this.storage);
            solver[(int)SituationType.CHANGED, (int)SituationType.MOVED] = new LocalObjectChangedRemoteObjectMoved(this.session, this.storage, changeChangeSolver);
            solver[(int)SituationType.MOVED, (int)SituationType.MOVED] = new LocalObjectMovedRemoteObjectMoved(this.session, this.storage);
            solver[(int)SituationType.RENAMED, (int)SituationType.MOVED] = new LocalObjectRenamedRemoteObjectMoved(this.session, this.storage, renameRenameSolver, changeChangeSolver);
            solver[(int)SituationType.REMOVED, (int)SituationType.MOVED] = new LocalObjectDeletedRemoteObjectRenamedOrMoved(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.RENAMED] = new RemoteObjectRenamed(this.session, this.storage);
            solver[(int)SituationType.CHANGED, (int)SituationType.RENAMED] = new LocalObjectChangedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver);
            solver[(int)SituationType.MOVED, (int)SituationType.RENAMED] = new LocalObjectMovedRemoteObjectRenamed(this.session, this.storage, changeChangeSolver, renameRenameSolver);
            solver[(int)SituationType.RENAMED, (int)SituationType.RENAMED] = renameRenameSolver;
            solver[(int)SituationType.REMOVED, (int)SituationType.RENAMED] = new LocalObjectDeletedRemoteObjectRenamedOrMoved(this.session, this.storage);

            solver[(int)SituationType.NOCHANGE, (int)SituationType.REMOVED] = new RemoteObjectDeleted(this.session, this.storage, this.filters);
            solver[(int)SituationType.CHANGED, (int)SituationType.REMOVED] = new RemoteObjectDeleted(this.session, this.storage, this.filters);
            solver[(int)SituationType.MOVED, (int)SituationType.REMOVED] = new LocalObjectRenamedOrMovedRemoteObjectDeleted(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.RENAMED, (int)SituationType.REMOVED] = new LocalObjectRenamedOrMovedRemoteObjectDeleted(this.session, this.storage, this.transmissionStorage, this.activityListener.TransmissionManager);
            solver[(int)SituationType.REMOVED, (int)SituationType.REMOVED] = new LocalObjectDeletedRemoteObjectDeleted(this.session, this.storage);

            return solver;
        }
        /// <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);
            }
        }
        private void RunSolveFileChanged(Mock<IFileInfo> fileInfo, Mock<IDocument> document, TransmissionManager transmissionManager = null)
        {
            if (transmissionManager == null) {
                transmissionManager = new TransmissionManager();
            }

            var solver = new LocalObjectChanged(this.session.Object, this.storage.Object, this.transmissionStorage.Object, transmissionManager);

            solver.Solve(fileInfo.Object, document.Object);
            Assert.That(transmissionManager.ActiveTransmissions, Is.Empty);
        }
 private void SetUpMocks() {
     this.manager = new Mock<ITransmissionManager>();
     this.storage = new Mock<IMetaDataStorage>();
     this.session = new Mock<ISession>();
     this.session.SetupTypeSystem();
     this.underTest = new LocalObjectChanged(this.session.Object, this.storage.Object, null, this.manager.Object);
     this.uuid = Guid.NewGuid();
     this.modificationDate = DateTime.UtcNow;
     this.localPath = Path.Combine("temp", this.objectName);
     this.remotePath = "/temp/" + this.objectName;
 }