private bool CheckIfInDb(string single_image_path, out PredictionResult result) { using (var db = new MyResultContext()) { byte[] RawImg = File.ReadAllBytes(single_image_path); byte[] hash = System.Security.Cryptography.MD5.Create().ComputeHash(RawImg); var query = db.Results.Where(p => p.Hash == hash).Select(p => p).ToList(); if (query.Count == 0) { result = null; return(false); } foreach (var single_image in query) { db.Entry(single_image).Reference(p => p.Detail).Load(); if (RawImg.SequenceEqual(single_image.Detail.RawImg)) { single_image.CountReffered++; db.SaveChanges(); result = new PredictionResult(single_image.Path, single_image.Label, single_image.Confidence); return(true); } } } result = null; return(true); }
private void AddToDb(PredictionResult pred) { using (var db = new MyResultContext()) { byte[] CurrentRawImg = File.ReadAllBytes(pred.Path); byte[] CurrentHash = System.Security.Cryptography.MD5.Create().ComputeHash(CurrentRawImg); ImgDetail detail_to_db = new ImgDetail { RawImg = CurrentRawImg }; db.ImgDetails.Add(detail_to_db); Result pred_to_db = new Result { Hash = CurrentHash, Path = pred.Path, Label = pred.Label, Confidence = pred.Confidence, CountReffered = 1, Detail = detail_to_db }; db.Results.Add(pred_to_db); db.SaveChanges(); }; }