コード例 #1
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_selectNextLeafRevision(C4Document *doc, [MarshalAs(UnmanagedType.U1)]bool includeDeleted, 
     [MarshalAs(UnmanagedType.U1)]bool withBody, C4Error *outError);
コード例 #2
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern int c4doc_insertRevision(C4Document *doc, C4Slice revID, C4Slice body, 
     [MarshalAs(UnmanagedType.U1)]bool deleted, [MarshalAs(UnmanagedType.U1)]bool hasAttachments,
     [MarshalAs(UnmanagedType.U1)]bool allowConflict, C4Error *outError);
コード例 #3
0
        private bool SaveDocument(C4Document *doc, string revId, IDictionary<string, object> properties)
        {
            // Is the new revision the winner?
            Native.c4doc_selectCurrentRevision(doc);
            bool isWinner = (string)doc->selectedRev.revID == revId;

            // Update the documentType:
            if (isWinner) {
                var type = properties == null ? null : properties.GetCast<string>("type");
                ForestDBBridge.Check(err => Native.c4doc_setType(doc, type, err));
            }

            // Save:
            ForestDBBridge.Check(err => Native.c4doc_save(doc, (uint)MaxRevTreeDepth, err));
            return isWinner;
        }
コード例 #4
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4indexer_emit(C4Indexer *indexer, C4Document *document, uint viewNumber, uint emitCount,
     C4Key** emittedKeys, C4Slice* emittedValues, C4Error *outError);
コード例 #5
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern int c4doc_purgeRevision(C4Document *doc, C4Slice revId, C4Error *outError);
コード例 #6
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static int c4doc_purgeRevision(C4Document *doc, string revId, C4Error *outError)
 {
     using(var revId_ = new C4String(revId)) {
         return c4doc_purgeRevision(doc, revId_.AsC4Slice(), outError);   
     }
 }
コード例 #7
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 /// Returns the document type (as set by setDocType.) This value is ignored by CBForest itself; by convention 
 /// Couchbase Lite sets it to the value of the current revision's "type" property, and uses it as an optimization 
 /// when indexing a view.
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <returns>The document type of the document in question</returns>
 public static string c4doc_getType(C4Document *doc)
 {
     return BridgeSlice(() => _c4doc_getType(doc));
 }
コード例 #8
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 ///  Adds a revision to a document, plus its ancestors (given in reverse chronological order.)
 /// On success, the new revision will be selected.
 /// Must be called within a transaction.
 /// <param name="doc">The document to operate on</param>
 /// <param name="body">The (JSON) body of the revision</param>
 /// <param name="deleted">True if this revision is a deletion (tombstone)</param>
 /// <param name="hasAttachments">True if this revision contains an _attachments dictionary</param>
 /// <param name="history">The ancestors' revision IDs, starting with the parent, in reverse order</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>The number of revisions added to the document, or -1 on error.</returns>
 public static int c4doc_insertRevisionWithHistory(C4Document *doc, string body, bool deleted, 
     bool hasAttachments, string[] history, C4Error *outError)
 {
     var flattenedStringArray = new C4String[history.Length + 1];
     flattenedStringArray[0] = new C4String(body);
     for(int i = 0; i < history.Length; i++) {
         flattenedStringArray[i + 1] = new C4String(history[i]);
     }
     
     var sliceArray = flattenedStringArray.Skip(1).Select<C4String, C4Slice>(x => x.AsC4Slice()).ToArray(); 
     var retVal = default(int);
     fixed(C4Slice *a = sliceArray) {
         retVal = c4doc_insertRevisionWithHistory(doc, 
             flattenedStringArray[0].AsC4Slice(), deleted, hasAttachments, a, (uint)history.Length, outError);
     }
     
     foreach(var s in flattenedStringArray) {
         s.Dispose();   
     }
     
     return retVal;
 }
コード例 #9
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static void c4doc_free(C4Document *doc)
 {
     #if DEBUG
     var ptr = (IntPtr)doc;
     #if ENABLE_LOGGING
     if(ptr != IntPtr.Zero && !_AllocatedObjects.ContainsKey(ptr)) {
         Console.WriteLine("WARNING: [c4doc_free] freeing object 0x{0} that was not found in allocated list", ptr.ToString("X"));
     } else {
     #endif
         _AllocatedObjects.Remove(ptr);
     #if ENABLE_LOGGING
     }
     #endif
     #endif
     _c4doc_free(doc);
 }
コード例 #10
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern C4Slice _c4doc_getType(C4Document *doc);
コード例 #11
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 private static extern void _c4doc_free(C4Document *doc);
コード例 #12
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
     public static bool c4indexer_emit(C4Indexer *indexer, C4Document *document, uint viewNumber,
         C4Key*[] emittedKeys, string[] emittedValues, C4Error *outError)
     {
         var c4StringArr = emittedValues.Select(x => new C4String(x)).ToArray();
         var sliceArr = c4StringArr.Select(x => x.AsC4Slice()).ToArray();
         var retVal = c4indexer_emit(indexer, document, viewNumber, emittedKeys, sliceArr, outError);
         foreach(var c4str in c4StringArr) {
             c4str.Dispose();
         }
 
         return retVal;
     }
