private void CreateConflictingRev(C4Database *db, FLSlice docID, FLSlice parentRevID, FLSlice newRevID, FLSlice body, C4RevisionFlags flags) { var history = new[] { newRevID, parentRevID }; fixed(FLSlice *h = history) { var rq = new C4DocPutRequest { existingRevision = true, allowConflict = true, docID = docID, history = h, historyCount = parentRevID.buf != null ? 2UL : 1UL, body = body, revFlags = flags, save = true }; var doc = (C4Document *)LiteCoreBridge.Check(err => { var localRq = rq; return(Native.c4doc_put(db, &localRq, null, err)); }); Native.c4doc_release(doc); } }
public static C4Document *c4doc_update(C4Document *doc, byte[] revisionBody, C4RevisionFlags revisionFlags, C4Error *error) { fixed(byte *revisionBody_ = revisionBody) { return(NativeRaw.c4doc_update(doc, new FLSlice(revisionBody_, revisionBody == null ? 0 : (ulong)revisionBody.Length), revisionFlags, error)); } }
internal ReplicatedDocument([NotNull] string docID, C4RevisionFlags flags, C4Error error, bool isTransient) { Id = docID; Flags = flags.ToDocumentFlags(); NativeError = error; Error = error.domain == 0 ? null : CouchbaseException.Create(error); IsTransient = isTransient; }
public static DocumentFlags ToDocumentFlags(this C4RevisionFlags flags) { var retVal = (DocumentFlags)0; if (flags.HasFlag(C4RevisionFlags.Deleted)) { retVal |= DocumentFlags.Deleted; } if (flags.HasFlag(C4RevisionFlags.Purged)) { retVal |= DocumentFlags.AccessRemoved; } return(retVal); }
private static bool PushFilterCallback(FLSlice docID, C4RevisionFlags revisionFlags, FLDict *dict, void *context) { var replicator = GCHandle.FromIntPtr((IntPtr)context).Target as Replicator; if (replicator == null) { WriteLog.To.Database.E(Tag, "Push filter context pointing to invalid object {0}, aborting and returning true...", replicator); return(true); } var docIDStr = docID.CreateString(); if (docIDStr == null) { WriteLog.To.Database.E(Tag, "Null document ID received in push filter, rejecting..."); return(false); } var flags = revisionFlags.ToDocumentFlags(); return(replicator.PushFilterCallback(docIDStr, dict, flags)); }
private void PutDocMustFail(string docID, string revID, string body, C4RevisionFlags flags, C4Error expected) { PutDocMustFail(Db, docID, revID, body, flags, expected); }
public static C4Document *c4doc_create(C4Database *db, FLSlice docID, FLSlice body, C4RevisionFlags revisionFlags, C4Error *error) => Impl.c4doc_create(db, docID, body, revisionFlags, error);
private C4Document *PutDoc(string docID, string revID, string body, C4RevisionFlags flags = 0) { return(PutDoc(Db, docID, revID, body, flags)); }
private C4Document *PutDoc(C4Database *db, string docID, string revID, string body, C4RevisionFlags flags, C4Error *error = null) { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err)); var success = false; try { using (var docID_ = new C4String(docID)) using (var revID_ = new C4String(revID)) using (var body_ = new C4String(body)) { var history = new C4Slice[] { revID_.AsC4Slice() }; fixed(C4Slice *history_ = history) { var rq = new C4DocPutRequest { allowConflict = false, docID = docID_.AsC4Slice(), history = revID == null ? null : history_, historyCount = revID == null ? 0UL : 1UL, body = body_.AsC4Slice(), revFlags = flags, save = true }; C4Document *doc; if (error != null) { var local = rq; doc = Native.c4doc_put(db, &local, null, error); } else { doc = (C4Document *)LiteCoreBridge.Check(err => { var local = rq; return(Native.c4doc_put(db, &local, null, err)); }); } success = true; return(doc); } } } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, success, err)); } }
public static C4Document *c4doc_update(C4Document *doc, FLSlice revisionBody, C4RevisionFlags revisionFlags, C4Error *error) => Impl.c4doc_update(doc, revisionBody, revisionFlags, error);
private C4Document *ForceInsert(C4Database *db, string docID, string[] history, string body, C4RevisionFlags flags, C4Error *error = null) { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err)); var c4History = new C4String[history.Length]; var success = false; try { var i = 0; var sliceHistory = new C4Slice[history.Length]; foreach (var entry in history) { var c4Str = new C4String(entry); c4History[i] = c4Str; sliceHistory[i++] = c4Str.AsC4Slice(); } using (var docID_ = new C4String(docID)) using (var body_ = new C4String(body)) { fixed(C4Slice *sliceHistory_ = sliceHistory) { var rq = new C4DocPutRequest { docID = docID_.AsC4Slice(), existingRevision = true, allowConflict = true, history = sliceHistory_, historyCount = (ulong)history.Length, body = body_.AsC4Slice(), revFlags = flags, save = true }; C4Document *doc; if (error != null) { var local = rq; doc = Native.c4doc_put(db, &local, null, error); } else { doc = (C4Document *)LiteCoreBridge.Check(err => { var local = rq; return(Native.c4doc_put(db, &local, null, err)); }); } success = true; return(doc); } } } finally { foreach (var entry in c4History) { entry.Dispose(); } LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, success, err)); } }
public bool c4doc_resolveConflict(C4Document *doc, string winningRevID, string losingRevID, byte[] mergedBody, C4RevisionFlags mergedFlags, C4Error *error) => Native.c4doc_resolveConflict(doc, winningRevID, losingRevID, mergedBody, mergedFlags, error);
public C4Document *c4doc_update(C4Document *doc, byte[] revisionBody, C4RevisionFlags revisionFlags, C4Error *error) => Native.c4doc_update(doc, revisionBody, revisionFlags, error);
private C4Document *PutDoc(C4Database *db, string docID, string revID, FLSlice body, C4RevisionFlags flags, C4Error *error = null) { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err)); var success = false; try { var encoded = EncodeBodyIfJSON(body); using (var docID_ = new C4String(docID)) using (var revID_ = new C4String(revID)) { var history = new FLSlice[] { revID_.AsFLSlice() }; fixed(FLSlice *history_ = history) { var rq = new C4DocPutRequest { allowConflict = false, docID = docID_.AsFLSlice(), history = revID == null ? null : history_, historyCount = revID == null ? 0UL : 1UL, body = encoded.buf == null ? body : (FLSlice)encoded, revFlags = flags, remoteDBID = _remoteDocID, save = true }; C4Document *doc; if (error != null) { var local = rq; doc = Native.c4doc_put(db, &local, null, error); } else { doc = (C4Document *)LiteCoreBridge.Check(err => { var local = rq; return(Native.c4doc_put(db, &local, null, err)); }); } Native.FLSliceResult_Release(encoded); success = true; return(doc); } } } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, success, err)); } }
public static bool c4doc_resolveConflict(C4Document *doc, string winningRevID, string losingRevID, byte[] mergedBody, C4RevisionFlags mergedFlags, C4Error *error) { using (var winningRevID_ = new C4String(winningRevID)) using (var losingRevID_ = new C4String(losingRevID)) fixed(byte *mergedBody_ = mergedBody) { return(NativeRaw.c4doc_resolveConflict(doc, winningRevID_.AsFLSlice(), losingRevID_.AsFLSlice(), new FLSlice(mergedBody_, mergedBody == null ? 0 : (ulong)mergedBody.Length), mergedFlags, error)); } }
public C4Document *c4doc_update(C4Document *doc, C4Slice revisionBody, C4RevisionFlags revisionFlags, C4Error *error) => NativeRaw.c4doc_update(doc, revisionBody, revisionFlags, error);
public C4Document *c4doc_create(C4Database *db, C4Slice docID, C4Slice body, C4RevisionFlags revisionFlags, C4Error *error) => NativeRaw.c4doc_create(db, docID, body, revisionFlags, error);
public bool c4doc_resolveConflict(C4Document *doc, C4Slice winningRevID, C4Slice losingRevID, C4Slice mergedBody, C4RevisionFlags mergedFlags, C4Error *error) => NativeRaw.c4doc_resolveConflict(doc, winningRevID, losingRevID, mergedBody, mergedFlags, error);
internal void CreateRev(C4Database *db, string docID, C4Slice revID, C4Slice body, C4RevisionFlags flags = (C4RevisionFlags)0) { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err)); try { var curDoc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(db, docID, false, err)); var history = new[] { revID, curDoc->revID }; fixed(C4Slice *h = history) { var rq = new C4DocPutRequest { existingRevision = true, docID = curDoc->docID, history = h, historyCount = curDoc->revID.buf != null ? 2UL : 1UL, body = body, revFlags = flags, save = true }; var doc = (C4Document *)LiteCoreBridge.Check(err => { var localRq = rq; return(Native.c4doc_put(db, &localRq, null, err)); }); Native.c4doc_free(doc); Native.c4doc_free(curDoc); } } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, true, err)); } }
public static extern C4Document *c4doc_create(C4Database *db, FLSlice docID, FLSlice body, C4RevisionFlags revisionFlags, C4Error *error);
internal void CreateRev(string docID, C4Slice revID, C4Slice body, C4RevisionFlags flags = (C4RevisionFlags)0) { CreateRev(Db, docID, revID, body, flags); }
public C4Document *c4doc_create(C4Database *db, string docID, byte[] body, C4RevisionFlags revisionFlags, C4Error *error) => Native.c4doc_create(db, docID, body, revisionFlags, error);
public static C4Document *c4doc_create(C4Database *db, string docID, byte[] body, C4RevisionFlags revisionFlags, C4Error *error) { using (var docID_ = new C4String(docID)) fixed(byte *body_ = body) { return(NativeRaw.c4doc_create(db, docID_.AsFLSlice(), new FLSlice(body_, body == null ? 0 : (ulong)body.Length), revisionFlags, error)); } }
private void PutDocMustFail(C4Database *db, string docID, string revID, string body, C4RevisionFlags flags, C4Error expected) { C4Error error; var doc = PutDoc(db, docID, revID, body, flags, &error); ((IntPtr)doc).Should().Be(IntPtr.Zero, "because the put operation was expected to fail"); WriteLine($"Error: {Native.c4error_getMessage(error)}"); error.domain.Should().Be(expected.domain); error.code.Should().Be(expected.code); }
public static extern bool c4doc_resolveConflict(C4Document *doc, FLSlice winningRevID, FLSlice losingRevID, FLSlice mergedBody, C4RevisionFlags mergedFlags, C4Error *error);
private void ForceInsert(string docID, string[] history, string body, C4RevisionFlags flags = 0) { var doc = ForceInsert(Db, docID, history, body, flags); Native.c4doc_free(doc); }
public static extern C4Document *c4doc_update(C4Document *doc, FLSlice revisionBody, C4RevisionFlags revisionFlags, C4Error *error);
internal void CreateRev(C4Database *db, string docID, FLSlice revID, FLSlice body, C4RevisionFlags flags = (C4RevisionFlags)0) { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(db, err)); try { var curDoc = (C4Document *)LiteCoreBridge.Check(err => Native.c4db_getDoc(db, docID, false, C4DocContentLevel.DocGetAll, err)); curDoc->Should().NotBeNull(); FLSlice parentID; if (IsRevTrees(db)) { parentID = curDoc->revID; } //else // parentID = c4doc_getRevisionHistory(curDoc, 0, nullptr, 0); CreateConflictingRev(db, curDoc->docID, curDoc->revID, revID, body, flags); Native.c4doc_release(curDoc); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(db, true, err)); } }