CmisSync.Lib.Consumer.SituationSolver.PWC.LocalObjectChangedRemoteObjectChangedWithPWC.Solve C# (CSharp) Метод

Solve() публичный Метод

Solve the specified situation by using localFile and remote object if the local file content is the only changed content. Otherwise the given fallback will be used.
public Solve ( IFileSystemInfo localFileSystemInfo, IObjectId remoteId, ContentChangeType localContent, ContentChangeType remoteContent ) : void
localFileSystemInfo IFileSystemInfo Local filesystem info instance.
remoteId IObjectId Remote identifier or object.
localContent ContentChangeType Hint if the local content has been changed.
remoteContent ContentChangeType Information if the remote content has been changed.
Результат void
        public override void Solve(
            IFileSystemInfo localFileSystemInfo,
            IObjectId remoteId,
            ContentChangeType localContent,
            ContentChangeType remoteContent)
        {
            if (!(localFileSystemInfo is IFileInfo)) {
                this.fallbackSolver.Solve(localFileSystemInfo, remoteId, localContent, remoteContent);
                return;
            }

            IFileInfo localFile = localFileSystemInfo as IFileInfo;
            IDocument remoteDocument = remoteId as IDocument;

            if (remoteContent != ContentChangeType.NONE) {
                this.fallbackSolver.Solve(localFile, remoteId, localContent, remoteContent);
                return;
            }

            bool updateLocalDate = false;
            bool updateRemoteDate = false;
            var obj = this.Storage.GetObjectByRemoteId(remoteDocument.Id);

            if (localFile.IsContentChangedTo(obj, true)) {
                updateRemoteDate = true;
                try {
                    var transmission = this.transmissionManager.CreateTransmission(TransmissionType.UPLOAD_MODIFIED_FILE, localFile.FullName);
                    obj.LastChecksum = UploadFileWithPWC(localFile, ref remoteDocument, transmission);
                    obj.ChecksumAlgorithmName = "SHA-1";
                    obj.LastContentSize = remoteDocument.ContentStreamLength ?? localFile.Length;
                    if (remoteDocument.Id != obj.RemoteObjectId) {
                        this.TransmissionStorage.RemoveObjectByRemoteObjectId(obj.RemoteObjectId);
                        obj.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;
                }
            } else {
                //  just date sync
                if (remoteDocument.LastModificationDate != null && localFile.LastWriteTimeUtc < remoteDocument.LastModificationDate) {
                    updateLocalDate = true;
                } else {
                    updateRemoteDate = true;
                }
            }

            if (this.ServerCanModifyDateTimes) {
                if (updateLocalDate) {
                    localFile.LastWriteTimeUtc = (DateTime)remoteDocument.LastModificationDate;
                } else if (updateRemoteDate) {
                    remoteDocument.UpdateLastWriteTimeUtc(localFile.LastWriteTimeUtc);
                } else {
                    throw new ArgumentException();
                }
            }

            obj.LastChangeToken = remoteDocument.ChangeToken;
            obj.LastLocalWriteTimeUtc = localFileSystemInfo.LastWriteTimeUtc;
            obj.LastRemoteWriteTimeUtc = remoteDocument.LastModificationDate;
            this.Storage.SaveMappedObject(obj);
        }
    }
LocalObjectChangedRemoteObjectChangedWithPWC