partial void DeleteImageMapping(ImageMapping instance);
 partial void InsertImageMapping(ImageMapping instance);
 partial void UpdateImageMapping(ImageMapping instance);
		private void detach_ImageMappings(ImageMapping entity)
		{
			this.SendPropertyChanging();
			entity.DBImage = null;
		}
		private void attach_ImageMappings(ImageMapping entity)
		{
			this.SendPropertyChanging();
			entity.DBImage = this;
		}
Esempio n. 6
0
 internal static void AddThumbnailImage(Title title, Dao.ImageMapping image)
 {
     Dao.Title daoTitle = Dao.TitleCollectionDao.GetTitleById(title.Id);
     //daoTitle.WatchedCount = (daoTitle.WatchedCount == null) ? 1 : daoTitle.WatchedCount.Value + 1;
     daoTitle.Images.Add(image);
 }
Esempio n. 7
0
        private static void UpdatesImagesForTitle(Dao.Title title)
        {
            const int MAX_FANART_HEIGHT = 1080;

            // if there's a new front cover image path
            if (title.UpdatedFrontCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte)ImageType.FrontCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedFrontCoverPath))
                {
                    // add the new one
                    int?id = ImageManager.AddImageToDB(title.UpdatedFrontCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId   = id.Value;
                        image.ImageType = (byte)ImageType.FrontCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedFrontCoverPath = null;
            }

            // if there's a new front cover image path
            if (title.UpdatedBackCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte)ImageType.BackCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedBackCoverPath))
                {
                    // add the new one
                    int?id = ImageManager.AddImageToDB(title.UpdatedBackCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId   = id.Value;
                        image.ImageType = (byte)ImageType.BackCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedBackCoverPath = null;
            }

            if (title.UpdatedFanArtPaths != null)
            {
                IEnumerable <string> originalCoverArt = from t in title.Images
                                                        where t.ImageType == (byte)ImageType.FanartImage
                                                        select ImageManager.ConstructImagePathById(t.ImageId, ImageSize.Original);

                List <string> added   = new List <string>(title.UpdatedFanArtPaths.Where(t => !originalCoverArt.Contains(t)));
                List <string> removed = new List <string>(originalCoverArt.Where(t => !title.UpdatedFanArtPaths.Contains(t)));

                // remove ones no longer used
                foreach (string remove in removed)
                {
                    int?id = ImageManager.GetIdFromImagePath(remove);
                    if (id != null)
                    {
                        Dao.ImageMapping mapping = title.Images.FirstOrDefault(t => t.ImageId == id.Value);

                        if (mapping != null)
                        {
                            Dao.TitleCollectionDao.SetDeleteImage(mapping.DBImage);
                            Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(mapping);
                            title.Images.Remove(mapping);
                        }
                    }
                }

                // add the new ones
                foreach (string add in added)
                {
                    if (!ImageManager.CheckImageOriginalNameTitleThreadSafe(title.Id, add))
                    {
                        int?id = ImageManager.AddImageToDB(add, MAX_FANART_HEIGHT);

                        if (id != null)
                        {
                            Dao.ImageMapping mapping = new Dao.ImageMapping();
                            mapping.ImageId      = id.Value;
                            mapping.ImageType    = (byte)ImageType.FanartImage;
                            mapping.OriginalName = Path.GetFileName(add);

                            title.Images.Add(mapping);
                        }
                    }
                }

                title.UpdatedFanArtPaths = null;
            }
        }
        private static void UpdatesImagesForTitle(Dao.Title title)
        {
            const int MAX_FANART_HEIGHT = 1080;

            // if there's a new front cover image path
            if (title.UpdatedFrontCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte) ImageType.FrontCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedFrontCoverPath))
                {
                    // add the new one
                    int? id = ImageManager.AddImageToDB(title.UpdatedFrontCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId = id.Value;
                        image.ImageType = (byte)ImageType.FrontCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedFrontCoverPath = null;
            }

            // if there's a new front cover image path
            if (title.UpdatedBackCoverPath != null)
            {
                // delete the old one if it exists
                for (int i = title.Images.Count - 1; i >= 0; i--)
                {
                    if (title.Images[i].ImageType == (byte)ImageType.BackCoverImage)
                    {
                        Dao.TitleCollectionDao.SetDeleteImage(title.Images[i].ImageId);
                        Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(title.Images[i]);
                        title.Images.RemoveAt(i);
                    }
                }

                if (!string.IsNullOrEmpty(title.UpdatedBackCoverPath))
                {
                    // add the new one
                    int? id = ImageManager.AddImageToDB(title.UpdatedBackCoverPath);

                    // if we got an id back let's associate it
                    if (id != null)
                    {
                        Dao.ImageMapping image = new OMLEngine.Dao.ImageMapping();
                        image.ImageId = id.Value;
                        image.ImageType = (byte)ImageType.BackCoverImage;

                        title.Images.Add(image);
                    }
                }

                // clear it out
                title.UpdatedBackCoverPath = null;
            }

            if (title.UpdatedFanArtPaths != null)
            {
                IEnumerable<string> originalCoverArt = from t in title.Images
                                                       where t.ImageType == (byte)ImageType.FanartImage
                                                       select ImageManager.ConstructImagePathById(t.ImageId, ImageSize.Original);

                List<string> added = new List<string>(title.UpdatedFanArtPaths.Where(t => !originalCoverArt.Contains(t)));
                List<string> removed = new List<string>(originalCoverArt.Where(t => !title.UpdatedFanArtPaths.Contains(t)));

                // remove ones no longer used
                foreach (string remove in removed)
                {
                    int? id = ImageManager.GetIdFromImagePath(remove);
                    if (id != null)
                    {
                        Dao.ImageMapping mapping = title.Images.FirstOrDefault(t => t.ImageId == id.Value);

                        if (mapping != null)
                        {
                            Dao.TitleCollectionDao.SetDeleteImage(mapping.DBImage);
                            Dao.DBContext.Instance.ImageMappings.DeleteOnSubmit(mapping);
                            title.Images.Remove(mapping);
                        }
                    }
                }

                // add the new ones
                foreach (string add in added)
                {
                    if (!ImageManager.CheckImageOriginalNameTitleThreadSafe(title.Id, add))
                    {
                        int? id = ImageManager.AddImageToDB(add, MAX_FANART_HEIGHT);

                        if (id != null)
                        {
                            Dao.ImageMapping mapping = new Dao.ImageMapping();
                            mapping.ImageId = id.Value;
                            mapping.ImageType = (byte)ImageType.FanartImage;
                            mapping.OriginalName = Path.GetFileName(add);

                            title.Images.Add(mapping);
                        }
                    }
                }

                title.UpdatedFanArtPaths = null;
            }
        }