public static Document CreateDocumentWithProperties(Database db, IDictionary <string
                                                                                      , object> properties)
        {
            Document doc = db.CreateDocument();

            NUnit.Framework.Assert.IsNotNull(doc);
            NUnit.Framework.Assert.IsNull(doc.GetCurrentRevisionId());
            NUnit.Framework.Assert.IsNull(doc.GetCurrentRevision());
            NUnit.Framework.Assert.IsNotNull("Document has no ID", doc.GetId());
            // 'untitled' docs are no longer untitled (8/10/12)
            try
            {
                doc.PutProperties(properties);
            }
            catch (Exception e)
            {
                Log.E(Tag, "Error creating document", e);
                NUnit.Framework.Assert.IsTrue("can't create new document in db:" + db.GetName() +
                                              " with properties:" + properties.ToString(), false);
            }
            NUnit.Framework.Assert.IsNotNull(doc.GetId());
            NUnit.Framework.Assert.IsNotNull(doc.GetCurrentRevisionId());
            NUnit.Framework.Assert.IsNotNull(doc.GetUserProperties());
            // this won't work until the weakref hashmap is implemented which stores all docs
            // Assert.assertEquals(db.getDocument(doc.getId()), doc);
            NUnit.Framework.Assert.AreEqual(db.GetDocument(doc.GetId()).GetId(), doc.GetId());
            return(doc);
        }
 /// <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;
 }
        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);
        }
        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);
        }
Beispiel #5
0
        public static Document CreateDocumentWithProperties(Database db, IDictionary <string
                                                                                      , object> properties)
        {
            Document doc = db.CreateDocument();

            NUnit.Framework.Assert.IsNotNull(doc);
            NUnit.Framework.Assert.IsNull(doc.GetCurrentRevisionId());
            NUnit.Framework.Assert.IsNull(doc.GetCurrentRevision());
            NUnit.Framework.Assert.IsNotNull("Document has no ID", doc.GetId());
            // 'untitled' docs are no longer untitled (8/10/12)
            try
            {
                doc.PutProperties(properties);
            }
            catch (Exception e)
            {
                Log.E(Tag, "Error creating document", e);
                NUnit.Framework.Assert.IsTrue("can't create new document in db:" + db.GetName() +
                                              " with properties:" + properties.ToString(), false);
            }
            NUnit.Framework.Assert.IsNotNull(doc.GetId());
            NUnit.Framework.Assert.IsNotNull(doc.GetCurrentRevisionId());
            NUnit.Framework.Assert.IsNotNull(doc.GetUserProperties());
            // should be same doc instance, since there should only ever be a single Document instance for a given document
            NUnit.Framework.Assert.AreEqual(db.GetDocument(doc.GetId()), doc);
            NUnit.Framework.Assert.AreEqual(db.GetDocument(doc.GetId()).GetId(), doc.GetId());
            return(doc);
        }
Beispiel #6
0
 ///////testing code///////
 void saveItems(MessageModel item)
 {
     try
     {
         Document doc;
         if (item.Id != null)
         {
             doc = db2.CreateDocument();
             var jsonData = JsonConvert.SerializeObject(item);
             var values   = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonData);
             doc.PutProperties(values);
             doc.Id = item.Id;
             Toast.MakeText(Application.Context, "Item saved", ToastLength.Short).Show();
             StartSync();
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
         Toast.MakeText(Application.Context, "failed to save item", ToastLength.Short);
     }
     finally
     {
         mButton.Text = "send" + messagesList.Count().ToString();
     }
 }
Beispiel #7
0
 /// <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;
 }
Beispiel #8
0
        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);
        }
        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;
        }
 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 private void PutDocViaUntitledDoc(Database db, IDictionary<string, object> props)
 {
     var document = db.CreateDocument();
     document.PutProperties(props);
 }
Beispiel #11
0
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        private void PutDocViaUntitledDoc(Database db, IDictionary <string, object> props)
        {
            var document = db.CreateDocument();

            document.PutProperties(props);
        }
Beispiel #12
0
        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;
		}
        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;
        }