本文整理汇总了C#中Couchbase.Lite.Database.CreateDocument方法的典型用法代码示例。如果您正苦于以下问题:C# Database.CreateDocument方法的具体用法?C# Database.CreateDocument怎么用?C# Database.CreateDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Couchbase.Lite.Database
的用法示例。
在下文中一共展示了Database.CreateDocument方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateTask
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static Couchbase.Lite.Document CreateTask(Database database, string title,
Bitmap image, string listId)
{
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("title", title);
properties.Put("checked", false);
properties.Put("created_at", currentTimeString);
properties.Put("list_id", listId);
Couchbase.Lite.Document document = database.CreateDocument();
UnsavedRevision revision = document.CreateRevision();
revision.SetUserProperties(properties);
if (image != null)
{
ByteArrayOutputStream @out = new ByteArrayOutputStream();
image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
revision.SetAttachment("image", "image/jpg", @in);
}
revision.Save();
return document;
}
示例2: CreateNewList
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
public static Couchbase.Lite.Document CreateNewList(Database database, string title, string userId)
{
var dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
var calendar = Calendar.CurrentEra;
string currentTimeString = dateFormatter.Format(calendar.GetTime());
IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Put("type", "list");
properties.Put("title", title);
properties.Put("created_at", currentTimeString);
properties.Put("owner", "profile:" + userId);
properties.Put("members", new AList<string>());
Couchbase.Lite.Document document = database.CreateDocument();
document.PutProperties(properties);
return document;
}
示例3: 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;
}
示例4: PutDocViaUntitledDoc
/// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
private void PutDocViaUntitledDoc(Database db, IDictionary<string, object> props)
{
var document = db.CreateDocument();
document.PutProperties(props);
}
示例5: 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;
}
示例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");
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;
}