private static async void MainSync3() { GetChangesRequest request = new GetChangesRequest(); request.IncludeDocs = true; request.Since = "0"; request.Heartbeat = 1000; request.Feed = ChangesFeed.Continuous; request.Style = ChangesStyle.AllDocs; DbConnectionInfo connectionInfo = new DbConnectionInfo("http://localhost:4984", "couchbasegames"); IDbConnection db = new DbConnection(connectionInfo); SerializationConfiguration serializationConfiguration = new SerializationConfiguration(new DefaultContractResolver()); ISerializer serializer = new DefaultSerializer(serializationConfiguration, new DocumentSerializationMetaProvider(), null); Changes changes = new Changes(db, serializer); try { using (var res = changes.GetAsync(request, data => { Console.WriteLine(data); }, new CancellationTokenSource().Token)) SpinWait.SpinUntil(() => Console.ReadLine() == "C"); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private static async void MainSync2() { GetChangesRequest request = new GetChangesRequest(); request.IncludeDocs = false; request.Since = "0"; request.Heartbeat = 1000; request.Feed = ChangesFeed.Continuous; request.Style = ChangesStyle.AllDocs; DbConnectionInfo connectionInfo = new DbConnectionInfo("http://localhost:4984", "couchbasegames"); IDbConnection db = new DbConnection(connectionInfo); SerializationConfiguration serializationConfiguration = new SerializationConfiguration(new DefaultContractResolver()); ISerializer serializer = new DefaultSerializer(serializationConfiguration, new DocumentSerializationMetaProvider(), null); Changes changes = new Changes(db, serializer); IObservable <string> observable = changes.ObserveContinuous(request, new CancellationToken(false)); observable.Subscribe(new MyObserver() { InterceptOnNext = v => { // Console.WriteLine(" no conflict detected Id : change {0}", v); if (!string.IsNullOrEmpty(v)) { RootObject c = JsonConvert.DeserializeObject <RootObject>(v); if (c.changes.Count > 1) { if (conflicts.ContainsKey(c.id)) { conflicts[c.id] = c.changes; } else { conflicts.Add(c.id, c.changes); } c.changes.ForEach(x => { Console.WriteLine(" conflict detected : id {0} and changes {1}", c.id, x.rev); }); } else { Console.WriteLine(" no conflict detected Id : {0}, change {1}", c.id, v); } } }, InterceptOnError = e => { Console.WriteLine(e.Message); } }); SpinWait.SpinUntil(() => Console.ReadLine() == "C"); }
public MyCouchClient(DbConnectionInfo connectionInfo, MyCouchClientBootstrapper bootstrapper = null) { EnsureArg.IsNotNull(connectionInfo, nameof(connectionInfo)); IsDisposed = false; bootstrapper = bootstrapper ?? MyCouchClientBootstrappers.Default; Connection = bootstrapper.DbConnectionFn(connectionInfo); Serializer = bootstrapper.SerializerFn(); // DocumentSerializer = bootstrapper.DocumentSerializerFn(); Changes = bootstrapper.ChangesFn(Connection); //Attachments = bootstrapper.AttachmentsFn(Connection); //Database = bootstrapper.DatabaseFn(Connection); //Documents = bootstrapper.DocumentsFn(Connection); //Entities = bootstrapper.EntitiesFn(Connection); //Queries = bootstrapper.QueriesFn(Connection); ////Searches = bootstrapper.SearchesFn(Connection); //Views = bootstrapper.ViewsFn(Connection); }
public DbConnection(DbConnectionInfo connectionInfo) : base(connectionInfo) { DbName = connectionInfo.DbName; }