Exemple #1
0
 private ClassifiedImage FromDbImage(ClassifiedDbImage dbImage)
 {
     return(new ClassifiedImage()
     {
         Id = dbImage.Id,
         Name = dbImage.Name,
         Class = dbImage.Class,
         Confidence = dbImage.Confidence,
         RetrieveCount = dbImage.RetrieveCount,
         ImageBase64 =
             Convert.ToBase64String(dbImage.Image.Bytes)
     });
 }
Exemple #2
0
 public ClassifiedImage FindImage(NewImage newImage)
 {
     using (ImageDbContext dbContext = new ImageDbContext())
     {
         var dbImages = dbContext.ClassifiedImages.
                        Where(img => img.Name.Equals(newImage.Name)).
                        ToList();
         if (dbImages.Any())
         {
             ClassifiedDbImage dbImage = dbImages.First();
             dbContext.Entry(dbImage).Reference(img => img.Image).Load();
             if (Enumerable.SequenceEqual(dbImage.Image.Bytes,
                                          Convert.FromBase64String(newImage.ImageBase64)))
             {
                 dbImage.RetrieveCount += 1;
                 dbContext.SaveChanges();
                 return(FromDbImage(dbImage));
             }
         }
     }
     return(null);
 }
Exemple #3
0
        public ClassifiedImage PutImage(ClassifiedImage classifiedImage)
        {
            ClassifiedDbImage dbImage = new ClassifiedDbImage()
            {
                Name          = classifiedImage.Name,
                Class         = classifiedImage.Class,
                Confidence    = classifiedImage.Confidence,
                RetrieveCount = classifiedImage.RetrieveCount,
            };

            using (ImageDbContext dbContext = new ImageDbContext())
            {
                Blob blob = new Blob()
                {
                    Bytes = Convert.FromBase64String(classifiedImage.ImageBase64)
                };
                dbContext.Add(blob);
                dbImage.Image = blob;
                dbContext.Add(dbImage);
                dbContext.SaveChanges();
            }
            classifiedImage.Id = dbImage.Id;
            return(classifiedImage);
        }