Esempio n. 1
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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
        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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
Esempio n. 10
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();
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 14
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();
        }
Esempio n. 15
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 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);
            }
        }
Esempio n. 17
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);
        }
Esempio n. 18
0
        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);
            }
        }
Esempio n. 19
0
        private int RotateImages()
        {
            // Rotate any images on the hard drive according to the user's wish.
            int returnValue = int.MinValue;

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

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

                    image.Rotation = kvp.Value;

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

            HelperFunctions.PurgeCache();

            return(returnValue);
        }
Esempio n. 20
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating at lesss than full trust. In this case,
        /// the ASP.NET FileUpload control is used. The logic is nearly identical to that in AddUploadedFilesForFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        private void AddUploadedFilesLessThanFullTrust()
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                for (int i = 0; i < 5; i++)
                {
                    FileUpload file = (FileUpload)phUpload.FindControl("fuUpload" + i);

                    if (!file.HasFile)
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        // Extract the files from the zipped file.
                        using (ZipUtility zip = new ZipUtility(Util.UserName, GetGalleryServerRolesForUser()))
                        {
                            this._skippedFiles.AddRange(zip.ExtractZipFile(file.FileContent, this.GetAlbum(), chkDiscardOriginalImage.Checked));
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

                        file.SaveAs(filepath);

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());

                            // Sueetie Modified - Fix Blank Title on individual uploads
                            if (go.Title.Trim().Length == 0)
                            {
                                go.Title = go.Original.FileName;
                            }

                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }

                            // Sueetie Modified - Add mediaobject to Sueetie_Content - Single File

                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID      = go.Id,
                                ContentTypeID = MediaHelper.ConvertContentType(go.MimeType.TypeCategory),
                                ApplicationID = (int)SueetieApplications.Current.ApplicationID,
                                UserID        = CurrentSueetieUserID,
                                IsRestricted  = this.GetAlbum().IsPrivate,
                                Permalink     = MediaHelper.SueetieMediaObjectUrl(go.Id, this.GalleryId)
                            };
                            SueetieCommon.AddSueetieContent(sueetieContent);

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject

                            SueetieMediaObject _sueetieMediaObject = new SueetieMediaObject();
                            _sueetieMediaObject.MediaObjectID    = go.Id;
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(go.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);

                            SueetieMediaAlbum sueetieAlbum = SueetieMedia.GetSueetieMediaAlbum(this.GetAlbum().Id);
                            if (CurrentSueetieGallery.IsLogged)
                            {
                                SueetieLogs.LogUserEntry((UserLogCategoryType)sueetieAlbum.AlbumMediaCategoryID, sueetieAlbum.ContentID, CurrentSueetieUserID);
                            }
                            SueetieMedia.ClearMediaPhotoListCache(0);
                            SueetieMedia.ClearSueetieMediaObjectListCache(this.CurrentSueetieGalleryID);
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Esempio n. 21
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.
            HtmlInputText   ta;
            HtmlTextArea    tdesc;
            HtmlInputHidden gc;
            IGalleryObject  mo;
            string          newTitle, previousTitle, previousTags, previousDescription;
            Message         msg = Message.None;

            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    = (HtmlInputText)rptrItem.Controls[1];   // The <input TEXT> tag
                    tdesc = (HtmlTextArea)rptrItem.Controls[3];    // The <TEXTAREA> tag
                    gc    = (HtmlInputHidden)rptrItem.Controls[5]; // 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), true);
                    previousTitle = mo.Title;

                    mo.Title = Util.RemoveHtmlTags(newTitle);

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

                    SueetieMediaObject _sueetieMediaObject = SueetieMedia.GetSueetieMediaObject(CurrentSueetieGalleryID, mo.Id);
                    previousDescription = _sueetieMediaObject.MediaObjectDescription;
                    _sueetieMediaObject.MediaObjectDescription = tdesc.Value;

                    if (_sueetieMediaObject.MediaObjectTitle != newTitle || _sueetieMediaObject.MediaObjectDescription != previousDescription)
                    {
                        SueetieMedia.UpdateSueetieMediaObject(_sueetieMediaObject);
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }

            HelperFunctions.PurgeCache();
            SueetieMedia.ClearSueetieMediaObjectListCache(CurrentSueetieGalleryID);
            return(msg);
        }
