コード例 #1
0
        private static void TotalAccumulate(object context, C4Key *key, C4Slice value)
        {
            var ctx = context as TotalContext;
            var v   = NativeRaw.FLValue_FromTrustedData((FLSlice)value);

            ctx.total += Native.FLValue_AsDouble(v);
        }
コード例 #2
0
        public static void WithC4Keys(object[] keySources, bool writeNull, C4KeyActionDelegate action)
        {
            if (keySources == null)
            {
                action(null);
                return;
            }

            var c4Keys = new C4Key *[keySources.Length];

            for (int i = 0; i < keySources.Length; i++)
            {
                if (keySources[i] == null && !writeNull)
                {
                    c4Keys[i] = null;
                }
                else
                {
                    c4Keys[i] = CouchbaseBridge.SerializeToKey(keySources[i]);
                }
            }

            try {
                action(c4Keys);
            } finally {
                foreach (C4Key *key in c4Keys)
                {
                    Native.c4key_free(key);
                }
            }
        }
コード例 #3
0
        private void UpdateIndex()
        {
            var ind = (C4Indexer *)LiteCoreBridge.Check(err => Native.c4indexer_begin(Db,
                                                                                      new[] { _view }, err));
            var         e = (C4DocEnumerator *)LiteCoreBridge.Check(err => Native.c4indexer_enumerateDocuments(ind, err));
            C4Document *doc;
            C4Error     error;

            while (null != (doc = Native.c4enum_nextDocument(e, &error)))
            {
                // Index 'doc':
                var keys   = new C4Key *[2];
                var values = new C4Slice[2];
                keys[0] = Native.c4key_new();
                keys[1] = Native.c4key_new();
                NativeRaw.c4key_addString(keys[0], doc->docID);
                Native.c4key_addNumber(keys[1], doc->sequence);
                values[0] = values[1] = C4Slice.Constant("1234");
                LiteCoreBridge.Check(err => Native.c4indexer_emit(ind, doc, 0, keys, values, err));
                Native.c4key_free(keys[0]);
                Native.c4key_free(keys[1]);
                Native.c4doc_free(doc);
            }

            error.Code.Should().Be(0, "because otherwise an error occurred somewhere");
            Native.c4enum_free(e);
            LiteCoreBridge.Check(err => Native.c4indexer_end(ind, true, err));
        }
コード例 #4
0
ファイル: C4ViewTest.cs プロジェクト: Rep2/DM_lab1
        private void CreateIndex()
        {
            for (int i = 1; i <= 100; i++)
            {
                var docId = String.Format("doc-{0}", i.ToString("D3"));
                CreateRev(docId, REV_ID, BODY);
            }

            C4Error    error;
            C4Indexer *ind = Native.c4indexer_begin(_db, new C4View *[] { _view }, &error);

            Assert.IsTrue(ind != null);

            var e = Native.c4indexer_enumerateDocuments(ind, &error);

            Assert.IsTrue(e != null);

            C4Document *doc;

            while (null != (doc = Native.c4enum_nextDocument(e, &error)))
            {
                // Index 'doc':
                var keys = new C4Key *[] { Native.c4key_new(), Native.c4key_new() };
                var vals = new string[] { "1234", "1234" };
                Native.c4key_addString(keys[0], doc->docID);
                Native.c4key_addNumber(keys[1], doc->sequence);
                Assert.IsTrue(Native.c4indexer_emit(ind, doc, 0, keys, vals, &error));
                Native.c4key_free(keys[0]);
                Native.c4key_free(keys[1]);
            }

            Assert.AreEqual(0, error.code);
            Assert.IsTrue(Native.c4indexer_end(ind, true, &error));
        }
