public bool IsResolved(RavenJObject destinationMetadata, ConflictItem conflict)
        {
            var conflictResolutionMetadata = destinationMetadata[SynchronizationConstants.RavenSynchronizationConflictResolution] as RavenJObject;
            if (conflictResolutionMetadata == null)
                return false;

            var conflictResolution = JsonExtensions.JsonDeserialization<ConflictResolution>(conflictResolutionMetadata);            
            return conflictResolution.Strategy == ConflictResolutionStrategy.RemoteVersion && conflictResolution.RemoteServerId == conflict.RemoteHistory.Last().ServerId;
        }
Example #2
0
		public bool IsResolved(NameValueCollection destinationMetadata, ConflictItem conflict)
		{
			var conflictResolutionString = destinationMetadata[SynchronizationConstants.RavenSynchronizationConflictResolution];
			if (String.IsNullOrEmpty(conflictResolutionString))
				return false;

			var conflictResolution = new TypeHidingJsonSerializer().Parse<ConflictResolution>(conflictResolutionString);
			return conflictResolution.Strategy == ConflictResolutionStrategy.RemoteVersion
				   && conflictResolution.RemoteServerId == conflict.RemoteHistory.Last().ServerId;
		}
		public void Create(string fileName, ConflictItem conflict)
		{
			NameValueCollection metadata = null;

			storage.Batch(
				accessor =>
				{
					metadata = accessor.GetFile(fileName, 0, 0).Metadata;
					accessor.SetConfig(RavenFileNameHelper.ConflictConfigNameForFile(fileName), conflict.AsConfig());
					metadata[SynchronizationConstants.RavenSynchronizationConflict] = "True";
					accessor.UpdateFileMetadata(fileName, metadata);
				});

			if (metadata != null)
				index.Index(fileName, metadata);
		}
		public void Create(string fileName, ConflictItem conflict)
		{
            RavenJObject metadata = null;

			storage.Batch(
				accessor =>
				{
					metadata = accessor.GetFile(fileName, 0, 0).Metadata;
					accessor.SetConfig(RavenFileNameHelper.ConflictConfigNameForFile(fileName), JsonExtensions.ToJObject(conflict) );
					metadata[SynchronizationConstants.RavenSynchronizationConflict] = true;
					accessor.UpdateFileMetadata(fileName, metadata);
				});

			if (metadata != null)
				index.Index(fileName, metadata);
		}
		public async Task<HttpResponseMessage> ApplyConflict(string filename, long remoteVersion, string remoteServerId,
															 string remoteServerUrl)
		{
			var localMetadata = GetLocalMetadata(filename);

			if (localMetadata == null)
				throw new HttpResponseException(HttpStatusCode.NotFound);

			var contentStream = await Request.Content.ReadAsStreamAsync();

			var current = new HistoryItem
			{
				ServerId = Storage.Id.ToString(),
				Version = long.Parse(localMetadata[SynchronizationConstants.RavenSynchronizationVersion])
			};

			var currentConflictHistory = Historian.DeserializeHistory(localMetadata);
			currentConflictHistory.Add(current);

			var remote = new HistoryItem
			{
				ServerId = remoteServerId,
				Version = remoteVersion
			};

			var remoteConflictHistory =
				new JsonSerializer().Deserialize<IList<HistoryItem>>(new JsonTextReader(new StreamReader(contentStream)));
			remoteConflictHistory.Add(remote);

			var conflict = new ConflictItem
			{
				CurrentHistory = currentConflictHistory,
				RemoteHistory = remoteConflictHistory,
				FileName = filename,
				RemoteServerUrl = Uri.UnescapeDataString(remoteServerUrl)
			};

			ConflictArtifactManager.Create(filename, conflict);

			Publisher.Publish(new ConflictDetected
			{
				FileName = filename,
				SourceServerUrl = remoteServerUrl
			});

			Log.Debug(
				"Conflict applied for a file '{0}' (remote version: {1}, remote server id: {2}).", filename, remoteVersion,
				remoteServerId);

			return new HttpResponseMessage(HttpStatusCode.NoContent);
		}
        protected async Task<SynchronizationReport> ApplyConflictOnDestinationAsync(ConflictItem conflict, RavenFileSystemClient.SynchronizationClient destination,
																					string localServerUrl, ILog log)
		{
			log.Debug("File '{0}' is in conflict with destination version from {1}. Applying conflict on destination", FileName,
					  destination.FileSystemUrl);

			try
			{
				var version = conflict.RemoteHistory.Last().Version;
				var serverId = conflict.RemoteHistory.Last().ServerId;
				var history = new List<HistoryItem>(conflict.RemoteHistory);
				history.RemoveAt(conflict.RemoteHistory.Count - 1);

				await destination.ApplyConflictAsync(FileName, version, serverId, history, localServerUrl);
			}
			catch (Exception ex)
			{
				log.WarnException(string.Format("Failed to apply conflict on {0} for file '{1}'", destination, FileName), ex);
			}

			return new SynchronizationReport(FileName, FileETag, SynchronizationType)
			{
				Exception = new SynchronizationException(string.Format("File {0} is conflicted", FileName)),
			};
		}