Ejemplo n.º 1
0
        /// <summary>
        /// Photos are equal if their id are equal.
        /// </summary>
        /// <param name="p1">First photo to be compared</param>
        /// <param name="p2">Second photo to be compared</param>
        /// <returns></returns>
        public bool Equals(P p1, P p2)
        {
            if (Object.ReferenceEquals(p1, p2))
            {
                return(true);
            }

            if (Object.ReferenceEquals(p1, null) || Object.ReferenceEquals(p2, null))
            {
                return(false);
            }

            if (p1 is Photo && p2 is Photo)
            {
                Photo photo1 = p1 as Photo;
                Photo photo2 = p2 as Photo;

                return(photo1.PhotoId == photo2.PhotoId);
            }

            if (p1 is PhotoTDO && p2 is PhotoTDO)
            {
                PhotoTDO photo1 = p1 as PhotoTDO;
                PhotoTDO photo2 = p2 as PhotoTDO;

                return(photo1.PhotoId == photo2.PhotoId);
            }

            return(false);
        }
Ejemplo n.º 2
0
        internal static IEnumerable <PhotoTDO> GetUnclaimedPhotos(Event ev, int page, int pageSize)
        {
            HashSet <PhotoTDO> photos = new HashSet <PhotoTDO>();

            if (string.IsNullOrEmpty(ev.EventFolder))
            {
                return(photos.AsEnumerable());
            }

            // Getting the list of photos' extensions
            string imageExts = GetImageExts();
            // Get all photos that belong to the event's folder
            string folder = (ev.EventFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? ev.EventFolder : (ev.EventFolder + Path.DirectorySeparatorChar)) + Constants.STR_UNCLAIMED;

            try {
                string[] filenames = PagingFileUtils.GetFileNames(folder, imageExts, page, pageSize);
                foreach (string filename in filenames)
                {
                    string   thumbnail = GetThumbnailVirtualPath(ev.EventVirtualPath, filename);
                    PhotoTDO photo     = GenerateUnclaimedTDO(ev, filename, thumbnail);
                    photos.Add(photo);
                }

                return(photos.OrderBy(p => p.Created));
            }
            catch (ObjectNotFoundException) {
                return(photos.AsEnumerable());
            }
        }
Ejemplo n.º 3
0
        private void SendEmails(UserTDO user, EventTDO ev, PhotoTDO photo, PhotoAnnotation photoAnnotation, string photoUrl)
        {
            if (ev.WebsiteId != null)
            {
                Website website = _fsWebService.Get <Website>("Websites/" + ev.WebsiteId, true);
                photoUrl = GeneratePhotoWebsiteUrl(photoUrl, website); // string.Format("{0}PhotoWebsite/{1}?website={2}", Regex.Replace(AppSettings.FsApiBaseAddress, @"api/", ""), photo.PhotoId, ev.WebsiteId);
            }

            ICollection <GuestTDO>   guests = photoAnnotation.Guests;
            IEnumerable <PhotoEmail> list   = this._fsWebService.GetList <PhotoEmail>("PhotoEmails/" + (object)photo.PhotoId, true);

            foreach (GuestTDO guestTdo in (IEnumerable <GuestTDO>)guests)
            {
                GuestTDO   guest      = guestTdo;
                bool       flag       = true;
                PhotoEmail postObject = list.Where(ee => ee.PhotoId == photo.PhotoId && ee.GuestId == guest.GuestId).FirstOrDefault();
                if (postObject == null)
                {
                    postObject = new PhotoEmail {
                        EventId = ev.EventId,
                        PhotoId = photo.PhotoId,
                        GuestId = guest.GuestId
                    };
                    flag = false;
                }
                else if (postObject.Status == (byte)1)
                {
                    continue;
                }
                this._emailService.Error = "";
                this._emailService.SendEmailTo(user, ev, guest, photoUrl);
                if (string.IsNullOrEmpty(this._emailService.Error))
                {
                    postObject.Status = (byte)1;
                    postObject.Error  = null;
                }
                else
                {
                    postObject.Status = byte.MaxValue;
                    postObject.Error  = this._emailService.Error;
                }
                if (flag)
                {
                    this._fsWebService.UploadString("PhotoEmails?photoEmailId=" + (object)postObject.PhotoEmailId, this.GeneratePostContent <PhotoEmail>(postObject), "PUT");
                }
                else
                {
                    this._fsWebService.UploadString("PhotoEmails", this.GeneratePostContent <PhotoEmail>(postObject), null);
                }
            }
        }