Esempio n. 22
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating under full trust. In this case,
        /// the ComponentArt Upload control is used. The logic is nearly identical to that in AddUploadedFilesLessThanFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        /// <param name="files">The files to add to the gallery.</param>
        private void AddUploadedFilesForFullTrust(UploadedFileInfoCollection files)
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                UploadedFileInfo[] fileInfos = new UploadedFileInfo[files.Count];
                files.CopyTo(fileInfos, 0);
                Array.Reverse(fileInfos);

                foreach (UploadedFileInfo file in fileInfos)
                {
                    if (String.IsNullOrEmpty(file.FileName))
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                using (ZipUtility zip = new ZipUtility(Util.UserName, RoleController.GetGalleryServerRolesForUser()))
                                {
                                    this._skippedFiles.AddRange(zip.ExtractZipFile(file.GetStream(), this.GetAlbum(), chkDiscardOriginalImage.Checked));
                                }
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

#if DEBUG
                        TechInfoSystems.TracingTools.Tools.MarkSpot(string.Format(CultureInfo.CurrentCulture, "Attempting to move file {0} to {1}...", file.FileName, filepath));
#endif
                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                file.SaveAs(filepath);
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Delete the uploaded temporary files, as by this time they have been saved to the destination directory.
                foreach (UploadedFileInfo file in files)
                {
                    try
                    {
                        System.IO.File.Delete(file.TempFileName);
                    }
                    catch (UnauthorizedAccessException) { }                     // Ignore an error; the file will end up getting deleted during cleanup maintenance
                }

                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Esempio n. 23
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating at lesss than full trust. In this case,
        /// the ASP.NET FileUpload control is used. The logic is nearly identical to that in AddUploadedFilesForFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        private void AddUploadedFilesLessThanFullTrust()
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                for (int i = 0; i < 5; i++)
                {
                    FileUpload file = (FileUpload)phUpload.FindControl("fuUpload" + i);

                    if (!file.HasFile)
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        // Extract the files from the zipped file.
                        using (ZipUtility zip = new ZipUtility(Util.UserName, RoleController.GetGalleryServerRolesForUser()))
                        {
                            this._skippedFiles.AddRange(zip.ExtractZipFile(file.FileContent, this.GetAlbum(), chkDiscardOriginalImage.Checked));
                        }

                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

#if DEBUG
                        TechInfoSystems.TracingTools.Tools.MarkSpot(string.Format(CultureInfo.CurrentCulture, "Attempting to move file {0} to {1}...", file.FileName, filepath));
#endif
                        file.SaveAs(filepath);

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }
Esempio n. 24
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.CreateEmptyAlbumInstance(parentAlbum.GalleryId);
                newAlbum.Title = GetAlbumTitle();
                //newAlbum.ThumbnailMediaObjectId = 0; // not needed
                newAlbum.Parent    = parentAlbum;
                newAlbum.IsPrivate = (parentAlbum.IsPrivate ? true : chkIsPrivate.Checked);
                GalleryObjectController.SaveGalleryObject(newAlbum);
                newAlbumID = newAlbum.Id;


                // Sueetie Modified - Save New Album to Sueetie_Content, Sueetie_gs_Album and log it in User Activity Log

                string grpString = string.Empty;
                if (SueetieApplications.Current.IsGroup)
                {
                    grpString = "/" + SueetieApplications.Current.GroupKey;
                }
                string albumUrl = grpString + "/" + SueetieApplications.Current.ApplicationKey + "/" + CurrentSueetieGallery.GalleryKey + ".aspx?aid=" + newAlbumID.ToString();

                SueetieContent sueetieContent = new SueetieContent
                {
                    SourceID      = newAlbumID,
                    ContentTypeID = int.Parse(ddSueetieAlbumType.SelectedValue),
                    ApplicationID = (int)SueetieApplications.Current.ApplicationID,
                    UserID        = CurrentSueetieUserID,
                    IsRestricted  = newAlbum.IsPrivate,
                    Permalink     = albumUrl,
                };
                int contentID = SueetieCommon.AddSueetieContent(sueetieContent);

                var albumLogCategory = SueetieMedia.GetAlbumContentTypeDescriptionList().Single(contentDescription => contentDescription.ContentTypeID.Equals(sueetieContent.ContentTypeID));

                UserLogEntry entry = new UserLogEntry
                {
                    UserLogCategoryID = albumLogCategory.UserLogCategoryID,
                    ItemID            = contentID,
                    UserID            = CurrentSueetieUserID,
                };
                if (CurrentSueetieGallery.IsLogged)
                {
                    SueetieLogs.LogUserEntry(entry);
                }

                string albumPath = SueetieMedia.CreateSueetieAlbumPath(newAlbum.FullPhysicalPath);
                SueetieMedia.CreateSueetieAlbum(newAlbumID, albumPath, sueetieContent.ContentTypeID);
                SueetieMedia.ClearSueetieMediaAlbumListCache(CurrentSueetieGalleryID);
                SueetieMedia.ClearSueetieMediaGalleryListCache();

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

            return(newAlbumID);
        }