コード例 #5
0
        private void CreateIndex()
        {
            var ind = (C4Indexer *)LiteCoreBridge.Check(err => Native.c4indexer_begin(Db,
                                                                                      new[] { _view }, err));
            var e = (C4DocEnumerator *)LiteCoreBridge.Check(err => Native.c4indexer_enumerateDocuments(ind, err));

            C4Document *doc;
            C4Error     error;

            while (null != (doc = Native.c4enum_nextDocument(e, &error)))
            {
                var body       = doc->selectedRev.body.CreateString();
                var components = body.Trim('(', ')').Split(',');
                var area       = new C4GeoArea();
                area.xmin = Double.Parse(components[0]);
                area.ymin = Double.Parse(components[1]);
                area.xmax = Double.Parse(components[2]);
                area.ymax = Double.Parse(components[3]);
                var keys   = new C4Key *[1];
                var values = new C4Slice[1];
                keys[0]   = Native.c4key_newGeoJSON("{\"geo\":true}", area);
                values[0] = C4Slice.Constant("1234");
                LiteCoreBridge.Check(err => Native.c4indexer_emit(ind, doc, 0, keys, values, err));
                Native.c4key_free(keys[0]);
                Native.c4doc_free(doc);
            }

            Native.c4enum_free(e);
            error.Code.Should().Be(0, "because otherwise an error occurred somewhere");
            LiteCoreBridge.Check(err => Native.c4indexer_end(ind, true, err));
        }
コード例 #6
0
 protected override void SetupVariant(int option)
 {
     _key = Native.c4key_new();
     Native.c4key_beginArray(_key);
     Native.c4key_addNull(_key);
     Native.c4key_addBool(_key, false);
     Native.c4key_addBool(_key, true);
     Native.c4key_addNumber(_key, 0);
     Native.c4key_addNumber(_key, 12345);
     Native.c4key_addNumber(_key, -2468);
     Native.c4key_addString(_key, "foo");
     Native.c4key_beginArray(_key);
     Native.c4key_endArray(_key);
     Native.c4key_endArray(_key);
 }
コード例 #7
0
ファイル: C4ViewTest.cs プロジェクト: Rep2/DM_lab1
        private void CreateFullTextIndex(uint docCount)
        {
            var docID = default(string);

            for (uint i = 1; i <= docCount; i++)
            {
                docID = String.Format("doc-{0}", i.ToString("D3"));
                var body = default(string);
                switch (i % 3)
                {
                case 0:
                    body = "The cat sat on the mat.";
                    break;

                case 1:
                    body = "Outside SomeWhere a cät was barking";
                    break;

                case 2:
                    body = "The bark of a tree is rough?";
                    break;
                }

                CreateRev(docID, REV_ID, body);
            }

            C4Error    error;
            C4Indexer *ind = Native.c4indexer_begin(_db, new C4View *[] { _view }, &error);

            Assert.IsTrue(ind != null);


            foreach (var doc in new CBForestDocEnumerator(ind))
            {
                // Index 'doc':
                C4Key *[] keys;
                using (var languageStr = new C4String("en")) {
                    keys = new C4Key *[] { Native.c4key_newFullTextString(doc.SelectedRev.body, languageStr.AsC4Slice()) };
                }

                Assert.IsTrue(Native.c4indexer_emit(ind, doc.GetDocument(), 0, keys, new[] { "1234" }, &error));
                Native.c4key_free(keys[0]);
            }

            Assert.AreEqual(0, error.code);
            Assert.IsTrue(Native.c4indexer_end(ind, true, &error));
        }
コード例 #8
0
        private void CreateFullTextIndex(uint docCount)
        {
            for (uint i = 1; i <= docCount; i++)
            {
                string docID = $"doc-{i:D3}";
                var    body  = C4Slice.Null;
                switch (i % 3)
                {
                case 0:
                    body = C4Slice.Constant("The cat sat on the mat");
                    break;

                case 1:
                    body = C4Slice.Constant("Outside SomeWhere a c\u00e4t was barking");
                    break;

                case 2:
                    body = C4Slice.Constant("The bark of a tree is rough?");
                    break;
                }

                CreateRev(docID, RevID, body);
            }

            var ind = (C4Indexer *)LiteCoreBridge.Check(err => Native.c4indexer_begin(Db,
                                                                                      new[] { _view }, err));
            var e = (C4DocEnumerator *)LiteCoreBridge.Check(err => Native.c4indexer_enumerateDocuments(ind, err));

            C4Document *doc;
            C4Error     error;

            while (null != (doc = Native.c4enum_nextDocument(e, &error)))
            {
                // Index 'doc':
                var keys   = new C4Key *[1];
                var values = new C4Slice[1];
                keys[0]   = NativeRaw.c4key_newFullTextString(doc->selectedRev.body, C4Slice.Constant("en"));
                values[0] = C4Slice.Constant("1234");
                LiteCoreBridge.Check(err => Native.c4indexer_emit(ind, doc, 0, keys, values, err));
                Native.c4key_free(keys[0]);
                Native.c4doc_free(doc);
            }

            error.Code.Should().Be(0, "because otherwise an error occurred somewhere");
            Native.c4enum_free(e);
            LiteCoreBridge.Check(err => Native.c4indexer_end(ind, true, err));
        }
