Example #1
0
        public static bool AssociatePhotos(string articleText, ProviderArticle anArticle, ref List<string> errorList)
        {
            bool returnValue = true;
            //Detach all Photos from their relationship with the article.
            anArticle.RemoveAllPhotos();

            // Note: There is a bit of a performance hit since we load the article body into the HtmlParser and then later do it again in ProviderArticle Save function.
            // We should revisit this area when we need to do performance optimization.
            List<string> imageHosts = InsideWordWebSettings.ImageHosts;
            List<ImageInfo> imageList = HtmlParser.GetImageInfos(articleText, null);
            int orderedCount = 1;
            Uri srcUri = null;
            foreach (ImageInfo anImageInfo in imageList)
            {
                ProviderPhotoRecord aRecord = new ProviderPhotoRecord();
                if(!Uri.TryCreate(anImageInfo.Src, UriKind.Absolute, out srcUri))
                {
                    errorList.Add(IWStringUtility.SuffixedNumber(orderedCount) + " photo has a bad link. Delete it and recreate it.");
                    returnValue = false;
                }
                else
                {
                    if (!aRecord.Load(srcUri))
                    {
                        aRecord = new ProviderPhotoRecord(anImageInfo);
                        aRecord.Save();
                        List<ProviderPhotoRecord> fakeThumbnailList = ProviderPhotoRecord.CreateFakeThumbnails(aRecord);
                        foreach (ProviderPhotoRecord fakeThumbnail in fakeThumbnailList)
                        {
                            fakeThumbnail.Save();
                        }
                    }

                    anArticle.AddPhoto(aRecord.Id.Value);
                }
                orderedCount++;
            }

            return returnValue;
        }
        protected bool EntityCopy(ProviderPhotoRecord aPhoto)
        {
            //Never copy over the id, otherwise we would be creating
            //a pseudo-reference copy, which we don't want.
            //Do not copy over the system times and only the business logic
            //times since the system times are specific to a given instance.
            _entityPhoto.CreateDate = aPhoto._entityPhoto.CreateDate;
            _entityPhoto.EditDate = aPhoto._entityPhoto.EditDate;
            _entityPhoto.IsThumbnail = aPhoto._entityPhoto.IsThumbnail;
            _entityPhoto.ImageType = aPhoto._entityPhoto.ImageType;
            _entityPhoto.OriginalId = aPhoto._entityPhoto.OriginalId;
            _entityPhoto.Photographer = aPhoto._entityPhoto.Photographer;
            _entityPhoto.Caption = aPhoto._entityPhoto.Caption;
            _entityPhoto.IsHidden = aPhoto._entityPhoto.IsHidden;
            _entityPhoto.DisplayWidth = aPhoto._entityPhoto.DisplayWidth;
            _entityPhoto.DisplayHeight = aPhoto._entityPhoto.DisplayHeight;
            _entityPhoto.IgnoreFlags = aPhoto._entityPhoto.IgnoreFlags;
            _entityPhoto.ImageUrl = aPhoto._entityPhoto.ImageUrl;

            //_entityPhoto.PhysicalPath = aPhoto._entityPhoto.PhysicalPath;
            // Do not copy over the physical path. Two records should never point to the same physical path.

            return true;
        }
 public ProviderPhotoRecord Thumbnail(ProviderPhotoRecord.ImageTypeEnum imageType)
 {
     try
     {
         return new ProviderPhotoRecord(_entityPhoto.Thumbnails.Where(photo => photo.ImageType == (int)imageType).Single());
     }
     catch
     {
         return null;
     }
 }
 public ProviderPhotoRecord CreateFakeThumbnailFromOriginal(ImageTypeEnum imageType)
 {
     if (this.IsThumbnail)
     {
         throw new Exception("warning: attempting to create thumbnail from non-original image");
     }
     ProviderPhotoRecord thumbnail = new ProviderPhotoRecord();
     thumbnail.Copy(this);
     thumbnail.OriginalId = this.Id;
     thumbnail.AdjustToDimensions(imageType);
     thumbnail.IsThumbnail = true;
     thumbnail.PhotoImageType = imageType;
     return thumbnail;
 }
 public void Copy(ProviderPhotoRecord aPhotoRecord)
 {
     EntityCopy(aPhotoRecord);
 }
        /// <summary>
        /// Create thumbnails from a given original of size smaller than the original
        /// </summary>
        /// <param name="filePhoto"></param>
        /// <param name="subFolder">sub folder name</param>
        /// <returns>list of thumbnail photos in decreasing order of size (order of the ImageType enum)</returns>
        public static List<ProviderPhotoRecord> CreateFakeThumbnails(ProviderPhotoRecord photo)
        {
            List<ProviderPhotoRecord> thumbnailList = new List<ProviderPhotoRecord>();
            // Cannot properly create thumbnails if we don't have the width and height dimensions.
            if (photo.DisplayHeight.HasValue && photo.DisplayHeight > 1 &&
                photo.DisplayWidth.HasValue && photo.DisplayWidth > 1)
            {
                foreach (ImageTypeEnum type in Enum.GetValues(typeof(ImageTypeEnum)))
                {
                    if (type != ImageTypeEnum.Original)
                    {
                        // optionally we could detect here if the thumbnail max dimensions are larger than
                        // the original and not create the thumbnail but for now we are creating them all
                        // so we can assume all thumbnail sizes are always available even if some are much
                        // smaller than their max dimensions
                        ProviderPhotoRecord thumbnail = photo.CreateFakeThumbnailFromOriginal(type);
                        thumbnailList.Add(thumbnail);
                    }
                }
            }

            return thumbnailList;
        }