本文整理汇总了C#中Couchbase.Lite.Database.GetDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Database.GetDocument方法的具体用法?C# Database.GetDocument怎么用?C# Database.GetDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Couchbase.Lite.Database
的用法示例。
在下文中一共展示了Database.GetDocument方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
private IEnumerator Start () {
Debug.LogFormat ("Data path = {0}", Application.persistentDataPath);
#if UNITY_EDITOR_WIN
Log.SetLogger(new UnityLogger());
#endif
_db = Manager.SharedInstance.GetDatabase ("spaceshooter");
_pull = _db.CreatePullReplication (GameController.SYNC_URL);
_pull.Continuous = true;
_pull.Start ();
while (_pull != null && _pull.Status == ReplicationStatus.Active) {
yield return new WaitForSeconds(0.5f);
}
var doc = _db.GetExistingDocument ("player_data");
if (doc != null) {
//We have a record! Get the ship data, if possible.
string assetName = String.Empty;
if(doc.UserProperties.ContainsKey("ship_data")) {
assetName = doc.UserProperties ["ship_data"] as String;
}
StartCoroutine(LoadAsset (assetName));
} else {
//Create a new record
doc = _db.GetDocument("player_data");
doc.PutProperties(new Dictionary<string, object> { { "ship_data", String.Empty } });
}
doc.Change += DocumentChanged;
_push = _db.CreatePushReplication (new Uri ("http://127.0.0.1:4984/spaceshooter"));
_push.Start();
}
示例2: SaveObject
public static void SaveObject(IStorable obj, Database db, IDReferenceResolver resolver = null)
{
Document doc = db.GetDocument (obj.ID.ToString ());
doc.Update ((UnsavedRevision rev) => {
JObject jo = SerializeObject (obj, rev, db, resolver);
IDictionary<string, object> props = jo.ToObject<IDictionary<string, object>> ();
/* SetProperties sets a new properties dictionary, removing the attachments we
* added in the serialization */
if (rev.Properties.ContainsKey ("_attachments")) {
props ["_attachments"] = rev.Properties ["_attachments"];
}
rev.SetProperties (props);
return true;
});
}
示例3: CreateDocs
private void CreateDocs(Database db, bool withAttachments)
{
Log.D(TAG, "Creating {0} documents in {1}", DOCUMENT_COUNT, db.Name);
db.RunInTransaction(() =>
{
for(int i = 1; i <= DOCUMENT_COUNT; i++) {
var doc = db.GetDocument(String.Format("doc-{0}", i));
var rev = doc.CreateRevision();
rev.SetUserProperties(new Dictionary<string, object> {
{ "index", i },
{ "bar", false }
});
if(withAttachments) {
int length = (int)(MIN_ATTACHMENT_LENGTH + _rng.Next() /
(double)Int32.MaxValue * (MAX_ATTACHMENT_LENGTH - MIN_ATTACHMENT_LENGTH));
var data = new byte[length];
_rng.NextBytes(data);
rev.SetAttachment("README", "application/octet-stream", data);
}
Assert.DoesNotThrow(() => rev.Save());
}
return true;
});
}
示例4: VerifyHistory
private void VerifyHistory(Database db, RevisionInternal rev, IList<string> history)
{
var gotRev = db.GetDocument(rev.GetDocId(), null,
true);
Assert.AreEqual(rev, gotRev);
AssertPropertiesAreEqual(rev.GetProperties(), gotRev.GetProperties());
var revHistory = db.Storage.GetRevisionHistory(gotRev, null);
Assert.AreEqual(history.Count, revHistory.Count);
for (int i = 0; i < history.Count; i++)
{
RevisionInternal hrev = revHistory[i];
Assert.AreEqual(rev.GetDocId(), hrev.GetDocId());
Assert.AreEqual(history[i], hrev.GetRevId());
Assert.IsFalse(rev.IsDeleted());
}
}
示例5: SavedRevision
/// <summary>Constructor</summary>
internal SavedRevision(Database database, RevisionInternal revision)
: this(database.GetDocument(revision == null ? null : revision.DocID), revision) { }
示例6: CreateDocumentWithProperties
internal static Document CreateDocumentWithProperties(Database db, IDictionary<string, object> properties)
{
var doc = db.CreateDocument();
Assert.IsNotNull(doc);
Assert.IsNull(doc.CurrentRevisionId);
Assert.IsNull(doc.CurrentRevision);
Assert.IsNotNull(doc.Id, "Document has no ID");
try
{
doc.PutProperties(properties);
}
catch (Exception e)
{
Log.E(Tag, "Error creating document", e);
Assert.IsTrue(false, "can't create new document in db:" + db.Name + " with properties:" + properties.ToString());
}
Assert.IsNotNull(doc.Id);
Assert.IsNotNull(doc.CurrentRevisionId);
Assert.IsNotNull(doc.CurrentRevision);
// should be same doc instance, since there should only ever be a single Document instance for a given document
Assert.AreEqual(db.GetDocument(doc.Id), doc);
Assert.AreEqual(db.GetDocument(doc.Id).Id, doc.Id);
return doc;
}
示例7: SavedRevision
/// <summary>Constructor</summary>
internal SavedRevision(Database database, RevisionInternal revision)
: this(database.GetDocument(revision.GetDocId()), revision) { }
示例8: CreateProfile
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static Couchbase.Lite.Document CreateProfile(Database database, string userId
, string name)
{
SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
);
Calendar calendar = GregorianCalendar.GetInstance();
string currentTimeString = dateFormatter.Format(calendar.GetTime());
IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Put("type", DocType);
properties.Put("user_id", userId);
properties.Put("name", name);
Couchbase.Lite.Document document = database.GetDocument("profile:" + userId);
document.PutProperties(properties);
return document;
}
示例9: CreateDocumentWithProperties
public static Document CreateDocumentWithProperties(Database db, IDictionary<String, Object> properties)
{
var doc = db.CreateDocument();
Assert.IsNotNull(doc);
Assert.IsNull(doc.CurrentRevisionId);
Assert.IsNull(doc.CurrentRevision);
Assert.IsNotNull("Document has no ID", doc.Id);
// 'untitled' docs are no longer untitled (8/10/12)
try
{
doc.PutProperties(properties);
}
catch (Exception e)
{
Log.E(Tag, "Error creating document", e);
Assert.IsTrue( false, "can't create new document in db:" + db.Name +
" with properties:" + properties.Aggregate(new StringBuilder(" >>> "), (str, kvp)=> { str.AppendFormat("'{0}:{1}' ", kvp.Key, kvp.Value); return str; }, str=>str.ToString()));
}
Assert.IsNotNull(doc.Id);
Assert.IsNotNull(doc.CurrentRevisionId);
Assert.IsNotNull(doc.UserProperties);
Assert.AreEqual(db.GetDocument(doc.Id), doc);
return doc;
}
示例10: CreateDocumentWithProperties
internal static Document CreateDocumentWithProperties(Database db, IDictionary<string, object> properties)
{
var doc = db.CreateDocument();
Assert.IsNotNull(doc);
Assert.IsNull(doc.CurrentRevisionId);
Assert.IsNull(doc.CurrentRevision);
Assert.IsNotNull(doc.Id, "Document has no ID");
doc.PutProperties(properties);
Assert.IsNotNull(doc.Id);
Assert.IsNotNull(doc.CurrentRevisionId);
Assert.IsNotNull(doc.CurrentRevision);
// should be same doc instance, since there should only ever be a single Document instance for a given document
Assert.AreEqual(db.GetDocument(doc.Id), doc);
Assert.AreEqual(db.GetDocument(doc.Id).Id, doc.Id);
return doc;
}