コード例 #9
0
ファイル: C4GeoTest.cs プロジェクト: Rep2/DM_lab1
        private void CreateIndex()
        {
            C4Error    error;
            C4Indexer *ind = Native.c4indexer_begin(_db, new C4View *[] { _view }, &error);

            Assert.IsTrue(ind != null);

            foreach (var doc in new CBForestDocEnumerator(ind))
            {
                var       body   = (string)doc.GetDocument()->selectedRev.body;
                var       pieces = body.Split(',');
                C4GeoArea area;
                Assert.IsTrue(Double.TryParse(pieces[0].TrimStart('('), out area.xmin));
                Assert.IsTrue(Double.TryParse(pieces[1], out area.ymin));
                Assert.IsTrue(Double.TryParse(pieces[2], out area.xmax));
                Assert.IsTrue(Double.TryParse(pieces[3].TrimEnd(')'), out area.ymax));
                var keys = new C4Key *[] { Native.c4key_newGeoJSON("{\"geo\":true}", area) };
                Assert.IsTrue(Native.c4indexer_emit(ind, doc.GetDocument(), 0, keys, new[] { "1234" }, &error));
                Native.c4key_free(keys[0]);
            }

            Assert.AreEqual(0, error.code);
            Assert.IsTrue(Native.c4indexer_end(ind, true, &error));
        }
コード例 #10
0
 public static void c4key_addMapKey(C4Key *key, string str)
 {
     using (var str_ = new C4String(str)) {
         NativeRaw.c4key_addMapKey(key, str_.AsC4Slice());
     }
 }
コード例 #11
0
 public static extern C4KeyReader c4key_read(C4Key *key);
コード例 #12
0
ファイル: C4KeyTest.cs プロジェクト: Rep2/DM_lab1
 public override void SetUp()
 {
     _key = Native.c4key_new();
 }
コード例 #13
0
 public static extern void c4key_endMap(C4Key *key);
コード例 #14
0
 public static extern void c4kv_add(C4KeyValueList *kv, C4Key *key, C4Slice value);
コード例 #15
0
ファイル: C4Test.cs プロジェクト: lordkev/cbforest
 public string ToJSON(C4Key *key)
 {
     return(ToJSON(Native.c4key_read(key)));
 }
コード例 #16
0
ファイル: C4KeyTest.cs プロジェクト: buzzfeed/cbforest
 public override void SetUp()
 {
     _key = Native.c4key_new();
 }
コード例 #17
0
 public static extern void c4key_addString(C4Key *key, C4Slice str);
コード例 #18
0
 public static extern void c4key_free(C4Key *key);
コード例 #19
0
 public static extern void c4key_addNull(C4Key *key);
コード例 #20
0
 public static extern void c4key_reset(C4Key *key);
コード例 #21
0
 private unsafe void Accumulate(void *context, C4Key *key, C4Slice value)
 {
     _accumulate?.Invoke(_context, key, value);
 }
コード例 #22
0
 private static void CountAccumulate(object context, C4Key *key, C4Slice value)
 {
     (context as CountContext).count++;
 }
コード例 #23
0
 public static extern C4KeyReader *c4key_newReader(C4Key *key);
コード例 #24
0
 public static extern void c4key_addNumber(C4Key *key, double num);
コード例 #25
0
 public static void c4kv_add(C4KeyValueList *kv, C4Key *key, string value)
 {
     using (var value_ = new C4String(value)) {
         NativeRaw.c4kv_add(kv, key, value_.AsC4Slice());
     }
 }
コード例 #26
0
 public static extern void c4key_beginArray(C4Key *key);
コード例 #27
0
 public static extern void c4key_addMapKey(C4Key *key, C4Slice str);
コード例 #28
0
 public static extern void c4key_endArray(C4Key *key);
コード例 #29
0
 public JsonC4KeyWriter(C4Key *key)
 {
     _c4key = key;
 }
コード例 #30
0
 public static extern void c4key_beginMap(C4Key *key);
コード例 #31
0
 public static extern void c4key_addBool(C4Key *key, [MarshalAs(UnmanagedType.U1)] bool b);
 public JsonC4KeyWriter(C4Key *key) 
 {
     _c4key = key;
 }