Ejemplo n.º 1
0
        ///
        /// 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);
        }
Ejemplo n.º 2
0
        // 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);
        }
Ejemplo n.º 3
0
 public PictureModel(string fileName)
 {
     _fileName = fileName;
     _iptc     = new IPTCModel();
     _exif     = new EXIFModel();
     _camera   = new CameraModel("", "");
 }
Ejemplo n.º 4
0
        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();
            }
        }
Ejemplo n.º 5
0
 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");
 }
Ejemplo n.º 6
0
        private IIPTCModel GetDemoIPTC()
        {
            IIPTCModel i = new IPTCModel();

            i.ByLine          = "ByLine";
            i.Caption         = "Captoin";
            i.CopyrightNotice = "CopyrightNotice";
            i.Headline        = "Headline";
            i.Keywords        = "Keywords";
            return(i);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        /// <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);
        }
Ejemplo n.º 9
0
        ///
        /// 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();
        }
Ejemplo n.º 10
0
        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;*/
        }
Ejemplo n.º 11
0
 ///
 /// Updates the IPTC Model in the Database
 ///
 public static void SaveIPTC(IPTCModel iptc)
 {
     DataAccessLayer.SaveIPTC(iptc);
 }
Ejemplo n.º 12
0
 public void SaveIptc(int id, IPTCModel iptc)
 {
     _dal.SaveIPTC(id, iptc);
 }