PageRenderTime 58ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/Raven.Database/Server/RavenFS/Synchronization/Conflictuality/ConflictDetector.cs

https://github.com/barryhagan/ravendb
C# | 41 lines | 36 code | 5 blank | 0 comment | 1 complexity | 58ad5dcfada759057b223c46272eecaf MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, BSD-3-Clause, CC-BY-SA-3.0
  1. using System.Collections.Generic;
  2. using System.Collections.Specialized;
  3. using Raven.Client.RavenFS;
  4. using Raven.Database.Server.RavenFS.Infrastructure;
  5. using Raven.Json.Linq;
  6. namespace Raven.Database.Server.RavenFS.Synchronization.Conflictuality
  7. {
  8. public class ConflictDetector
  9. {
  10. public ConflictItem Check(string fileName, RavenJObject localMetadata, RavenJObject remoteMetadata, string remoteServerUrl)
  11. {
  12. if (Historian.IsDirectChildOfCurrent(localMetadata, remoteMetadata))
  13. return null;
  14. return
  15. new ConflictItem
  16. {
  17. CurrentHistory = TransformToFullConflictHistory(localMetadata),
  18. RemoteHistory = TransformToFullConflictHistory(remoteMetadata),
  19. FileName = fileName,
  20. RemoteServerUrl = remoteServerUrl
  21. };
  22. }
  23. public ConflictItem CheckOnSource(string fileName, RavenJObject localMetadata, RavenJObject remoteMetadata, string localServerUrl)
  24. {
  25. return Check(fileName, remoteMetadata, localMetadata, localServerUrl);
  26. }
  27. private static List<HistoryItem> TransformToFullConflictHistory(RavenJObject metadata)
  28. {
  29. var version = metadata.Value<long>(SynchronizationConstants.RavenSynchronizationVersion);
  30. var serverId = metadata.Value<string>(SynchronizationConstants.RavenSynchronizationSource);
  31. var fullHistory = Historian.DeserializeHistory(metadata);
  32. fullHistory.Add(new HistoryItem { ServerId = serverId, Version = version });
  33. return fullHistory;
  34. }
  35. }
  36. }