/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { if (obj is Criteria2) { var c = (Criteria2)obj; if (!CreateDoc.Equals(c.CreateDoc)) { return(false); } if (!DocID.Equals(c.DocID)) { return(false); } if (!CreateFolder.Equals(c.CreateFolder)) { return(false); } if (!FolderID.Equals(c.FolderID)) { return(false); } if (!DocListFilteredCriteria.Equals(c.DocListFilteredCriteria)) { return(false); } return(true); } return(false); }
public void TestPossibleAncestors() { RunTestVariants(() => { if (!IsRevTrees()) { return; } var docID = DocID.CreateString(); CreateRev(docID, RevID, Body); CreateRev(docID, Rev2ID, Body); CreateRev(docID, Rev3ID, Body); var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, docID, true, err)); var newRevID = "3-f00f00"; LiteCoreBridge.Check(err => Native.c4doc_selectFirstPossibleAncestorOf(doc, newRevID)); doc->selectedRev.revID.Should().Equal(Rev2ID, "because the 2nd generation is the first ancestor of the third"); LiteCoreBridge.Check(err => Native.c4doc_selectNextPossibleAncestorOf(doc, newRevID)); doc->selectedRev.revID.Should().Equal(RevID, "because the first generation comes before the second"); Native.c4doc_selectNextPossibleAncestorOf(doc, newRevID).Should().BeFalse("because we are at the root"); newRevID = "2-f00f00"; LiteCoreBridge.Check(err => Native.c4doc_selectFirstPossibleAncestorOf(doc, newRevID)); doc->selectedRev.revID.Should().Equal(RevID, "because the first generation comes before the second"); Native.c4doc_selectNextPossibleAncestorOf(doc, newRevID).Should().BeFalse("because we are at the root"); newRevID = "1-f00f00"; Native.c4doc_selectFirstPossibleAncestorOf(doc, newRevID).Should().BeFalse("because we are at the root"); Native.c4doc_free(doc); }); }
public void TestCreateMultipleRevisions() { RunTestVariants(() => { var Body2 = JSON2Fleece("{\"ok\":\"go\"}"); var Body3 = JSON2Fleece("{\"ubu\":\"roi\"}"); var docID = DocID.CreateString(); CreateRev(docID, RevID, FleeceBody); CreateRev(docID, Rev2ID, (FLSlice)Body2, C4RevisionFlags.KeepBody); CreateRev(docID, Rev2ID, (FLSlice)Body2); // test redundant Insert // Reload the doc: var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, docID, true, err)); doc->flags.Should().HaveFlag(C4DocumentFlags.DocExists, "because the document was saved"); doc->docID.Should().Be(DocID, "because the doc ID should save correctly"); doc->revID.Should().Be(Rev2ID, "because the doc's rev ID should load correctly"); doc->selectedRev.revID.Should().Be(Rev2ID, "because the rev's rev ID should load correctly"); doc->selectedRev.sequence.Should().Be(2, "because it is the second revision"); doc->selectedRev.body.Should().Be(Body2, "because the body should load correctly"); if (Versioning == C4DocumentVersioning.RevisionTrees) { // Select 1st revision: LiteCoreBridge.Check(err => Native.c4doc_selectParentRevision(doc)); doc->selectedRev.revID.Should().Be(RevID, "because now the first revision is selected"); doc->selectedRev.sequence.Should().Be(1, "because now the first revision is selected"); doc->selectedRev.body.Should().Be(FLSlice.Null, "because the body of the old revision should be gone"); Native.c4doc_hasRevisionBody(doc).Should().BeFalse("because the body of the old revision should be gone"); Native.c4doc_selectParentRevision(doc).Should().BeFalse("because a root revision has no parent"); Native.c4doc_free(doc); // Add a 3rd revision: CreateRev(docID, Rev3ID, (FLSlice)Body3); // Revision 2 should keep its body due to the KeepBody flag doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, docID, true, err)); Native.c4doc_selectParentRevision(doc).Should().BeTrue("because otherwise the selection of the 2nd revision failed"); doc->selectedRev.revID.Should().Be(Rev2ID, "because the rev's rev ID should load correctly"); doc->selectedRev.sequence.Should().Be(2, "because it is the second revision"); doc->selectedRev.flags.Should().HaveFlag(C4RevisionFlags.KeepBody, "because the KeepBody flag was saved on the revision"); doc->selectedRev.body.Should().Be(Body2, "because the body should load correctly"); Native.c4doc_free(doc); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, docID, true, err)); var nPurged = NativeRaw.c4doc_purgeRevision(doc, Rev3ID, null); nPurged.Should().Be(3, "because there are three revisions to purge"); LiteCoreBridge.Check(err => Native.c4doc_save(doc, 20, err)); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); Native.c4doc_free(doc); doc = null; } } Native.FLSliceResult_Release(Body2); Native.FLSliceResult_Release(Body3); Native.c4doc_free(doc); }); }
public void TestCreateMultipleRevisions() { RunTestVariants(() => { var docID = DocID.CreateString(); var Body2 = C4Slice.Constant("{\"ok\":\"go\"}"); CreateRev(docID, RevID, Body); CreateRev(docID, Rev2ID, Body2); CreateRev(docID, Rev2ID, Body2, false); // test redundant insert // Reload the doc: var doc = (C4Document *)LiteCoreBridge.Check(err => NativeRaw.c4doc_get(Db, DocID, true, err)); doc->flags.Should().Be(C4DocumentFlags.Exists); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the stored doc ID"); doc->revID.Equals(Rev2ID).Should().BeTrue("because the doc should have the current rev ID"); doc->selectedRev.revID.Equals(Rev2ID).Should().BeTrue("because the current revision is selected"); doc->selectedRev.sequence.Should().Be(2L, "because the current revision is the second one"); doc->selectedRev.body.Equals(Body2).Should().BeTrue("because the selected rev should have the correct body"); if (Versioning == C4DocumentVersioning.RevisionTrees) { // Select 1st revision: Native.c4doc_selectParentRevision(doc).Should().BeTrue("because otherwise selecting the parent revision failed"); doc->selectedRev.revID.Equals(RevID).Should().BeTrue("because the first revision is selected"); doc->selectedRev.sequence.Should().Be(1L, "because the first revision is selected"); doc->selectedRev.body.Equals(C4Slice.Null).Should().BeTrue("because the body hasn't been loaded"); Native.c4doc_hasRevisionBody(doc).Should().BeTrue("because the body still exists"); LiteCoreBridge.Check(err => Native.c4doc_loadRevisionBody(doc, err)); doc->selectedRev.body.Equals(Body).Should().BeTrue("because the body is loaded"); Native.c4doc_selectParentRevision(doc).Should().BeFalse("because the root revision is selected"); Native.c4doc_free(doc); // Compact database: LiteCoreBridge.Check(err => Native.c4db_compact(Db, err)); doc = (C4Document *)LiteCoreBridge.Check(err => NativeRaw.c4doc_get(Db, DocID, true, err)); Native.c4doc_selectParentRevision(doc).Should().BeTrue("because otherwise selecting the parent revision failed"); doc->selectedRev.revID.Equals(RevID).Should().BeTrue("because the first revision is selected"); doc->selectedRev.sequence.Should().Be(1L, "because the first revision is selected"); if (Storage != C4StorageEngine.SQLite) { doc->selectedRev.body.Equals(C4Slice.Null).Should().BeTrue("because the body is not available"); Native.c4doc_hasRevisionBody(doc).Should().BeFalse("because the body has been compacted"); C4Error error; Native.c4doc_loadRevisionBody(doc, &error).Should().BeFalse("because the body is unavailable"); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { C4Error error; NativeRaw.c4doc_purgeRevision(doc, Rev2ID, &error).Should().Be(2); LiteCoreBridge.Check(err => Native.c4doc_save(doc, 20, err)); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } } Native.c4doc_free(doc); }); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { if (obj is CriteriaGetByObject) { var c = (CriteriaGetByObject)obj; if (!DocID.Equals(c.DocID)) { return(false); } if (!FolderID.Equals(c.FolderID)) { return(false); } return(true); } return(false); }
public List <String> GetDocItemTagInsertString(Int32 hid) { List <String> listSqls = new List <string>(); foreach (var term in TagTerms) { listSqls.Add(@"INSERT INTO [dbo].[t_tag] ([HID],[TagType],[TagID],[TagSubID],[Term]) VALUES (" + string.Join(",", new string[] { hid.ToString(), ((Int32)(HIHTagTypeEnum.FinanceDocumentItem)).ToString(), DocID.ToString(), ItemID.ToString(), "N'" + term + "'" }) + ")"); } return(listSqls); }
public void TestTransaction() { RunTestVariants(() => { Native.c4db_getDocumentCount(Db).Should().Be(0, "because no documents have been added"); Native.c4db_isInTransaction(Db).Should().BeFalse("because no transaction has started yet"); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); Native.c4db_isInTransaction(Db).Should().BeTrue("because a transaction has started"); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); Native.c4db_isInTransaction(Db).Should().BeTrue("because another transaction has started"); LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); Native.c4db_isInTransaction(Db).Should().BeTrue("because a transaction is still active"); LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); Native.c4db_isInTransaction(Db).Should().BeFalse("because all transactions have ended"); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); Native.c4db_isInTransaction(Db).Should().BeTrue("because a transaction has started"); CreateRev(DocID.CreateString(), RevID, Body); LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, false, err)); Native.c4db_isInTransaction(Db).Should().BeFalse("because all transactions have ended"); Native.c4db_getDocumentCount(Db).Should().Be(0, "because the transaction was aborted"); }); }
protected void SearchBtn_Click(object sender, EventArgs e) { Stemmer stemmer = new Stemmer(); ListBox DidUMean = ((ListBox)form1.FindControl("DidUMeanLBID")); ListBox ResultsBox = ((ListBox)form1.FindControl("REsultsBoxID")); string inputText = ((TextBox)form1.FindControl("SearchTxt")).Text.ToLower(); inputText = inputText.ToLower(); string DocID, frequency, Positions; Boolean exact_query = false; List <Term> terms = new List <Term>(); List <singelTerm> SingleTermsList = new List <singelTerm>(); Term T; singelTerm singleterm; Details D; SqlConnection conn = new SqlConnection("Server = AYMAN-PC; Database = IRdb; Trusted_Connection = True; MultipleActiveResultSets = true"); conn.Open(); if (inputText[0] == '"') { inputText = inputText.Replace(@"""", ""); exact_query = true; } inputText = StopWords.RemoveStopwords(inputText); DidUMean.Items.Clear(); ResultsBox.Items.Clear(); string[] query = SplitWords(inputText); for (int i = 0; i < query.Count(); i++) { query[i] = stemmer.stem(query[i]); SqlCommand cmd = new SqlCommand("select [term],[doc_id],[frequency],[positions] from [IRdb].[dbo].[Inverted_Index] where [term]= @term ", conn); cmd.Parameters.AddWithValue("@term", query[i]); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { singleterm = new singelTerm(); singleterm.name = (reader["term"].ToString());//Term frequency = reader["frequency"].ToString(); DocID = reader["doc_id"].ToString(); Positions = reader["positions"].ToString(); string[] Pos_terms = Positions.Split('@'); string[] freqs = frequency.Split(','); string[] _DocIDs = DocID.Split(','); List <string> positionsList = new List <string>(); foreach (string p in Pos_terms) { positionsList = p.Split(',').ToList(); } foreach (string doc_id in _DocIDs) { singleterm.doc_id.Add(int.Parse(doc_id)); } //frequency foreach (string f in freqs) { singleterm.frequency.Add(int.Parse(f)); } //postions foreach (string p in Pos_terms) { singleterm.position.Add(p); } SingleTermsList.Add(singleterm); } } } ////////////////another Form /////////// for (int i = 0; i < SingleTermsList.Count(); i++) { T = new Term(); T.name = SingleTermsList[i].name; for (int j = 0; j < SingleTermsList[i].doc_id.Count(); j++) { Details details = new Details(); details.doc_id = SingleTermsList[i].doc_id[j]; details.frequency = SingleTermsList[i].frequency[j]; string [] positions = SingleTermsList[i].position[j].Split(','); foreach (string pos in positions) { details.positions.Add(int.Parse(pos)); } T.details.Add(details); } terms.Add(T); } ///////////////////////////////////////////////// HtmlGenericControl div = ((HtmlGenericControl)form1.FindControl("SearchingResultsDiv"));//Div That Will Contain Links searchClass searchObj = new searchClass(); if (terms.Count == 1) { searchObj.singleWordSearch(terms, query, ResultsBox, DidUMeanLabelID, div); } else { if (exact_query == false) { //1.Multi Keyword Search searchObj.MultiKeywordSearch(terms, query, ResultsBox, DidUMeanLabelID, div); } else { searchObj.ExactSearch(terms, query, ResultsBox, DidUMeanLabelID, div); } } }
public void TestConflict() { RunTestVariants(() => { if (!IsRevTrees()) { return; } var body2 = C4Slice.Constant("{\"ok\":\"go\"}"); var body3 = C4Slice.Constant("{\"ubu\":\"roi\"}"); CreateRev(DocID.CreateString(), RevID, Body); CreateRev(DocID.CreateString(), Rev2ID, body2, C4RevisionFlags.KeepBody); CreateRev(DocID.CreateString(), C4Slice.Constant("3-aaaaaa"), body3); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { // "Pull" a conflicting revision: var history = new C4Slice[] { C4Slice.Constant("4-dddd"), C4Slice.Constant("3-ababab"), Rev2ID }; fixed(C4Slice * history_ = history) { var rq = new C4DocPutRequest { existingRevision = true, docID = DocID, history = history_, historyCount = 3, body = body3, save = true }; C4Error error; var doc = Native.c4doc_put(Db, &rq, null, &error); ((IntPtr)doc).Should().NotBe(IntPtr.Zero); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", "4-dddd").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "4-dddd", "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-ababab", "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", "3-ababab").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, Rev2ID.CreateString(), "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", Rev2ID.CreateString()).Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); NativeRaw.c4doc_selectCommonAncestorRevision(doc, Rev2ID, Rev2ID).Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); } } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, DocID.CreateString(), true, err)); LiteCoreBridge.Check(err => Native.c4doc_resolveConflict(doc, "4-dddd", "3-aaaaaa", Encoding.UTF8.GetBytes("{\"merged\":true}"), 0, err)); Native.c4doc_selectCurrentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("5-940fe7e020dbf8db0f82a5d764870c4b6c88ae99"); doc->selectedRev.body.CreateString().Should().Be("{\"merged\":true}"); Native.c4doc_selectParentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("4-dddd"); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, false, err)); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, DocID.CreateString(), true, err)); LiteCoreBridge.Check(err => Native.c4doc_resolveConflict(doc, "3-aaaaaa", "4-dddd", Encoding.UTF8.GetBytes("{\"merged\":true}"), 0, err)); Native.c4doc_selectCurrentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("4-333ee0677b5f1e1e5064b050d417a31d2455dc30"); doc->selectedRev.body.CreateString().Should().Be("{\"merged\":true}"); Native.c4doc_selectParentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("3-aaaaaa"); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, false, err)); } }); }
public void TestGetForPut() { RunTestVariants(() => { LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { // Creating doc given ID: var doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, DocID, C4Slice.Null, false, false, err)); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the correct doc ID"); doc->revID.Equals(C4Slice.Null).Should().BeTrue("because a rev ID has not been assigned yet"); ((int)doc->flags).Should().Be(0, "because the document has no flags yet"); doc->selectedRev.revID.Equals(C4Slice.Null).Should().BeTrue("because no rev ID has been assigned yet"); Native.c4doc_free(doc); // Creating doc, no ID: doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, C4Slice.Null, C4Slice.Null, false, false, err)); doc->docID.size.Should().BeGreaterOrEqualTo(20, "because the document should be assigned a random ID"); doc->revID.Equals(C4Slice.Null).Should().BeTrue("because the doc doesn't have a rev ID yet"); ((int)doc->flags).Should().Be(0, "because the document has no flags yet"); doc->selectedRev.revID.Equals(C4Slice.Null).Should().BeTrue("because no rev ID has been assigned yet"); Native.c4doc_free(doc); // Delete with no revID given C4Error error; doc = NativeRawPrivate.c4doc_getForPut(Db, C4Slice.Null, C4Slice.Null, true, false, &error); ((long)doc).Should().Be(0, "because the document does not exist"); error.code.Should().Be((int)C4ErrorCode.NotFound, "because the correct error should be returned"); // Adding new rev of nonexistent doc: doc = NativeRawPrivate.c4doc_getForPut(Db, DocID, RevID, false, false, &error); ((long)doc).Should().Be(0, "because the document does not exist"); error.code.Should().Be((int)C4ErrorCode.NotFound, "because the correct error should be returned"); // Adding new rev of existing doc: CreateRev(DocID.CreateString(), RevID, Body); doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, DocID, RevID, false, false, err)); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the correct doc ID"); doc->revID.Equals(RevID).Should().BeTrue("because the doc should have the correct rev ID"); doc->flags.Should().Be(C4DocumentFlags.DocExists, "because the document has no flags yet"); doc->selectedRev.revID.Equals(RevID).Should().BeTrue("because the selected rev should have the correct rev ID"); Native.c4doc_free(doc); // Adding new rev, with nonexistent parent doc = NativeRawPrivate.c4doc_getForPut(Db, DocID, Rev2ID, false, false, &error); ((long)doc).Should().Be(0, "because the document does not exist"); error.code.Should().Be((int)C4ErrorCode.Conflict, "because the correct error should be returned"); // Conflict -- try & fail to update non-current rev: var body2 = C4Slice.Constant("{\"ok\":\"go\"}"); CreateRev(DocID.CreateString(), Rev2ID, body2); doc = NativeRawPrivate.c4doc_getForPut(Db, DocID, RevID, false, false, &error); ((long)doc).Should().Be(0, "because the document does not exist"); error.code.Should().Be((int)C4ErrorCode.Conflict, "because the correct error should be returned"); if (Versioning == C4DocumentVersioning.RevisionTrees) { // Conflict -- force an update of non-current rev: doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, DocID, RevID, false, true, err)); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the correct doc ID"); doc->selectedRev.revID.Equals(RevID).Should().BeTrue("because the doc should have the correct rev ID"); Native.c4doc_free(doc); } // Deleting the doc: doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, DocID, Rev2ID, true, false, err)); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the correct doc ID"); doc->selectedRev.revID.Equals(Rev2ID).Should().BeTrue("because the doc should have the correct rev ID"); Native.c4doc_free(doc); // Actually delete it: CreateRev(DocID.CreateString(), Rev3ID, C4Slice.Null, C4RevisionFlags.Deleted); LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); // Re-creating the doc (no revID given): doc = (C4Document *)LiteCoreBridge.Check(err => NativeRawPrivate.c4doc_getForPut(Db, DocID, C4Slice.Null, false, false, err)); doc->docID.Equals(DocID).Should().BeTrue("because the doc should have the correct doc ID"); doc->selectedRev.revID.Equals(Rev3ID).Should().BeTrue("because the doc should have the correct rev ID"); doc->flags.Should().Be(C4DocumentFlags.DocExists | C4DocumentFlags.DocDeleted, "because the document was deleted"); doc->selectedRev.revID.Equals(Rev3ID).Should().BeTrue("because the doc should have the correct rev ID"); Native.c4doc_free(doc); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } }); }
public void TestPurge() { RunTestVariants(() => { var body2 = C4Slice.Constant("{\"ok\":\"go\"}"); var body3 = C4Slice.Constant("{\"ubu\":\"roi\"}"); CreateRev(DocID.CreateString(), RevID, Body); CreateRev(DocID.CreateString(), Rev2ID, body2); CreateRev(DocID.CreateString(), Rev3ID, body3); var history = new[] { C4Slice.Constant("3-ababab"), Rev2ID }; fixed(C4Slice * history_ = history) { var rq = new C4DocPutRequest { existingRevision = true, docID = DocID, history = history_, historyCount = 2, body = body3, save = true }; C4Error error; C4Document *doc = null; LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { doc = Native.c4doc_put(Db, &rq, null, &error); ((IntPtr)doc).Should().NotBe(IntPtr.Zero); Native.c4doc_free(doc); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { LiteCoreBridge.Check(err => NativeRaw.c4db_purgeDoc(Db, DocID, err)); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } Native.c4db_getDocumentCount(Db).Should().Be(0UL); CreateRev(DocID.CreateString(), RevID, Body); CreateRev(DocID.CreateString(), Rev2ID, body2); CreateRev(DocID.CreateString(), Rev3ID, body3); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { doc = Native.c4doc_put(Db, &rq, null, &error); ((IntPtr)doc).Should().NotBe(IntPtr.Zero); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { LiteCoreBridge.Check(err => Native.c4doc_purgeRevision(doc, null, err)); LiteCoreBridge.Check(err => Native.c4doc_save(doc, 0, err)); } finally { Native.c4doc_free(doc); LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } Native.c4db_getDocumentCount(Db).Should().Be(0UL); } }); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/> is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.</returns> public override bool Equals(object obj) { if (obj is DocListFilteredCriteria) { var c = (DocListFilteredCriteria)obj; if (!DocID.Equals(c.DocID)) { return(false); } if (!DocClassID.Equals(c.DocClassID)) { return(false); } if (!DocTypeID.Equals(c.DocTypeID)) { return(false); } if (!SenderID.Equals(c.SenderID)) { return(false); } if (!RecipientID.Equals(c.RecipientID)) { return(false); } if (!DocRef.Equals(c.DocRef)) { return(false); } if (!DocDate.Equals(c.DocDate)) { return(false); } if (!Subject.Equals(c.Subject)) { return(false); } if (!DocStatusID.Equals(c.DocStatusID)) { return(false); } if (!CreateDate.Equals(c.CreateDate)) { return(false); } if (!CreateUserID.Equals(c.CreateUserID)) { return(false); } if (!ChangeDate.Equals(c.ChangeDate)) { return(false); } if (!ChangeUserID.Equals(c.ChangeUserID)) { return(false); } return(true); } return(false); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns>An hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns> public override int GetHashCode() { return(string.Concat("DocListFilteredCriteria", DocID.ToString(), DocClassID.ToString(), DocTypeID.ToString(), SenderID.ToString(), RecipientID.ToString(), DocRef.ToString(), DocDate.ToString(), Subject.ToString(), DocStatusID.ToString(), CreateDate.ToString(), CreateUserID.ToString(), ChangeDate.ToString(), ChangeUserID.ToString()).GetHashCode()); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns>An hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns> public override int GetHashCode() { return(string.Concat("CriteriaGetByObject", DocID.ToString(), FolderID.ToString()).GetHashCode()); }
/// <summary> /// Returns a string that represents the current <see cref="Doc"/> /// </summary> /// <returns>A <see cref="System.String"/> that represents this instance.</returns> public override string ToString() { // Return the Primary Key as a string return(DocID.ToString() + ", " + DocRef.ToString()); }
public void TestConflict() { RunTestVariants(() => { if (!IsRevTrees()) { return; } var body2 = JSON2Fleece("{\"ok\":\"go\"}"); var body3 = JSON2Fleece("{\"ubu\":\"roi\"}"); CreateRev(DocID.CreateString(), RevID, FleeceBody); CreateRev(DocID.CreateString(), Rev2ID, (FLSlice)body2, C4RevisionFlags.KeepBody); CreateRev(DocID.CreateString(), FLSlice.Constant("3-aaaaaa"), (FLSlice)body3); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { // "Pull" a conflicting revision: var history = new FLSlice[] { FLSlice.Constant("4-dddd"), FLSlice.Constant("3-ababab"), Rev2ID }; fixed(FLSlice * history_ = history) { var rq = new C4DocPutRequest { existingRevision = true, docID = DocID, history = history_, historyCount = 3, allowConflict = true, body = (FLSlice)body3, save = true, remoteDBID = 1 }; C4Error error; var doc = Native.c4doc_put(Db, &rq, null, &error); ((IntPtr)doc).Should().NotBe(IntPtr.Zero); Native.FLSliceResult_Release(body2); Native.FLSliceResult_Release(body3); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", "4-dddd").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "4-dddd", "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-ababab", "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", "3-ababab").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, Rev2ID.CreateString(), "3-aaaaaa").Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); Native.c4doc_selectCommonAncestorRevision(doc, "3-aaaaaa", Rev2ID.CreateString()).Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); NativeRaw.c4doc_selectCommonAncestorRevision(doc, Rev2ID, Rev2ID).Should().BeTrue(); doc->selectedRev.revID.CreateString().Should().Be(Rev2ID.CreateString()); } } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, true, err)); } var mergedBody = JSON2Fleece("{\"merged\":true}"); LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, DocID.CreateString(), true, err)); LiteCoreBridge.Check(err => NativeRaw.c4doc_resolveConflict(doc, FLSlice.Constant("4-dddd"), FLSlice.Constant("3-aaaaaa"), (FLSlice)mergedBody, 0, err)); Native.c4doc_selectCurrentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("5-79b2ecd897d65887a18c46cc39db6f0a3f7b38c4"); doc->selectedRev.body.Equals(mergedBody).Should().BeTrue(); Native.c4doc_selectParentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("4-dddd"); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, false, err)); } LiteCoreBridge.Check(err => Native.c4db_beginTransaction(Db, err)); try { var doc = (C4Document *)LiteCoreBridge.Check(err => Native.c4doc_get(Db, DocID.CreateString(), true, err)); LiteCoreBridge.Check(err => NativeRaw.c4doc_resolveConflict(doc, FLSlice.Constant("3-aaaaaa"), FLSlice.Constant("4-dddd"), (FLSlice)mergedBody, 0, err)); Native.c4doc_selectCurrentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("4-1fa2dbcb66b5e0456f6d6fc4a90918d42f3dd302"); doc->selectedRev.body.Equals(mergedBody).Should().BeTrue(); Native.c4doc_selectParentRevision(doc); doc->selectedRev.revID.CreateString().Should().Be("3-aaaaaa"); } finally { LiteCoreBridge.Check(err => Native.c4db_endTransaction(Db, false, err)); } }); }
/// <summary> /// Returns a hash code for this instance. /// </summary> /// <returns>An hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.</returns> public override int GetHashCode() { return(string.Concat("Criteria2", CreateDoc.ToString(), DocID.ToString(), CreateFolder.ToString(), FolderID.ToString(), DocListFilteredCriteria.ToString()).GetHashCode()); }
private void LogIn_Load(object sender, EventArgs e) { loadData(); DocID.Select(); }