本文整理汇总了C#中System.Collections.Dictionary.Put方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.Put方法的具体用法?C# Dictionary.Put怎么用?C# Dictionary.Put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.Put方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: TestCreateDocument
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public virtual void TestCreateDocument()
{
IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Put("testName", "testCreateDocument");
properties.Put("tag", 1337);
Database db = StartDatabase();
Document doc = CreateDocumentWithProperties(db, properties);
string docID = doc.GetId();
NUnit.Framework.Assert.IsTrue("Invalid doc ID: " + docID, docID.Length > 10);
string currentRevisionID = doc.GetCurrentRevisionId();
NUnit.Framework.Assert.IsTrue("Invalid doc revision: " + docID, currentRevisionID
.Length > 10);
NUnit.Framework.Assert.AreEqual(doc.GetUserProperties(), properties);
NUnit.Framework.Assert.AreEqual(db.GetDocument(docID), doc);
db.ClearDocumentCache();
// so we can load fresh copies
Document doc2 = db.GetExistingDocument(docID);
NUnit.Framework.Assert.AreEqual(doc2.GetId(), docID);
NUnit.Framework.Assert.AreEqual(doc2.GetCurrentRevisionId(), currentRevisionID);
NUnit.Framework.Assert.IsNull(db.GetExistingDocument("b0gus"));
}
示例3: MakeRevisionHistoryDict
public static IDictionary<string, object> MakeRevisionHistoryDict(IList<RevisionInternal
> history)
{
if (history == null)
{
return null;
}
// Try to extract descending numeric prefixes:
IList<string> suffixes = new AList<string>();
int start = -1;
int lastRevNo = -1;
foreach (RevisionInternal rev in history)
{
int revNo = ParseRevIDNumber(rev.GetRevId());
string suffix = ParseRevIDSuffix(rev.GetRevId());
if (revNo > 0 && suffix.Length > 0)
{
if (start < 0)
{
start = revNo;
}
else
{
if (revNo != lastRevNo - 1)
{
start = -1;
break;
}
}
lastRevNo = revNo;
suffixes.AddItem(suffix);
}
else
{
start = -1;
break;
}
}
IDictionary<string, object> result = new Dictionary<string, object>();
if (start == -1)
{
// we failed to build sequence, just stuff all the revs in list
suffixes = new AList<string>();
foreach (RevisionInternal rev_1 in history)
{
suffixes.AddItem(rev_1.GetRevId());
}
}
else
{
result.Put("start", start);
}
result.Put("ids", suffixes);
return result;
}
示例4: TestPushPurgedDoc
public void TestPushPurgedDoc()
{
if (!Boolean.Parse((string)Runtime.Properties["replicationTestsEnabled"]))
{
Assert.Inconclusive("Replication tests disabled.");
return;
}
var numBulkDocRequests = 0;
HttpRequestMessage lastBulkDocsRequest = null;
var doc = CreateDocumentWithProperties(
database,
new Dictionary<string, object>
{
{"testName", "testPurgeDocument"}
}
);
Assert.IsNotNull(doc);
using (var remoteDb = _sg.CreateDatabase(TempDbName())) {
var remote = remoteDb.RemoteUri;
var factory = new MockHttpClientFactory();
factory.HttpHandler.ClearResponders();
factory.HttpHandler.AddResponderRevDiffsAllMissing();
factory.HttpHandler.AddResponderFakeLocalDocumentUpdate404();
factory.HttpHandler.AddResponderFakeBulkDocs();
manager.DefaultHttpClientFactory = factory;
var pusher = database.CreatePushReplication(remote);
var replicationCaughtUpSignal = new CountdownEvent(1);
pusher.Changed += (sender, e) =>
{
var changesCount = e.Source.ChangesCount;
var completedChangesCount = e.Source.CompletedChangesCount;
var msg = "changes: {0} completed changes: {1}".Fmt(changesCount, completedChangesCount);
Log.D(Tag, msg);
if (changesCount > 0 && changesCount == completedChangesCount
&& replicationCaughtUpSignal.CurrentCount > 0) {
replicationCaughtUpSignal.Signal();
}
};
pusher.Start();
// wait until that doc is pushed
var didNotTimeOut = replicationCaughtUpSignal.Wait(TimeSpan.FromSeconds(15));
Assert.IsTrue(didNotTimeOut);
// at this point, we should have captured exactly 1 bulk docs request
numBulkDocRequests = 0;
var handler = factory.HttpHandler;
foreach (var capturedRequest in handler.CapturedRequests) {
if (capturedRequest.Method == HttpMethod.Post && capturedRequest.RequestUri.AbsoluteUri.EndsWith("_bulk_docs", StringComparison.Ordinal)) {
lastBulkDocsRequest = capturedRequest;
numBulkDocRequests++;
}
}
Assert.AreEqual(1, numBulkDocRequests);
// that bulk docs request should have the "start" key under its _revisions
var jsonMap = MockHttpRequestHandler.GetJsonMapFromRequest(lastBulkDocsRequest);
var docs = (jsonMap.Get("docs")).AsList<IDictionary<string,object>>();
var onlyDoc = docs[0];
var revisions = onlyDoc.Get("_revisions").AsDictionary<string,object>();
Assert.IsTrue(revisions.ContainsKey("start"));
// Reset for the next attempt.
handler.ClearCapturedRequests();
// now add a new revision, which will trigger the pusher to try to push it
var properties = new Dictionary<string, object>();
properties.Put("testName2", "update doc");
var unsavedRevision = doc.CreateRevision();
unsavedRevision.SetUserProperties(properties);
unsavedRevision.Save();
// but then immediately purge it
doc.Purge();
pusher.Start();
// wait for a while to give the replicator a chance to push it
// (it should not actually push anything)
Sleep(5 * 1000);
// we should not have gotten any more _bulk_docs requests, because
// the replicator should not have pushed anything else.
// (in the case of the bug, it was trying to push the purged revision)
numBulkDocRequests = 0;
foreach (var capturedRequest in handler.CapturedRequests) {
if (capturedRequest.Method == HttpMethod.Post && capturedRequest.RequestUri.AbsoluteUri.EndsWith("_bulk_docs", StringComparison.Ordinal)) {
numBulkDocRequests++;
}
}
Assert.AreEqual(0, numBulkDocRequests);
//.........这里部分代码省略.........
示例5: ParseSourceOrTarget
private IDictionary<string, object> ParseSourceOrTarget(IDictionary<string, object
> properties, string key)
{
IDictionary<string, object> result = new Dictionary<string, object>();
object value = properties.Get(key);
if (value is string)
{
result.Put("url", (string)value);
}
else
{
if (value is IDictionary)
{
result = (IDictionary<string, object>)value;
}
}
return result;
}
示例6: PruneRevsToMaxDepth
internal int PruneRevsToMaxDepth(int maxDepth)
{
int outPruned = 0;
bool shouldCommit = false;
IDictionary<long, int> toPrune = new Dictionary<long, int>();
if (maxDepth == 0)
{
maxDepth = MaxRevTreeDepth;
}
// First find which docs need pruning, and by how much:
Cursor cursor = null;
var sql = "SELECT doc_id, MIN(revid), MAX(revid) FROM revs GROUP BY doc_id";
long docNumericID = -1;
var minGen = 0;
var maxGen = 0;
try
{
cursor = StorageEngine.RawQuery(sql);
while (cursor.MoveToNext())
{
docNumericID = cursor.GetLong(0);
var minGenRevId = cursor.GetString(1);
var maxGenRevId = cursor.GetString(2);
minGen = RevisionInternal.GenerationFromRevID(minGenRevId);
maxGen = RevisionInternal.GenerationFromRevID(maxGenRevId);
if ((maxGen - minGen + 1) > maxDepth)
{
toPrune.Put(docNumericID, (maxGen - minGen));
}
}
BeginTransaction();
if (toPrune.Count == 0)
{
return 0;
}
foreach (long id in toPrune.Keys)
{
string minIDToKeep = String.Format("{0}-", (toPrune.Get(id) + 1));
string[] deleteArgs = new string[] { System.Convert.ToString(docNumericID), minIDToKeep };
int rowsDeleted = StorageEngine.Delete("revs", "doc_id=? AND revid < ? AND current=0", deleteArgs);
outPruned += rowsDeleted;
}
shouldCommit = true;
}
catch (Exception e)
{
throw new CouchbaseLiteException(e, StatusCode.InternalServerError);
}
finally
{
EndTransaction(shouldCommit);
if (cursor != null)
{
cursor.Close();
}
}
return outPruned;
}
示例7: EncodeDocumentJSON
/// <summary>INSERTION:</summary>
internal IEnumerable<Byte> EncodeDocumentJSON(RevisionInternal rev)
{
var origProps = rev.GetProperties();
if (origProps == null)
{
return null;
}
var specialKeysToLeave = new[] { "_removed", "_replication_id", "_replication_state", "_replication_state_time" };
// Don't allow any "_"-prefixed keys. Known ones we'll ignore, unknown ones are an error.
var properties = new Dictionary<String, Object>(origProps.Count);
foreach (var key in origProps.Keys)
{
var shouldAdd = false;
if (key.StartsWith("_", StringComparison.InvariantCultureIgnoreCase))
{
if (!KnownSpecialKeys.Contains(key))
{
Log.E(Tag, "Database: Invalid top-level key '" + key + "' in document to be inserted");
return null;
}
if (specialKeysToLeave.Contains(key))
{
shouldAdd = true;
}
}
else
{
shouldAdd = true;
}
if (shouldAdd)
{
properties.Put(key, origProps.Get(key));
}
}
IEnumerable<byte> json = null;
try
{
json = Manager.GetObjectMapper().WriteValueAsBytes(properties);
}
catch (Exception e)
{
Log.E(Tag, "Error serializing " + rev + " to JSON", e);
}
return json;
}
示例8: StubOutAttachmentsInRevBeforeRevPos
// Replaces attachment data whose revpos is < minRevPos with stubs.
// If attachmentsFollow==YES, replaces data with "follows" key.
private static void StubOutAttachmentsInRevBeforeRevPos(RevisionInternal rev, int minRevPos, bool attachmentsFollow)
{
if (minRevPos <= 1 && !attachmentsFollow)
{
return;
}
rev.MutateAttachments((s, attachment)=>
{
var revPos = 0;
if (attachment.Get("revpos") != null)
{
revPos = (int)attachment.Get("revpos");
}
var includeAttachment = (revPos == 0 || revPos >= minRevPos);
var stubItOut = !includeAttachment && (attachment.Get("stub") == null || (bool)attachment.Get("stub") == false);
var addFollows = includeAttachment && attachmentsFollow && (attachment.Get("follows") == null || !(bool)attachment.Get ("follows"));
if (!stubItOut && !addFollows)
{
return attachment;
}
// no change
// Need to modify attachment entry:
var editedAttachment = new Dictionary<string, object>(attachment);
editedAttachment.Remove("data");
if (stubItOut)
{
// ...then remove the 'data' and 'follows' key:
editedAttachment.Remove("follows");
editedAttachment.Put("stub", true);
Log.V(Tag, "Stubbed out attachment {0}: revpos {1} < {2}".Fmt(rev, revPos, minRevPos));
}
else
{
if (addFollows)
{
editedAttachment.Remove("stub");
editedAttachment.Put("follows", true);
Log.V(Tag, "Added 'follows' for attachment {0}: revpos {1} >= {2}".Fmt(rev, revPos, minRevPos));
}
}
return editedAttachment;
});
}
示例9: ExtraPropertiesForRevision
/// <summary>Inserts the _id, _rev and _attachments properties into the JSON data and stores it in rev.
/// </summary>
/// <remarks>
/// Inserts the _id, _rev and _attachments properties into the JSON data and stores it in rev.
/// Rev must already have its revID and sequence properties set.
/// </remarks>
internal IDictionary<String, Object> ExtraPropertiesForRevision(RevisionInternal rev, DocumentContentOptions contentOptions)
{
var docId = rev.GetDocId();
var revId = rev.GetRevId();
var sequenceNumber = rev.GetSequence();
Debug.Assert((revId != null));
Debug.Assert((sequenceNumber > 0));
// Get attachment metadata, and optionally the contents:
IDictionary<string, object> attachmentsDict = null;
if (!contentOptions.HasFlag(DocumentContentOptions.NoAttachments))
{
attachmentsDict = GetAttachmentsDictForSequenceWithContent (sequenceNumber, contentOptions);
}
// Get more optional stuff to put in the properties:
//OPT: This probably ends up making redundant SQL queries if multiple options are enabled.
var localSeq = -1L;
if (contentOptions.HasFlag(DocumentContentOptions.IncludeLocalSeq))
{
localSeq = sequenceNumber;
}
IDictionary<string, object> revHistory = null;
if (contentOptions.HasFlag(DocumentContentOptions.IncludeRevs))
{
revHistory = GetRevisionHistoryDict(rev);
}
IList<object> revsInfo = null;
if (contentOptions.HasFlag(DocumentContentOptions.IncludeRevsInfo))
{
revsInfo = new AList<object>();
var revHistoryFull = GetRevisionHistory(rev);
foreach (RevisionInternal historicalRev in revHistoryFull)
{
var revHistoryItem = new Dictionary<string, object>();
var status = "available";
if (historicalRev.IsDeleted())
{
status = "deleted";
}
if (historicalRev.IsMissing())
{
status = "missing";
}
revHistoryItem.Put("rev", historicalRev.GetRevId());
revHistoryItem["status"] = status;
revsInfo.AddItem(revHistoryItem);
}
}
IList<string> conflicts = null;
if (contentOptions.HasFlag(DocumentContentOptions.IncludeConflicts))
{
var revs = GetAllRevisionsOfDocumentID(docId, true);
if (revs.Count > 1)
{
conflicts = new AList<string>();
foreach (RevisionInternal savedRev in revs)
{
if (!(savedRev.Equals(rev) || savedRev.IsDeleted()))
{
conflicts.AddItem(savedRev.GetRevId());
}
}
}
}
var result = new Dictionary<string, object>();
result["_id"] = docId;
result["_rev"] = revId;
if (rev.IsDeleted())
{
result["_deleted"] = true;
}
if (attachmentsDict != null)
{
result["_attachments"] = attachmentsDict;
}
if (localSeq > -1)
{
result["_local_seq"] = localSeq;
}
if (revHistory != null)
{
result["_revisions"] = revHistory;
}
if (revsInfo != null)
{
result["_revs_info"] = revsInfo;
}
if (conflicts != null)
//.........这里部分代码省略.........
示例10: TestRevTreeChangeNotifications
/// <summary>
/// Test that the public API works as expected in change notifications after a rev tree
/// insertion.
/// </summary>
/// <remarks>
/// Test that the public API works as expected in change notifications after a rev tree
/// insertion. See https://github.com/couchbase/couchbase-lite-android-core/pull/27
/// </remarks>
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public virtual void TestRevTreeChangeNotifications()
{
string DocumentId = "MyDocId";
// add a document with a single (first) revision
RevisionInternal rev = new RevisionInternal(DocumentId, "1-one", 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);
IList<string> revHistory = Arrays.AsList(rev.GetRevId());
Database.ChangeListener listener = new _ChangeListener_154(this, DocumentId, rev);
database.AddChangeListener(listener);
database.ForceInsert(rev, revHistory, null);
database.RemoveChangeListener(listener);
// add two more revisions to the document
RevisionInternal rev3 = new RevisionInternal(DocumentId, "3-three", false, database
);
IDictionary<string, object> rev3Properties = new Dictionary<string, object>();
rev3Properties.Put("_id", rev3.GetDocId());
rev3Properties.Put("_rev", rev3.GetRevId());
rev3Properties.Put("message", "hi again");
rev3.SetProperties(rev3Properties);
IList<string> rev3History = Arrays.AsList(rev3.GetRevId(), "2-two", rev.GetRevId(
));
listener = new _ChangeListener_182(this, DocumentId, rev3);
database.AddChangeListener(listener);
database.ForceInsert(rev3, rev3History, null);
database.RemoveChangeListener(listener);
// 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.
RevisionInternal conflictRev = new RevisionInternal(DocumentId, "3-winner", false
, database);
IDictionary<string, object> conflictProperties = new Dictionary<string, object>();
conflictProperties.Put("_id", conflictRev.GetDocId());
conflictProperties.Put("_rev", conflictRev.GetRevId());
conflictProperties.Put("message", "winner");
conflictRev.SetProperties(conflictProperties);
IList<string> conflictRevHistory = Arrays.AsList(conflictRev.GetRevId(), "2-two",
rev.GetRevId());
listener = new _ChangeListener_217(this, DocumentId, conflictRev);
database.AddChangeListener(listener);
database.ForceInsert(conflictRev, conflictRevHistory, null);
database.RemoveChangeListener(listener);
}
示例11: GetAttachmentsFromRevision
internal IDictionary<string, AttachmentInternal> GetAttachmentsFromRevision(RevisionInternal
rev)
{
IDictionary<string, object> revAttachments = (IDictionary<string, object>)rev.GetPropertyForKey
("_attachments");
if (revAttachments == null || revAttachments.Count == 0 || rev.IsDeleted())
{
return new Dictionary<string, AttachmentInternal>();
}
IDictionary<string, AttachmentInternal> attachments = new Dictionary<string, AttachmentInternal
>();
foreach (string name in revAttachments.Keys)
{
IDictionary<string, object> attachInfo = (IDictionary<string, object>)revAttachments
.Get(name);
string contentType = (string)attachInfo.Get("content_type");
AttachmentInternal attachment = new AttachmentInternal(name, contentType);
string newContentBase64 = (string)attachInfo.Get("data");
if (newContentBase64 != null)
{
// If there's inline attachment data, decode and store it:
byte[] newContents;
try
{
newContents = Base64.Decode(newContentBase64);
}
catch (IOException e)
{
throw new CouchbaseLiteException(e, Status.BadEncoding);
}
attachment.SetLength(newContents.Length);
BlobKey outBlobKey = new BlobKey();
bool storedBlob = GetAttachments().StoreBlob(newContents, outBlobKey);
attachment.SetBlobKey(outBlobKey);
if (!storedBlob)
{
throw new CouchbaseLiteException(Status.StatusAttachmentError);
}
}
else
{
if (attachInfo.ContainsKey("follows") && ((bool)attachInfo.Get("follows")) == true)
{
// "follows" means the uploader provided the attachment in a separate MIME part.
// This means it's already been registered in _pendingAttachmentsByDigest;
// I just need to look it up by its "digest" property and install it into the store:
InstallAttachment(attachment, attachInfo);
}
else
{
// This item is just a stub; validate and skip it
if (((bool)attachInfo.Get("stub")) == false)
{
throw new CouchbaseLiteException("Expected this attachment to be a stub", Status.
BadAttachment);
}
int revPos = ((int)attachInfo.Get("revpos"));
if (revPos <= 0)
{
throw new CouchbaseLiteException("Invalid revpos: " + revPos, Status.BadAttachment
);
}
continue;
}
}
// Handle encoded attachment:
string encodingStr = (string)attachInfo.Get("encoding");
if (encodingStr != null && encodingStr.Length > 0)
{
if (Sharpen.Runtime.EqualsIgnoreCase(encodingStr, "gzip"))
{
attachment.SetEncoding(AttachmentInternal.AttachmentEncoding.AttachmentEncodingGZIP
);
}
else
{
throw new CouchbaseLiteException("Unnkown encoding: " + encodingStr, Status.BadEncoding
);
}
attachment.SetEncodedLength(attachment.GetLength());
if (attachInfo.ContainsKey("length"))
{
Number attachmentLength = (Number)attachInfo.Get("length");
attachment.SetLength(attachmentLength);
}
}
if (attachInfo.ContainsKey("revpos"))
{
attachment.SetRevpos((int)attachInfo.Get("revpos"));
}
else
{
attachment.SetRevpos(1);
}
attachments.Put(name, attachment);
}
return attachments;
}
示例12: EncodeDocumentJSON
public byte[] EncodeDocumentJSON(RevisionInternal rev)
{
IDictionary<string, object> origProps = rev.GetProperties();
if (origProps == null)
{
return null;
}
// Don't allow any "_"-prefixed keys. Known ones we'll ignore, unknown ones are an error.
IDictionary<string, object> properties = new Dictionary<string, object>(origProps
.Count);
foreach (string key in origProps.Keys)
{
if (key.StartsWith("_"))
{
if (!KnownSpecialKeys.Contains(key))
{
Log.E(Tag, "Database: Invalid top-level key '" + key + "' in document to be inserted"
);
return null;
}
}
else
{
properties.Put(key, origProps.Get(key));
}
}
byte[] json = null;
try
{
json = Manager.GetObjectMapper().WriteValueAsBytes(properties);
}
catch (Exception e)
{
Log.E(Database.Tag, "Error serializing " + rev + " to JSON", e);
}
return json;
}
示例13: StubOutAttachmentsIn
public void StubOutAttachmentsIn(RevisionInternal rev, int minRevPos)
{
if (minRevPos <= 1)
{
return;
}
IDictionary<string, object> properties = (IDictionary<string, object>)rev.GetProperties
();
IDictionary<string, object> attachments = null;
if (properties != null)
{
attachments = (IDictionary<string, object>)properties.Get("_attachments");
}
IDictionary<string, object> editedProperties = null;
IDictionary<string, object> editedAttachments = null;
foreach (string name in attachments.Keys)
{
IDictionary<string, object> attachment = (IDictionary<string, object>)attachments
.Get(name);
int revPos = (int)attachment.Get("revpos");
object stub = attachment.Get("stub");
if (revPos > 0 && revPos < minRevPos && (stub == null))
{
// Strip this attachment's body. First make its dictionary mutable:
if (editedProperties == null)
{
editedProperties = new Dictionary<string, object>(properties);
editedAttachments = new Dictionary<string, object>(attachments);
editedProperties.Put("_attachments", editedAttachments);
}
// ...then remove the 'data' and 'follows' key:
IDictionary<string, object> editedAttachment = new Dictionary<string, object>(attachment
);
Sharpen.Collections.Remove(editedAttachment, "data");
Sharpen.Collections.Remove(editedAttachment, "follows");
editedAttachment.Put("stub", true);
editedAttachments.Put(name, editedAttachment);
Log.D(Database.Tag, "Stubbed out attachment" + rev + " " + name + ": revpos" + revPos
+ " " + minRevPos);
}
}
if (editedProperties != null)
{
rev.SetProperties(editedProperties);
}
}
示例14: GetAttachmentsDictForSequenceWithContent
public IDictionary<string, object> GetAttachmentsDictForSequenceWithContent(long
sequence, EnumSet<Database.TDContentOptions> contentOptions)
{
System.Diagnostics.Debug.Assert((sequence > 0));
Cursor cursor = null;
string[] args = new string[] { System.Convert.ToString(sequence) };
try
{
cursor = database.RawQuery("SELECT filename, key, type, length, revpos FROM attachments WHERE sequence=?"
, args);
if (!cursor.MoveToNext())
{
return null;
}
IDictionary<string, object> result = new Dictionary<string, object>();
while (!cursor.IsAfterLast())
{
bool dataSuppressed = false;
int length = cursor.GetInt(3);
byte[] keyData = cursor.GetBlob(1);
BlobKey key = new BlobKey(keyData);
string digestString = "sha1-" + Base64.EncodeBytes(keyData);
string dataBase64 = null;
if (contentOptions.Contains(Database.TDContentOptions.TDIncludeAttachments))
{
if (contentOptions.Contains(Database.TDContentOptions.TDBigAttachmentsFollow) &&
length >= Database.kBigAttachmentLength)
{
dataSuppressed = true;
}
else
{
byte[] data = attachments.BlobForKey(key);
if (data != null)
{
dataBase64 = Base64.EncodeBytes(data);
}
else
{
// <-- very expensive
Log.W(Database.Tag, "Error loading attachment");
}
}
}
IDictionary<string, object> attachment = new Dictionary<string, object>();
if (dataBase64 == null || dataSuppressed == true)
{
attachment.Put("stub", true);
}
if (dataBase64 != null)
{
attachment.Put("data", dataBase64);
}
if (dataSuppressed == true)
{
attachment.Put("follows", true);
}
attachment.Put("digest", digestString);
string contentType = cursor.GetString(2);
attachment.Put("content_type", contentType);
attachment.Put("length", length);
attachment.Put("revpos", cursor.GetInt(4));
string filename = cursor.GetString(0);
result.Put(filename, attachment);
cursor.MoveToNext();
}
return result;
}
catch (SQLException e)
{
Log.E(Database.Tag, "Error getting attachments for sequence", e);
return null;
}
finally
{
if (cursor != null)
{
cursor.Close();
}
}
}
示例15: GetAllDocs
//.........这里部分代码省略.........
string revId = cursor.GetString(2);
long sequenceNumber = cursor.GetLong(3);
bool deleted = includeDeletedDocs && cursor.GetInt(GetDeletedColumnIndex(options)
) > 0;
IDictionary<string, object> docContents = null;
if (options.IsIncludeDocs())
{
byte[] json = cursor.GetBlob(4);
docContents = DocumentPropertiesFromJSON(json, docId, revId, deleted, sequenceNumber
, options.GetContentOptions());
}
// Iterate over following rows with the same doc_id -- these are conflicts.
// Skip them, but collect their revIDs if the 'conflicts' option is set:
IList<string> conflicts = new AList<string>();
while (((keepGoing = cursor.MoveToNext()) == true) && cursor.GetLong(0) == docNumericID
)
{
if (options.GetAllDocsMode() == Query.AllDocsMode.ShowConflicts || options.GetAllDocsMode
() == Query.AllDocsMode.OnlyConflicts)
{
if (conflicts.IsEmpty())
{
conflicts.AddItem(revId);
}
conflicts.AddItem(cursor.GetString(2));
}
}
if (options.GetAllDocsMode() == Query.AllDocsMode.OnlyConflicts && conflicts.IsEmpty
())
{
continue;
}
IDictionary<string, object> value = new Dictionary<string, object>();
value.Put("rev", revId);
value.Put("_conflicts", conflicts);
if (includeDeletedDocs)
{
value.Put("deleted", (deleted ? true : null));
}
QueryRow change = new QueryRow(docId, sequenceNumber, docId, value, docContents);
change.SetDatabase(this);
if (options.GetKeys() != null)
{
docs.Put(docId, change);
}
else
{
rows.AddItem(change);
}
}
if (options.GetKeys() != null)
{
foreach (object docIdObject in options.GetKeys())
{
if (docIdObject is string)
{
string docId = (string)docIdObject;
QueryRow change = docs.Get(docId);
if (change == null)
{
IDictionary<string, object> value = new Dictionary<string, object>();
long docNumericID = GetDocNumericID(docId);
if (docNumericID > 0)
{
bool deleted;
IList<bool> outIsDeleted = new AList<bool>();