Exemplo n.º 1
0
        /// <summary>
        /// Function creates a ProviderPhoto class from a raw image file and assigns it to the member that created/uploaded it
        /// </summary>
        /// <param name="owningMember">owning member of the article/photo</param>
        /// <param name="filePhoto">raw image file of the photo</param>
        /// <returns>photo url</returns>
        public static ProviderPhoto CreatePhoto(ProviderMember owningMember, HttpPostedFileBase filePhoto)
        {
            ProviderPhoto originalPhoto = null;

            // check if there is any data to attach
            if (filePhoto.ContentLength > 0)
            {
                string subFolder = (owningMember.IsNew) ? "anonymous" : owningMember.Id.ToString();
                originalPhoto = new ProviderPhoto(filePhoto, subFolder);
                originalPhoto.AdjustToDimensions(InsideWordProvider.ProviderPhotoRecord.ImageTypeEnum.Original);
                originalPhoto.Save();

                List<ProviderPhoto> thumbnails = ProviderPhoto.CreateThumbnails(originalPhoto);
                foreach (ProviderPhoto thumbnail in thumbnails)
                {
                    thumbnail.Save();
                }
            }
            else
            {
                throw new Exception("no uploaded photo data");
            }

            return originalPhoto;
        }
Exemplo n.º 2
0
        /* TODO: revisit all copy functions. LEAVE THIS ONE UNCOMMENTED FOR NOW AS IT IS ACTUALLY BEING USED.*/
        public bool Copy(ProviderPhoto aPhoto)
        {
            bool retValue = EntityCopy(aPhoto);

            //Don't copy the following since these are only for change tracking
            //_pathChanged
            //_oldPath
            //_photoChanged
            //_oldImage

            if(retValue)
            {
                //two records should never point to the same physical file so setup to create a new file
                //Saving the file, like in all providers, will occur on Save().
                if (aPhoto.IsPhysicalPhoto)
                {
                    _physicalHeight = aPhoto._physicalHeight;
                    _physicalWidth = aPhoto._physicalWidth;
                    _physicalPhoto = (Image)aPhoto._physicalPhoto.Clone();

                    string extention = aPhoto.Extention;
                    string subFolder = aPhoto.SubFolder;
                    string fileName = _generator.TimeUniqueAlphaNumeric() + extention;
                    _entityPhoto.PhysicalPath = CreatePath(subFolder, fileName);
                    _entityPhoto.ImageUrl = CreateAbsoluteUrl(subFolder, fileName).AbsoluteUri;
                }
                else
                {
                    _entityPhoto.ImageUrl = aPhoto._entityPhoto.ImageUrl;
                    _entityPhoto.PhysicalPath = aPhoto._entityPhoto.PhysicalPath;
                }
            }

            return true;
        }
Exemplo n.º 3
0
 public ProviderPhoto CreateThumbnailFromOriginal(ImageTypeEnum imageType)
 {
     if (this.IsThumbnail)
     {
         throw new Exception("warning: attempting to create thumbnail from non-original image");
     }
     ProviderPhoto thumbnail = new ProviderPhoto();
     thumbnail.Copy(this);
     thumbnail.OriginalId = this.Id;
     thumbnail.AdjustToDimensions(imageType);
     thumbnail.IsThumbnail = true;
     thumbnail.PhotoImageType = imageType;
     return thumbnail;
 }
Exemplo n.º 4
0
        /// <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<ProviderPhoto> CreateThumbnails(ProviderPhoto photo)
        {
            List<ProviderPhoto> photos = new List<ProviderPhoto>();
            foreach (ImageTypeEnum type in Enum.GetValues(typeof(ImageTypeEnum)))
            {
                if (type == ImageTypeEnum.Original)
                {
                    continue;
                }
                // 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
                ProviderPhoto thumbnail = photo.CreateThumbnailFromOriginal(type);
                photos.Add(thumbnail);
            }

            return photos;
        }