private int RotateImage()
        {
            // Rotate any images on the hard drive according to the user's wish.
            int returnValue = int.MinValue;

            var imagesToRotate = RetrieveUserSelections();

            foreach (var kvp in imagesToRotate)
            {
                var mo = Factory.LoadMediaObjectInstance(kvp.Key, true);

                IGalleryObjectMetadataItem metaOrientation;
                if (kvp.Value == MediaObjectRotation.Rotate0 && !mo.MetadataItems.TryGetMetadataItem(MetadataItemName.Orientation, out metaOrientation))
                {
                    continue;
                }

                mo.Rotation = kvp.Value;

                try
                {
                    GalleryObjectController.SaveGalleryObject(mo);
                }
                catch (UnsupportedImageTypeException)
                {
                    returnValue = (int)MessageType.CannotRotateInvalidImage;
                }
            }

            HelperFunctions.PurgeCache();

            return(returnValue);
        }
Exemple #2
0
        private bool AddExternalHtmlContent()
        {
            string externalHtmlSource = txtExternalHtmlSource.Text.Trim();

            if (!this.ValidateExternalHtmlSource(externalHtmlSource))
            {
                return(false);
            }

            MimeTypeCategory mimeTypeCategory       = MimeTypeCategory.Other;
            string           mimeTypeCategoryString = ddlMediaTypes.SelectedValue;

            try
            {
                mimeTypeCategory = (MimeTypeCategory)Enum.Parse(typeof(MimeTypeCategory), mimeTypeCategoryString, true);
            }
            catch { }             // Suppress any parse errors so that category remains the default value 'Other'.

            string title = txtTitle.Text.Trim();

            if (String.IsNullOrEmpty(title))
            {
                // If user didn't enter a title, use the media category (e.g. Video, Audio, Image, Other).
                title = mimeTypeCategory.ToString();
            }

            IGalleryObject mediaObject = Factory.CreateExternalMediaObjectInstance(externalHtmlSource, mimeTypeCategory, this.GetAlbum());

            mediaObject.Title = Utils.CleanHtmlTags(title, GalleryId);
            GalleryObjectController.SaveGalleryObject(mediaObject);
            HelperFunctions.PurgeCache();

            return(true);
        }
Exemple #3
0
        /// <summary>
        /// Updates the root album title so that it no longer contains the message about creating an admin account.
        /// </summary>
        private void UpdateRootAlbumTitleAfterAdminCreation()
        {
            var album = Factory.LoadRootAlbumInstance(GalleryId, true, true);

            album.Caption = Resources.GalleryServerPro.Site_Welcome_Msg;
            GalleryObjectController.SaveGalleryObject(album);
        }