コード例 #13
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 /// Emits new keys/values derived from one document, for one view.
 /// This function needs to be called once for each(document, view) pair.Even if the view's map
 /// function didn't emit anything, the old keys/values need to be cleaned up.
 ///      
 /// Values are uninterpreted by CBForest, but by convention are JSON. A special value "*"
 /// (a single asterisk) is used as a placeholder for the entire document.
 ///
 /// </summary>
 /// <param name="indexer">The indexer to operate on</param>
 /// <param name="document">The document being indexed</param>
 /// <param name="viewNumber">The position of the view in the indexer's views[] array</param>
 /// <param name="emittedKeys">Array of keys being emitted</param>
 /// <param name="emittedValues">Array of values being emitted. (JSON by convention.)</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4indexer_emit(C4Indexer *indexer, C4Document *document, uint viewNumber,
     C4Key*[] emittedKeys, C4Slice[] emittedValues, C4Error *outError)
 {
     fixed(C4Key** keysPtr = emittedKeys)
     fixed(C4Slice* valuesPtr = emittedValues)
     {
         return c4indexer_emit(indexer, document, viewNumber, (uint)emittedKeys.Length, keysPtr, valuesPtr, outError);
     }
 }
コード例 #14
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 /// Adds a revision to a document, as a child of the currently selected revision
 /// (or as a root revision if there is no selected revision.)
 /// On success, the new revision will be selected.
 /// Must be called within a transaction.
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="revID">The ID of the revision being inserted</param>
 /// <param name="body">The (JSON) body of the revision</param>
 /// <param name="deleted">True if this revision is a deletion (tombstone)</param>
 /// <param name="hasAttachments">True if this revision contains an _attachments dictionary</param>
 /// <param name="allowConflict">If false, and the parent is not a leaf, a 409 error is returned</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>The number of revisions inserted (0, 1, or -1 on error)</returns>
 public static int c4doc_insertRevision(C4Document *doc, string revID, string body, bool deleted, bool hasAttachments,
     bool allowConflict, C4Error *outError)
 {
     using(var revID_ = new C4String(revID))
     using(var body_ = new C4String(body)) {
         return c4doc_insertRevision(doc, revID_.AsC4Slice(), body_.AsC4Slice(), deleted, 
             hasAttachments, allowConflict, outError);
     }
 }
コード例 #15
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_selectRevision(C4Document *doc, C4Slice revID, [MarshalAs(UnmanagedType.U1)]bool withBody, 
     C4Error *outError);
コード例 #16
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern int c4doc_insertRevisionWithHistory(C4Document *doc, C4Slice body, 
     [MarshalAs(UnmanagedType.U1)]bool deleted, [MarshalAs(UnmanagedType.U1)]bool hasAttachments, C4Slice* history, 
     uint historyCount, C4Error *outError);
コード例 #17
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 /// Selects a specific revision of a document (or no revision, if revID is NULL.)
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="revID">The revID of the revision to select</param>
 /// <param name="withBody">Whether or not to load the body of the revision</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4doc_selectRevision(C4Document *doc, string revID, bool withBody, C4Error *outError)
 {
     using(var revID_ = new C4String(revID)) {
         return c4doc_selectRevision(doc, revID_.AsC4Slice(), withBody, outError);
     }
 }
コード例 #18
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_setType(C4Document *doc, C4Slice docType, C4Error *outError);
コード例 #19
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_loadRevisionBody(C4Document *doc, C4Error *outError);
コード例 #20
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 /// <summary>
 /// Sets a document's docType. (By convention this is the value of the "type" property of the 
 /// current revision's JSON; this value can be used as optimization when indexing a view.)
 /// The change will not be persisted until the document is saved.
 /// </summary>
 /// <param name="doc">The document to operate on</param>
 /// <param name="docType">The document type to set</param>
 /// <param name="outError">The error that occurred if the operation doesn't succeed</param>
 /// <returns>true on success, false otherwise</returns>
 public static bool c4doc_setType(C4Document *doc, string docType, C4Error *outError)
 {
     using(var docType_ = new C4String(docType)) {
         return c4doc_setType(doc, docType_.AsC4Slice(), outError);   
     }
 }
コード例 #21
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_hasRevisionBody(C4Document *doc);
コード例 #22
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_save(C4Document *doc, uint maxRevTreeDepth, C4Error *outError);
コード例 #23
0
ファイル: Native.cs プロジェクト: buzzfeed/cbforest
 public static extern bool c4doc_selectNextRevision(C4Document *doc);
コード例 #24
0
        private DocumentChange ChangeWithNewRevision(RevisionInternal inRev, bool isWinningRev, C4Document *doc, Uri source)
        {
            var winningRevId = default(string);
            if(isWinningRev) {
                winningRevId = inRev.GetRevId();
            } else {
                winningRevId = (string)doc->revID;
            }

            return new DocumentChange(inRev, winningRevId, doc->IsConflicted, source);
        }
コード例 #25
0
        private bool SaveDocument(C4Document* doc, RevisionID revId, IDictionary<string, object> properties)
        {
            // Is the new revision the winner?
            var winningRevID = doc->revID.AsRevID();
            bool isWinner = winningRevID.Equals(revId);

            // Update the documentType:
            if(!isWinner) {
                Native.c4doc_selectCurrentRevision(doc);
                properties = Manager.GetObjectMapper().ReadValue<IDictionary<string, object>>(doc->selectedRev.body);
            }

            Native.c4doc_setType(doc, properties?.GetCast<string>("type"));
            // Save:
            ForestDBBridge.Check(err => Native.c4doc_save(doc, (uint)MaxRevTreeDepth, err));
            return isWinner;
        }