Ejemplo n.º 4
0
        internal static IEnumerable <PhotoTDO> GetPhotos(Event ev)
        {
            if (string.IsNullOrEmpty(ev.EventFolder))
            {
                throw new ArgumentNullException("Folder name is empty.");
            }

            HashSet <PhotoTDO> photos = new HashSet <PhotoTDO>();

            // Get all photos that belong to the event
            string[]      filenames = PagingFileUtils.GetFileNames(ev.EventFolder, GetImageExts());
            string        folder    = ev.EventFolder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? ev.EventFolder : (ev.EventFolder + Path.DirectorySeparatorChar);
            DirectoryInfo dirInfo   = FotoShoutUtils.Utils.IO.DirectoryUtils.CreateSubFolder(folder, Constants.STR_THUMB);

            foreach (string filename in filenames)
            {
                bool     succeeded = (dirInfo != null) ? ImageUtils.CreateThumbnailFileIfAny(folder + filename, GetThumbnailPath(folder, filename)) : false;
                string   thumbnail = succeeded ? GetThumbnailVirtualPath(ev.EventVirtualPath, filename) : "";
                PhotoTDO photo     = GenerateTDO(ev, filename, thumbnail);
                photos.Add(photo);
            }

            return(photos.OrderBy(p => p.Filename));
        }
Ejemplo n.º 5
0
        internal static IEnumerable <PhotoTDO> GetProcessedPhotos(Event ev, string created, int page, int pageSize, FotoShoutDbContext db)
        {
            Func <Photo, Boolean> func;

            if (string.IsNullOrEmpty(created))
            {
                func = p => (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published);
            }
            else
            {
                created = DateTime.Parse(created).ToShortDateString();
                func    = p => (p.Created.ToShortDateString().Equals(created, StringComparison.InvariantCultureIgnoreCase) && (p.Status == (byte)PhotoStatus.Submitted || p.Status == (byte)PhotoStatus.PendingPublish || p.Status == (byte)PhotoStatus.Published));
            }
            IEnumerable <Photo> photos = ev.Photos.Where(func).OrderBy(p => p.Created);

            if (page > 0 && pageSize > 0 && (photos.Count() > pageSize))
            {
                photos = photos.Skip((page - 1) * pageSize).Take(pageSize);
            }

            HashSet <PhotoTDO> tdos = new HashSet <PhotoTDO>();

            if (!photos.Any())
            {
                return(tdos);
            }

            foreach (Photo photo in photos)
            {
                PhotoTDO tdo = EventPhotosService.GenerateTDO(ev, photo);
                tdo.Guests = PhotoAnnotationService.GetGuestTDOs(photo, true);
                tdos.Add(tdo);
            }

            return(tdos);
        }
Ejemplo n.º 6
0
        private void PublishPhotoToChannel(EventTDO ev, PhotoTDO photo, ChannelGroup channelGroup)
        {
            if (channelGroup.Fields == null || !channelGroup.Fields.Any())
            {
                FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("There is no broadcast fields in the {0} template.", channelGroup.Name));
                return;
            }

            PhotoAnnotation annotation = _fsWebService.Get <PhotoAnnotation>("PhotoAnnotation/" + photo.PhotoId, true);

            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Publishing the {0} photo to the {1} channel group...", photo.Filename, string.IsNullOrEmpty(channelGroup.Name) ? channelGroup.ID.ToString() : channelGroup.Name));

            string        filename = photo.Folder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? photo.Folder : (photo.Folder + Path.DirectorySeparatorChar) + Constants.STR_PROCESSED + Path.DirectorySeparatorChar + photo.Filename;
            PostBroadcast bc       = new PostBroadcast {
                TemplateID      = channelGroup.ID,
                Status          = "Pending Publish",
                Description     = "FotoShout Broadcast",
                Name            = Path.GetFileNameWithoutExtension(photo.Filename),
                ScheduledTime   = DateTime.Now.ToShortDateString(),
                BroadcastFields = new List <BroadcastFieldValue>()
            };

            foreach (BroadcastField bf in channelGroup.Fields)
            {
                if (bf.Name.Equals("Album Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = string.IsNullOrEmpty(ev.PublishAlbum) ? ev.EventName : ev.PublishAlbum
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Album Description", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = string.IsNullOrEmpty(ev.PublishAlbum) ? ev.EventName : ev.PublishAlbum
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Upload Photos", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Title", StringComparison.InvariantCultureIgnoreCase))
                {
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = bc.Name
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("Image File", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
                else if (bf.Name.Equals("File", StringComparison.InvariantCultureIgnoreCase))
                {
                    string serverUri = _c9WebService.UploadFile("Media/Upload", filename);
                    if (string.IsNullOrEmpty(serverUri))
                    {
                        throw new PublishingException(string.Format("Unexpected error: Can not upload the {0} photo.", photo.Filename));
                    }
                    BroadcastFieldValue bfv = new BroadcastFieldValue {
                        IdToken = bf.IdToken,
                        Value   = serverUri
                    };
                    bc.BroadcastFields.Add(bfv);
                }
            }

            string ret = _c9WebService.UploadString("Broadcast", GeneratePostContent <PostBroadcast>(bc));

            if (!string.IsNullOrEmpty(ret))
            {
                EventBroadcast eventBroadcast = new EventBroadcast {
                    BroadcastId = int.Parse(ret.Trim(new char[] { '\"' })),
                    EventId     = ev.EventId,
                    PhotoId     = photo.PhotoId,
                    Status      = 0
                };
                ret = _fsWebService.UploadString("EventBroadcasts", GeneratePostContent <EventBroadcast>(eventBroadcast));
            }
            else
            {
                throw new PublishingException(string.Format("Unsuccessully publishing the \"{0}\" photo using the \"{1}\" channel group.", photo.Filename, channelGroup.Name));
            }

            FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("Published the {0} photo.", photo.Filename));
        }
