Exemplo n.º 1
0
        /// <summary>
        /// Returns latest added Pictures db.
        /// </summary>
        /// <param name="type">Type of data to fetch</param>
        /// <returns>Resultset of matching data</returns>
        private LatestsCollection GetLatestPictures()
        {
            latestPictures      = new LatestsCollection();
            latestPicturesFiles = new Hashtable();

            if (!PictureDatabase.DbHealth)
            {
                return(latestPictures);
            }

            int x = 0;

            try
            {
                CurrentFacade.HasNew = false;

                string sqlQuery = "SELECT strFile, strDateTaken FROM picture" +
                                  (PictureDatabase.FilterPrivate ? " WHERE idPicture NOT IN (SELECT DISTINCT idPicture FROM picturekeywords WHERE strKeyword = 'Private')" : string.Empty) +
                                  " ORDER BY strDateTaken DESC LIMIT " + Utils.FacadeMaxNum + ";";
                List <PictureData> pictures = PictureDatabase.GetPicturesByFilter(sqlQuery, "pictures");

                if (pictures != null)
                {
                    if (pictures.Count > 0)
                    {
                        int i0 = 1;
                        for (int i = 0; i < pictures.Count; i++)
                        {
                            string filename = pictures[i].FileName;
                            if (string.IsNullOrEmpty(filename))
                            {
                                continue;
                            }

                            // string thumb = String.Format(@"{0}\{1}L.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename));
                            string thumb = MediaPortal.Util.Utils.GetPicturesLargeThumbPathname(filename);
                            if (!File.Exists(thumb))
                            {
                                // thumb = String.Format(@"{0}\{1}.jpg", Thumbs.Pictures, MediaPortal.Util.Utils.EncryptLine(filename));
                                thumb = MediaPortal.Util.Utils.GetPicturesThumbPathname(filename);
                                if (!File.Exists(thumb))
                                {
                                    // thumb = "DefaultPictureBig.png";
                                    thumb = filename;
                                }
                            }
                            if (!File.Exists(thumb))
                            {
                                continue;
                            }

                            bool isnew = false;
                            isnew = (pictures[i].DateTaken > Utils.NewDateTime);
                            if (isnew)
                            {
                                CurrentFacade.HasNew = true;
                            }

                            string title = Path.GetFileNameWithoutExtension(Utils.GetFilenameNoPath(filename)).ToUpperInvariant();

                            string exif        = string.Empty;
                            string exifoutline = string.Empty;
                            if (File.Exists(filename))
                            {
                                using (ExifMetadata extractor = new ExifMetadata())
                                {
                                    ExifMetadata.Metadata metaData = extractor.GetExifMetadata(filename);

                                    if (!metaData.IsEmpty())
                                    {
                                        exif        = metaData.ToString();
                                        exifoutline = metaData.ToShortString();
                                    }
                                }
                            }

                            latestPictures.Add(new Latest()
                            {
                                DateTimeAdded  = pictures[i].DateTaken,
                                Title          = title,
                                Subtitle       = exifoutline,
                                Thumb          = thumb,
                                Fanart         = filename,
                                Classification = exif,
                                IsNew          = isnew
                            });

                            latestPicturesFiles.Add(i0, filename);
                            Utils.ThreadToSleep();

                            x++;
                            i0++;
                            if (x == Utils.FacadeMaxNum)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("GetLatestPictures: " + ex.ToString());
            }
            return(latestPictures);
        }