Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
        public static void AttachImage(Couchbase.Lite.Document task, Bitmap image)
        {
            if (task == null || image == null)
            {
                return;
            }
            UnsavedRevision       revision = task.CreateRevision();
            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();
        }
Ejemplo n.º 3
0
 public void TestSerializeStorableByReference()
 {
     StorableImageTest img = new StorableImageTest {
         ID = Guid.NewGuid (),
         Image1 = Utils.LoadImageFromFile (),
     };
     StorableContainerTest cont = new StorableContainerTest {
         ID = Guid.NewGuid (),
         Image = img,
     };
     Document doc = db.CreateDocument ();
     UnsavedRevision rev = doc.CreateRevision ();
     JObject jo = DocumentsSerializer.SerializeObject (cont, rev, db, null);
     Assert.AreEqual (img.ID, jo ["Image"].Value<Guid> ());
     Assert.AreEqual (1, db.DocumentCount);
     Assert.IsNotNull (storage.Retrieve<StorableImageTest> (img.ID));
     rev.Save ();
     Assert.AreEqual (2, db.DocumentCount);
 }