本文整理汇总了C#中Couchbase.Lite.Internal.RevisionInternal.GetRevId方法的典型用法代码示例。如果您正苦于以下问题:C# RevisionInternal.GetRevId方法的具体用法?C# RevisionInternal.GetRevId怎么用?C# RevisionInternal.GetRevId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Couchbase.Lite.Internal.RevisionInternal
的用法示例。
在下文中一共展示了RevisionInternal.GetRevId方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestForceInsertEmptyHistory
public void TestForceInsertEmptyHistory()
{
var rev = new RevisionInternal("FakeDocId", "1-abcd", false);
var revProperties = new Dictionary<string, object>();
revProperties.Put("_id", rev.GetDocId());
revProperties.Put("_rev", rev.GetRevId());
revProperties["message"] = "hi";
rev.SetProperties(revProperties);
IList<string> revHistory = null;
database.ForceInsert(rev, revHistory, null);
}
示例2: TestForceInsertEmptyHistory
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public virtual void TestForceInsertEmptyHistory()
{
IList<string> revHistory = null;
RevisionInternal rev = new RevisionInternal("FakeDocId", "1-tango", false, database
);
IDictionary<string, object> revProperties = new Dictionary<string, object>();
revProperties.Put("_id", rev.GetDocId());
revProperties.Put("_rev", rev.GetRevId());
revProperties.Put("message", "hi");
rev.SetProperties(revProperties);
database.ForceInsert(rev, revHistory, null);
}
示例3: Winner
internal RevisionInternal Winner(Int64 docNumericID, String oldWinningRevID, Boolean oldWinnerWasDeletion, RevisionInternal newRev)
{
if (oldWinningRevID == null)
{
return newRev;
}
var newRevID = newRev.GetRevId();
if (!newRev.IsDeleted())
{
if (oldWinnerWasDeletion || RevisionInternal.CBLCompareRevIDs(newRevID, oldWinningRevID) > 0)
{
return newRev;
}
}
else
{
// this is now the winning live revision
if (oldWinnerWasDeletion)
{
if (RevisionInternal.CBLCompareRevIDs(newRevID, oldWinningRevID) > 0)
{
return newRev;
}
}
else
{
// doc still deleted, but this beats previous deletion rev
// Doc was alive. How does this deletion affect the winning rev ID?
var outIsDeleted = new AList<bool>();
var outIsConflict = new AList<bool>();
var winningRevID = WinningRevIDOfDoc(docNumericID, outIsDeleted, outIsConflict);
if (!winningRevID.Equals(oldWinningRevID))
{
if (winningRevID.Equals(newRev.GetRevId()))
{
return newRev;
}
else
{
var deleted = false;
var winningRev = new RevisionInternal(newRev.GetDocId(), winningRevID, deleted, this);
return winningRev;
}
}
}
}
return null;
}
示例4: ChangeWithNewRevision
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);
}
示例5: GetRevisionHistory
/// <summary>Returns an array of TDRevs in reverse chronological order, starting with the given revision.
/// </summary>
/// <remarks>Returns an array of TDRevs in reverse chronological order, starting with the given revision.
/// </remarks>
internal IList<RevisionInternal> GetRevisionHistory(RevisionInternal rev)
{
string docId = rev.GetDocId();
string revId = rev.GetRevId();
Debug.Assert(((docId != null) && (revId != null)));
long docNumericId = GetDocNumericID(docId);
if (docNumericId < 0)
{
return null;
}
else
{
if (docNumericId == 0)
{
return new AList<RevisionInternal>();
}
}
Cursor cursor = null;
IList<RevisionInternal> result;
var args = new [] { Convert.ToString(docNumericId) };
var sql = "SELECT sequence, parent, revid, deleted, json isnull FROM revs WHERE doc_id=? ORDER BY sequence DESC";
try
{
cursor = StorageEngine.RawQuery(sql, args);
cursor.MoveToNext();
long lastSequence = 0;
result = new AList<RevisionInternal>();
while (!cursor.IsAfterLast())
{
var sequence = cursor.GetLong(0);
var parent = cursor.GetLong(1);
bool matches = false;
if (lastSequence == 0)
{
matches = revId.Equals(cursor.GetString(2));
}
else
{
matches = (sequence == lastSequence);
}
if (matches)
{
revId = cursor.GetString(2);
var deleted = (cursor.GetInt(3) > 0);
var missing = (cursor.GetInt(4) > 0);
var aRev = new RevisionInternal(docId, revId, deleted, this);
aRev.SetSequence(sequence);
aRev.SetMissing(missing);
result.AddItem(aRev);
if (parent > -1)
lastSequence = parent;
if (lastSequence == 0)
{
break;
}
}
cursor.MoveToNext();
}
}
catch (SQLException e)
{
Log.E(Tag, "Error getting revision history", e);
return null;
}
finally
{
if (cursor != null)
{
cursor.Close();
}
}
return result;
}
示例6: LoadRevisionBody
//Doesn't handle CouchbaseLiteException
internal RevisionInternal LoadRevisionBody(RevisionInternal rev)
{
if (rev.GetSequence() > 0) {
var props = rev.GetProperties();
if (props != null && props.GetCast<string>("_rev") != null && props.GetCast<string>("_id") != null) {
return rev;
}
}
Debug.Assert(rev.GetDocId() != null && rev.GetRevId() != null);
Storage.LoadRevisionBody(rev);
return rev;
}
示例7: TransformRevision
internal RevisionInternal TransformRevision(RevisionInternal rev)
{
if (RevisionBodyTransformationFunction != null) {
try {
var generation = rev.GetGeneration();
var xformed = RevisionBodyTransformationFunction(rev);
if (xformed == null) {
return null;
}
if (xformed != rev) {
Debug.Assert((xformed.GetDocId().Equals(rev.GetDocId())));
Debug.Assert((xformed.GetRevId().Equals(rev.GetRevId())));
Debug.Assert((xformed.GetProperties().Get("_revisions").Equals(rev.GetProperties().Get("_revisions"))));
if (xformed.GetProperties().ContainsKey("_attachments")) {
// Insert 'revpos' properties into any attachments added by the callback:
var mx = new RevisionInternal(xformed.GetProperties());
xformed = mx;
mx.MutateAttachments((name, info) =>
{
if (info.Get("revpos") != null) {
return info;
}
if (info.Get("data") == null) {
throw new InvalidOperationException("Transformer added attachment without adding data");
}
var newInfo = new Dictionary<string, object>(info);
newInfo["revpos"] = generation;
return newInfo;
});
}
}
} catch (Exception e) {
Log.W(TAG, String.Format("Exception transforming a revision of doc '{0}'", rev.GetDocId()), e);
}
}
return rev;
}
示例8: ChangesDictForRev
/// <summary>
/// Creates a dictionary of metadata for one specific revision
/// </summary>
/// <returns>The metadata dictionary</returns>
/// <param name="rev">The revision to examine</param>
/// <param name="responseState">The current response state</param>
public static IDictionary<string, object> ChangesDictForRev(RevisionInternal rev, DBMonitorCouchbaseResponseState responseState)
{
if (responseState.ChangesIncludeDocs) {
var status = new Status();
var rev2 = DocumentMethods.ApplyOptions(responseState.ContentOptions, rev, responseState.Context, responseState.Db, status);
if (rev2 != null) {
rev2.SetSequence(rev.GetSequence());
rev = rev2;
}
}
return new NonNullDictionary<string, object> {
{ "seq", rev.GetSequence() },
{ "id", rev.GetDocId() },
{ "changes", new List<object> {
new Dictionary<string, object> {
{ "rev", rev.GetRevId() }
}
}
},
{ "deleted", rev.IsDeleted() ? (object)true : null },
{ "doc", responseState.ChangesIncludeDocs ? rev.GetProperties() : null }
};
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:29,代码来源:DatabaseMethods.cs
示例9: GetRevisionSequence
public long GetRevisionSequence(RevisionInternal rev)
{
var retVal = 0L;
WithC4Document(rev.GetDocId(), rev.GetRevId(), false, false, doc => retVal = (long)doc->selectedRev.sequence);
return retVal;
}
示例10: TestLocalDocs
public void TestLocalDocs()
{
//create a document
var documentProperties = new Dictionary<string, object>();
documentProperties["_id"] = "_local/doc1";
documentProperties["foo"] = 1;
documentProperties["bar"] = false;
var body = new Body(documentProperties);
var rev1 = new RevisionInternal(body);
rev1 = database.Storage.PutLocalRevision(rev1, null, true);
Log.V(Tag, "Created " + rev1);
Assert.AreEqual("_local/doc1", rev1.GetDocId());
Assert.IsTrue(rev1.GetRevId().StartsWith("1-"));
//read it back
var readRev = database.Storage.GetLocalDocument(rev1.GetDocId(), null);
Assert.IsNotNull(readRev);
var readRevProps = readRev.GetProperties();
Assert.AreEqual(rev1.GetDocId(), readRevProps.Get("_id"));
Assert.AreEqual(rev1.GetRevId(), readRevProps.Get("_rev"));
AssertPropertiesAreEqual(UserProperties(readRevProps),
UserProperties(body.GetProperties()));
//now update it
documentProperties = (Dictionary<string, object>)readRev.GetProperties();
documentProperties["status"] = "updated!";
body = new Body(documentProperties);
var rev2 = new RevisionInternal(body);
var rev2input = rev2;
rev2 = database.Storage.PutLocalRevision(rev2, rev1.GetRevId(), true);
Log.V(Tag, "Updated " + rev1);
Assert.AreEqual(rev1.GetDocId(), rev2.GetDocId());
Assert.IsTrue(rev2.GetRevId().StartsWith("2-"));
//read it back
readRev = database.Storage.GetLocalDocument(rev2.GetDocId(), null);
Assert.IsNotNull(readRev);
AssertPropertiesAreEqual(UserProperties(readRev.GetProperties()),
UserProperties(body.GetProperties()));
// Try to update the first rev, which should fail:
var gotException = false;
try
{
database.Storage.PutLocalRevision(rev2input, rev1.GetRevId(), true);
}
catch (CouchbaseLiteException e)
{
Assert.AreEqual(StatusCode.Conflict, e.CBLStatus.Code);
gotException = true;
}
Assert.IsTrue(gotException);
// Delete it:
var revD = new RevisionInternal(rev2.GetDocId(), null, true);
gotException = false;
try
{
var revResult = database.Storage.PutLocalRevision(revD, null, true);
Assert.IsNull(revResult);
}
catch (CouchbaseLiteException e)
{
Assert.AreEqual(StatusCode.Conflict, e.CBLStatus.Code);
gotException = true;
}
Assert.IsTrue(gotException);
revD = database.Storage.PutLocalRevision(revD, rev2.GetRevId(), true);
// Delete nonexistent doc:
gotException = false;
var revFake = new RevisionInternal("_local/fake", null, true);
try
{
database.Storage.PutLocalRevision(revFake, null, true);
}
catch (CouchbaseLiteException e)
{
Assert.AreEqual(StatusCode.NotFound, e.CBLStatus.Code);
gotException = true;
}
Assert.IsTrue(gotException);
// Read it back (should fail):
readRev = database.Storage.GetLocalDocument(revD.GetDocId(), null);
Assert.IsNull(readRev);
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:87,代码来源:LocalDocsTest.cs
示例11: TestRevTreeChangeNotification
public void TestRevTreeChangeNotification()
{
const string DOCUMENT_ID = "MyDocId";
var rev = new RevisionInternal(DOCUMENT_ID, "1-abcd", false);
var revProperties = new Dictionary<string, object>();
revProperties["_id"] = rev.GetDocId();
revProperties["_rev"] = rev.GetRevId();
revProperties["message"] = "hi";
rev.SetProperties(revProperties);
var revHistory = new List<string>();
revHistory.Add(rev.GetRevId());
EventHandler<DatabaseChangeEventArgs> handler = (sender, e) =>
{
var changes = e.Changes.ToList();
Assert.AreEqual(1, changes.Count);
var change = changes[0];
Assert.AreEqual(DOCUMENT_ID, change.DocumentId);
Assert.AreEqual(rev.GetRevId(), change.RevisionId);
Assert.IsTrue(change.IsCurrentRevision);
Assert.IsFalse(change.IsConflict);
var current = database.GetDocument(change.DocumentId).CurrentRevision;
Assert.AreEqual(rev.GetRevId(), current.Id);
};
database.Changed += handler;
database.ForceInsert(rev, revHistory, null);
database.Changed -= handler;
// add two more revisions to the document
var rev3 = new RevisionInternal(DOCUMENT_ID, "3-abcd", false);
var rev3Properties = new Dictionary<string, object>();
rev3Properties["_id"] = rev3.GetDocId();
rev3Properties["_rev"] = rev3.GetRevId();
rev3Properties["message"] = "hi again";
rev3.SetProperties(rev3Properties);
var rev3History = new List<string>();
rev3History.Add(rev3.GetRevId());
rev3History.Add("2-abcd");
rev3History.Add(rev.GetRevId());
handler = (sender, e) =>
{
var changes = e.Changes.ToList();
Assert.AreEqual(1, changes.Count);
var change = changes[0];
Assert.AreEqual(DOCUMENT_ID, change.DocumentId);
Assert.AreEqual(rev3.GetRevId(), change.RevisionId);
Assert.IsTrue(change.IsCurrentRevision);
Assert.IsFalse(change.IsConflict);
var doc = database.GetDocument(change.DocumentId);
Assert.AreEqual(rev3.GetRevId(), doc.CurrentRevisionId);
try
{
Assert.AreEqual(3, doc.RevisionHistory.ToList().Count);
}
catch (CouchbaseLiteException)
{
Assert.Fail();
}
};
database.Changed += handler;
database.ForceInsert(rev3, rev3History, null);
database.Changed -= handler;
// add a conflicting revision, with the same history length as the last revision we
// inserted. Since this new revision's revID has a higher ASCII sort, it should become the
// new winning revision.
var conflictRev = new RevisionInternal(DOCUMENT_ID, "3-bcde", false);
var conflictProperties = new Dictionary<string, object>();
conflictProperties["_id"] = conflictRev.GetDocId();
conflictProperties["_rev"] = conflictRev.GetRevId();
conflictProperties["message"] = "winner";
conflictRev.SetProperties(conflictProperties);
var conflictRevHistory = new List<string>();
conflictRevHistory.Add(conflictRev.GetRevId());
conflictRevHistory.Add("2-abcd");
conflictRevHistory.Add(rev.GetRevId());
handler = (sender, e) =>
{
var changes = e.Changes.ToList();
Assert.AreEqual(1, changes.Count);
var change = changes[0];
Assert.AreEqual(DOCUMENT_ID, change.DocumentId);
Assert.AreEqual(conflictRev.GetRevId(), change.RevisionId);
Assert.IsTrue(change.IsCurrentRevision);
Assert.IsFalse(change.IsConflict);
var doc = database.GetDocument(change.DocumentId);
Assert.AreEqual(rev3.GetRevId(), doc.CurrentRevisionId);
try
{
//.........这里部分代码省略.........
示例12: GetRevisionHistory
public IList<RevisionInternal> GetRevisionHistory(RevisionInternal rev, ICollection<string> ancestorRevIds)
{
var history = new List<RevisionInternal>();
WithC4Document(rev.GetDocId(), rev.GetRevId(), false, false, doc =>
{
var enumerator = new CBForestHistoryEnumerator(doc, false);
foreach(var next in enumerator) {
if(ancestorRevIds != null && ancestorRevIds.Contains((string)next.Document->selectedRev.revID)) {
break;
}
var newRev = new RevisionInternal(next.Document, false);
newRev.SetMissing(!Native.c4doc_hasRevisionBody(next.Document));
history.Add(newRev);
}
});
return history;
}
示例13: TestLocalDocs
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public virtual void TestLocalDocs()
{
//create a document
IDictionary<string, object> documentProperties = new Dictionary<string, object>();
documentProperties.Put("_id", "_local/doc1");
documentProperties.Put("foo", 1);
documentProperties.Put("bar", false);
Body body = new Body(documentProperties);
RevisionInternal rev1 = new RevisionInternal(body, database);
Status status = new Status();
rev1 = database.PutLocalRevision(rev1, null);
Log.V(Tag, "Created " + rev1);
NUnit.Framework.Assert.AreEqual("_local/doc1", rev1.GetDocId());
NUnit.Framework.Assert.IsTrue(rev1.GetRevId().StartsWith("1-"));
//read it back
RevisionInternal readRev = database.GetLocalDocument(rev1.GetDocId(), null);
NUnit.Framework.Assert.IsNotNull(readRev);
IDictionary<string, object> readRevProps = readRev.GetProperties();
NUnit.Framework.Assert.AreEqual(rev1.GetDocId(), readRev.GetProperties().Get("_id"
));
NUnit.Framework.Assert.AreEqual(rev1.GetRevId(), readRev.GetProperties().Get("_rev"
));
NUnit.Framework.Assert.AreEqual(UserProperties(readRevProps), UserProperties(body
.GetProperties()));
//now update it
documentProperties = readRev.GetProperties();
documentProperties.Put("status", "updated!");
body = new Body(documentProperties);
RevisionInternal rev2 = new RevisionInternal(body, database);
RevisionInternal rev2input = rev2;
rev2 = database.PutLocalRevision(rev2, rev1.GetRevId());
Log.V(Tag, "Updated " + rev1);
NUnit.Framework.Assert.AreEqual(rev1.GetDocId(), rev2.GetDocId());
NUnit.Framework.Assert.IsTrue(rev2.GetRevId().StartsWith("2-"));
//read it back
readRev = database.GetLocalDocument(rev2.GetDocId(), null);
NUnit.Framework.Assert.IsNotNull(readRev);
NUnit.Framework.Assert.AreEqual(UserProperties(readRev.GetProperties()), UserProperties
(body.GetProperties()));
// Try to update the first rev, which should fail:
bool gotException = false;
try
{
database.PutLocalRevision(rev2input, rev1.GetRevId());
}
catch (CouchbaseLiteException e)
{
NUnit.Framework.Assert.AreEqual(Status.Conflict, e.GetCBLStatus().GetCode());
gotException = true;
}
NUnit.Framework.Assert.IsTrue(gotException);
// Delete it:
RevisionInternal revD = new RevisionInternal(rev2.GetDocId(), null, true, database
);
gotException = false;
try
{
RevisionInternal revResult = database.PutLocalRevision(revD, null);
NUnit.Framework.Assert.IsNull(revResult);
}
catch (CouchbaseLiteException e)
{
NUnit.Framework.Assert.AreEqual(Status.Conflict, e.GetCBLStatus().GetCode());
gotException = true;
}
NUnit.Framework.Assert.IsTrue(gotException);
revD = database.PutLocalRevision(revD, rev2.GetRevId());
// Delete nonexistent doc:
gotException = false;
RevisionInternal revFake = new RevisionInternal("_local/fake", null, true, database
);
try
{
database.PutLocalRevision(revFake, null);
}
catch (CouchbaseLiteException e)
{
NUnit.Framework.Assert.AreEqual(Status.NotFound, e.GetCBLStatus().GetCode());
gotException = true;
}
NUnit.Framework.Assert.IsTrue(gotException);
// Read it back (should fail):
readRev = database.GetLocalDocument(revD.GetDocId(), null);
NUnit.Framework.Assert.IsNull(readRev);
}
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:86,代码来源:LocalDocsTest.cs
示例14: FindCommonAncestor
public string FindCommonAncestor(RevisionInternal rev, IEnumerable<string> revIds)
{
var generation = RevisionInternal.GenerationFromRevID(rev.GetRevId());
var revIdArray = revIds == null ? null : revIds.ToList();
if (generation <= 1 || revIdArray == null || revIdArray.Count == 0) {
return null;
}
revIdArray.Sort(RevisionInternal.CBLCompareRevIDs);
var commonAncestor = default(string);
WithC4Document(rev.GetDocId(), null, false, false, doc =>
{
foreach(var possibleRevId in revIds) {
if(RevisionInternal.GenerationFromRevID(possibleRevId) <= generation &&
Native.c4doc_selectRevision(doc, possibleRevId, false, null)) {
commonAncestor = possibleRevId;
return;
}
}
});
return commonAncestor;
}
示例15: GetPossibleAncestors
public IEnumerable<string> GetPossibleAncestors(RevisionInternal rev, int limit, bool onlyAttachments)
{
var returnedCount = 0;
var generation = RevisionInternal.GenerationFromRevID(rev.GetRevId());
var enumerator = GetHistoryEnumerator(rev, generation);
if(enumerator == null) {
yield break;
}
foreach (var next in enumerator) {
if(returnedCount >= limit) {
break;
}
var revId = next.CurrentRevID;
if(RevisionInternal.GenerationFromRevID(revId) < generation &&
!next.SelectedRev.IsDeleted && next.HasRevisionBody &&
!(onlyAttachments && !next.SelectedRev.HasAttachments)) {
returnedCount++;
yield return revId;
}
}
}