当前位置: 首页>>代码示例>>C#>>正文


C# Database.GetDocument方法代码示例

本文整理汇总了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();
	}
开发者ID:serjee,项目名称:space-shooter,代码行数:32,代码来源:AssetChangeListener.cs

示例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;
     });
 }
开发者ID:GNOME,项目名称:longomatch,代码行数:15,代码来源:DocumentsSerializer.cs

示例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;
            });
        }
开发者ID:pkdevboxy,项目名称:couchbase-lite-net,代码行数:27,代码来源:PeerToPeerTest.cs

示例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());
            }
        }
开发者ID:JackWangCUMT,项目名称:couchbase-lite-net,代码行数:18,代码来源:RevTreeTest.cs

示例5: SavedRevision

 /// <summary>Constructor</summary>
 internal SavedRevision(Database database, RevisionInternal revision)
     : this(database.GetDocument(revision == null ? null : revision.DocID), revision) { }
开发者ID:jonfunkhouser,项目名称:couchbase-lite-net,代码行数:3,代码来源:SavedRevision.cs

示例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;
        }
开发者ID:ertrupti9,项目名称:couchbase-lite-net,代码行数:29,代码来源:LiteTestCase.cs

示例7: SavedRevision

 /// <summary>Constructor</summary>
 internal SavedRevision(Database database, RevisionInternal revision)
     : this(database.GetDocument(revision.GetDocId()), revision) { }
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:3,代码来源:SavedRevision.cs

示例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;
 }
开发者ID:jonlipsky,项目名称:couchbase-lite-net,代码行数:16,代码来源:Profile.cs

示例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;
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:28,代码来源:ApiTest.cs

示例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;
        }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:21,代码来源:LiteTestCase.cs


注:本文中的Couchbase.Lite.Database.GetDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。