Exemple #4
0
        public IAlbum GetByPeople(string q, int sortByMetaNameId = int.MinValue, bool sortAscending = true, string destinationUrl = null, string filter = "all", int galleryId = int.MinValue)
        {
            IAlbum album = null;

            try
            {
                album = GalleryObjectController.GetGalleryObjectsHavingTags(null, Utils.ToArray(q), GalleryObjectTypeEnumHelper.Parse(filter, GalleryObjectType.All), ValidateGallery(galleryId));

                album.FeedFormatterOptions = new FeedFormatterOptions()
                {
                    SortByMetaName = (MetadataItemName)sortByMetaNameId,
                    SortAscending  = sortAscending,
                    DestinationUrl = String.IsNullOrWhiteSpace(destinationUrl) ? String.Concat(Utils.AppRoot, "/") : destinationUrl
                };

                return(album);
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex, (album != null ? album.GalleryId : new int?()));

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
        public IQueryable <Entity.GalleryItem> Sort(Entity.AlbumAction albumAction)
        {
            // POST /api/albums/getsortedalbum -
            try
            {
                return(GalleryObjectController.SortGalleryItems(albumAction));
            }
            catch (InvalidAlbumException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find album with ID = {0}", albumAction.Album.Id)),
                    ReasonPhrase = "Album Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Exemple #6
0
        public IAlbum GetByRating(string rating, int top = 50, int sortByMetaNameId = (int)MetadataItemName.DateAdded, bool sortAscending = false, string destinationUrl = null, string filter = "mediaobject", int galleryId = int.MinValue)
        {
            IAlbum album = null;

            try
            {
                album = GalleryObjectController.GetRatedMediaObjects(rating, top, ValidateGallery(galleryId), GalleryObjectTypeEnumHelper.Parse(filter, GalleryObjectType.MediaObject));

                album.FeedFormatterOptions = new FeedFormatterOptions()
                {
                    SortByMetaName = (MetadataItemName)sortByMetaNameId,
                    SortAscending  = sortAscending,
                    DestinationUrl = String.IsNullOrWhiteSpace(destinationUrl) ? String.Concat(Utils.AppRoot, "/") : destinationUrl
                };

                return(album);
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex, (album != null ? album.GalleryId : new int?()));

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Exemple #7
0
        public IQueryable <Entity.MetaItem> GetMetaItemsForMediaObjectId(int id)
        {
            // GET /api/mediaitems/12/meta - Gets metadata items for media object #12
            try
            {
                return(GalleryObjectController.GetMetaItemsForMediaObject(id).AsQueryable());
            }
            catch (InvalidMediaObjectException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find media object with ID = {0}", id)),
                    ReasonPhrase = "Media Object Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
        public IQueryable <Entity.GalleryItem> GetGalleryItemsForAlbumId(int id, int sortByMetaNameId = int.MinValue, bool sortAscending = true)
        {
            // GET /api/albums/12/galleryitems?sortByMetaNameId=11&sortAscending=true - Gets gallery items for album #12
            try
            {
                return(GalleryObjectController.GetGalleryItemsInAlbum(id, (MetadataItemName)sortByMetaNameId, sortAscending));
            }
            catch (InvalidAlbumException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find album with ID = {0}", id)),
                    ReasonPhrase = "Album Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets the media object with the specified <paramref name="id" />.
        /// Example: api/mediaitems/4/get
        /// </summary>
        /// <param name="id">The media object ID.</param>
        /// <returns>An instance of <see cref="Entity.MediaItem" />.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the media object is not found, the user
        /// doesn't have permission to view it, or some other error occurs.</exception>
        public Entity.MediaItem Get(int id)
        {
            try
            {
                IGalleryObject mediaObject = Factory.LoadMediaObjectInstance(id);
                SecurityManager.ThrowIfUserNotAuthorized(SecurityActions.ViewAlbumOrMediaObject, RoleController.GetGalleryServerRolesForUser(), mediaObject.Parent.Id, mediaObject.GalleryId, Utils.IsAuthenticated, mediaObject.Parent.IsPrivate, ((IAlbum)mediaObject.Parent).IsVirtualAlbum);
                var siblings         = mediaObject.Parent.GetChildGalleryObjects(GalleryObjectType.MediaObject, !Utils.IsAuthenticated).ToSortedList();
                int mediaObjectIndex = siblings.IndexOf(mediaObject);

                return(GalleryObjectController.ToMediaItem(mediaObject, mediaObjectIndex + 1, MediaObjectHtmlBuilder.GetMediaObjectHtmlBuilderOptions(mediaObject)));
            }
            catch (InvalidMediaObjectException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find media object with ID = {0}", id)),
                    ReasonPhrase = "Media Object Not Found"
                });
            }
            catch (GallerySecurityException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
Exemple #10
0
        private int btnOkClicked()
        {
            //User clicked 'Create album'. Create the new album and return the new album ID.
            var parentAlbum = Factory.LoadAlbumInstance(tvUC.SelectedAlbum.Id, true, true);

            this.CheckUserSecurity(SecurityActions.AddChildAlbum, parentAlbum);

            int newAlbumId;

            if (parentAlbum.Id > 0)
            {
                IAlbum newAlbum = Factory.CreateEmptyAlbumInstance(parentAlbum.GalleryId);
                newAlbum.Title = Utils.CleanHtmlTags(txtTitle.Text.Trim(), GalleryId);
                //newAlbum.ThumbnailMediaObjectId = 0; // not needed
                newAlbum.Parent    = parentAlbum;
                newAlbum.IsPrivate = parentAlbum.IsPrivate;
                GalleryObjectController.SaveGalleryObject(newAlbum);
                newAlbumId = newAlbum.Id;

                // Re-sort the items in the album. This will put the media object in the right position relative to its neighbors.
                ((IAlbum)newAlbum.Parent).Sort(true, Utils.UserName);

                HelperFunctions.PurgeCache();
            }
            else
            {
                throw new GalleryServerPro.Events.CustomExceptions.InvalidAlbumException(parentAlbum.Id);
            }

            return(newAlbumId);
        }
        private bool btnOkClicked()
        {
            //User clicked 'Delete images'.  Delete the hi-res images for the selected albums and images.
            string[] selectedItems = RetrieveUserSelections();

            if (selectedItems.Length == 0)
            {
                // No images were selected. Inform user and exit function.
                string msg = String.Format(CultureInfo.CurrentCulture, "<p class='gsp_msgwarning'><span class='gsp_bold'>{0} </span>{1}</p>", Resources.GalleryServerPro.Task_No_Objects_Selected_Hdr, Resources.GalleryServerPro.Task_No_Objects_Selected_Dtl);
                phMsg.Controls.Clear();
                phMsg.Controls.Add(new System.Web.UI.LiteralControl(msg));

                return(false);
            }

            try
            {
                HelperFunctions.BeginTransaction();

                // Convert the string array of IDs to integers. Also assign whether each is an album or media object.
                // (Determined by the first character of each id's string: a=album; m=media object)
                foreach (string selectedItem in selectedItems)
                {
                    int  id     = Convert.ToInt32(selectedItem.Substring(1), CultureInfo.InvariantCulture);
                    char idType = Convert.ToChar(selectedItem.Substring(0, 1), CultureInfo.InvariantCulture);                     // 'a' or 'm'

                    if (idType == 'm')
                    {
                        Image image;
                        try
                        {
                            image = (Image)Factory.LoadMediaObjectInstance(id, GalleryObjectType.Image, true);
                        }
                        catch (InvalidMediaObjectException)
                        {
                            continue;                             // Image may have been deleted by someone else, so just skip it.
                        }

                        image.DeleteHiResImage();

                        GalleryObjectController.SaveGalleryObject(image);
                    }

                    if (idType == 'a')
                    {
                        DeleteHiResImagesFromAlbum(Factory.LoadAlbumInstance(id, true, true));
                    }
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();

            return(true);
        }
Exemple #12
0
        public string UpdateMediaObjectTitle(int mediaObjectId, string title)
        {
            try
            {
                IGalleryObject mo = Factory.LoadMediaObjectInstance(mediaObjectId);
                if (GalleryPage.IsUserAuthorized(SecurityActions.EditMediaObject, mo.Parent.Id))
                {
                    string previousTitle = mo.Title;
                    mo.Title = Util.CleanHtmlTags(title);

                    if (mo.Title != previousTitle)
                    {
                        GalleryObjectController.SaveGalleryObject(mo);
                    }

                    HelperFunctions.PurgeCache();
                }

                return(mo.Title);
            }
            catch (Exception ex)
            {
                AppErrorController.LogError(ex);
                throw;
            }
        }
Exemple #13
0
        private int btnOkClicked()
        {
            //User clicked 'Create album'. Create the new album and return the new album ID.
            TreeViewNode selectedNode  = tvUC.SelectedNode;
            int          parentAlbumID = Int32.Parse(selectedNode.Value, CultureInfo.InvariantCulture);
            IAlbum       parentAlbum   = Factory.LoadAlbumInstance(parentAlbumID, false);

            this.CheckUserSecurity(SecurityActions.AddChildAlbum, parentAlbum);

            int newAlbumID;

            if (parentAlbumID > 0)
            {
                IAlbum newAlbum = Factory.CreateAlbumInstance();
                newAlbum.Title = GetAlbumTitle();
                //newAlbum.ThumbnailMediaObjectId = 0; // not needed
                newAlbum.Parent    = parentAlbum;
                newAlbum.IsPrivate = (parentAlbum.IsPrivate ? true : chkIsPrivate.Checked);
                GalleryObjectController.SaveGalleryObject(newAlbum);
                newAlbumID = newAlbum.Id;

                HelperFunctions.PurgeCache();
            }
            else
            {
                throw new GalleryServerPro.ErrorHandler.CustomExceptions.InvalidAlbumException(parentAlbumID);
            }

            return(newAlbumID);
        }
Exemple #14
0
        private int rotateImage()
        {
            // Rotate any images on the hard drive according to the user's wish.
            int returnValue = int.MinValue;

            Dictionary <int, RotateFlipType> imagesToRotate = retrieveUserSelections();

            foreach (KeyValuePair <int, RotateFlipType> kvp in imagesToRotate)
            {
                IGalleryObject image = Factory.LoadImageInstance(kvp.Key);
                image.Rotation = kvp.Value;
                try
                {
                    GalleryObjectController.SaveGalleryObject(image);
                }
                catch (UnsupportedImageTypeException)
                {
                    returnValue = (int)Message.CannotRotateInvalidImage;
                }
            }

            HelperFunctions.PurgeCache();

            return(returnValue);
        }
Exemple #15
0
        private Message saveCaptions()
        {
            // Iterate through all the textboxes, saving any captions that have changed.
            // The media object IDs are stored in a hidden input tag.
            HtmlTextArea    ta;
            HtmlInputHidden gc;
            IGalleryObject  mo;
            string          newTitle, previousTitle;
            Message         msg            = Message.None;
            int             maxTitleLength = GalleryServerPro.Configuration.ConfigManager.GetGalleryServerProConfigSection().DataStore.MediaObjectTitleLength;

            if (!IsUserAuthorized(SecurityActions.EditMediaObject))
            {
                return(msg);
            }

            try
            {
                HelperFunctions.BeginTransaction();

                // Loop through each item in the repeater control. If an item is checked, extract the ID.
                foreach (RepeaterItem rptrItem in rptr.Items)
                {
                    ta = (HtmlTextArea)rptrItem.Controls[1];                     // The <TEXTAREA> tag
                    gc = (HtmlInputHidden)rptrItem.Controls[3];                  // The hidden <input> tag

                    // Retrieve new title. Since the Value property of <TEXTAREA> HTML ENCODEs the text,
                    // and we want to store the actual text, we must decode to get back to the original.
                    newTitle = Util.HtmlDecode(ta.Value);

                    mo            = Factory.LoadMediaObjectInstance(Convert.ToInt32(gc.Value, CultureInfo.InvariantCulture));
                    previousTitle = mo.Title;

                    mo.Title = Util.CleanHtmlTags(newTitle);

                    if (mo.Title.Length > maxTitleLength)
                    {
                        // This caption exceeds the maximum allowed length. Set message ID so that user
                        // can be notified. This caption will be truncated when saved to the databse.
                        msg = Message.OneOrMoreCaptionsExceededMaxLength;
                    }

                    if (mo.Title != previousTitle)
                    {
                        GalleryObjectController.SaveGalleryObject(mo);
                    }
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();

            return(msg);
        }
 public AlbumsController(AlbumController albumController, GalleryObjectController galleryObjectController, UserController userController, ExceptionController exController, IAuthorizationService authorizationService)
 {
     _albumController         = albumController;
     _galleryObjectController = galleryObjectController;
     _userController          = userController;
     _exController            = exController;
     _authorizationService    = authorizationService;
 }
Exemple #17
0
        private void SaveCaptions()
        {
            // Iterate through all the textboxes, saving any captions that have changed.
            // The media object IDs are stored in a hidden input tag.
            HtmlTextArea    ta;
            HtmlInputHidden gc;
            IGalleryObject  mo;

            if (!IsUserAuthorized(SecurityActions.EditMediaObject))
            {
                return;
            }

            try
            {
                HelperFunctions.BeginTransaction();

                // Loop through each item in the repeater control. If an item is checked, extract the ID.
                foreach (RepeaterItem rptrItem in rptr.Items)
                {
                    ta = (HtmlTextArea)rptrItem.Controls[1];                      // The <TEXTAREA> tag
                    gc = (HtmlInputHidden)rptrItem.Controls[3];                   // The hidden <input> tag

                    // Retrieve new title. Since the Value property of <TEXTAREA> HTML ENCODEs the text,
                    // and we want to store the actual text, we must decode to get back to the original.
                    string newTitle = Utils.HtmlDecode(ta.Value);

                    try
                    {
                        mo = Factory.LoadMediaObjectInstance(Convert.ToInt32(gc.Value, CultureInfo.InvariantCulture), true);
                    }
                    catch (InvalidMediaObjectException)
                    {
                        continue;                         // Gallery object may have been deleted by someone else, so just skip it.
                    }

                    string previousTitle = mo.Title;

                    mo.Title = Utils.CleanHtmlTags(newTitle, GalleryId);

                    if (mo.Title != previousTitle)
                    {
                        GalleryObjectController.SaveGalleryObject(mo);
                    }
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();
        }
Exemple #18
0
 private void MoveAlbum(IAlbum albumToMove)
 {
     try
     {
         GalleryObjectController.MoveGalleryObject(albumToMove, this.DestinationAlbum);
     }
     catch (System.IO.IOException ex)
     {
         throw new GalleryServerPro.ErrorHandler.CustomExceptions.CannotMoveDirectoryException(String.Format(CultureInfo.CurrentCulture, "Error while trying to move album {0}.", albumToMove.Id), ex);
     }
 }
Exemple #19
0
        /// <summary>
        /// Updates the root album title so that it no longer contains the message about creating an admin account.
        /// </summary>
        private void UpdateRootAlbumTitleAfterAdminCreation()
        {
            var rootAlbum           = Factory.LoadRootAlbumInstance(GalleryId, true);
            var updateableRootAlbum = Factory.LoadAlbumInstance(new AlbumLoadOptions(rootAlbum.Id)
            {
                IsWritable = true
            });

            updateableRootAlbum.Caption = Resources.GalleryServer.Site_Welcome_Msg;
            GalleryObjectController.SaveGalleryObject(updateableRootAlbum);
        }
Exemple #20
0
        /// <summary>
        /// Adds a media file to an album. Prior to calling this method, the file should exist in the
        /// temporary upload directory (<see cref="GlobalConstants.TempUploadDirectory" />) in the
        /// App_Data directory with the name <see cref="AddMediaObjectSettings.FileNameOnServer" />. The
        /// file is copied to the destination album and given the name of
        /// <see cref="AddMediaObjectSettings.FileName" /> (instead of whatever name it currently has, which
        /// may contain a GUID).
        /// </summary>
        /// <param name="settings">The settings that contain data and configuration options for the media file.</param>
        /// <returns>List{ActionResult}.</returns>
        /// <exception cref="System.Web.Http.HttpResponseException">Thrown when the user does not have permission to add media
        /// objects or some other error occurs.</exception>
        public List <ActionResult> CreateFromFile(AddMediaObjectSettings settings)
        {
            try
            {
                settings.CurrentUserName = Utils.UserName;

                var fileExt = Path.GetExtension(settings.FileName);

                if (fileExt != null && fileExt.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    Task.Factory.StartNew(() =>
                    {
                        var results = GalleryObjectController.AddMediaObject(settings);

                        // Since we don't have access to the user's session here, let's create a log entry.
                        LogUploadZipFileResults(results, settings);
                    });

                    return(new List <ActionResult>
                    {
                        new ActionResult
                        {
                            Title = settings.FileName,
                            Status = ActionResultStatus.Async.ToString()
                        }
                    });
                }
                else
                {
                    var results = GalleryObjectController.AddMediaObject(settings);

                    Utils.AddResultToSession(results);

                    return(results);
                }
            }
            catch (GallerySecurityException)
            {
                AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "Unauthorized access detected. The security system prevented a user from adding a media object."), null, EventType.Warning);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
 public List <ActionResult> AddMediaObject(AddMediaObjectSettings settings)
 {
     try
     {
         return(GalleryObjectController.AddMediaObject(settings));
     }
     catch (Exception ex)
     {
         AppErrorController.LogError(ex);
         throw;
     }
 }
 public MediaItemsController(GalleryController galleryController, AlbumController albumController, GalleryObjectController galleryObjectController, FileStreamController streamController, HtmlController htmlController, UrlController urlController, UserController userController, ExceptionController exController, IAuthorizationService authorizationService)
 {
     _galleryController       = galleryController;
     _albumController         = albumController;
     _galleryObjectController = galleryObjectController;
     _streamController        = streamController;
     _htmlController          = htmlController;
     _urlController           = urlController;
     _userController          = userController;
     _exController            = exController;
     _authorizationService    = authorizationService;
 }
        private void btnOkClicked()
        {
            //User clicked 'Assign thumbnail'.  Assign the specified thumbnail to this album.
            int moid = getSelectedMediaObjectID();

            IAlbum album = this.GetAlbum();

            album.ThumbnailMediaObjectId = moid;
            GalleryObjectController.SaveGalleryObject(album);

            HelperFunctions.PurgeCache();
        }
        private int RotateImages()
        {
            // Rotate any images on the hard drive according to the user's wish.
            var returnValue = int.MinValue;

            var imagesToRotate = RetrieveUserSelections();

            try
            {
                HelperFunctions.BeginTransaction();
                foreach (var kvp in imagesToRotate)
                {
                    IGalleryObject mo;
                    try
                    {
                        mo = Factory.LoadMediaObjectInstance(kvp.Key, true);
                    }
                    catch (InvalidMediaObjectException)
                    {
                        continue;                         // Image may have been deleted by someone else, so just skip it.
                    }

                    IGalleryObjectMetadataItem metaOrientation;
                    if (kvp.Value == MediaObjectRotation.Rotate0 && !mo.MetadataItems.TryGetMetadataItem(MetadataItemName.Orientation, out metaOrientation))
                    {
                        continue;
                    }

                    mo.Rotation = kvp.Value;

                    try
                    {
                        GalleryObjectController.SaveGalleryObject(mo);
                    }
                    catch (UnsupportedImageTypeException)
                    {
                        returnValue = (int)MessageType.CannotRotateInvalidImage;
                    }
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();

            return(returnValue);
        }
Exemple #25
0
        private void btnOkClicked()
        {
            object formFieldGalleryObjectIds = Request.Form["goIds"];

            if ((formFieldGalleryObjectIds == null) || (String.IsNullOrEmpty(formFieldGalleryObjectIds.ToString())))
            {
                // The hidden field will be empty when no changes have been made. Just return.
                return;
            }

            string strGoIds = formFieldGalleryObjectIds.ToString();

            string[] goIds = strGoIds.Split(new char[] { ',' });

            // User wants to persist the reordering changes to the data store. As the user has been dragging and dropping objects
            // in their new locations, server-side code has been keeping the CurrentSequences property synchronized with the order
            // of the objects in the user's browser. Now we want to loop through those objects and update the Sequence property
            // of each one according to it's position within the list.
            IGalleryObjectCollection galleryObjects = this.GetAlbum().GetChildGalleryObjects(true);

            int newSequence = 0;

            try
            {
                HelperFunctions.BeginTransaction();
                foreach (string galleryObjectIdentifier in goIds)
                {
                    // Parse the string into its 2 parts: (a) The first character is either "a" (for album) or "m" (for media object);
                    // (b) The rest of the string is the ID for the album of media object. Ex: "a132" is an album with ID=132.
                    GalleryObjectType galleryObjectType = (galleryObjectIdentifier.Substring(0, 1) == "a" ? GalleryObjectType.Album : GalleryObjectType.MediaObject);
                    int galleryObjectId = Convert.ToInt32(galleryObjectIdentifier.Substring(1), CultureInfo.InvariantCulture);

                    IGalleryObject matchingGalleryObject = galleryObjects.FindById(galleryObjectId, galleryObjectType);

                    if ((matchingGalleryObject != null) && (matchingGalleryObject.Sequence != newSequence))
                    {
                        matchingGalleryObject.Sequence = newSequence;
                        GalleryObjectController.SaveGalleryObject(matchingGalleryObject);
                    }
                    newSequence++;
                }
                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();
        }
Exemple #26
0
        /// <summary>
        /// Persists the media item to the data store. The current implementation requires that
        /// an existing item exist in the data store.
        /// </summary>
        /// <param name="mediaItem">An instance of <see cref="Entity.MediaItem"/> to persist to the data
        /// store.</param>
        /// <exception cref="System.Web.Http.HttpResponseException"></exception>
        public ActionResult PutMediaItem(Entity.MediaItem mediaItem)
        {
            try
            {
                var mo = Factory.LoadMediaObjectInstance(mediaItem.Id, true);

                var isUserAuthorized = Utils.IsUserAuthorized(SecurityActions.EditMediaObject, mo.Parent.Id, mo.GalleryId, mo.IsPrivate, ((IAlbum)mo.Parent).IsVirtualAlbum);
                if (!isUserAuthorized)
                {
                    AppEventController.LogEvent(String.Format(CultureInfo.InvariantCulture, "Unauthorized access detected. The security system prevented a user from editing media object {0}.", mo.Id), mo.GalleryId, EventType.Warning);

                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.Forbidden));
                }

                mo.Title = mediaItem.Title;
                GalleryObjectController.SaveGalleryObject(mo);

                HelperFunctions.PurgeCache();

                return(new ActionResult
                {
                    Status = ActionResultStatus.Success.ToString(),
                    Title = String.Empty,
                    Message = String.Empty,
                    ActionTarget = mediaItem
                });
            }
            catch (InvalidMediaObjectException)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent(String.Format("Could not find media item with ID = {0}", mediaItem.Id)),
                    ReasonPhrase = "Media Object Not Found"
                });
            }
            catch (HttpResponseException)
            {
                throw;                 // Rethrow, since we've already logged it above
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
        private static void DeleteHiResImagesFromAlbum(IAlbum album)
        {
            // Delete the hi-res image for each image in the album. Then recursively do the same thing to all child albums.
            foreach (GalleryServerPro.Business.Image image in album.GetChildGalleryObjects(GalleryObjectType.Image))
            {
                image.DeleteHiResImage();

                GalleryObjectController.SaveGalleryObject(image);
            }

            foreach (IAlbum childAlbum in album.GetChildGalleryObjects(GalleryObjectType.Album))
            {
                DeleteHiResImagesFromAlbum(childAlbum);
            }
        }
Exemple #28
0
        private void UpdateSortOnExistingAlbumsAsync()
        {
            var rootAlbumId = Factory.LoadRootAlbumInstance(GalleryId).Id;
            var rootAlbum   = Factory.LoadAlbumInstance(new AlbumLoadOptions(rootAlbumId)
            {
                IsWritable = true
            });

            rootAlbum.SortByMetaName = GallerySettingsUpdateable.DefaultAlbumSortMetaName;
            rootAlbum.SortAscending  = GallerySettingsUpdateable.DefaultAlbumSortAscending;

            GalleryObjectController.SaveGalleryObject(rootAlbum);

            rootAlbum.SortAsync(true, Utils.UserName, true, true);
        }
        private static void DeleteOriginalFilesFromAlbum(IAlbum album)
        {
            // Delete the original file for each item in the album. Then recursively do the same thing to all child albums.
            foreach (IGalleryObject mediaObject in album.GetChildGalleryObjects(GalleryObjectType.MediaObject))
            {
                mediaObject.DeleteOriginalFile();

                GalleryObjectController.SaveGalleryObject(mediaObject);
            }

            foreach (IAlbum childAlbum in album.GetChildGalleryObjects(GalleryObjectType.Album))
            {
                DeleteOriginalFilesFromAlbum(childAlbum);
            }
        }
        public ActionResult RotateFlip(GalleryItem[] galleryItems, MediaAssetRotateFlip rotateFlip, DisplayObjectType viewSize)
        {
            try
            {
                return(GalleryObjectController.RotateFlip(galleryItems, rotateFlip, viewSize));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }