public override void OnPut(string key, Stream data, RavenJObject metadata) { using (Database.DisableAllTriggersForCurrentThread()) { metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts metadata.Remove(Constants.RavenReplicationConflictDocument); var oldVersion = Database.Attachments.GetStatic(key); if (oldVersion == null) { return; } if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null) { return; } var history = new RavenJArray(ReplicationData.GetOrCreateHistory(metadata)); metadata[Constants.RavenReplicationHistory] = history; // this is a conflict document, holding document keys in the // values of the properties var conflictData = oldVersion.Data().ToJObject(); var conflicts = conflictData.Value <RavenJArray>("Conflicts"); if (conflicts == null) { return; } foreach (var prop in conflicts) { var id = prop.Value <string>(); Attachment attachment = Database.Attachments.GetStatic(id); if (attachment == null) { continue; } Database.Attachments.DeleteStatic(id, null); // add the conflict history to the mix, so we make sure that we mark that we resolved the conflict var conflictHistory = new RavenJArray(ReplicationData.GetOrCreateHistory(attachment.Metadata)); conflictHistory.Add(new RavenJObject { { Constants.RavenReplicationVersion, attachment.Metadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, attachment.Metadata[Constants.RavenReplicationSource] } }); foreach (var item in conflictHistory) { if (history.Any(x => RavenJTokenEqualityComparer.Default.Equals(x, item))) { continue; } history.Add(item); } } } }
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { using (Database.DisableAllTriggersForCurrentThread()) { metadata.Remove(Constants.RavenReplicationConflict); // you can't put conflicts var oldVersion = Database.Get(key, transactionInformation); if (oldVersion == null) { return; } if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null) { return; } RavenJArray history = new RavenJArray(ReplicationData.GetHistory(metadata)); metadata[Constants.RavenReplicationHistory] = history; var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer(); // this is a conflict document, holding document keys in the // values of the properties var conflicts = oldVersion.DataAsJson.Value <RavenJArray>("Conflicts"); if (conflicts == null) { return; } foreach (var prop in conflicts) { RavenJObject deletedMetadata; Database.Delete(prop.Value <string>(), null, transactionInformation, out deletedMetadata); // add the conflict history to the mix, so we make sure that we mark that we resolved the conflict var conflictHistory = new RavenJArray(ReplicationData.GetHistory(deletedMetadata)); conflictHistory.Add(new RavenJObject { { Constants.RavenReplicationVersion, deletedMetadata[Constants.RavenReplicationVersion] }, { Constants.RavenReplicationSource, deletedMetadata[Constants.RavenReplicationSource] } }); foreach (var item in conflictHistory) { if (history.Any(x => ravenJTokenEqualityComparer.Equals(x, item))) { continue; } history.Add(item); } } } }
public override void OnPut(string key, Stream data, RavenJObject metadata) { using (Database.DisableAllTriggersForCurrentThread()) { metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts var oldVersion = Database.Attachments.GetStatic(key); if (oldVersion == null) return; if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null) return; var history = new RavenJArray(ReplicationData.GetHistory(metadata)); metadata[Constants.RavenReplicationHistory] = history; var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer(); // this is a conflict document, holding document keys in the // values of the properties var conflictData = oldVersion.Data().ToJObject(); var conflicts = conflictData.Value<RavenJArray>("Conflicts"); if (conflicts == null) return; foreach (var prop in conflicts) { var id = prop.Value<string>(); Attachment attachment = Database.Attachments.GetStatic(id); if(attachment == null) continue; Database.Attachments.DeleteStatic(id, null); // add the conflict history to the mix, so we make sure that we mark that we resolved the conflict var conflictHistory = new RavenJArray(ReplicationData.GetHistory(attachment.Metadata)); conflictHistory.Add(new RavenJObject { {Constants.RavenReplicationVersion, attachment.Metadata[Constants.RavenReplicationVersion]}, {Constants.RavenReplicationSource, attachment.Metadata[Constants.RavenReplicationSource]} }); foreach (var item in conflictHistory) { if (history.Any(x => ravenJTokenEqualityComparer.Equals(x, item))) continue; history.Add(item); } } } }
public override void OnPut(string key, RavenJObject document, RavenJObject metadata, TransactionInformation transactionInformation) { using (Database.DisableAllTriggersForCurrentThread()) { metadata.Remove(Constants.RavenReplicationConflict);// you can't put conflicts var oldVersion = Database.Get(key, transactionInformation); if (oldVersion == null) return; if (oldVersion.Metadata[Constants.RavenReplicationConflict] == null) return; RavenJArray history = new RavenJArray(ReplicationData.GetHistory(metadata)); metadata[Constants.RavenReplicationHistory] = history; var ravenJTokenEqualityComparer = new RavenJTokenEqualityComparer(); // this is a conflict document, holding document keys in the // values of the properties var conflicts = oldVersion.DataAsJson.Value<RavenJArray>("Conflicts"); if(conflicts == null) return; foreach (var prop in conflicts) { RavenJObject deletedMetadata; Database.Delete(prop.Value<string>(), null, transactionInformation, out deletedMetadata); // add the conflict history to the mix, so we make sure that we mark that we resolved the conflict var conflictHistory = new RavenJArray(ReplicationData.GetHistory(deletedMetadata)); conflictHistory.Add(new RavenJObject { {Constants.RavenReplicationVersion, deletedMetadata[Constants.RavenReplicationVersion]}, {Constants.RavenReplicationSource, deletedMetadata[Constants.RavenReplicationSource]} }); foreach (var item in conflictHistory) { if(history.Any(x=>ravenJTokenEqualityComparer.Equals(x, item))) continue; history.Add(item); } } } }