Esempio n. 1
0
        public async static void ProcessAlbum(PhotoAlbum album)
        {
            using (BibNumbersMysqlContext db = new BibNumbersMysqlContext())
            {
                var foundAlbum = db.PhotoAlbumSet.FirstOrDefault(a => a.Id == album.Id);

                if (foundAlbum != null)
                {
                    var photosCount = foundAlbum.Photos.Count;
                    foundAlbum.DetectionProgress = 0;
                    db.Entry(foundAlbum).State = EntityState.Modified;
                    db.SaveChanges();
                    await CommunicateProgress(album.Id, 0);

                    for (int photoIndex = 0; photoIndex < photosCount; photoIndex++)
                    {
                        int percentage = ((photoIndex + 1) * 100) / photosCount;
                        foundAlbum.DetectionProgress = percentage;
                        db.Entry(foundAlbum).State = EntityState.Modified;
                        db.SaveChanges();
                        var photo = foundAlbum.Photos.ElementAt(photoIndex);
                        ProcessPhoto(photo, db);
                        await CommunicateProgress(foundAlbum.Id, percentage);
                    }

                    album.DetectionProgress = 100;
                    db.Entry(foundAlbum).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
                    
        }
Esempio n. 2
0
        public static void ProcessPhoto(Photo photo, BibNumbersMysqlContext db)
        {
            var tempFile = Path.GetTempFileName();
            using (WebClient webClient = new WebClient())
            {
                webClient.DownloadFile(photo.Url, tempFile);
                Console.Write("photo url: " + photo.Url);
                Class1 c = new Class1();
                var foundBibNumbers = c.DetectNumbers(tempFile);

                if (foundBibNumbers != null
                    && foundBibNumbers.Count > 0)
                {
                    foreach (var number in foundBibNumbers)
                    {
                        photo.BibNumbers.Add(number.ToString());
                    }

                    db.Entry(photo).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }
        }