Esempio n. 25
0
        /// <summary>
        /// Adds the uploaded files to the gallery. This method is called when the application is operating under full trust. In this case,
        /// the ComponentArt Upload control is used. The logic is nearly identical to that in AddUploadedFilesLessThanFullTrust - the only
        /// differences are syntax differences arising from the different file upload control.
        /// </summary>
        /// <param name="files">The files to add to the gallery.</param>
        private void AddUploadedFilesForFullTrust(UploadedFileInfoCollection files)
        {
            // Clear the list of hash keys so we're starting with a fresh load from the data store.
            try
            {
                MediaObjectHashKeys.Clear();

                string albumPhysicalPath = this.GetAlbum().FullPhysicalPathOnDisk;

                HelperFunctions.BeginTransaction();

                UploadedFileInfo[] fileInfos = new UploadedFileInfo[files.Count];
                files.CopyTo(fileInfos, 0);
                Array.Reverse(fileInfos);

                foreach (UploadedFileInfo file in fileInfos)
                {
                    if (String.IsNullOrEmpty(file.FileName))
                    {
                        continue;
                    }

                    if ((System.IO.Path.GetExtension(file.FileName).Equals(".zip", StringComparison.OrdinalIgnoreCase)) && (!chkDoNotExtractZipFile.Checked))
                    {
                        #region Extract the files from the zipped file.

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                using (ZipUtility zip = new ZipUtility(Util.UserName, GetGalleryServerRolesForUser()))
                                {
                                    this._skippedFiles.AddRange(zip.ExtractZipFile(file.GetStream(), this.GetAlbum(), chkDiscardOriginalImage.Checked));
                                }
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        // Sueetie Modified - Add contents of ZIP file - All

                        List <SueetieMediaObject> sueetieMediaObjects = SueetieMedia.GetSueetieMediaUpdateList(this.GetAlbumId());
                        int i = 0;
                        foreach (SueetieMediaObject _sueetieMediaObject in sueetieMediaObjects)
                        {
                            int            _moid          = _sueetieMediaObject.MediaObjectID;
                            IGalleryObject mo             = Factory.LoadMediaObjectInstance(_moid);
                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID        = _sueetieMediaObject.MediaObjectID,
                                ContentTypeID   = MediaHelper.ConvertContentType(mo.MimeType.TypeCategory),
                                ApplicationID   = (int)SueetieApplications.Current.ApplicationID,
                                UserID          = _sueetieMediaObject.SueetieUserID,
                                DateTimeCreated = mo.DateAdded,
                                IsRestricted    = mo.IsPrivate,
                                Permalink       = MediaHelper.SueetieMediaObjectUrl(_moid, this.GalleryId)
                            };

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(mo.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);
                            SueetieCommon.AddSueetieContent(sueetieContent);
                            i++;
                        }


                        #endregion
                    }
                    else
                    {
                        #region Add the file

                        string filename = HelperFunctions.ValidateFileName(albumPhysicalPath, file.FileName);
                        string filepath = Path.Combine(albumPhysicalPath, filename);

                        lock (file)
                        {
                            if (File.Exists(file.TempFileName))
                            {
                                file.SaveAs(filepath);
                            }
                            else
                            {
                                // When one of the files causes an OutOfMemoryException, this can cause the other files to disappear from the
                                // temp upload directory. This seems to be an issue with the ComponentArt Upload control, since this does not
                                // seem to happen with the ASP.NET FileUpload control. If the file doesn't exist, make a note of it and move on
                                // to the next one.
                                this._skippedFiles.Add(new KeyValuePair <string, string>(file.FileName, Resources.GalleryServerPro.Task_Add_Objects_Uploaded_File_Does_Not_Exist_Msg));
                                continue;                                 // Skip to the next file.
                            }
                        }

                        try
                        {
                            IGalleryObject go = Factory.CreateMediaObjectInstance(filepath, this.GetAlbum());
                            GalleryObjectController.SaveGalleryObject(go);

                            if ((chkDiscardOriginalImage.Checked) && (go is Business.Image))
                            {
                                ((Business.Image)go).DeleteHiResImage();
                                GalleryObjectController.SaveGalleryObject(go);
                            }


                            // Sueetie Modified - Add mediaobject to Sueetie_Content - Single File

                            SueetieContent sueetieContent = new SueetieContent
                            {
                                SourceID      = go.Id,
                                ContentTypeID = MediaHelper.ConvertContentType(go.MimeType.TypeCategory),
                                ApplicationID = (int)SueetieApplications.Current.ApplicationID,
                                UserID        = CurrentSueetieUserID,
                                IsRestricted  = this.GetAlbum().IsPrivate,
                                Permalink     = MediaHelper.SueetieMediaObjectUrl(go.Id, this.GalleryId)
                            };
                            SueetieCommon.AddSueetieContent(sueetieContent);

                            // Add Sueetie-specific data to Sueetie_gs_MediaObject

                            SueetieMediaObject _sueetieMediaObject = new SueetieMediaObject();
                            _sueetieMediaObject.MediaObjectID    = go.Id;
                            _sueetieMediaObject.ContentTypeID    = MediaHelper.ConvertContentType(go.MimeType.TypeCategory);
                            _sueetieMediaObject.AlbumID          = this.GetAlbum().Id;
                            _sueetieMediaObject.InDownloadReport = false;
                            SueetieMedia.CreateSueetieMediaObject(_sueetieMediaObject);

                            SueetieMediaAlbum sueetieAlbum = SueetieMedia.GetSueetieMediaAlbum(this.GetAlbum().Id);
                            if (CurrentSueetieGallery.IsLogged)
                            {
                                SueetieLogs.LogUserEntry((UserLogCategoryType)sueetieAlbum.AlbumMediaCategoryID, sueetieAlbum.ContentID, CurrentSueetieUserID);
                            }
                        }
                        catch (UnsupportedMediaObjectTypeException ex)
                        {
                            try
                            {
                                File.Delete(filepath);
                            }
                            catch (UnauthorizedAccessException) { }                             // Ignore an error; the file will end up getting deleted during cleanup maintenance

                            this._skippedFiles.Add(new KeyValuePair <string, string>(filename, ex.Message));
                        }

                        #endregion
                    }
                }

                SueetieMedia.ClearMediaPhotoListCache(0);
                SueetieMedia.ClearSueetieMediaObjectListCache(this.CurrentSueetieGalleryID);

                HelperFunctions.CommitTransaction();
            }
            catch
            {
                HelperFunctions.RollbackTransaction();
                throw;
            }
            finally
            {
                // Delete the uploaded temporary files, as by this time they have been saved to the destination directory.
                foreach (UploadedFileInfo file in files)
                {
                    try
                    {
                        System.IO.File.Delete(file.TempFileName);
                    }
                    catch (UnauthorizedAccessException) { }                     // Ignore an error; the file will end up getting deleted during cleanup maintenance
                }

                // Clear the list of hash keys to free up memory.
                MediaObjectHashKeys.Clear();

                HelperFunctions.PurgeCache();
            }
        }