Ejemplo n.º 7
0
        //private async Task<string> PublishDelayAsync() {
        //    await Task.Delay(PublishDelay * 1000);
        //    return "Done";
        //}

        private void PublishPhoto(EventTDO ev, PhotoTDO photo, ChannelGroup channelGroup)
        {
            bool pending        = false;
            bool publishedPhoto = false;
            bool published      = false;

            try {
                this.Error = "";
                string filename = photo.Folder.EndsWith(Path.DirectorySeparatorChar.ToString()) ? photo.Folder : (photo.Folder + Path.DirectorySeparatorChar) + Constants.STR_PROCESSED + Path.DirectorySeparatorChar + photo.Filename;
                if (File.Exists(filename))
                {
                    HttpResponseMessage response = _fsWebService.Put("EventPhotos/PendingPublish/" + ev.EventId + "?filename=" + photo.Filename, null, true);
                    if (!response.IsSuccessStatusCode)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to mark the {0} as pending publish.\r\nStatus Code: {0} - {1}\r\n{2}", (int)response.StatusCode, response.ReasonPhrase));
                    }
                    pending = true;

                    PublishPhotoToChannel(ev, photo, channelGroup);

                    publishedPhoto = true;

                    response = _fsWebService.Put("EventPhotos/Published/" + ev.EventId + "?filename=" + photo.Filename, null, true);
                    if (!response.IsSuccessStatusCode)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("Failed to mark the {0} as published.\r\nStatus Code: {0} - {1}\r\n{2}", (int)response.StatusCode, response.ReasonPhrase));
                    }
                    published = true;
                }
                else
                {
                    FotoShoutUtils.Log.LogManager.Info(_logger, string.Format("{0} has not been uploaded. It will be published once uploaded.", filename));
                }
            }
            catch (HttpClientServiceException ex) {
                this.Error = string.Format("HTTP request failed\r\nStatus Code: {0} - {1}\r\n{2}", (int)ex.StatusCode, ex.Message, ex.ToString());
                FotoShoutUtils.Log.LogManager.Error(_logger, this.Error);
            }
            catch (Exception ex) {
                this.Error = ex.ToString();
                FotoShoutUtils.Log.LogManager.Error(_logger, this.Error);
            }
            finally {
                if (!published)
                {
                    if (publishedPhoto)
                    {
                        FotoShoutUtils.Log.LogManager.Error(_logger, string.Format("The {0} photo of the {1} event is published. However, it failed to mark the photo as published.", photo.Filename, ev.EventName));
                    }
                    else if (pending)
                    {
                        try {
                            _fsWebService.Put("EventPhotos/UnpendingPublish/" + ev.EventId + "?filename=" + photo.Filename + "&error=" + this.Error, null, true);
                        }
                        catch (Exception ex) {
                            FotoShoutUtils.Log.LogManager.Error(_logger, ex.ToString());
                        }
                    }
                }
            }
        }