Skip to content

Instantly share code, notes, and snippets.

@jmarmolejos
Created November 4, 2015 13:41
Show Gist options
  • Select an option

  • Save jmarmolejos/507c51440a66ef216c41 to your computer and use it in GitHub Desktop.

Select an option

Save jmarmolejos/507c51440a66ef216c41 to your computer and use it in GitHub Desktop.
public void DownloadAndReadMetadata(int imageId)
{
// Get scheduled image from db
var image = _context.ScheduledImages.Find(imageId);
// Download file
var stream = _downloader.Download(image.DownloadUrl);
// Read metadata
var metadata = _reader.ReadFromStream(stream);
// Save entities
image.JobCompletedDate = DateTime.UtcNow;
_context.MarkAsModified(image);
metadata.ForEach(tag =>
{
tag.ScheduledImageId = imageId;
_context.ImageMetadataTags.Add(tag);
});
_context.SaveChanges();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment