/// /// Returns the n-th Picture's IPTC-Data /// public static IPTCModel GetIPTC(int pictureId) { SqlCommand command = DbHelper.CreateCommand("SELECT * FROM IPTC WHERE PictureId = @Id"); command.Parameters.AddWithValue("@Id", pictureId); SqlDataReader reader = command.ExecuteReader(); if (!reader.HasRows) { reader.Close(); Log.Information("IPTC-data for Picture with Id {pictureId} does not exist.", pictureId); return(null); } reader.Read(); int i = 0; IPTCModel iptc = new IPTCModel() { PictureId = (int)reader[i++], License = reader[i++] is DBNull ? null : (string)reader[i - 1], PhotographerName = reader[i++] is DBNull ? null : (string)reader[i - 1], Category = reader[i++] is DBNull ? null : (string)reader[i - 1], IsEdited = reader[i++] is DBNull ? null : (bool?)reader[i - 1], KeyWords = reader[i++] is DBNull ? null : (string)reader[i - 1], Notes = reader[i++] is DBNull ? null : (string)reader[i - 1], CreationDate = reader[i++] is DBNull ? null : (DateTime?)reader[i - 1] }; reader.Close(); return(iptc); }
// ReSharper disable once InconsistentNaming public static IIPTCModel ExtractIPTC(string filename) { var filePath = Path.Combine(Constants.PicPath, filename); //var filePath = Constants.DeployPath + @"\Pictures\" + filename; if (!File.Exists(filePath)) { throw new FileNotFoundException(); } var iptc = new IPTCModel(); using (Stream fs = File.Open(filePath, FileMode.Open, FileAccess.ReadWrite)) { var decoder = BitmapDecoder.Create(fs, BitmapCreateOptions.None, BitmapCacheOption.Default); var frame = decoder.Frames[0]; if (!(frame.Metadata is BitmapMetadata metadata)) { return(iptc); } iptc.Caption = (string)metadata.GetQuery("/app13/irb/8bimiptc/iptc/caption") ?? iptc.Caption; iptc.Keywords = (string)metadata.GetQuery("/app13/irb/8bimiptc/iptc/keywords") ?? iptc.Keywords; iptc.ByLine = (string)metadata.GetQuery("/app13/irb/8bimiptc/iptc/by-line") ?? iptc.ByLine; iptc.CopyrightNotice = (string)metadata.GetQuery("/app13/irb/8bimiptc/iptc/copyright notice") ?? iptc.CopyrightNotice; iptc.Headline = (string)metadata.GetQuery("/app13/irb/8bimiptc/iptc/headline") ?? iptc.Headline; fs.Close(); } return(iptc); }
public PictureModel(string fileName) { _fileName = fileName; _iptc = new IPTCModel(); _exif = new EXIFModel(); _camera = new CameraModel("", ""); }
public IIPTCModel ExtractIPTC(string filename) { var pic = DAL.GetPictures(filename, null, null, null); if (pic.Count() > 0) { string filepath = Directory.GetCurrentDirectory(); filepath += "\\Pictures\\" + filename; if (File.Exists(filepath)) { var stream = new FileStream(filepath, FileMode.Open, FileAccess.Read); var decoder = new JpegBitmapDecoder(stream, BitmapCreateOptions.None, BitmapCacheOption.None); var metadata = decoder.Frames[0].Metadata as BitmapMetadata; if (metadata != null) { var IPTC = new IPTCModel(); if (metadata.Author != null) { IPTC.ByLine = metadata.Author.ToString(); } if (metadata.Title != null) { IPTC.Headline = metadata.Title; } if (metadata.Subject != null) { IPTC.Caption = metadata.Subject; } if (metadata.Copyright != null) { IPTC.CopyrightNotice = metadata.Copyright; } if (metadata.Keywords != null) { IPTC.Keywords = metadata.Keywords.ToString(); } stream.Close(); return(IPTC); } else { throw new FileFormatException(); } } else { throw new FileNotFoundException(); } } else { throw new FileNotFoundException(); } }
public IPTCViewModel(IPTCModel core_model) { _byline = core_model.ByLine; _caption = core_model.Caption; _copyRightNotice = core_model.CopyrightNotice; _headline = core_model.Headline; _keywords = core_model.Keywords; _copyRightNotices.Add("upps"); _copyRightNotices.Add("upps1"); _copyRightNotices.Add("upps2"); }
private IIPTCModel GetDemoIPTC() { IIPTCModel i = new IPTCModel(); i.ByLine = "ByLine"; i.Caption = "Captoin"; i.CopyrightNotice = "CopyrightNotice"; i.Headline = "Headline"; i.Keywords = "Keywords"; return(i); }
void saveIPTC(object id) { var iptc = new IPTCModel() //Skips ViewModelLayer { PictureId = (int)id, License = (string)(LicenseBox.SelectedItem ?? LicenseBox.Text), Category = CategoryBox.Text, KeyWords = KeyWordsBox.Text, PhotographerName = (string)(PhotographerBox.SelectedItem ?? PhotographerBox.Text), Notes = NotesBox.Text }; BusinessLayer.SaveIPTC(iptc); }
/// <summary> /// Extracts IPTC information from a picture. NOTE: You may simulate the action. /// </summary> /// <param name="filename"></param> /// <returns></returns> public IIPTCModel ExtractIPTC(string filename) { var iptcData = new IPTCModel(); IEnumerable <string> pathFiles = Directory.EnumerateFiles(GlobalInformation.Path); if (!pathFiles.Contains(Path.Combine(GlobalInformation.Path, filename))) { throw new FileNotFoundException(); } iptcData.ByLine = "ByLine"; iptcData.Caption = "caption"; iptcData.CopyrightNotice = "this is my shit - bro!"; iptcData.Headline = "I'm the Head"; iptcData.Keywords = "Blame on me"; return(iptcData); }
/// /// Saves or Updates new IPTC-Data. /// public static void SaveIPTC(IPTCModel iptc) { SqlCommand command; var old = GetIPTC(iptc.PictureId); if (old != null) { command = DbHelper.CreateCommand("UPDATE IPTC SET " + "License = @license," + "PhotographerName = @photographer," + "Category = @category," + "IsEdited = @edited," + "KeyWords = @keyWords," + "Notes = @notes," + "CreationDate = @date" + " WHERE PictureId = @id"); command.Parameters.AddWithValue("@edited", true); if (old.CreationDate != null) { command.Parameters.AddWithValue("@date", old.CreationDate); } else { command.Parameters.AddWithValue("@date", DateTime.Now); } } else { command = DbHelper.CreateCommand("INSERT INTO IPTC " + "(PictureId, License, PhotographerName, Category, IsEdited, KeyWords, Notes, CreationDate)" + " VALUES (@id, @license, @photographer, @category, @edited, @keyWords, @notes, @date)"); command.Parameters.AddWithValue("@edited", false); command.Parameters.AddWithValue("@date", DateTime.Now); } command.Parameters.AddWithValue("@id", iptc.PictureId); command.Parameters.AddWithValue("@license", iptc.License ?? old.License); command.Parameters.AddWithValue("@photographer", iptc.PhotographerName ?? old.PhotographerName); command.Parameters.AddWithValue("@category", iptc.Category ?? old.Category); command.Parameters.AddWithValue("@keyWords", iptc.KeyWords ?? old.KeyWords); command.Parameters.AddWithValue("@notes", iptc.Notes ?? old.Notes); command.ExecuteNonQuery(); }
public IPTCViewModel(IPTCModel mdl) { imdl = mdl; //, , , , , CC - BY - NC - SA, CC - BY - NC - ND notices.Add("All rights reserved"); notices.Add("CC - BY"); notices.Add("CC - BY - SA"); notices.Add("CC - BY - ND"); notices.Add("CC - BY - NC"); notices.Add("CC - BY - NC - SA"); notices.Add("CC - BY - NC - ND"); /* * ByLine = imdl.ByLine; * Caption = imdl.Caption; * CopyrightNotice = imdl.CopyrightNotice; * Headline = imdl.Headline; * Keywords = imdl.Keywords;*/ }
/// /// Updates the IPTC Model in the Database /// public static void SaveIPTC(IPTCModel iptc) { DataAccessLayer.SaveIPTC(iptc); }
public void SaveIptc(int id, IPTCModel iptc) { _dal.SaveIPTC(id, iptc); }