예제 #1
0
        public void SetCoverPhoto(long photoId)
        {
            Photo      photo = PhotoEntityRepository.Single(p => p.ID == photoId, p => p.Site);
            Collection col   = CollectionRepository.Single(c => c.Site.ID == photo.Site.ID && c.Type == CollectionType.SITE);

            if (col != null)
            {
                col.CoverPhoto = photo;
                CollectionRepository.Update(col);
                Unit.Commit();
            }
        }
예제 #2
0
        public void FullResolutionDownload(DownloadModel model)
        {
            //need to access photos and names on main thread
            List <string> fileNames = new List <string>();

            string[] ids = model.PhotoIds.Split(',');

            foreach (var id in ids)
            {
                long  photoID = Convert.ToInt32(id);
                Photo photo   = PhotoEntityRepository.Single(p => p.ID == photoID, p => p.Site);

                if (photo != null)
                {
                    fileNames.Add(photo.FileName);
                }
            }

            string        email         = UserRepository.First(u => u.ProviderID == this.User.Identity.Name).EmailAddress;
            List <string> downloadLinks = new List <string>();

            // For all groups of photosPerZip, save zip
            int photosPerZip = 500;
            int photoCount   = fileNames.Count();
            var fileCount    = Math.Ceiling((Double)photoCount / (Double)photosPerZip);

            for (int i = 0; i < fileCount; i++)
            {
                string FileName = string.Format("{0}.{1}.zip", (DateTime.Now.ToString("MM-dd-yyyy-hh-mm-ss")), Convert.ToString(i + 1));

                string downloadURL = string.Format("{0}://{1}{2}",
                                                   Request.RequestUri.Scheme,
                                                   Request.RequestUri.Authority,
                                                   string.Format(@"/Photo/Download?fileName={0}", FileName));
                downloadLinks.Add(downloadURL);

                var startIndex = i * photosPerZip;
                var endIndex   = (i + 1) * photosPerZip;

                List <string> subsetFileNames = new List <string>();
                if (photoCount > endIndex)
                {
                    subsetFileNames = fileNames.GetRange(startIndex, photosPerZip);
                }
                else
                {
                    var remainingCount = photoCount - startIndex;
                    subsetFileNames = fileNames.GetRange(startIndex, remainingCount);
                }

                DownloadImages(subsetFileNames, FileName);
            }

            var emailText = "";

            if (fileCount > 1)
            {
                emailText = string.Format("The images you requested for download were saved to {0} zip files. Please visit the links below to download the zip files. <br>{1}", Convert.ToString(fileCount), String.Join("<br>", downloadLinks));
            }
            else
            {
                emailText = "Please visit " + downloadLinks[0] + " to download the images.";
            }

            //after all saved, send email
            EmailService.SendMail(email, "Phocalstream Download", emailText);
        }