Esempio n. 1
0
        private void AssertConflictDetection(string fileName, RavenJObject localMetadata, RavenJObject sourceMetadata, ServerInfo sourceServer, out bool isConflictResolved)
        {
            var conflict = ConflictDetector.Check(fileName, localMetadata, sourceMetadata, sourceServer.FileSystemUrl);

            if (conflict == null)
            {
                isConflictResolved = false;
                return;
            }

            isConflictResolved = ConflictResolver.CheckIfResolvedByRemoteStrategy(localMetadata, conflict);

            if (isConflictResolved)
            {
                return;
            }

            ConflictResolutionStrategy strategy;

            if (ConflictResolver.TryResolveConflict(fileName, conflict, localMetadata, sourceMetadata, out strategy))
            {
                switch (strategy)
                {
                case ConflictResolutionStrategy.RemoteVersion:
                    Log.Debug("Conflict automatically resolved by choosing remote version of the file {0}", fileName);
                    return;

                case ConflictResolutionStrategy.CurrentVersion:

                    Storage.Batch(accessor =>
                    {
                        accessor.UpdateFileMetadata(fileName, localMetadata);

                        ConflictArtifactManager.Delete(fileName, accessor);
                    });

                    Log.Debug("Conflict automatically resolved by choosing current version of the file {0}", fileName);

                    throw new ConflictResolvedInFavourOfCurrentVersionException();
                }
            }

            ConflictArtifactManager.Create(fileName, conflict);

            Publisher.Publish(new ConflictNotification
            {
                FileName         = fileName,
                SourceServerUrl  = sourceServer.FileSystemUrl,
                Status           = ConflictStatus.Detected,
                RemoteFileHeader = new FileHeader(fileName, localMetadata)
            });

            Log.Debug(
                "File '{0}' is in conflict with synchronized version from {1} ({2}). File marked as conflicted, conflict configuration item created",
                fileName, sourceServer.FileSystemUrl, sourceServer.Id);

            throw new SynchronizationException(string.Format("File {0} is conflicted", fileName));
        }
        protected ConflictItem CheckConflictWithDestination(RavenJObject sourceMetadata,
                                                            RavenJObject destinationMetadata, string localServerUrl)
        {
            var conflict           = conflictDetector.CheckOnSource(FileName, sourceMetadata, destinationMetadata, localServerUrl);
            var isConflictResolved = conflictResolver.CheckIfResolvedByRemoteStrategy(destinationMetadata, conflict);

            // optimization - conflict checking on source side before any changes pushed
            if (conflict != null && !isConflictResolved)
            {
                return(conflict);
            }

            return(null);
        }