forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
76 lines (69 loc) · 2.27 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//-----------------------------------------------------------------------
// <copyright file="Program.cs" company="Hibernating Rhinos LTD">
// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using Raven.Abstractions.Data;
using Raven.Client.Document;
using Raven.Client.Exceptions;
namespace Raven.Sample.Replication
{
class Program
{
static void Main()
{
var documentStore1 = new DocumentStore { Url = "http://localhost:8080" }.Initialize();
var documentStore2 = new DocumentStore { Url = "http://localhost:8081" }.Initialize();
using(var session1 = documentStore1.OpenSession())
{
session1.Store(new User { Id = "users/ayende", Name = "Ayende" });
session1.SaveChanges();
}
using (var session2 = documentStore2.OpenSession())
{
session2.Store(new User { Id = "users/ayende", Name = "Oren" });
session2.SaveChanges();
}
Console.WriteLine("Conflicted documents set up");
Console.WriteLine("Please setup replicaton now...");
Console.ReadLine();
using (var session2 = documentStore2.OpenSession())
{
try
{
session2.Load<User>("users/ayende");
}
catch (ConflictException e)
{
Console.WriteLine("Choose which document you want to preserve:");
var list = new List<JsonDocument>();
for (int i = 0; i < e.ConflictedVersionIds.Length; i++)
{
var doc = documentStore2.DatabaseCommands.Get(e.ConflictedVersionIds[i]);
list.Add(doc);
Console.WriteLine("{0}. {1}", i, doc.DataAsJson);
}
var select = int.Parse(Console.ReadLine());
var resolved = list[select];
documentStore2.DatabaseCommands.Put("users/ayende", null, resolved.DataAsJson, resolved.Metadata);
}
}
Console.WriteLine("Conflict resolved...");
Console.ReadLine();
using (var session2 = documentStore2.OpenSession())
{
var user = session2.Load<User>("users/ayende");
Console.WriteLine(user.Name);
user.Name = "Ayende Rahien";
session2.SaveChanges();
}
}
}
public class User
{
public string Id { get; set; }
public string Name { get; set; }
}
}