Ejemplo n.º 1
0
        public static ImageAnnotation AddAnnotation(string library, Bitmap image, IBoundingBox region, JObject data)
        {
            CouchDatabase   db    = GetDatabase(library);
            string          imgid = AddImage(db, image);
            ImageAnnotation toAdd = new ImageAnnotation(region, data, imgid);

            if (HasDocument(db, toAdd.Id))
            {
                throw new InvalidOperationException("There already exists an annotation for this image with this location. Retreive that annotation and update its data accordingly.");
            }

            CouchDbAnnotation ca = new CouchDbAnnotation();

            ca.data         = toAdd.Data;
            ca.top          = toAdd.Region.Top;
            ca.left         = toAdd.Region.Left;
            ca.width        = toAdd.Region.Width;
            ca.height       = toAdd.Region.Height;
            ca.screenshotId = toAdd.ImageId;
            ca.type         = "annotation";
            Document <CouchDbAnnotation> document = new Document <CouchDbAnnotation>(ca);

            document.Id = toAdd.Id;
            db.CreateDocument(document);


            return(toAdd);
        }
Ejemplo n.º 2
0
        public static ImageAnnotation AddAnnotation(string library, Bitmap image, IBoundingBox region, JObject data)
        {

            CouchDatabase db = GetDatabase(library);
            string imgid = AddImage(db, image);
            ImageAnnotation toAdd = new ImageAnnotation(region, data, imgid);

            if (HasDocument(db, toAdd.Id))
                throw new InvalidOperationException("There already exists an annotation for this image with this location. Retreive that annotation and update its data accordingly.");

            CouchDbAnnotation ca = new CouchDbAnnotation();

            ca.data = toAdd.Data;
            ca.top = toAdd.Region.Top;
            ca.left = toAdd.Region.Left;
            ca.width = toAdd.Region.Width;
            ca.height = toAdd.Region.Height;
            ca.screenshotId = toAdd.ImageId;
            ca.type = "annotation";
            Document<CouchDbAnnotation> document = new Document<CouchDbAnnotation>(ca);
            document.Id = toAdd.Id;
            db.CreateDocument(document);


            return toAdd;
        }
Ejemplo n.º 3
0
        public static ImageAnnotation GetAnnotation(string library, Bitmap image, IBoundingBox region)
        {
            CouchDatabase   db    = GetDatabase(library);
            string          imgid = ImageAnnotation.GetImageId(image);
            ImageAnnotation ia    = new ImageAnnotation(region, null, imgid);

            try
            {
                CouchDbAnnotation ca = db.GetDocument <CouchDbAnnotation>(ia.Id);
                return(new ImageAnnotation(region, ca.data, imgid));
            }
            catch
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public static ImageAnnotation UpdateExisting(string library, string id, JObject data)
        {
            CouchDbAnnotation toUpdate = null;
            CouchDatabase     db       = GetDatabase(library);

            try
            {
                toUpdate = db.GetDocument <CouchDbAnnotation>(id);
            }
            catch {
                return(null);
            }

            toUpdate.data = data;

            Document <CouchDbAnnotation> document = new Document <CouchDbAnnotation>(toUpdate);

            db.SaveDocument(document);

            return(CouchDbAnnotationToImageAnnotation(toUpdate));
        }
Ejemplo n.º 5
0
        private static ImageAnnotation CouchDbAnnotationToImageAnnotation(CouchDbAnnotation toUpdate)
        {
            BoundingBox region = new BoundingBox(toUpdate.left, toUpdate.top, toUpdate.width, toUpdate.height);

            return(new ImageAnnotation(region, toUpdate.data, toUpdate.screenshotId));
        }
Ejemplo n.º 6
0
 private static ImageAnnotation CouchDbAnnotationToImageAnnotation( CouchDbAnnotation toUpdate)
 {
     BoundingBox region = new BoundingBox(toUpdate.left, toUpdate.top, toUpdate.width, toUpdate.height);
     return new ImageAnnotation( region, toUpdate.data, toUpdate.screenshotId);
 }